diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-21 14:26:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-21 14:26:15 +0000 |
commit | eb49bd8bd671fa3c8997cbea5f139132c1db843c (patch) | |
tree | f9306a52194acf6d1df1928782bb67c2b64fd176 /src/statistics | |
parent | ea2e2343ed8fdb1544f94c31a98061fdea989975 (diff) | |
download | gnunet-eb49bd8bd671fa3c8997cbea5f139132c1db843c.tar.gz gnunet-eb49bd8bd671fa3c8997cbea5f139132c1db843c.zip |
improve test shutdown and indentation
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/statistics_api.c | 8 | ||||
-rw-r--r-- | src/statistics/test_statistics_api.c | 47 | ||||
-rw-r--r-- | src/statistics/test_statistics_api_loop.c | 16 |
3 files changed, 53 insertions, 18 deletions
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) | |||
1015 | return; | 1015 | return; |
1016 | } | 1016 | } |
1017 | if (0 < GNUNET_MQ_get_length (h->mq)) | 1017 | if (0 < GNUNET_MQ_get_length (h->mq)) |
1018 | return; /* Wait for queue to be reduced more */ | 1018 | return; /* Wait for queue to be reduced more */ |
1019 | /* schedule next action */ | 1019 | /* schedule next action */ |
1020 | while (NULL == h->current) | 1020 | while (NULL == h->current) |
1021 | { | 1021 | { |
@@ -1253,8 +1253,10 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
1253 | } | 1253 | } |
1254 | for (ai = h->action_head; NULL != ai; ai = ai->next) | 1254 | for (ai = h->action_head; NULL != ai; ai = ai->next) |
1255 | { | 1255 | { |
1256 | if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) && | 1256 | if (! ( (0 == strcmp (ai->subsystem, |
1257 | (0 == strcmp (ai->name, name)) && | 1257 | h->subsystem)) && |
1258 | (0 == strcmp (ai->name, | ||
1259 | name)) && | ||
1258 | ( (ACTION_UPDATE == ai->type) || | 1260 | ( (ACTION_UPDATE == ai->type) || |
1259 | (ACTION_SET == ai->type) ) ) ) | 1261 | (ACTION_SET == ai->type) ) ) ) |
1260 | continue; | 1262 | 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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2012 GNUnet e.V. | 3 | Copyright (C) 2009, 2012, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -29,6 +29,21 @@ | |||
29 | 29 | ||
30 | static struct GNUNET_STATISTICS_Handle *h; | 30 | static struct GNUNET_STATISTICS_Handle *h; |
31 | 31 | ||
32 | static struct GNUNET_STATISTICS_GetHandle *g; | ||
33 | |||
34 | |||
35 | static void | ||
36 | do_shutdown () | ||
37 | { | ||
38 | if (NULL != g) | ||
39 | { | ||
40 | GNUNET_STATISTICS_get_cancel (g); | ||
41 | g = NULL; | ||
42 | } | ||
43 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | ||
44 | h = NULL; | ||
45 | } | ||
46 | |||
32 | 47 | ||
33 | static int | 48 | static int |
34 | check_1 (void *cls, | 49 | check_1 (void *cls, |
@@ -96,7 +111,8 @@ next_fin (void *cls, | |||
96 | { | 111 | { |
97 | int *ok = cls; | 112 | int *ok = cls; |
98 | 113 | ||
99 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 114 | g = NULL; |
115 | GNUNET_SCHEDULER_shutdown (); | ||
100 | GNUNET_assert (success == GNUNET_OK); | 116 | GNUNET_assert (success == GNUNET_OK); |
101 | *ok = 0; | 117 | *ok = 0; |
102 | } | 118 | } |
@@ -105,6 +121,7 @@ next_fin (void *cls, | |||
105 | static void | 121 | static void |
106 | next (void *cls, int success) | 122 | next (void *cls, int success) |
107 | { | 123 | { |
124 | g = NULL; | ||
108 | GNUNET_assert (success == GNUNET_OK); | 125 | GNUNET_assert (success == GNUNET_OK); |
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
110 | "Issuing GET request\n"); | 127 | "Issuing GET request\n"); |
@@ -122,15 +139,23 @@ run (void *cls, | |||
122 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 139 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
123 | { | 140 | { |
124 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); | 141 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); |
142 | if (NULL == h) | ||
143 | { | ||
144 | GNUNET_break (0); | ||
145 | return; | ||
146 | } | ||
147 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
148 | NULL); | ||
125 | GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); | 149 | GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); |
126 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); | 150 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); |
127 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); | 151 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); |
128 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); | 152 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); |
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "Issuing GET request\n"); | ||
130 | GNUNET_break (NULL != | 155 | GNUNET_break (NULL != |
131 | GNUNET_STATISTICS_get (h, NULL, "test-1", | 156 | (g = GNUNET_STATISTICS_get (h, NULL, "test-1", |
132 | &next, | 157 | &next, |
133 | &check_1, cls)); | 158 | &check_1, cls))); |
134 | } | 159 | } |
135 | 160 | ||
136 | 161 | ||
@@ -142,11 +167,13 @@ run_more (void *cls, | |||
142 | { | 167 | { |
143 | h = GNUNET_STATISTICS_create ("test-statistics-api", | 168 | h = GNUNET_STATISTICS_create ("test-statistics-api", |
144 | cfg); | 169 | cfg); |
170 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
171 | NULL); | ||
145 | GNUNET_break (NULL != | 172 | GNUNET_break (NULL != |
146 | GNUNET_STATISTICS_get (h, NULL, | 173 | (g = GNUNET_STATISTICS_get (h, NULL, |
147 | "test-3", | 174 | "test-3", |
148 | &next_fin, | 175 | &next_fin, |
149 | &check_3, cls)); | 176 | &check_3, cls))); |
150 | } | 177 | } |
151 | 178 | ||
152 | 179 | ||
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; | |||
31 | 31 | ||
32 | 32 | ||
33 | static int | 33 | static int |
34 | check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | 34 | check_1 (void *cls, |
35 | const char *subsystem, | ||
36 | const char *name, | ||
37 | uint64_t value, | ||
35 | int is_persistent) | 38 | int is_persistent) |
36 | { | 39 | { |
37 | GNUNET_assert (0 == strcmp (name, "test-0")); | 40 | GNUNET_assert (0 == strcmp (name, "test-0")); |
@@ -42,7 +45,8 @@ check_1 (void *cls, const char *subsystem, const char *name, uint64_t value, | |||
42 | 45 | ||
43 | 46 | ||
44 | static void | 47 | static void |
45 | next (void *cls, int success) | 48 | next (void *cls, |
49 | int success) | ||
46 | { | 50 | { |
47 | int *ok = cls; | 51 | int *ok = cls; |
48 | 52 | ||
@@ -53,7 +57,9 @@ next (void *cls, int success) | |||
53 | 57 | ||
54 | 58 | ||
55 | static void | 59 | static void |
56 | run (void *cls, char *const *args, const char *cfgfile, | 60 | run (void *cls, |
61 | char *const *args, | ||
62 | const char *cfgfile, | ||
57 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 63 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
58 | { | 64 | { |
59 | unsigned int i; | 65 | unsigned int i; |
@@ -62,9 +68,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
62 | h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg); | 68 | h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg); |
63 | for (i = 0; i < ROUNDS; i++) | 69 | for (i = 0; i < ROUNDS; i++) |
64 | { | 70 | { |
65 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 256); | 71 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 32); |
66 | GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); | 72 | GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); |
67 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 128); | 73 | GNUNET_snprintf (name, sizeof (name), "test-%d", i % 16); |
68 | GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); | 74 | GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); |
69 | } | 75 | } |
70 | i = 0; | 76 | i = 0; |