...
authoralex <[email protected]>
Tue, 26 Apr 2022 23:54:06 +0000 (16:54 -0700)
committeralex <[email protected]>
Tue, 26 Apr 2022 23:54:06 +0000 (16:54 -0700)
Makefile.am
test/integration/Makefile.am
test/integration/basic.test
test/integration/basic.test.c [deleted file]
test/integration/basic.tests.c [new file with mode: 0644]
test/integration/test_macros.h
test/integration/test_utils.c
test/integration/test_utils.h
test/unit/Makefile.am

index 9a1fc3c2b0094aac4dd3cffb848bc78e02ae03e2..978cc666a301c41c3b9942d37bcbae03d5fcbbfa 100644 (file)
@@ -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
index b610eef99165c2f11b9bb88358df634db1a3a01e..a9f941dc172a4696fd185b9269ed677bb0eef0ce 100644 (file)
@@ -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)
index dce91021db2448de50be8c932cc3b6ce1e7f933e..508464c74b4818262b196d9e76d1901f48d33414 100755 (executable)
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 (file)
index b6a16a3..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include<test_utils.h>
-
-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 (file)
index 0000000..0bf86c1
--- /dev/null
@@ -0,0 +1,28 @@
+#include<test_utils.h>
+
+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();
+}
index e229fe5a3b00ca7a72eb064dcc729f4430c5ec26..42062574165ff064cc1f695aa8ba6f6d88f21f81 100644 (file)
@@ -1,4 +1,7 @@
 #ifndef __TEST_MACROS_H_
 #define __TEST_MACROS_H_
 
+#define TEST_DIRECTORY PREFIX
+#define TEST_DIRECTORY_1 TEST_DIRECTORY "/test"
+
 #endif
index 331953b8eef5ef7c3a6a247b8f5e5e624b0d6607..ed3cda2655f786704787d7643f09d9c4a5a173e7 100644 (file)
@@ -1,16 +1,56 @@
 #include<test_utils.h>
 
+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);
 }
index 4e9eb0d0590457e745d2dfe6b7e06da939e61ab7..0640a7c07eba81043e4acdfc23b86519cd5a08e4 100644 (file)
@@ -4,12 +4,19 @@
 #include<test_macros.h>
 
 #include<assert.h>
+#include<signal.h>
 #include<stdlib.h>
 #include<string.h>
+#include<sys/stat.h>
+#include<sys/types.h>
+#include<sys/wait.h>
 #include<time.h>
+#include<unistd.h>
 
 void clean_env();
 void reset_env();
+pid_t run(char*const[]);
+void run_and_exit_successfully(char*const[]);
 void setup_env();
 
 #endif
index 050f8eaf204b4bbc5ea4b8588c8be56d213e5c76..e31546e2b74498b3f35010a59929f72130ce07eb 100644 (file)
@@ -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)