diff options
Diffstat (limited to 'src/util/test_scheduler.c')
-rw-r--r-- | src/util/test_scheduler.c | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 234a2aae1..236bb4e76 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.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 util/test_scheduler.c | 21 | * @file util/test_scheduler.c |
22 | * @brief tests for the scheduler | 22 | * @brief tests for the scheduler |
@@ -33,135 +33,135 @@ static struct GNUNET_SCHEDULER_Task *never_run_task; | |||
33 | 33 | ||
34 | 34 | ||
35 | static void | 35 | static void |
36 | task2 (void *cls) | 36 | task2(void *cls) |
37 | { | 37 | { |
38 | int *ok = cls; | 38 | int *ok = cls; |
39 | 39 | ||
40 | /* t3 should be ready (albeit with lower priority) */ | 40 | /* t3 should be ready (albeit with lower priority) */ |
41 | GNUNET_assert (1 == | 41 | GNUNET_assert(1 == |
42 | GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); | 42 | GNUNET_SCHEDULER_get_load(GNUNET_SCHEDULER_PRIORITY_COUNT)); |
43 | GNUNET_assert (2 == *ok); | 43 | GNUNET_assert(2 == *ok); |
44 | (*ok) = 3; | 44 | (*ok) = 3; |
45 | } | 45 | } |
46 | 46 | ||
47 | 47 | ||
48 | static void | 48 | static void |
49 | task3 (void *cls) | 49 | task3(void *cls) |
50 | { | 50 | { |
51 | int *ok = cls; | 51 | int *ok = cls; |
52 | 52 | ||
53 | GNUNET_assert (3 == *ok); | 53 | GNUNET_assert(3 == *ok); |
54 | (*ok) = 4; | 54 | (*ok) = 4; |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | static void | 58 | static void |
59 | taskWrt (void *cls) | 59 | taskWrt(void *cls) |
60 | { | 60 | { |
61 | static char c; | 61 | static char c; |
62 | int *ok = cls; | 62 | int *ok = cls; |
63 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 63 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
64 | 64 | ||
65 | tc = GNUNET_SCHEDULER_get_task_context (); | 65 | tc = GNUNET_SCHEDULER_get_task_context(); |
66 | GNUNET_assert (6 == *ok); | 66 | GNUNET_assert(6 == *ok); |
67 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1])); | 67 | GNUNET_assert(GNUNET_NETWORK_fdset_handle_isset(tc->write_ready, fds[1])); |
68 | (*ok) = 7; | 68 | (*ok) = 7; |
69 | GNUNET_assert (1 == GNUNET_DISK_file_write (fds[1], &c, 1)); | 69 | GNUNET_assert(1 == GNUNET_DISK_file_write(fds[1], &c, 1)); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | static void | 73 | static void |
74 | taskNeverRun (void *cls) | 74 | taskNeverRun(void *cls) |
75 | { | 75 | { |
76 | GNUNET_assert (0); | 76 | GNUNET_assert(0); |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | static void | 80 | static void |
81 | taskLastRd (void *cls) | 81 | taskLastRd(void *cls) |
82 | { | 82 | { |
83 | int *ok = cls; | 83 | int *ok = cls; |
84 | 84 | ||
85 | GNUNET_assert (8 == *ok); | 85 | GNUNET_assert(8 == *ok); |
86 | (*ok) = 0; | 86 | (*ok) = 0; |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | static void | 90 | static void |
91 | taskLastSig (void *cls) | 91 | taskLastSig(void *cls) |
92 | { | 92 | { |
93 | int *ok = cls; | 93 | int *ok = cls; |
94 | 94 | ||
95 | GNUNET_SCHEDULER_cancel (never_run_task); | 95 | GNUNET_SCHEDULER_cancel(never_run_task); |
96 | GNUNET_assert (9 == *ok); | 96 | GNUNET_assert(9 == *ok); |
97 | (*ok) = 0; | 97 | (*ok) = 0; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | static void | 101 | static void |
102 | taskLastShutdown (void *cls) | 102 | taskLastShutdown(void *cls) |
103 | { | 103 | { |
104 | int *ok = cls; | 104 | int *ok = cls; |
105 | 105 | ||
106 | GNUNET_assert (10 == *ok); | 106 | GNUNET_assert(10 == *ok); |
107 | (*ok) = 0; | 107 | (*ok) = 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | static void | 111 | static void |
112 | taskRd (void *cls) | 112 | taskRd(void *cls) |
113 | { | 113 | { |
114 | static char c; | 114 | static char c; |
115 | int *ok = cls; | 115 | int *ok = cls; |
116 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 116 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
117 | 117 | ||
118 | tc = GNUNET_SCHEDULER_get_task_context (); | 118 | tc = GNUNET_SCHEDULER_get_task_context(); |
119 | GNUNET_assert (7 == *ok); | 119 | GNUNET_assert(7 == *ok); |
120 | GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); | 120 | GNUNET_assert(GNUNET_NETWORK_fdset_handle_isset(tc->read_ready, fds[0])); |
121 | GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); | 121 | GNUNET_assert(1 == GNUNET_DISK_file_read(fds[0], &c, 1)); |
122 | (*ok) = 8; | 122 | (*ok) = 8; |
123 | GNUNET_SCHEDULER_add_shutdown (&taskLastRd, | 123 | GNUNET_SCHEDULER_add_shutdown(&taskLastRd, |
124 | cls); | 124 | cls); |
125 | GNUNET_SCHEDULER_shutdown (); | 125 | GNUNET_SCHEDULER_shutdown(); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | static void | 129 | static void |
130 | task4 (void *cls) | 130 | task4(void *cls) |
131 | { | 131 | { |
132 | int *ok = cls; | 132 | int *ok = cls; |
133 | 133 | ||
134 | GNUNET_assert (4 == *ok); | 134 | GNUNET_assert(4 == *ok); |
135 | (*ok) = 6; | 135 | (*ok) = 6; |
136 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | 136 | p = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
137 | GNUNET_assert (NULL != p); | 137 | GNUNET_assert(NULL != p); |
138 | fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); | 138 | fds[0] = GNUNET_DISK_pipe_handle(p, GNUNET_DISK_PIPE_END_READ); |
139 | fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); | 139 | fds[1] = GNUNET_DISK_pipe_handle(p, GNUNET_DISK_PIPE_END_WRITE); |
140 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 140 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
141 | fds[0], | 141 | fds[0], |
142 | &taskRd, | 142 | &taskRd, |
143 | cls); | ||
144 | GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, | ||
145 | fds[1], | ||
146 | &taskWrt, | ||
143 | cls); | 147 | cls); |
144 | GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
145 | fds[1], | ||
146 | &taskWrt, | ||
147 | cls); | ||
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | static void | 151 | static void |
152 | task1 (void *cls) | 152 | task1(void *cls) |
153 | { | 153 | { |
154 | int *ok = cls; | 154 | int *ok = cls; |
155 | 155 | ||
156 | GNUNET_assert (1 == *ok); | 156 | GNUNET_assert(1 == *ok); |
157 | (*ok) = 2; | 157 | (*ok) = 2; |
158 | GNUNET_SCHEDULER_add_now (&task3, cls); | 158 | GNUNET_SCHEDULER_add_now(&task3, cls); |
159 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, | 159 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI, |
160 | &task2, | 160 | &task2, |
161 | cls); | 161 | cls); |
162 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 162 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
163 | &task4, | 163 | &task4, |
164 | cls); | 164 | cls); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -170,27 +170,27 @@ task1 (void *cls) | |||
170 | * checks that "ok" is correct at the end. | 170 | * checks that "ok" is correct at the end. |
171 | */ | 171 | */ |
172 | static int | 172 | static int |
173 | check () | 173 | check() |
174 | { | 174 | { |
175 | int ok; | 175 | int ok; |
176 | 176 | ||
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 177 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
178 | "[Check scheduling]\n"); | 178 | "[Check scheduling]\n"); |
179 | ok = 1; | 179 | ok = 1; |
180 | GNUNET_SCHEDULER_run (&task1, &ok); | 180 | GNUNET_SCHEDULER_run(&task1, &ok); |
181 | return ok; | 181 | return ok; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | static void | 185 | static void |
186 | taskShutdown (void *cls) | 186 | taskShutdown(void *cls) |
187 | { | 187 | { |
188 | int *ok = cls; | 188 | int *ok = cls; |
189 | 189 | ||
190 | GNUNET_assert (1 == *ok); | 190 | GNUNET_assert(1 == *ok); |
191 | *ok = 10; | 191 | *ok = 10; |
192 | GNUNET_SCHEDULER_add_shutdown (&taskLastShutdown, cls); | 192 | GNUNET_SCHEDULER_add_shutdown(&taskLastShutdown, cls); |
193 | GNUNET_SCHEDULER_shutdown (); | 193 | GNUNET_SCHEDULER_shutdown(); |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
@@ -199,33 +199,33 @@ taskShutdown (void *cls) | |||
199 | * checks that "ok" is correct at the end. | 199 | * checks that "ok" is correct at the end. |
200 | */ | 200 | */ |
201 | static int | 201 | static int |
202 | checkShutdown () | 202 | checkShutdown() |
203 | { | 203 | { |
204 | int ok; | 204 | int ok; |
205 | 205 | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
207 | "[Check shutdown]\n"); | 207 | "[Check shutdown]\n"); |
208 | ok = 1; | 208 | ok = 1; |
209 | GNUNET_SCHEDULER_run (&taskShutdown, &ok); | 209 | GNUNET_SCHEDULER_run(&taskShutdown, &ok); |
210 | return ok; | 210 | return ok; |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | #ifndef MINGW | 214 | #ifndef MINGW |
215 | static void | 215 | static void |
216 | taskSig (void *cls) | 216 | taskSig(void *cls) |
217 | { | 217 | { |
218 | int *ok = cls; | 218 | int *ok = cls; |
219 | 219 | ||
220 | GNUNET_assert (1 == *ok); | 220 | GNUNET_assert(1 == *ok); |
221 | *ok = 9; | 221 | *ok = 9; |
222 | GNUNET_SCHEDULER_add_shutdown (&taskLastSig, cls); | 222 | GNUNET_SCHEDULER_add_shutdown(&taskLastSig, cls); |
223 | never_run_task = | 223 | never_run_task = |
224 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 224 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
225 | &taskNeverRun, | 225 | &taskNeverRun, |
226 | NULL); | 226 | NULL); |
227 | GNUNET_break (0 == kill (getpid (), | 227 | GNUNET_break(0 == kill(getpid(), |
228 | GNUNET_TERM_SIG)); | 228 | GNUNET_TERM_SIG)); |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
@@ -234,27 +234,27 @@ taskSig (void *cls) | |||
234 | * checks that "ok" is correct at the end. | 234 | * checks that "ok" is correct at the end. |
235 | */ | 235 | */ |
236 | static int | 236 | static int |
237 | checkSignal () | 237 | checkSignal() |
238 | { | 238 | { |
239 | int ok; | 239 | int ok; |
240 | 240 | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 241 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
242 | "[Check signal handling]\n"); | 242 | "[Check signal handling]\n"); |
243 | ok = 1; | 243 | ok = 1; |
244 | GNUNET_SCHEDULER_run (&taskSig, &ok); | 244 | GNUNET_SCHEDULER_run(&taskSig, &ok); |
245 | return ok; | 245 | return ok; |
246 | } | 246 | } |
247 | #endif | 247 | #endif |
248 | 248 | ||
249 | 249 | ||
250 | static void | 250 | static void |
251 | taskCancel (void *cls) | 251 | taskCancel(void *cls) |
252 | { | 252 | { |
253 | int *ok = cls; | 253 | int *ok = cls; |
254 | 254 | ||
255 | GNUNET_assert (1 == *ok); | 255 | GNUNET_assert(1 == *ok); |
256 | *ok = 0; | 256 | *ok = 0; |
257 | GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL)); | 257 | GNUNET_SCHEDULER_cancel(GNUNET_SCHEDULER_add_now(&taskNeverRun, NULL)); |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
@@ -263,31 +263,31 @@ taskCancel (void *cls) | |||
263 | * checks that "ok" is correct at the end. | 263 | * checks that "ok" is correct at the end. |
264 | */ | 264 | */ |
265 | static int | 265 | static int |
266 | checkCancel () | 266 | checkCancel() |
267 | { | 267 | { |
268 | int ok; | 268 | int ok; |
269 | 269 | ||
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 270 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
271 | "[Check task cancellation]\n"); | 271 | "[Check task cancellation]\n"); |
272 | ok = 1; | 272 | ok = 1; |
273 | GNUNET_SCHEDULER_run (&taskCancel, &ok); | 273 | GNUNET_SCHEDULER_run(&taskCancel, &ok); |
274 | return ok; | 274 | return ok; |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | int | 278 | int |
279 | main (int argc, char *argv[]) | 279 | main(int argc, char *argv[]) |
280 | { | 280 | { |
281 | int ret = 0; | 281 | int ret = 0; |
282 | 282 | ||
283 | GNUNET_log_setup ("test_scheduler", "WARNING", NULL); | 283 | GNUNET_log_setup("test_scheduler", "WARNING", NULL); |
284 | ret += check (); | 284 | ret += check(); |
285 | ret += checkCancel (); | 285 | ret += checkCancel(); |
286 | #ifndef MINGW | 286 | #ifndef MINGW |
287 | ret += checkSignal (); | 287 | ret += checkSignal(); |
288 | #endif | 288 | #endif |
289 | ret += checkShutdown (); | 289 | ret += checkShutdown(); |
290 | GNUNET_DISK_pipe_close (p); | 290 | GNUNET_DISK_pipe_close(p); |
291 | 291 | ||
292 | return ret; | 292 | return ret; |
293 | } | 293 | } |