From: alex Date: Tue, 26 Apr 2022 23:54:06 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=09312fefb321562f73b24e3b9c23d12de9172dd0;p=seeder ... --- diff --git a/Makefile.am b/Makefile.am index 9a1fc3c..978cc66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,8 +124,9 @@ seederd_SOURCES += \ SUBDIRS = . test/unit test/integration bench -# test target/shortcuts +# recipes for integration/unit testing +# NOTE: integration requires all target +integration: all + $(MAKE) -C test/integration check unit: $(MAKE) -C test/unit check -integration: - $(MAKE) -C test/integration check diff --git a/test/integration/Makefile.am b/test/integration/Makefile.am index b610eef..a9f941d 100644 --- a/test/integration/Makefile.am +++ b/test/integration/Makefile.am @@ -1,5 +1,8 @@ +TEST_DIRECTORY = .test + AM_CPPFLAGS = \ - -DPREFIX=\".test\" \ + -DPREFIX=\"$(TEST_DIRECTORY)\" \ + -DSEEDERD=\"$(top_srcdir)/seederd\" \ -Wall \ -Werror @@ -13,18 +16,20 @@ AM_CPPFLAGS += \ -DNDEBUG endif -check_PROGRAMS = basic.test +check_PROGRAMS = basic.tests TESTS = $(check_PROGRAMS) if ENABLE_MEMCHECK LOG_COMPILER = $(VALGRIND) -AM_LOG_FLAGS = --leak-check=full -v --track-origins=yes --error-exitcode=1 +AM_LOG_FLAGS = --leak-check=full -v --trace-children=yes --track-origins=yes --error-exitcode=1 endif common_SOURCES = \ - $(seederd_SOURCES) \ test_utils.c -basic_test_SOURCES = \ +basic_tests_SOURCES = \ $(common_SOURCES) \ - basic.test.c + basic.tests.c + +clean-local: + -rm -rf $(TEST_DIRECTORY) diff --git a/test/integration/basic.test b/test/integration/basic.test index dce9102..508464c 100755 Binary files a/test/integration/basic.test and b/test/integration/basic.test differ diff --git a/test/integration/basic.test.c b/test/integration/basic.test.c deleted file mode 100644 index b6a16a3..0000000 --- a/test/integration/basic.test.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(); - -int main() { - return EXIT_SUCCESS; -} diff --git a/test/integration/basic.tests.c b/test/integration/basic.tests.c new file mode 100644 index 0000000..0bf86c1 --- /dev/null +++ b/test/integration/basic.tests.c @@ -0,0 +1,28 @@ +#include + +int main(); +void basic_test(); + +int main() { + setup_env(); + + basic_test(); + + reset_env(); + + return EXIT_SUCCESS; +} + +void basic_test() { + char *opts[] = { + SEEDERD, + "--watch-directory", + TEST_DIRECTORY_1, + "--log-file=" TEST_DIRECTORY "/basic.test.seederd.log", + NULL + }; + + run_and_exit_successfully(opts); + + reset_env(); +} diff --git a/test/integration/test_macros.h b/test/integration/test_macros.h index e229fe5..4206257 100644 --- a/test/integration/test_macros.h +++ b/test/integration/test_macros.h @@ -1,4 +1,7 @@ #ifndef __TEST_MACROS_H_ #define __TEST_MACROS_H_ +#define TEST_DIRECTORY PREFIX +#define TEST_DIRECTORY_1 TEST_DIRECTORY "/test" + #endif diff --git a/test/integration/test_utils.c b/test/integration/test_utils.c index 331953b..ed3cda2 100644 --- a/test/integration/test_utils.c +++ b/test/integration/test_utils.c @@ -1,16 +1,56 @@ #include +static void create_test_directory(const char*); + void clean_env() { system("rm -rf " PREFIX); } +static void create_test_directory(const char *directory) { + assert(mkdir(directory,0700)==0); +} + void reset_env() { clean_env(); setup_env(); } +pid_t run(char *const opts[]) { + pid_t pid = fork(); + + assert(pid!=-1); + if(pid==0) { /* child */ + execve(SEEDERD,opts,NULL); + assert(0); + } + + return pid; +} + +void run_and_exit_successfully(char *const opts[]) { + int status; + + pid_t child_pid = run(opts); + + // wait 5 seconds for startup + sleep(5); + + // verify still running + assert(0==waitpid(child_pid,&status,WNOHANG)); + + // SIGINT to shutdown + assert(0==kill(child_pid,SIGINT)); + + // verify child process exited successfully + assert(child_pid==waitpid(child_pid,&status,0)); + assert(WIFEXITED(status)); +} + void setup_env() { clean_env(); srand(time(NULL)); + + create_test_directory(TEST_DIRECTORY); + create_test_directory(TEST_DIRECTORY_1); } diff --git a/test/integration/test_utils.h b/test/integration/test_utils.h index 4e9eb0d..0640a7c 100644 --- a/test/integration/test_utils.h +++ b/test/integration/test_utils.h @@ -4,12 +4,19 @@ #include #include +#include #include #include +#include +#include +#include #include +#include void clean_env(); void reset_env(); +pid_t run(char*const[]); +void run_and_exit_successfully(char*const[]); void setup_env(); #endif diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 050f8ea..e31546e 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -1,5 +1,7 @@ +TEST_DIRECTORY = .test + AM_CPPFLAGS = \ - -DPREFIX=\".test\" \ + -DPREFIX=\"$(TEST_DIRECTORY)\" \ -Wall \ -Werror @@ -219,3 +221,6 @@ watch_tests_SOURCES = \ watch_tests_CPPFLAGS = $(AM_CPPFLAGS) \ -DWATCH_SRC_FILE="$(top_srcdir)/src/watch.c" + +clean-local: + -rm -rf $(TEST_DIRECTORY)