From eb49bd8bd671fa3c8997cbea5f139132c1db843c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 21 Oct 2016 14:26:15 +0000 Subject: [PATCH] improve test shutdown and indentation --- src/curl/curl.c | 1 - src/statistics/statistics_api.c | 8 ++-- src/statistics/test_statistics_api.c | 47 ++++++++++++++++++----- src/statistics/test_statistics_api_loop.c | 16 +++++--- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/curl/curl.c b/src/curl/curl.c index d21b88d8f..6087cbddb 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -407,7 +407,6 @@ download_get_result (struct DownloadBuffer *db, } return NULL; } - json = NULL; if (0 == db->eno) { diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index e8aa9cf9c..bfa2da3b4 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -1015,7 +1015,7 @@ schedule_action (void *cls) return; } if (0 < GNUNET_MQ_get_length (h->mq)) - return; /* Wait for queue to be reduced more */ + return; /* Wait for queue to be reduced more */ /* schedule next action */ while (NULL == h->current) { @@ -1253,8 +1253,10 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, } for (ai = h->action_head; NULL != ai; ai = ai->next) { - if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) && - (0 == strcmp (ai->name, name)) && + if (! ( (0 == strcmp (ai->subsystem, + h->subsystem)) && + (0 == strcmp (ai->name, + name)) && ( (ACTION_UPDATE == ai->type) || (ACTION_SET == ai->type) ) ) ) continue; diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 0c7bb3488..41f1ef562 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2009, 2012 GNUnet e.V. + Copyright (C) 2009, 2012, 2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -29,6 +29,21 @@ static struct GNUNET_STATISTICS_Handle *h; +static struct GNUNET_STATISTICS_GetHandle *g; + + +static void +do_shutdown () +{ + if (NULL != g) + { + GNUNET_STATISTICS_get_cancel (g); + g = NULL; + } + GNUNET_STATISTICS_destroy (h, GNUNET_NO); + h = NULL; +} + static int check_1 (void *cls, @@ -96,7 +111,8 @@ next_fin (void *cls, { int *ok = cls; - GNUNET_STATISTICS_destroy (h, GNUNET_NO); + g = NULL; + GNUNET_SCHEDULER_shutdown (); GNUNET_assert (success == GNUNET_OK); *ok = 0; } @@ -105,6 +121,7 @@ next_fin (void *cls, static void next (void *cls, int success) { + g = NULL; GNUNET_assert (success == GNUNET_OK); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); @@ -122,15 +139,23 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); + if (NULL == h) + { + GNUNET_break (0); + return; + } + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + NULL); GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Issuing GET request\n"); GNUNET_break (NULL != - GNUNET_STATISTICS_get (h, NULL, "test-1", - &next, - &check_1, cls)); + (g = GNUNET_STATISTICS_get (h, NULL, "test-1", + &next, + &check_1, cls))); } @@ -142,11 +167,13 @@ run_more (void *cls, { h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + NULL); GNUNET_break (NULL != - GNUNET_STATISTICS_get (h, NULL, - "test-3", - &next_fin, - &check_3, cls)); + (g = GNUNET_STATISTICS_get (h, NULL, + "test-3", + &next_fin, + &check_3, cls))); } diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index a7e2cbab5..a1664cde5 100644 --- a/src/statistics/test_statistics_api_loop.c +++ b/src/statistics/test_statistics_api_loop.c @@ -31,7 +31,10 @@ static struct GNUNET_STATISTICS_Handle *h; static int -check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, +check_1 (void *cls, + const char *subsystem, + const char *name, + uint64_t value, int is_persistent) { GNUNET_assert (0 == strcmp (name, "test-0")); @@ -42,7 +45,8 @@ check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, static void -next (void *cls, int success) +next (void *cls, + int success) { int *ok = cls; @@ -53,7 +57,9 @@ next (void *cls, int success) static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { unsigned int i; @@ -62,9 +68,9 @@ run (void *cls, char *const *args, const char *cfgfile, h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg); for (i = 0; i < ROUNDS; i++) { - GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256); + GNUNET_snprintf (name, sizeof (name), "test-%d", i % 32); GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); - GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128); + GNUNET_snprintf (name, sizeof (name), "test-%d", i % 16); GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); } i = 0; -- 2.25.1