From: alex Date: Fri, 10 Sep 2021 00:22:29 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=e4d23ca0e25043d8ec9fd00f2a26a97578f6154d;p=seeder ... --- diff --git a/Makefile.am b/Makefile.am index 5150b9e..f165ee1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,3 +49,5 @@ seederd_SOURCES += \ inc/tree.h \ inc/usage.h \ inc/util.h + +SUBDIRS = . test/unit diff --git a/configure.ac b/configure.ac index a8c66d4..ef805bc 100644 --- a/configure.ac +++ b/configure.ac @@ -73,5 +73,6 @@ AC_TYPE_SIZE_T AC_FUNC_MALLOC AC_CHECK_FUNCS([atexit]) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile + test/unit/Makefile]) AC_OUTPUT diff --git a/inc/setup.h b/inc/setup.h index a255aaf..950da59 100644 --- a/inc/setup.h +++ b/inc/setup.h @@ -4,7 +4,7 @@ #include #include -int setup(); +int setup_logging(); int setup_session(); #endif diff --git a/src/main.c b/src/main.c index 743f173..f7d7ff3 100644 --- a/src/main.c +++ b/src/main.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) { } } - if(setup()<0) { return EXIT_FAILURE; } + if(setup_logging()<0) { return EXIT_FAILURE; } if(add()<0) { return EXIT_FAILURE; } diff --git a/src/setup.c b/src/setup.c index 53ce50b..983a26d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -1,18 +1,9 @@ #include -static int setup_logging(); - -int setup() { - // logging must be setup first - if(setup_logging()<0) { return -1; } - - return 1; -} - pthread_t logging_thread; pthread_mutex_t logging_mutex = PTHREAD_MUTEX_INITIALIZER; -static int setup_logging() { +int setup_logging() { if(0!=atexit(&log_entries_clean)) { perror("atexit"); return -1; diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am new file mode 100644 index 0000000..69dc37d --- /dev/null +++ b/test/unit/Makefile.am @@ -0,0 +1,31 @@ +AM_CPPFLAGS = \ + -DPREFIX=\"/tmp/seeder\" \ + -Wall \ + -Werror + +EXTRA_DIST = \ + test_utils.h \ + util.filter.tests.h + +if ENABLE_DEBUG +else +AM_CPPFLAGS += \ + -DNDEBUG +endif + +check_PROGRAMS = util.filter.tests +TESTS = $(check_PROGRAMS) + +if ENABLE_MEMCHECK +LOG_COMPILER = $(VALGRIND) +AM_LOG_FLAGS = --leak-check=full -v --track-origins=yes --error-exitcode=1 +endif + +common_SOURCES = test_utils.c + +common_SOURCES += $(top_srcdir)/src/default.c +common_SOURCES += $(top_srcdir)/src/log.c + +util_filter_tests_SOURCES = \ + $(common_SOURCES) \ + util.filter.tests.c diff --git a/test/unit/test_utils.c b/test/unit/test_utils.c new file mode 100644 index 0000000..1f21932 --- /dev/null +++ b/test/unit/test_utils.c @@ -0,0 +1,16 @@ +#include + +void clean() { + system("rm -rf " PREFIX); +} + +void reset_env() { + clean(); + setup_env(); +} + +void setup_env() { + assert(setup_session()==1); + assert(defaults()==1); + assert(setup_logging()==1); +} diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h new file mode 100644 index 0000000..762acff --- /dev/null +++ b/test/unit/test_utils.h @@ -0,0 +1,13 @@ +#ifndef __TEST_UTILS_H_ +#define __TEST_UTILS_H_ + +#include + +#include +#include + +void clean(); +void reset_env(); +void setup_env(); + +#endif diff --git a/test/unit/util.filter.tests.c b/test/unit/util.filter.tests.c new file mode 100644 index 0000000..e06fa6b --- /dev/null +++ b/test/unit/util.filter.tests.c @@ -0,0 +1,9 @@ +#include + +int main() { + setup_env(); + + clean(); + + return EXIT_FAILURE; +} diff --git a/test/unit/util.filter.tests.h b/test/unit/util.filter.tests.h new file mode 100644 index 0000000..d6bf96d --- /dev/null +++ b/test/unit/util.filter.tests.h @@ -0,0 +1,8 @@ +#ifndef __UTIL_FILTER_TESTS_H_ +#define __UTIL_FILTER_TESTS_H_ + +#include + +int main(); + +#endif