X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftestbed%2Ftest_testbed_logger_api.c;h=bbc9e33d23e2b5c58c27e17a0ba6bdbdc2a6f295;hb=a900b29ddaa9ea46c731b054b5e3ef3e725b95a8;hp=f2fef7e41f578d6411b6412acf91d819493a8203;hpb=0793e4b7af79a49bf1bc275be95f306136ac8cbb;p=oweals%2Fgnunet.git diff --git a/src/testbed/test_testbed_logger_api.c b/src/testbed/test_testbed_logger_api.c index f2fef7e41..bbc9e33d2 100644 --- a/src/testbed/test_testbed_logger_api.c +++ b/src/testbed/test_testbed_logger_api.c @@ -44,7 +44,11 @@ /** * Opaque handle for the logging service */ -struct GNUNET_TESTBED_LOGGER_Handle *h; +static struct GNUNET_TESTBED_LOGGER_Handle *h; + +static struct GNUNET_TESTING_Peer *peer; + +static char *search_dir; /** * Abort task identifier @@ -85,6 +89,7 @@ shutdown_now () { CANCEL_TASK (abort_task); CANCEL_TASK (write_task); + GNUNET_free_non_null (search_dir); GNUNET_SCHEDULER_shutdown (); } @@ -100,6 +105,52 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) #define BSIZE 1024 + +/** + * Function called to iterate over a directory. + * + * @param cls closure + * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to + * get called on the next entry (or finish cleanly); + * NULL on error (will be the last call in that case) + * @param filename complete filename (absolute path) + * @param dirname directory name (absolute path) + */ +static void +iterator_cb (void *cls, struct GNUNET_DISK_DirectoryIterator *di, + const char *filename, const char *dirname) +{ + const char *fn; + size_t len; + uint64_t fs; + int cancel; + + cancel = GNUNET_NO; + if (NULL == filename) + goto iteration_cont; + len = strlen (filename); + if (len < 5) /* log file: `pid'.dat */ + goto iteration_cont; + fn = filename + len; + if (0 != strcasecmp (".dat", fn - 4)) + goto iteration_cont; + if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, + GNUNET_NO, GNUNET_YES)) + goto iteration_cont; + if ((BSIZE * 2) != fs) /* The file size should be equal to what we + have written */ + goto iteration_cont; + + cancel = GNUNET_YES; + result = GNUNET_OK; + + iteration_cont: + if ( (NULL != di) && + (GNUNET_YES == GNUNET_DISK_directory_iterator_next (di, cancel)) ) + return; + shutdown_now (); +} + /** * Functions of this type are called to notify a successful transmission of the * message to the logger service @@ -112,8 +163,10 @@ flush_comp (void *cls, size_t size) { FAIL_TEST (&write_task == cls, return); FAIL_TEST ((BSIZE * 2) == size, return); - result = GNUNET_OK; - shutdown_now (); + FAIL_TEST (GNUNET_OK == GNUNET_TESTING_peer_stop (peer), return); + FAIL_TEST (GNUNET_YES == GNUNET_DISK_directory_iterator_start + (GNUNET_SCHEDULER_PRIORITY_DEFAULT, search_dir, + &iterator_cb, NULL), return); } @@ -130,7 +183,8 @@ do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TESTBED_LOGGER_write (h, buf, BSIZE); if (0 == i++) return; - GNUNET_TESTBED_LOGGER_flush (h, &flush_comp, &write_task); + GNUNET_TESTBED_LOGGER_flush (h, GNUNET_TIME_UNIT_FOREVER_REL, + &flush_comp, &write_task); } @@ -144,9 +198,13 @@ do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void test_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) + struct GNUNET_TESTING_Peer *p) { FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), return); + FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string + (cfg, "testbed-logger", "dir", &search_dir), return); + search_dir = GNUNET_CONFIGURATION_expand_dollar (cfg, search_dir); + peer = p; write_task = GNUNET_SCHEDULER_add_now (&do_write, NULL); abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10), &do_abort, NULL);