]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_segv.c
tests: improve the ospfapi test (move to square topology)
[mirror_frr.git] / tests / lib / test_segv.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * SEGV / backtrace handling test.
4 *
5 * copied from test-sig.c
6 *
7 * Copyright (C) 2013 by David Lamparter, Open Source Routing.
8 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
9 *
10 * This file is part of Quagga
11 */
12
13 #include <zebra.h>
14 #include <sigevent.h>
15 #include "lib/log.h"
16 #include "lib/memory.h"
17
18 struct frr_signal_t sigs[] = {};
19
20 struct thread_master *master;
21
22 void func1(int *arg);
23 void func3(void);
24
25 void func1(int *arg)
26 {
27 int *null = NULL;
28 *null += 1;
29 *arg = 1;
30 }
31
32 static void func2(size_t depth, int *arg)
33 {
34 /* variable stack frame size */
35 int buf[depth];
36 for (size_t i = 0; i < depth; i++)
37 buf[i] = arg[i] + 1;
38 if (depth > 0)
39 func2(depth - 1, buf);
40 else
41 func1(&buf[0]);
42 for (size_t i = 0; i < depth; i++)
43 buf[i] = arg[i] + 2;
44 }
45
46 void func3(void)
47 {
48 int buf[6];
49 func2(6, buf);
50 }
51
52 static void threadfunc(struct thread *thread)
53 {
54 func3();
55 }
56
57 int main(void)
58 {
59 master = thread_master_create(NULL);
60 signal_init(master, array_size(sigs), sigs);
61
62 zlog_aux_init("NONE: ", LOG_DEBUG);
63
64 thread_execute(master, threadfunc, 0, 0);
65
66 exit(0);
67 }