Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added gitlab testing infrastructure to the test #3

Merged
merged 4 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
job:
tags:
- quartz
- shell
script:
- module load cmake/3.9.2
- cmake -DWITH_KVTREE_PREFIX=$HOME/kvtree/KVTree.git/install -DWITH_SPATH_PREFIX=$HOME/spath/install -DWITH_AXL_PREFIX=$HOME/axl/AXL.git/install -DMPI=ON
- make VERBOSE=1
- make check
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ INCLUDE(GNUInstallDirs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_SUBDIRECTORY(src)

# INCLUDE(CTest)
# ADD_SUBDIRECTORY(test)
INCLUDE(CTest)
ADD_SUBDIRECTORY(test)

# Generate config.h with all our build #defs
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/cmake/config.h.in ${PROJECT_BINARY_DIR}/config.h)
Expand Down
25 changes: 25 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###############
# Build tests
###############

################
# Add tests to ctest
################

ADD_EXECUTABLE(filo_test test_filo.c)
TARGET_LINK_LIBRARIES(filo_test ${SPATH_EXTERNAL_LIBS} filo)
ADD_TEST(NAME filo_test COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ./filo_test)

ADD_EXECUTABLE(filo_corrupt_fetch_test test_filo_corrupt_fetch.c)
TARGET_LINK_LIBRARIES(filo_corrupt_fetch_test ${SPATH_EXTERNAL_LIBS} filo)
ADD_TEST(NAME filo_corrupt_fetch_test COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ./filo_corrupt_fetch_test)

ADD_EXECUTABLE(filo_async_test test_filo_async.c)
TARGET_LINK_LIBRARIES(filo_async_test ${SPATH_EXTERNAL_LIBS} filo)
ADD_TEST(NAME filo_async_test COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ./filo_async_test)

####################
# make a verbose "test" target named "check"
####################

ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
51 changes: 41 additions & 10 deletions test/test_filo.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,90 @@
#include "mpi.h"
#include "filo.h"

#define TEST_PASS (0)
#define TEST_FAIL (1)

int main(int argc, char* argv[])
{
int rc = TEST_PASS;
MPI_Init(&argc, &argv);

int rank, ranks;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &ranks);

char buf[256];
sprintf(buf, "data from rank %d\n", rank);

char proc_specific_file_content[256];
sprintf(proc_specific_file_content, "data from rank %d\n", rank);
char filename[256];
sprintf(filename, "/dev/shm/testfile_%d.out", rank);
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
if (fd != -1) {
write(fd, buf, strlen(buf));
write(fd, proc_specific_file_content, strlen(proc_specific_file_content));
close(fd);
} else {
rc = TEST_FAIL;
printf("Error opening file %s: %d %s\n", filename, errno, strerror(errno));
}

char dest_filename[256];
sprintf(dest_filename, "./testfile_%d.out", rank);

Filo_Init();
rc = Filo_Init();
CamStan marked this conversation as resolved.
Show resolved Hide resolved

const char* filelist[1] = { filename };
const char* dest_filelist[1] = { dest_filename };

Filo_Flush("mapfile", NULL, 1, filelist, dest_filelist, MPI_COMM_WORLD);
/* base path for storage is NULL, so destination files will be written to the local dir*/
rc = Filo_Flush("mapfile", NULL, 1, filelist, dest_filelist, MPI_COMM_WORLD);
//printf("pre-fetch src file name is %s\n", filelist[0]);
//printf("pre-fetch dst_file name is %s\n", dest_filelist[0]);
////in file name, rank precedes ".out" suffix
//int rank_from_file_name = *((strstr(dest_filelist[0], ".out"))-1) - '0';
//printf("char at .out is %d\n",rank_from_file_name);

unlink(filename);

/* fetch list of files recorded in mapfile to /dev/shm */
int num_files;
char** src_filelist;
char** dst_filelist;
Filo_Fetch("mapfile", NULL, "/dev/shm", &num_files, &src_filelist, &dst_filelist, MPI_COMM_WORLD);
/* src base path is still NULL (consistent with Filo_Flush), but the dest base path is /dev/shm*/
rc = Filo_Fetch("mapfile", NULL, "/dev/shm", &num_files, &src_filelist, &dst_filelist, MPI_COMM_WORLD);

/* free file list returned by fetch */
int i;
for (i = 0; i < num_files; i++) {
//in file name, rank precedes ".out" suffix
int rank_from_file_name = *((strstr(dst_filelist[i], ".out"))-1) - '0';
//assertain that the filename with consistant process marker was passed through flush/fetch
if(rank != rank_from_file_name){
rc = TEST_FAIL;
printf("rank = %d, rank_from_file_name = %d\n", rank, rank_from_file_name);
}
//assertain that the file content is consistent with the process
FILE *file = fopen(filename, "r");
CamStan marked this conversation as resolved.
Show resolved Hide resolved
char *readContent = NULL;
size_t readContent_size = 0;
if (!file){
rc = TEST_FAIL;
printf("Error opening file %s: %d %s\n", filename, errno, strerror(errno));
}
size_t line_size = getline(&readContent, &readContent_size, file);
if (strcmp(readContent, proc_specific_file_content) != 0){
rc = TEST_FAIL;
printf("flushed file content = %s, fetched file content = %s\n", proc_specific_file_content, readContent);
}

free(src_filelist[i]);
free(dst_filelist[i]);
}
free(src_filelist);
free(dst_filelist);

