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
+TEST_DIRECTORY = .test
+
AM_CPPFLAGS = \
- -DPREFIX=\".test\" \
+ -DPREFIX=\"$(TEST_DIRECTORY)\" \
+ -DSEEDERD=\"$(top_srcdir)/seederd\" \
-Wall \
-Werror
-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)
+++ /dev/null
-#include<test_utils.h>
-
-int main();
-
-int main() {
- return EXIT_SUCCESS;
-}
--- /dev/null
+#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();
+}
#ifndef __TEST_MACROS_H_
#define __TEST_MACROS_H_
+#define TEST_DIRECTORY PREFIX
+#define TEST_DIRECTORY_1 TEST_DIRECTORY "/test"
+
#endif
#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);
}
#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
+TEST_DIRECTORY = .test
+
AM_CPPFLAGS = \
- -DPREFIX=\".test\" \
+ -DPREFIX=\"$(TEST_DIRECTORY)\" \
-Wall \
-Werror
watch_tests_CPPFLAGS = $(AM_CPPFLAGS) \
-DWATCH_SRC_FILE="$(top_srcdir)/src/watch.c"
+
+clean-local:
+ -rm -rf $(TEST_DIRECTORY)