aboutsummaryrefslogtreecommitdiff
path: root/tools/test/stress2/misc/signal2.sh
blob: 2cb0589f1dce6174510b1a7e95e5d228942ca206 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh

# Test scenario from:
# Bug 265889 - sys.kern.basic_signal.trap_signal_test crashes bhyve in i386 VM 
# Test scenario by: Li-Wen Hsu <lwhsu@FreeBSD.org>

cat > /tmp/signal2.c <<EOF
#include <stdio.h>
#include <signal.h>

#include <machine/psl.h>
#define    SET_TRACE_FLAG(ucp)    (ucp)->uc_mcontext.mc_eflags |= PSL_T
#define    CLR_TRACE_FLAG(ucp)    (ucp)->uc_mcontext.mc_eflags &= ~PSL_T

static volatile sig_atomic_t trap_signal_fired = 0;

static void
trap_sig_handler(int signo __unused, siginfo_t *info __unused, void *_ucp)
{
	ucontext_t *ucp = _ucp;

	if (trap_signal_fired < 9) {
		SET_TRACE_FLAG(ucp);
	} else {
		CLR_TRACE_FLAG(ucp);
	}
	trap_signal_fired++;
}

int main() {
	struct sigaction sa = {
		.sa_sigaction = trap_sig_handler,
		.sa_flags = SA_SIGINFO,
	};

	sigemptyset(&sa.sa_mask);
	sigaction(SIGTRAP, &sa, NULL);

	raise(SIGTRAP);

	printf("test\n");
}
EOF
cc -o /tmp/signal2 -Wall -Wextra -O0 -m32 /tmp/signal2.c || exit 1

/tmp/signal2; s=$?
for i in `jot 30`; do
	/tmp/signal2 &
done > /dev/null
wait

rm -f /tmp/signal2 /tmp/signal2.c
exit $s