]> git.proxmox.com Git - mirror_frr.git/blame - tests/lib/test_segv.c
*: Convert `struct event_master` to `struct event_loop`
[mirror_frr.git] / tests / lib / test_segv.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
4d474fa3
DL
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
4d474fa3
DL
11 */
12
13#include <zebra.h>
14#include <sigevent.h>
15#include "lib/log.h"
16#include "lib/memory.h"
17
7cc91e67 18struct frr_signal_t sigs[] = {};
4d474fa3 19
cd9d0537 20struct event_loop *master;
4d474fa3 21
68b8a15f
DL
22void func1(int *arg);
23void func3(void);
24
25void func1(int *arg)
4d474fa3 26{
d62a17ae 27 int *null = NULL;
28 *null += 1;
68b8a15f
DL
29 *arg = 1;
30}
31
32static 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
46void func3(void)
47{
48 int buf[6];
49 func2(6, buf);
50}
51
e6685141 52static void threadfunc(struct event *thread)
68b8a15f
DL
53{
54 func3();
4d474fa3
DL
55}
56
d62a17ae 57int main(void)
4d474fa3 58{
ce50d11c 59 master = event_master_create(NULL);
d62a17ae 60 signal_init(master, array_size(sigs), sigs);
4d474fa3 61
0bdeb5e5 62 zlog_aux_init("NONE: ", LOG_DEBUG);
4d474fa3 63
8c1186d3 64 event_execute(master, threadfunc, 0, 0);
4d474fa3 65
d62a17ae 66 exit(0);
4d474fa3 67}