Filo_Finalize();
rc = Filo_Finalize();

unlink(filename);

MPI_Finalize();

return 0;
return rc;
}
98 changes: 98 additions & 0 deletions test/test_filo_async.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include <limits.h>
#include <unistd.h>

#include "mpi.h"
#include "filo.h"

#define TEST_PASS (0)
#define TEST_FAIL (1)

int main(int argc, char* argv[])
{
int rc = TEST_PASS;
MPI_Init(&argc, &argv);
int rank, ranks;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &ranks);

char proc_specific_file_content[256];
sprintf(proc_specific_file_content, "data from rank %d\n", rank);
char filename[256];
sprintf(filename, "/dev/shm/testfile_%d.out", rank);
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
if (fd != -1) {
write(fd, proc_specific_file_content, strlen(proc_specific_file_content));
close(fd);
} else {
rc = TEST_FAIL;
printf("Error opening file %s: %d %s\n", filename, errno, strerror(errno));
}

char dest_filename[256];
sprintf(dest_filename, "./testfile_%d.out", rank);

rc = Filo_Init();

const char* filelist[1] = { filename };
const char* dest_filelist[1] = { dest_filename };

/* base path for storage is NULL, so destination files will be written to the local dir*/
rc = Filo_Flush_start("mapfile", NULL, 1, filelist, dest_filelist, MPI_COMM_WORLD);
rc = Filo_Flush_test("mapfile", MPI_COMM_WORLD);
rc = Filo_Flush_wait("mapfile", MPI_COMM_WORLD);

unlink(filename);

/* fetch list of files recorded in mapfile to /dev/shm */
int num_files;
char** src_filelist;
char** dst_filelist;
/* src base path is still NULL (consistent with Filo_Flush), but the dest base path is /dev/shm*/
rc = Filo_Fetch("mapfile", NULL, "/dev/shm", &num_files, &src_filelist, &dst_filelist, MPI_COMM_WORLD);

/* free file list returned by fetch */
int i;
for (i = 0; i < num_files; i++) {
//in file name, rank precedes ".out" suffix
int rank_from_file_name = *((strstr(dst_filelist[i], ".out"))-1) - '0';
//assertain that the filename with consistant process marker was passed through flush/fetch
if(rank != rank_from_file_name){
rc = TEST_FAIL;
printf("rank = %d, rank_from_file_name = %d\n", rank, rank_from_file_name);
}
//assertain that the file content is consistent with the process
FILE *file = fopen(filename, "r");
CamStan marked this conversation as resolved.
Show resolved Hide resolved
char *readContent = NULL;
size_t readContent_size = 0;
if (!file){
rc = TEST_FAIL;
printf("Error opening file %s: %d %s\n", filename, errno, strerror(errno));
}
size_t line_size = getline(&readContent, &readContent_size, file);
if (strcmp(readContent, proc_specific_file_content) != 0){
rc = TEST_FAIL;
printf("flushed file content = %s, fetched file content = %s\n", proc_specific_file_content, readContent);
}

free(src_filelist[i]);
free(dst_filelist[i]);
}
free(src_filelist);
free(dst_filelist);

rc = Filo_Finalize();

unlink(filename);

MPI_Finalize();

return rc;
}
72 changes: 72 additions & 0 deletions test/test_filo_corrupt_fetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include <limits.h>
#include <unistd.h>

#include "mpi.h"
#include "filo.h"

#define TEST_PASS (0)
#define TEST_FAIL (1)

int main(int argc, char* argv[])
{
int rc = TEST_PASS;
MPI_Init(&argc, &argv);
int rank, ranks;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &ranks);

char proc_specific_file_content[256];
sprintf(proc_specific_file_content, "data from rank %d\n", rank);
char filename[256];
sprintf(filename, "/dev/shm/testfile_%d.out", rank);
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
if (fd != -1) {
write(fd, proc_specific_file_content, strlen(proc_specific_file_content));
close(fd);
} else {
rc = TEST_FAIL;
printf("Error opening file %s: %d %s\n", filename, errno, strerror(errno));
}

char dest_filename[256];
sprintf(dest_filename, "./testfile_%d.out", rank);

rc = Filo_Init();

const char* filelist[1] = { filename };
const char* dest_filelist[1] = { dest_filename };

/* base path for storage is NULL, so destination files will be written to the local dir*/
rc = Filo_Flush("mapfile", NULL, 1, filelist, dest_filelist, MPI_COMM_WORLD);
printf("pre-fetch src file name is %s\n", filelist[0]);
printf("pre-fetch dst_file name is %s\n", dest_filelist[0]);

//remove one of the flush destination files. This should result in Filo_Fetch returning error on ALL processes.
if(rank == 1) unlink(dest_filename);

unlink(filename);

/* fetch list of files recorded in mapfile to /dev/shm */
int num_files;
char** src_filelist;
char** dst_filelist;
/* src base path is still NULL (consistent with Filo_Flush), but the dest base path is /dev/shm*/
int filo_ret = Filo_Fetch("mapfile", NULL, "/dev/shm", &num_files, &src_filelist, &dst_filelist, MPI_COMM_WORLD);
//check if the return value is error -- which is the correct behavior -- otherwise return fail
if(filo_ret ==0){
printf("Error: Filo_Fetch should fail because rank 1 destination file was removed pre- fetch. rank = %d, filo_ret = %d\n", rank, filo_ret);
rc = TEST_FAIL;
}

MPI_Finalize();

return rc;
}