]>
Commit | Line | Data |
---|---|---|
64dd7736 DL |
1 | /* |
2 | * Quick test for assert() | |
3 | * Copyright (C) 2021 David Lamparter for NetDEF, Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #ifdef HAVE_CONFIG_H | |
21 | #include "config.h" | |
22 | #endif | |
23 | ||
24 | /* make sure this works with assert.h & nothing else. also check the include | |
25 | * shadowing, we don't want to pick up system assert.h | |
26 | */ | |
27 | #include <assert.h> | |
28 | ||
29 | __attribute__((noinline)) | |
f3d2d1e0 | 30 | static void func_for_bt(int number) |
64dd7736 DL |
31 | { |
32 | assert(number > 2); | |
33 | assertf(number > 3, "(A) the number was %d", number); | |
34 | } | |
35 | ||
36 | #include <zebra.h> | |
37 | #include "lib/zlog.h" | |
38 | #include "lib/thread.h" | |
39 | #include "lib/sigevent.h" | |
40 | ||
41 | int main(int argc, char **argv) | |
42 | { | |
43 | int number = 10; | |
44 | struct thread_master *master; | |
45 | ||
46 | zlog_aux_init("NONE: ", LOG_DEBUG); | |
47 | ||
48 | if (argc > 1) | |
49 | number = atoi(argv[1]); | |
50 | ||
51 | assert(number > 0); | |
52 | assertf(number > 1, "(B) the number was %d", number); | |
53 | ||
54 | /* set up SIGABRT handler */ | |
55 | master = thread_master_create("test"); | |
56 | signal_init(master, 0, NULL); | |
57 | ||
58 | func_for_bt(number); | |
59 | assert(number > 4); | |
60 | assertf(number > 5, "(C) the number was %d", number); | |
61 | ||
62 | assertf(number > 10, "(D) the number was %d", number); | |
63 | return 0; | |
64 | } |