The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
acutest_common_init.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/** Common initialisation for acutest binaries
19 *
20 * @file src/lib/util/test/acutest_common_init.h
21 *
22 * The test wrapper's timeout arrives as SIGALRM, and stdout is block
23 * buffered when redirected to a log file, so a test binary without signal
24 * handlers dies with no backtrace and loses every progress line since the
25 * last buffer flush. The TEST_INIT hook below installs the fatal signal
26 * handlers and switches stdout to line buffering before each test runs.
27 *
28 * To use: include this header first, in place of acutest.h.
29 *
30 * TEST_INIT must be defined before acutest.h is included, but the function
31 * body reads acutest_argv0_, which acutest.h defines, so the declaration
32 * sits above the include and the definition below.
33 *
34 * @copyright 2026 Arran Cudbard-Bell
35 */
36static void acutest_common_init(void);
37
38#define TEST_INIT acutest_common_init()
39
40#include "acutest.h"
41
42#include <freeradius-devel/util/debug.h>
43#include <freeradius-devel/util/strerror.h>
44#include <freeradius-devel/util/talloc.h>
45
46#include <stdio.h>
47#include <stdlib.h>
48#include <talloc.h>
49
50static void acutest_common_init(void)
51{
52 setvbuf(stdout, NULL, _IOLBF, 0);
53
54 /*
55 * Needed to prevent fr_fault_setup calling fr_get_debug_state,
56 * which can populate the error stack with a message about ptrace
57 * when running as a normal user, breaking the strerror tests.
58 */
59 setenv("DEBUGGER_ATTACHED", "no", 0);
60
61 /*
62 * fr_fault_setup allocates in the given context, and the autofree
63 * context is torn down at exit, so LeakSanitizer stays quiet.
64 */
66 fprintf(stderr, "Running without fatal signal handlers, because fr_fault_setup failed: %s\n",
67 fr_strerror());
68 }
69}
static char * acutest_argv0_
Definition acutest.h:396
static void acutest_common_init(void)
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program, unsigned long fault_signals)
Registers signal handlers to execute panic_action on fatal signal.
Definition debug.c:1074
#define PANIC_ACTION_SIGNALS
Definition debug.h:128
Functions which we wish were included in the standard talloc distribution.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:55
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:558