]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
64dd7736 DL |
2 | /* |
3 | * Quick test for assert() | |
4 | * Copyright (C) 2021 David Lamparter for NetDEF, Inc. | |
64dd7736 DL |
5 | */ |
6 | ||
7 | #ifdef HAVE_CONFIG_H | |
8 | #include "config.h" | |
9 | #endif | |
10 | ||
11 | /* make sure this works with assert.h & nothing else. also check the include | |
12 | * shadowing, we don't want to pick up system assert.h | |
13 | */ | |
14 | #include <assert.h> | |
15 | ||
16 | __attribute__((noinline)) | |
f3d2d1e0 | 17 | static void func_for_bt(int number) |
64dd7736 DL |
18 | { |
19 | assert(number > 2); | |
20 | assertf(number > 3, "(A) the number was %d", number); | |
21 | } | |
22 | ||
23 | #include <zebra.h> | |
24 | #include "lib/zlog.h" | |
25 | #include "lib/thread.h" | |
26 | #include "lib/sigevent.h" | |
27 | ||
28 | int main(int argc, char **argv) | |
29 | { | |
30 | int number = 10; | |
31 | struct thread_master *master; | |
32 | ||
33 | zlog_aux_init("NONE: ", LOG_DEBUG); | |
34 | ||
35 | if (argc > 1) | |
36 | number = atoi(argv[1]); | |
37 | ||
38 | assert(number > 0); | |
39 | assertf(number > 1, "(B) the number was %d", number); | |
40 | ||
41 | /* set up SIGABRT handler */ | |
42 | master = thread_master_create("test"); | |
43 | signal_init(master, 0, NULL); | |
44 | ||
45 | func_for_bt(number); | |
46 | assert(number > 4); | |
47 | assertf(number > 5, "(C) the number was %d", number); | |
48 | ||
49 | assertf(number > 10, "(D) the number was %d", number); | |
50 | return 0; | |
51 | } |