diff options
Diffstat (limited to 'src/statistics/test_statistics_api_watch.c')
-rw-r--r-- | src/statistics/test_statistics_api_watch.c | 139 |
1 files changed, 69 insertions, 70 deletions
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c index 38ba0e84e..e8cd15047 100644 --- a/src/statistics/test_statistics_api_watch.c +++ b/src/statistics/test_statistics_api_watch.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file statistics/test_statistics_api_watch.c | 21 | * @file statistics/test_statistics_api_watch.c |
22 | * @brief testcase for statistics_api.c watch functions | 22 | * @brief testcase for statistics_api.c watch functions |
@@ -37,118 +37,117 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task; | |||
37 | 37 | ||
38 | 38 | ||
39 | static void | 39 | static void |
40 | force_shutdown (void *cls) | 40 | force_shutdown(void *cls) |
41 | { | 41 | { |
42 | fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok); | 42 | fprintf(stderr, "Timeout, failed to receive notifications: %d\n", ok); |
43 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 43 | GNUNET_STATISTICS_destroy(h, GNUNET_NO); |
44 | GNUNET_STATISTICS_destroy (h2, GNUNET_NO); | 44 | GNUNET_STATISTICS_destroy(h2, GNUNET_NO); |
45 | ok = 7; | 45 | ok = 7; |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | static void | 49 | static void |
50 | normal_shutdown (void *cls) | 50 | normal_shutdown(void *cls) |
51 | { | 51 | { |
52 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 52 | GNUNET_STATISTICS_destroy(h, GNUNET_NO); |
53 | GNUNET_STATISTICS_destroy (h2, GNUNET_NO); | 53 | GNUNET_STATISTICS_destroy(h2, GNUNET_NO); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | static int | 57 | static int |
58 | watch_1 (void *cls, | 58 | watch_1(void *cls, |
59 | const char *subsystem, | 59 | const char *subsystem, |
60 | const char *name, | 60 | const char *name, |
61 | uint64_t value, | 61 | uint64_t value, |
62 | int is_persistent) | 62 | int is_persistent) |
63 | { | 63 | { |
64 | GNUNET_assert (value == 42); | 64 | GNUNET_assert(value == 42); |
65 | GNUNET_assert (0 == strcmp (name, "test-1")); | 65 | GNUNET_assert(0 == strcmp(name, "test-1")); |
66 | ok &= ~1; | 66 | ok &= ~1; |
67 | if (0 == ok) | 67 | if (0 == ok) |
68 | { | 68 | { |
69 | GNUNET_SCHEDULER_cancel (shutdown_task); | 69 | GNUNET_SCHEDULER_cancel(shutdown_task); |
70 | GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); | 70 | GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); |
71 | } | 71 | } |
72 | return GNUNET_OK; | 72 | return GNUNET_OK; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static int | 76 | static int |
77 | watch_2 (void *cls, | 77 | watch_2(void *cls, |
78 | const char *subsystem, | 78 | const char *subsystem, |
79 | const char *name, | 79 | const char *name, |
80 | uint64_t value, | 80 | uint64_t value, |
81 | int is_persistent) | 81 | int is_persistent) |
82 | { | 82 | { |
83 | GNUNET_assert (value == 43); | 83 | GNUNET_assert(value == 43); |
84 | GNUNET_assert (0 == strcmp (name, "test-2")); | 84 | GNUNET_assert(0 == strcmp(name, "test-2")); |
85 | ok &= ~2; | 85 | ok &= ~2; |
86 | if (0 == ok) | 86 | if (0 == ok) |
87 | { | 87 | { |
88 | GNUNET_SCHEDULER_cancel (shutdown_task); | 88 | GNUNET_SCHEDULER_cancel(shutdown_task); |
89 | GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); | 89 | GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); |
90 | } | 90 | } |
91 | return GNUNET_OK; | 91 | return GNUNET_OK; |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | static void | 95 | static void |
96 | run (void *cls, | 96 | run(void *cls, |
97 | char *const *args, | 97 | char *const *args, |
98 | const char *cfgfile, | 98 | const char *cfgfile, |
99 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 99 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
100 | { | 100 | { |
101 | h = GNUNET_STATISTICS_create ("dummy", cfg); | 101 | h = GNUNET_STATISTICS_create("dummy", cfg); |
102 | GNUNET_assert (GNUNET_OK == | 102 | GNUNET_assert(GNUNET_OK == |
103 | GNUNET_STATISTICS_watch (h, "test-statistics-api-watch", | 103 | GNUNET_STATISTICS_watch(h, "test-statistics-api-watch", |
104 | "test-1", &watch_1, NULL)); | 104 | "test-1", &watch_1, NULL)); |
105 | GNUNET_assert (GNUNET_OK == | 105 | GNUNET_assert(GNUNET_OK == |
106 | GNUNET_STATISTICS_watch (h, "test-statistics-api-watch", | 106 | GNUNET_STATISTICS_watch(h, "test-statistics-api-watch", |
107 | "test-2", &watch_2, NULL)); | 107 | "test-2", &watch_2, NULL)); |
108 | h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg); | 108 | h2 = GNUNET_STATISTICS_create("test-statistics-api-watch", cfg); |
109 | GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO); | 109 | GNUNET_STATISTICS_set(h2, "test-1", 42, GNUNET_NO); |
110 | GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO); | 110 | GNUNET_STATISTICS_set(h2, "test-2", 43, GNUNET_NO); |
111 | shutdown_task = | 111 | shutdown_task = |
112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 112 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, |
113 | &force_shutdown, | 113 | &force_shutdown, |
114 | NULL); | 114 | NULL); |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | int | 118 | int |
119 | main (int argc, char *argv_ign[]) | 119 | main(int argc, char *argv_ign[]) |
120 | { | 120 | { |
121 | char *const argv[] = { "test-statistics-api", | 121 | char *const argv[] = { "test-statistics-api", |
122 | "-c", | 122 | "-c", |
123 | "test_statistics_api_data.conf", | 123 | "test_statistics_api_data.conf", |
124 | NULL | 124 | NULL }; |
125 | }; | ||
126 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 125 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
127 | GNUNET_GETOPT_OPTION_END | 126 | GNUNET_GETOPT_OPTION_END |
128 | }; | 127 | }; |
129 | struct GNUNET_OS_Process *proc; | 128 | struct GNUNET_OS_Process *proc; |
130 | char *binary; | 129 | char *binary; |
131 | 130 | ||
132 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); | 131 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); |
133 | proc = | 132 | proc = |
134 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 133 | GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
135 | NULL, NULL, NULL, | 134 | NULL, NULL, NULL, |
136 | binary, | 135 | binary, |
137 | "gnunet-service-statistics", | 136 | "gnunet-service-statistics", |
138 | "-c", "test_statistics_api_data.conf", NULL); | 137 | "-c", "test_statistics_api_data.conf", NULL); |
139 | GNUNET_assert (NULL != proc); | 138 | GNUNET_assert(NULL != proc); |
140 | ok = 3; | 139 | ok = 3; |
141 | GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run, | 140 | GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run, |
142 | NULL); | 141 | NULL); |
143 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 142 | if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) |
144 | { | 143 | { |
145 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 144 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); |
146 | ok = 1; | 145 | ok = 1; |
147 | } | 146 | } |
148 | GNUNET_OS_process_wait (proc); | 147 | GNUNET_OS_process_wait(proc); |
149 | GNUNET_OS_process_destroy (proc); | 148 | GNUNET_OS_process_destroy(proc); |
150 | proc = NULL; | 149 | proc = NULL; |
151 | GNUNET_free (binary); | 150 | GNUNET_free(binary); |
152 | return ok; | 151 | return ok; |
153 | } | 152 | } |
154 | 153 | ||