blob: 60066b1eaf9c37bc4fe6212ab4cb90f8577c4e06 [file] [log] [blame]
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +01001/* Test implementation for osmo_tdef API. */
2/*
3 * (C) 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 *
9 * Author: Neels Hofmeyr <neels@hofmeyr.de>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#include <stdio.h>
27#include <errno.h>
28#include <limits.h>
29
30#include <osmocom/core/logging.h>
31#include <osmocom/core/application.h>
32#include <osmocom/core/fsm.h>
33
34#include <osmocom/core/tdef.h>
35
36static void *ctx = NULL;
37
38static struct osmo_tdef tdefs[] = {
39 { .T=1, .default_val=100, .desc="100s" },
40 { .T=2, .default_val=100, .unit=OSMO_TDEF_MS, .desc="100ms" },
41 { .T=3, .default_val=100, .unit=OSMO_TDEF_M, .desc="100m" },
42 { .T=4, .default_val=100, .unit=OSMO_TDEF_CUSTOM, .desc="100 potatoes" },
43
Pau Espin Pedrol0cbe8f02019-09-17 13:13:52 +020044 { .T=7, .default_val=50, .desc="Water Boiling Timeout", .min_val=20, .max_val=800 }, // default is .unit=OSMO_TDEF_S == 0
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +010045 { .T=8, .default_val=300, .desc="Tea brewing" },
46 { .T=9, .default_val=5, .unit=OSMO_TDEF_M, .desc="Let tea cool down before drinking" },
47 { .T=10, .default_val=20, .unit=OSMO_TDEF_M, .desc="Forgot to drink tea while it's warm" },
48
49 /* test conversions */
50 { .T=1000, .default_val=2*1000, .unit=OSMO_TDEF_MS, .desc="two seconds from ms" },
51 { .T=1001, .default_val=60*1000, .unit=OSMO_TDEF_MS, .desc="one minute from ms" },
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +010052 { .T=1004, .default_val=1, .unit=OSMO_TDEF_MS, .desc="one ms" },
53 { .T=1005, .default_val=0, .unit=OSMO_TDEF_MS, .desc="zero ms" },
54 { .T=1006, .default_val=0, .unit=OSMO_TDEF_S, .desc="zero s" },
55 { .T=1007, .default_val=0, .unit=OSMO_TDEF_M, .desc="zero m" },
56 { .T=1008, .default_val=0, .unit=OSMO_TDEF_CUSTOM, .desc="zero" },
57
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +010058 { .T=0, .default_val=1, .unit=OSMO_TDEF_CUSTOM, .desc="zero" },
59
60 /* no desc */
61 { .T=123, .default_val=1 },
62
63 {} // <-- important! last entry shall be zero
64};
65
Neels Hofmeyr7b740f72019-02-06 01:08:43 +010066static struct osmo_tdef tdefs_range[] = {
67 { .T=1002, .default_val=(ULONG_MAX/60), .unit=OSMO_TDEF_M, .desc="almost too many seconds" },
68 { .T=1003, .default_val=ULONG_MAX, .unit=OSMO_TDEF_M, .desc="too many seconds" },
69
70 { .T=INT_MAX, .default_val=ULONG_MAX, .unit=OSMO_TDEF_S, .desc="very large" },
71 { .T=INT_MAX-1, .default_val=ULONG_MAX-1, .unit=OSMO_TDEF_S, .desc="very large" },
72 { .T=INT_MAX-2, .default_val=LONG_MAX, .unit=OSMO_TDEF_S, .desc="very large" },
73 { .T=INT_MAX-3, .default_val=ULONG_MAX, .unit=OSMO_TDEF_M, .desc="very large in minutes" },
74 { .T=INT_MIN, .default_val=ULONG_MAX, .unit=OSMO_TDEF_S, .desc="negative" },
75
76 {}
77};
78
79#define print_tdef_get(TDEFS, T, AS_UNIT) do { \
80 unsigned long val = osmo_tdef_get(TDEFS, T, AS_UNIT, 999); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +010081 printf("osmo_tdef_get(tdefs, %d, %s, 999)\t= %lu\n", T, osmo_tdef_unit_name(AS_UNIT), val); \
82 } while (0)
83
Neels Hofmeyr7b740f72019-02-06 01:08:43 +010084#define print_tdef_get_short(TDEFS, T, AS_UNIT) do { \
85 unsigned long val = osmo_tdef_get(TDEFS, T, AS_UNIT, 999); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +010086 printf("osmo_tdef_get(%d, %s)\t= %lu\n", T, osmo_tdef_unit_name(AS_UNIT), val); \
87 } while (0)
88
89void print_tdef_info(unsigned int T)
90{
91 const struct osmo_tdef *t = osmo_tdef_get_entry(tdefs, T);
92 if (!t) {
93 printf("T%d=NULL", T);
94 return;
95 }
96 printf("T%d=%lu%s", T, t->val, osmo_tdef_unit_name(t->unit));
97 if (t->val != t->default_val)
98 printf("(def=%lu)", t->default_val);
99 printf("\n");
100}
101
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100102static void test_tdef_get(bool test_range)
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100103{
104 int i;
105 enum osmo_tdef_unit as_unit;
106
107 printf("\n%s()\n", __func__);
108
109 osmo_tdefs_reset(tdefs); // make all values the default
110
111 for (i = 0; i < ARRAY_SIZE(tdefs)-1; i++) {
112 unsigned int T = tdefs[i].T;
113 print_tdef_info(T);
114 for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_CUSTOM; as_unit++) {
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100115 print_tdef_get_short(tdefs, T, as_unit);
116 }
117 }
118
119 if (!test_range)
120 return;
121
122 for (i = 0; i < ARRAY_SIZE(tdefs_range)-1; i++) {
123 unsigned int T = tdefs_range[i].T;
124 print_tdef_info(T);
125 for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_CUSTOM; as_unit++) {
126 print_tdef_get_short(tdefs_range, T, as_unit);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100127 }
128 }
129}
130
131static void test_tdef_get_nonexisting()
132{
133 printf("\n%s()\n", __func__);
134
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100135 print_tdef_get(tdefs, 5, OSMO_TDEF_S);
136 print_tdef_get(tdefs, 5, OSMO_TDEF_MS);
137 print_tdef_get(tdefs, 5, OSMO_TDEF_M);
138 print_tdef_get(tdefs, 5, OSMO_TDEF_CUSTOM);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100139}
140
141static void test_tdef_set_and_get()
142{
143 struct osmo_tdef *t;
144 printf("\n%s()\n", __func__);
145
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100146 printf("setting 7 = 42\n");
Pau Espin Pedrol0cbe8f02019-09-17 13:13:52 +0200147 t = osmo_tdef_get_entry(tdefs, 7);
148 OSMO_ASSERT(osmo_tdef_val_in_range(t, 42));
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100149 t->val = 42;
150 print_tdef_info(7);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100151 print_tdef_get_short(tdefs, 7, OSMO_TDEF_MS);
152 print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
153 print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
154 print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100155
156 printf("setting 7 = 420\n");
Pau Espin Pedrol0cbe8f02019-09-17 13:13:52 +0200157 OSMO_ASSERT(osmo_tdef_set(tdefs, 7, 420, OSMO_TDEF_S) == 0);
158 print_tdef_info(7);
159 print_tdef_get_short(tdefs, 7, OSMO_TDEF_MS);
160 print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
161 print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
162 print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
163
164 printf("setting 7 = 10 (ERANGE)\n");
165 OSMO_ASSERT(!osmo_tdef_val_in_range(t, 10));
166 OSMO_ASSERT(osmo_tdef_set(tdefs, 7, 10, OSMO_TDEF_S) == -ERANGE);
167 print_tdef_info(7);
168 print_tdef_get_short(tdefs, 7, OSMO_TDEF_MS);
169 print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
170 print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
171 print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
172
173 printf("setting 7 = 900 (ERANGE)\n");
174 OSMO_ASSERT(!osmo_tdef_val_in_range(t, 900));
175 OSMO_ASSERT(osmo_tdef_set(tdefs, 7, 900, OSMO_TDEF_S) == -ERANGE);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100176 print_tdef_info(7);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100177 print_tdef_get_short(tdefs, 7, OSMO_TDEF_MS);
178 print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
179 print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
180 print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100181
182 printf("resetting\n");
183 osmo_tdefs_reset(tdefs);
184 print_tdef_info(7);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100185 print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100186}
187
188enum test_tdef_fsm_states {
189 S_A = 0,
190 S_B,
191 S_C,
192 S_D,
193 S_G,
194 S_H,
195 S_I,
196 S_J,
197 S_K,
198 S_L,
199 S_M,
200 S_N,
201 S_O,
202 S_X,
203 S_Y,
204 S_Z,
205};
206
207static const struct osmo_tdef_state_timeout test_tdef_state_timeouts[32] = {
208 [S_A] = { .T = 1 },
209 [S_B] = { .T = 2 },
210 [S_C] = { .T = 3 },
211 [S_D] = { .T = 4 },
212
213 [S_G] = { .T = 7 },
214 [S_H] = { .T = 8 },
215 [S_I] = { .T = 9 },
216 [S_J] = { .T = 10 },
217
218 /* keep_timer: adopt whichever T was running before and continue the timeout. */
219 [S_K] = { .keep_timer = true },
220 /* S_F defines an undefined T, but should continue previous state's timeout. */
221 [S_L] = { .T = 123, .keep_timer = true },
222
223 /* range */
224 [S_M] = { .T = INT_MAX },
225 [S_N] = { .T = INT_MIN },
226
227 /* T0 is not addressable from osmo_tdef_state_timeout, since it is indistinguishable from an unset entry. Even
228 * though a timeout value is set for T=0, the transition to state S_O will show "no timer configured". */
229 [S_O] = { .T = 0 },
230
231 /* S_X undefined on purpose */
232 /* S_Y defines a T that does not exist */
233 [S_Y] = { .T = 666 },
234 /* S_Z undefined on purpose */
235};
236
237#define S(x) (1 << (x))
238
239static const struct osmo_fsm_state test_tdef_fsm_states[] = {
240#define DEF_STATE(NAME) \
241 [S_##NAME] = { \
242 .name = #NAME, \
243 .out_state_mask = 0 \
244 | S(S_A) \
245 | S(S_B) \
246 | S(S_C) \
247 | S(S_D) \
248 | S(S_G) \
249 | S(S_H) \
250 | S(S_I) \
251 | S(S_J) \
252 | S(S_K) \
253 | S(S_L) \
254 | S(S_M) \
255 | S(S_N) \
256 | S(S_O) \
257 | S(S_X) \
258 | S(S_Y) \
259 | S(S_Z) \
260 , \
261 }
262
263 DEF_STATE(A),
264 DEF_STATE(B),
265 DEF_STATE(C),
266 DEF_STATE(D),
267
268 DEF_STATE(G),
269 DEF_STATE(H),
270 DEF_STATE(I),
271 DEF_STATE(J),
272
273 DEF_STATE(K),
274 DEF_STATE(L),
275
276 DEF_STATE(M),
277 DEF_STATE(N),
278 DEF_STATE(O),
279
280 DEF_STATE(X),
281 DEF_STATE(Y),
282 /* Z: test not being allowed to transition to other states. */
283 [S_Z] = {
284 .name = "Z",
285 .out_state_mask = 0
286 | S(S_A)
287 ,
288 },
289};
290
291static const struct value_string test_tdef_fsm_event_names[] = { {} };
292
293static struct osmo_fsm test_tdef_fsm = {
294 .name = "tdef_test",
295 .states = test_tdef_fsm_states,
296 .event_names = test_tdef_fsm_event_names,
297 .num_states = ARRAY_SIZE(test_tdef_fsm_states),
298 .log_subsys = DLGLOBAL,
299};
300
301const struct timeval fake_time_start_time = { 123, 456 };
302
303#define fake_time_passes(secs, usecs) do \
304{ \
305 struct timeval diff; \
306 osmo_gettimeofday_override_add(secs, usecs); \
307 osmo_clock_override_add(CLOCK_MONOTONIC, secs, usecs * 1000); \
308 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
Neels Hofmeyr4f54c6c2019-03-06 06:03:24 +0100309 printf("Time passes: %ld.%06ld s\n", (long)secs, (long)usecs); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100310 osmo_timers_prepare(); \
311 osmo_timers_update(); \
312} while (0)
313
314void fake_time_start()
315{
316 struct timespec *clock_override;
317
318 osmo_gettimeofday_override_time = fake_time_start_time;
319 osmo_gettimeofday_override = true;
320 clock_override = osmo_clock_override_gettimespec(CLOCK_MONOTONIC);
321 OSMO_ASSERT(clock_override);
322 clock_override->tv_sec = fake_time_start_time.tv_sec;
323 clock_override->tv_nsec = fake_time_start_time.tv_usec * 1000;
324 osmo_clock_override_enable(CLOCK_MONOTONIC, true);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100325}
326
327static void print_fsm_state(struct osmo_fsm_inst *fi)
328{
329 struct timeval remaining;
330 printf("state=%s T=%d", osmo_fsm_inst_state_name(fi), fi->T);
331
332 if (!osmo_timer_pending(&fi->timer)) {
333 printf(", no timeout\n");
334 return;
335 }
336
337 osmo_timer_remaining(&fi->timer, &osmo_gettimeofday_override_time, &remaining);
338 printf(", %lu.%06lu s remaining\n", remaining.tv_sec, remaining.tv_usec);
339}
340
341
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100342#define test_tdef_fsm_state_chg(tdefs, NEXT_STATE) do { \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100343 const struct osmo_tdef_state_timeout *st = osmo_tdef_get_state_timeout(NEXT_STATE, \
344 test_tdef_state_timeouts); \
Neels Hofmeyr4ea69822019-03-06 06:14:01 +0100345 int rc = osmo_tdef_fsm_inst_state_chg(fi, NEXT_STATE, test_tdef_state_timeouts, tdefs, 999); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100346 if (!st) { \
Neels Hofmeyr4ea69822019-03-06 06:14:01 +0100347 printf(" --> %s (no timer configured for this state) rc=%d;\t", \
348 osmo_fsm_state_name(&test_tdef_fsm, NEXT_STATE), rc); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100349 } else { \
350 struct osmo_tdef *t = osmo_tdef_get_entry(tdefs, st->T); \
Neels Hofmeyr4f54c6c2019-03-06 06:03:24 +0100351 printf(" --> %s (configured as T%d%s %lu %s) rc=%d;\t", \
352 osmo_fsm_state_name(&test_tdef_fsm, NEXT_STATE), \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100353 st->T, st->keep_timer ? "(keep_timer)" : "", \
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100354 t? t->val : 0, t? osmo_tdef_unit_name(t->unit) : "-", \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100355 rc); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100356 } \
Neels Hofmeyr4f54c6c2019-03-06 06:03:24 +0100357 print_fsm_state(fi); \
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100358 } while(0)
359
360
361
362static void test_tdef_state_timeout(bool test_range)
363{
364 struct osmo_fsm_inst *fi;
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100365 unsigned long m_secs;
366 printf("\n%s()\n", __func__);
367
368 osmo_tdefs_reset(tdefs);
369
370 fake_time_start();
371
372 fi = osmo_fsm_inst_alloc(&test_tdef_fsm, ctx, NULL, LOGL_DEBUG, __func__);
373 OSMO_ASSERT(fi);
374 print_fsm_state(fi);
375
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100376 test_tdef_fsm_state_chg(tdefs, S_A);
377 test_tdef_fsm_state_chg(tdefs, S_B);
378 test_tdef_fsm_state_chg(tdefs, S_C);
379 test_tdef_fsm_state_chg(tdefs, S_D);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100380
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100381 test_tdef_fsm_state_chg(tdefs, S_G);
382 test_tdef_fsm_state_chg(tdefs, S_H);
383 test_tdef_fsm_state_chg(tdefs, S_I);
384 test_tdef_fsm_state_chg(tdefs, S_J);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100385
386 printf("- test keep_timer:\n");
387 fake_time_passes(123, 45678);
388 print_fsm_state(fi);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100389 test_tdef_fsm_state_chg(tdefs, S_K);
390 test_tdef_fsm_state_chg(tdefs, S_A);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100391 fake_time_passes(23, 45678);
392 print_fsm_state(fi);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100393 test_tdef_fsm_state_chg(tdefs, S_K);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100394
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100395 test_tdef_fsm_state_chg(tdefs, S_A);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100396 fake_time_passes(23, 45678);
397 print_fsm_state(fi);
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100398 test_tdef_fsm_state_chg(tdefs, S_L);
Neels Hofmeyr4f54c6c2019-03-06 06:03:24 +0100399 test_tdef_fsm_state_chg(tdefs, S_O);
400 test_tdef_fsm_state_chg(tdefs, S_L);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100401
402 printf("- test T=0:\n");
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100403 test_tdef_fsm_state_chg(tdefs, S_O);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100404
405 printf("- test no timer:\n");
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100406 test_tdef_fsm_state_chg(tdefs, S_X);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100407
408 printf("- test undefined timer, using default_val arg of osmo_tdef_fsm_inst_state_chg(), here passed as 999:\n");
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100409 test_tdef_fsm_state_chg(tdefs, S_Y);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100410
411 /* the range of unsigned long is architecture dependent. This test can be invoked manually to see whether
412 * clamping the timeout values works, but the output will be of varying lengths depending on the system's
413 * unsigned long range, and would cause differences in expected output. */
414 if (test_range) {
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100415 struct osmo_tdef *m;
416
417 printf("- test large T:\n");
418 test_tdef_fsm_state_chg(tdefs_range, S_M);
419
420 printf("- test T<0:\n");
421 test_tdef_fsm_state_chg(tdefs_range, S_N);
422
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100423 printf("- test range:\n");
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100424 test_tdef_fsm_state_chg(tdefs_range, S_M);
425
426 m = osmo_tdef_get_entry(tdefs_range, INT_MAX);
427 OSMO_ASSERT(m);
428
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100429 /* sweep through all the bits, shifting in 0xfffff.. from the right. */
430 m_secs = 0;
431 do {
432 m_secs = (m_secs << 1) + 1;
433 switch (m_secs) {
434 case 0x7fff:
435 printf("--- int32_t max ---\n");
436 break;
437 case 0xffff:
438 printf("--- uint32_t max ---\n");
439 break;
440 case 0x7fffffff:
441 printf("--- int64_t max ---\n");
442 break;
443 case 0xffffffff:
444 printf("--- uint64_t max ---\n");
445 break;
446 default:
447 break;
448 }
449
450 m->val = m_secs - 1;
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100451 test_tdef_fsm_state_chg(tdefs_range, S_M);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100452 m->val = m_secs;
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100453 test_tdef_fsm_state_chg(tdefs_range, S_M);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100454 m->val = m_secs + 1;
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100455 test_tdef_fsm_state_chg(tdefs_range, S_M);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100456 } while (m_secs < ULONG_MAX);
457 }
458
459 printf("- test disallowed transition:\n");
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100460 test_tdef_fsm_state_chg(tdefs, S_Z);
461 test_tdef_fsm_state_chg(tdefs, S_B);
462 test_tdef_fsm_state_chg(tdefs, S_C);
463 test_tdef_fsm_state_chg(tdefs, S_D);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100464}
465
466int main(int argc, char **argv)
467{
468 ctx = talloc_named_const(NULL, 0, "tdef_test.c");
469 osmo_init_logging2(ctx, NULL);
470
471 log_set_print_filename(osmo_stderr_target, 0);
472 log_set_print_category(osmo_stderr_target, 1);
473 log_set_use_color(osmo_stderr_target, 0);
474
475 osmo_fsm_register(&test_tdef_fsm);
476
Neels Hofmeyr7b740f72019-02-06 01:08:43 +0100477 test_tdef_get(argc > 1);
Neels Hofmeyr0fd615f2019-01-26 20:36:12 +0100478 test_tdef_get_nonexisting();
479 test_tdef_set_and_get();
480 /* Run range test iff any argument is passed on the cmdline. For the rationale, see the comment in
481 * test_tdef_state_timeout(). */
482 test_tdef_state_timeout(argc > 1);
483
484 return EXIT_SUCCESS;
485}