]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sun, 12 Sep 2021 23:25:05 +0000 (16:25 -0700)
committeralex <[email protected]>
Sun, 12 Sep 2021 23:25:05 +0000 (16:25 -0700)
inc/shutdown.h
src/shutdown.c
src/util/filter.c
test/unit/Makefile.am
test/unit/hashmap.tests.c [new file with mode: 0644]
test/unit/test_utils.c
test/unit/test_utils.h
test/unit/util.filter.tests.c
test/unit/util.filter.tests.h [deleted file]

index 9b39dccef1e5e6243cc472695ec5ef5f622c0508..1ab723eafa15770bc405f554c9cebb2a47729d6c 100644 (file)
@@ -7,7 +7,8 @@
 
 #include<log.h>
 
-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();
index 3a0f50ab14a1c07d9e66df95a58e5beed9f4d31b..c3ee5d1017af1afd2f79122eae884cefb16b5721 100644 (file)
@@ -1,5 +1,7 @@
 #include<shutdown.h>
 
+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);
+       }
 }
index 5d0589cbe19f551eba8b5aca7d2488bb6e0686b4..2b36b00f52ce6db6502348639098ea22c743aefe 100644 (file)
@@ -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; }
        }
        
index 8c53df34adf79285797fb3a6623aa65941697c3f..a362d57e23ab20651af146d71d75ef6c79ad7994 100644 (file)
@@ -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 (file)
index 0000000..3699336
--- /dev/null
@@ -0,0 +1,20 @@
+#include<test_utils.h>
+
+#include<hashmap.h>
+
+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);
+}
index 4390381b4702d93ece3d56eb21728cad7357b3a6..0b0520c2584ea07eb6f77911b333d88ee689c250 100644 (file)
@@ -1,5 +1,8 @@
 #include<test_utils.h>
 
+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);
index 3d49ff88d457028d3e8481a2489da34a547dcb5d..9fc057d644d34a64dbf9c9f358b86218610a2994 100644 (file)
@@ -5,10 +5,19 @@
 
 #include<default.h>
 #include<setup.h>
+#include<shutdown.h>
+
+#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();
 
index bd11dcf14bdc9e7705f96fb5cb4a1b75f812272e..737c4ca3cc000418187c4c517bcc9ab86072bc79 100644 (file)
@@ -1,16 +1,30 @@
-#include<util.filter.tests.h>
+#include<test_utils.h>
+
+#include<util.h>
+
+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 (file)
index ce4993e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef __UTIL_FILTER_TESTS_H_
-#define __UTIL_FILTER_TESTS_H_
-
-#include<test_utils.h>
-
-int main();
-void file_filter_all_basic_tests();
-
-#endif