From: alex Date: Sun, 12 Sep 2021 23:25:05 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=13267ff81ee2fcb89957ea6bba17a31d94dd59fb;p=seeder ... --- diff --git a/inc/shutdown.h b/inc/shutdown.h index 9b39dcc..1ab723e 100644 --- a/inc/shutdown.h +++ b/inc/shutdown.h @@ -7,7 +7,8 @@ #include -extern pthread_mutex_t shutdown_mutex; +#define SHUTDOWN_MESSAGE_FAILED "graceful shutdown failed\n" +#define SHUTDOWN_MESSAGE_SUCCESS "shutdown successful\n" int shutdown_register(); void shutdown(); diff --git a/src/shutdown.c b/src/shutdown.c index 3a0f50a..c3ee5d1 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -1,5 +1,7 @@ #include +static void shutdown_logging(); + int shutdown_register() { if(0!=atexit(&shutdown)) { perror("atexit"); @@ -10,5 +12,20 @@ int shutdown_register() { } void shutdown() { - pthread_cancel(logging_thread); + shutdown_logging(); +} + +static void shutdown_logging() { + int ret_cancel, ret_join; + void *res; + + ret_cancel = pthread_cancel(logging_thread); + ret_join = pthread_join(logging_thread,&res); + + logging_thread = pthread_self(); + if((ret_cancel!=0)||(ret_join!=0)||(res!=PTHREAD_CANCELED)) { + log_err(SHUTDOWN_MESSAGE_FAILED); + } else { + log_msg(SHUTDOWN_MESSAGE_SUCCESS); + } } diff --git a/src/util/filter.c b/src/util/filter.c index 5d0589c..2b36b00 100644 --- a/src/util/filter.c +++ b/src/util/filter.c @@ -11,7 +11,6 @@ int file_filter_ignore_dotfiles(const char *path) { p = path; while((p = strchr(p, '/'))!=NULL) { p++; - log_info("p: %s\n",p); if(p[0]=='.') { return -1; } } diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 8c53df3..a362d57 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -4,8 +4,7 @@ AM_CPPFLAGS = \ -Werror EXTRA_DIST = \ - test_utils.h \ - util.filter.tests.h + test_utils.h if ENABLE_DEBUG else @@ -13,7 +12,7 @@ AM_CPPFLAGS += \ -DNDEBUG endif -check_PROGRAMS = util.filter.tests +check_PROGRAMS = hashmap.tests util.filter.tests TESTS = $(check_PROGRAMS) if ENABLE_MEMCHECK @@ -23,22 +22,12 @@ endif common_SOURCES = test_utils.c -common_SOURCES += $(top_srcdir)/src/default.c -common_SOURCES += $(top_srcdir)/src/file.c -common_SOURCES += $(top_srcdir)/src/hashmap.c -common_SOURCES += $(top_srcdir)/src/log.c -common_SOURCES += $(top_srcdir)/src/session.c -common_SOURCES += $(top_srcdir)/src/setup.c -common_SOURCES += $(top_srcdir)/src/torrent.c -common_SOURCES += $(top_srcdir)/src/tree.c -common_SOURCES += $(top_srcdir)/src/opt/loglevel.c +hashmap_tests_SOURCES = \ + $(common_SOURCES) \ + hashmap.tests.c \ + $(top_srcdir)/src/hashmap.c util_filter_tests_SOURCES = \ $(common_SOURCES) \ util.filter.tests.c \ - $(top_srcdir)/src/opt/filter.c \ - $(top_srcdir)/src/opt/piecel.c \ - $(top_srcdir)/src/opt/watch.c \ - $(top_srcdir)/src/opt/worker.c \ - $(top_srcdir)/src/util/dir.c \ - $(top_srcdir)/src/util/file.c + $(top_srcdir)/src/util/filter.c diff --git a/test/unit/hashmap.tests.c b/test/unit/hashmap.tests.c new file mode 100644 index 0000000..3699336 --- /dev/null +++ b/test/unit/hashmap.tests.c @@ -0,0 +1,20 @@ +#include + +#include + +int main(); +static void hashmap_init_basic_tests(); + +int main() { + setup_env(); + + hashmap_init_basic_tests(); + + clean_env(); + + return EXIT_SUCCESS; +} + +static void hashmap_init_basic_tests() { + assert(0); +} diff --git a/test/unit/test_utils.c b/test/unit/test_utils.c index 4390381..0b0520c 100644 --- a/test/unit/test_utils.c +++ b/test/unit/test_utils.c @@ -1,5 +1,8 @@ #include +static void create_test_directory(const char*); +static void create_test_file(const char*,const char*); + void clean_env() { system("rm -rf " PREFIX); } @@ -12,16 +15,16 @@ void reset_env() { void setup_env() { clean_env(); - assert(setup_session()==1); - assert(defaults()==1); - assert(setup_logging()==1); + create_test_directory(TEST_DIRECTORY); + create_test_file(TEST_FILE_1,TEST_FILE_1_CONTENTS); + create_test_file(TEST_FILE_2,TEST_FILE_2_CONTENTS); } -void create_test_directory(const char *directory) { +static void create_test_directory(const char *directory) { assert(mkdir(directory,0700)==0); } -void create_test_file(const char *filename, const char *contents) { +static void create_test_file(const char *filename, const char *contents) { FILE *fp; printf("creating %s\n",filename); diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h index 3d49ff8..9fc057d 100644 --- a/test/unit/test_utils.h +++ b/test/unit/test_utils.h @@ -5,10 +5,19 @@ #include #include +#include + +#define TEST_DIRECTORY PREFIX +#define TEST_FILE_1 PREFIX "/test" +#define TEST_FILE_1_CONTENTS "asldfkjaslkdfjalskdjf" +#define TEST_FILE_2 PREFIX "/test2" +#define TEST_FILE_2_CONTENTS "lsakjflkadkjfasjkldfhasdjf" +#define TEST_FILE_3 PREFIX "/.test" +#define TEST_FILE_3_CONTENTS "sdlifjasdiofjasoidfjaois" +#define TEST_FILE_4 PREFIX "/.test.meta" +#define TEST_FILE_4_CONTENTS ";alsikdjf;lkasdjflk\n;asjdflk\n;ajsdklfjl;aksdfjla;kj" void clean_env(); -void create_test_directory(const char*); -void create_test_file(const char*,const char*); void reset_env(); void setup_env(); diff --git a/test/unit/util.filter.tests.c b/test/unit/util.filter.tests.c index bd11dcf..737c4ca 100644 --- a/test/unit/util.filter.tests.c +++ b/test/unit/util.filter.tests.c @@ -1,16 +1,30 @@ -#include +#include + +#include + +int main(); +static void file_filter_all_basic_tests(); +static void file_filter_ignore_dotfiles_basic_tests(); int main() { setup_env(); file_filter_all_basic_tests(); + file_filter_ignore_dotfiles_basic_tests(); clean_env(); - return EXIT_FAILURE; + return EXIT_SUCCESS; } void file_filter_all_basic_tests() { - log_info("%s\n",PREFIX); - assert(1); + assert(1==file_filter_all(TEST_FILE_1)); + assert(1==file_filter_all(TEST_FILE_2)); +} + +void file_filter_ignore_dotfiles_basic_tests() { + assert(1==file_filter_ignore_dotfiles(TEST_FILE_1)); + assert(1==file_filter_ignore_dotfiles(TEST_FILE_2)); + assert(-1==file_filter_ignore_dotfiles(TEST_FILE_3)); + assert(-1==file_filter_ignore_dotfiles(TEST_FILE_4)); } diff --git a/test/unit/util.filter.tests.h b/test/unit/util.filter.tests.h deleted file mode 100644 index ce4993e..0000000 --- a/test/unit/util.filter.tests.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __UTIL_FILTER_TESTS_H_ -#define __UTIL_FILTER_TESTS_H_ - -#include - -int main(); -void file_filter_all_basic_tests(); - -#endif