xref: /freebsd/tools/test/stress2/misc/signal0.sh (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1#!/bin/sh
2
3#
4# Copyright (c) 2013 EMC Corp.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Zero signal number seen.
30# Test scenario by Vitaly Magerya <vmagerya gmail com>
31# http://people.freebsd.org/~pho/stress/log/kostik646.txt
32# Panic fixed in r258497
33# Signal number fixed in r258499
34
35# panic: vm_fault: fault on nofault entry, addr: cdbbe000
36# https://people.freebsd.org/~pho/stress/log/kostik838.txt
37# Fixed by r289661.
38
39dir=/tmp
40odir=`pwd`
41cd $dir
42sed '1,/^EOF/d' < $odir/$0 > $dir/signal0.c
43c99 -o signal0  signal0.c -lpthread || exit 1
44rm -f signal0.c
45cd $odir
46
47(cd ../testcases/swap; ./swap -t 5m -i 20 -h -v) > /dev/null 2>&1 &
48s=0
49# The timeout was added after r345702, due to a longer runtime for
50# an INVARIANTS kernel
51start=`date +%s`
52for i in `jot 500`; do
53	/tmp/signal0 || { s=1; break; }
54	[ $((`date +%s` - start)) -gt 900 ] &&
55	    { echo "Timeout @ loop $i/500"; s=1; break; }
56done
57while pkill -9 swap; do :; done
58wait
59
60rm -f /tmp/signal0
61exit $s
62
63EOF
64#include <pthread.h>
65#include <signal.h>
66#include <stdio.h>
67#include <stdlib.h>
68
69#define N 3000
70
71static void
72signal_handler(int signum, siginfo_t *si, void *context) {
73	if (signum != SIGUSR1) {
74		printf("FAIL bad signal, signum=%d\n", signum);
75		exit(1);
76	}
77}
78
79static void
80*thread_func(void *arg) {
81	return arg;
82}
83
84int
85main(void)
86{
87	struct sigaction sa = { 0 };
88
89	sa.sa_flags = SA_SIGINFO;
90	sa.sa_sigaction = signal_handler;
91	if (sigfillset(&sa.sa_mask) != 0) abort();
92	if (sigaction(SIGUSR1, &sa, NULL) != 0) abort();
93	for (int i = 0; i < N; i++) {
94		pthread_t t;
95
96		if (pthread_create(&t, NULL, thread_func, NULL) == 0)
97			pthread_kill(t, SIGUSR1);
98
99	}
100
101	return (0);
102}
103