aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/test_statistics_api_watch_zero_value.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/test_statistics_api_watch_zero_value.c')
-rw-r--r--src/statistics/test_statistics_api_watch_zero_value.c187
1 files changed, 93 insertions, 94 deletions
diff --git a/src/statistics/test_statistics_api_watch_zero_value.c b/src/statistics/test_statistics_api_watch_zero_value.c
index 05dc75366..1dc093658 100644
--- a/src/statistics/test_statistics_api_watch_zero_value.c
+++ b/src/statistics/test_statistics_api_watch_zero_value.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_zero_value.c 21 * @file statistics/test_statistics_api_watch_zero_value.c
22 * @brief testcase for statistics_api.c watch functions with initial 0 value 22 * @brief testcase for statistics_api.c watch functions with initial 0 value
@@ -37,157 +37,156 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
37 37
38 38
39static void 39static void
40force_shutdown (void *cls) 40force_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
49static void 49static void
50normal_shutdown (void *cls) 50normal_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
57static int 57static int
58watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value, 58watch_1(void *cls, const char *subsystem, const char *name, uint64_t value,
59 int is_persistent) 59 int is_persistent)
60{ 60{
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 61 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
62 "Received value `%s' `%s' %llu\n", 62 "Received value `%s' `%s' %llu\n",
63 subsystem, 63 subsystem,
64 name, 64 name,
65 (unsigned long long) value); 65 (unsigned long long)value);
66 GNUNET_assert (0 == strcmp (name, "test-1")); 66 GNUNET_assert(0 == strcmp(name, "test-1"));
67 if ((0 == value) && (3 == ok)) 67 if ((0 == value) && (3 == ok))
68 { 68 {
69 ok--; 69 ok--;
70 GNUNET_STATISTICS_set (h, "test-1", 42, GNUNET_NO); 70 GNUNET_STATISTICS_set(h, "test-1", 42, GNUNET_NO);
71 } 71 }
72 72
73 if ((42 == value) && (2 == ok)) 73 if ((42 == value) && (2 == ok))
74 { 74 {
75 ok--; 75 ok--;
76 GNUNET_STATISTICS_set (h, "test-1", 0, GNUNET_NO); 76 GNUNET_STATISTICS_set(h, "test-1", 0, GNUNET_NO);
77 } 77 }
78 78
79 if ((0 == value) && (1 == ok)) 79 if ((0 == value) && (1 == ok))
80 { 80 {
81 ok--; 81 ok--;
82 } 82 }
83 if ((0 == ok) && (0 == ok2)) 83 if ((0 == ok) && (0 == ok2))
84 { 84 {
85 GNUNET_SCHEDULER_cancel (shutdown_task); 85 GNUNET_SCHEDULER_cancel(shutdown_task);
86 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); 86 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL);
87 } 87 }
88 88
89 return GNUNET_OK; 89 return GNUNET_OK;
90} 90}
91 91
92 92
93static int 93static int
94watch_2 (void *cls, 94watch_2(void *cls,
95 const char *subsystem, 95 const char *subsystem,
96 const char *name, 96 const char *name,
97 uint64_t value, 97 uint64_t value,
98 int is_persistent) 98 int is_persistent)
99{ 99{
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 100 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
101 "Received value `%s' `%s' %llu\n", 101 "Received value `%s' `%s' %llu\n",
102 subsystem, 102 subsystem,
103 name, 103 name,
104 (unsigned long long) value); 104 (unsigned long long)value);
105 105
106 GNUNET_assert (0 == strcmp (name, "test-2")); 106 GNUNET_assert(0 == strcmp(name, "test-2"));
107 if ((42 == value) && (1 == ok2)) 107 if ((42 == value) && (1 == ok2))
108 {
109 ok2 = 0;
110 if (0 == ok)
111 { 108 {
112 GNUNET_SCHEDULER_cancel (shutdown_task); 109 ok2 = 0;
113 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); 110 if (0 == ok)
111 {
112 GNUNET_SCHEDULER_cancel(shutdown_task);
113 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL);
114 }
114 } 115 }
115 }
116 else 116 else
117 { 117 {
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
119 "Received unexpected value %llu\n", 119 "Received unexpected value %llu\n",
120 (unsigned long long) value); 120 (unsigned long long)value);
121 121
122 GNUNET_break (0); 122 GNUNET_break(0);
123 GNUNET_SCHEDULER_cancel (shutdown_task); 123 GNUNET_SCHEDULER_cancel(shutdown_task);
124 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL); 124 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL);
125 } 125 }
126 126
127 return GNUNET_OK; 127 return GNUNET_OK;
128} 128}
129 129
130 130
131static void 131static void
132run (void *cls, char *const *args, const char *cfgfile, 132run(void *cls, char *const *args, const char *cfgfile,
133 const struct GNUNET_CONFIGURATION_Handle *cfg) 133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{ 134{
135 h = GNUNET_STATISTICS_create ("dummy", cfg); 135 h = GNUNET_STATISTICS_create("dummy", cfg);
136 h2 = GNUNET_STATISTICS_create ("dummy-2", cfg); 136 h2 = GNUNET_STATISTICS_create("dummy-2", cfg);
137 GNUNET_assert (GNUNET_OK == 137 GNUNET_assert(GNUNET_OK ==
138 GNUNET_STATISTICS_watch (h, "dummy", 138 GNUNET_STATISTICS_watch(h, "dummy",
139 "test-1", &watch_1, NULL)); 139 "test-1", &watch_1, NULL));
140 140
141 GNUNET_assert (GNUNET_OK == 141 GNUNET_assert(GNUNET_OK ==
142 GNUNET_STATISTICS_watch (h2, "dummy-2", 142 GNUNET_STATISTICS_watch(h2, "dummy-2",
143 "test-2", &watch_2, NULL)); 143 "test-2", &watch_2, NULL));
144 144
145 /* Set initial value to 0 */ 145 /* Set initial value to 0 */
146 GNUNET_STATISTICS_set (h, "test-1", 0, GNUNET_NO); 146 GNUNET_STATISTICS_set(h, "test-1", 0, GNUNET_NO);
147 GNUNET_STATISTICS_set (h2, "test-2", 42, GNUNET_NO); 147 GNUNET_STATISTICS_set(h2, "test-2", 42, GNUNET_NO);
148 148
149 shutdown_task = 149 shutdown_task =
150 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 150 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
151 &force_shutdown, 151 &force_shutdown,
152 NULL); 152 NULL);
153} 153}
154 154
155 155
156int 156int
157main (int argc, char *argv_ign[]) 157main(int argc, char *argv_ign[])
158{ 158{
159 char *const argv[] = { "test-statistics-api", 159 char *const argv[] = { "test-statistics-api",
160 "-c", 160 "-c",
161 "test_statistics_api_data.conf", 161 "test_statistics_api_data.conf",
162 NULL 162 NULL };
163 };
164 struct GNUNET_GETOPT_CommandLineOption options[] = { 163 struct GNUNET_GETOPT_CommandLineOption options[] = {
165 GNUNET_GETOPT_OPTION_END 164 GNUNET_GETOPT_OPTION_END
166 }; 165 };
167 struct GNUNET_OS_Process *proc; 166 struct GNUNET_OS_Process *proc;
168 char *binary; 167 char *binary;
169 168
170 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); 169 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics");
171 proc = 170 proc =
172 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 171 GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
173 NULL, NULL, NULL, 172 NULL, NULL, NULL,
174 binary, 173 binary,
175 "gnunet-service-statistics", 174 "gnunet-service-statistics",
176 "-c", "test_statistics_api_data.conf", NULL); 175 "-c", "test_statistics_api_data.conf", NULL);
177 GNUNET_assert (NULL != proc); 176 GNUNET_assert(NULL != proc);
178 ok = 3; 177 ok = 3;
179 ok2 = 1; 178 ok2 = 1;
180 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run, 179 GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run,
181 NULL); 180 NULL);
182 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) 181 if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG))
183 { 182 {
184 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 183 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
185 ok = 1; 184 ok = 1;
186 } 185 }
187 GNUNET_OS_process_wait (proc); 186 GNUNET_OS_process_wait(proc);
188 GNUNET_OS_process_destroy (proc); 187 GNUNET_OS_process_destroy(proc);
189 proc = NULL; 188 proc = NULL;
190 GNUNET_free (binary); 189 GNUNET_free(binary);
191 if ((0 == ok) && (0 == ok2)) 190 if ((0 == ok) && (0 == ok2))
192 return 0; 191 return 0;
193 return 1; 192 return 1;