xref: /freebsd/tools/test/stress2/misc/sigxcpu.sh (revision f7c32ed617858bcd22f8d1b03199099d50125721)
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[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
30
31# "panic: softdep_deallocate_dependencies: dangling deps" seen:
32# http://people.freebsd.org/~pho/stress/log/sigxcpu7.txt
33
34. ../default.cfg
35
36here=`pwd`
37cd /tmp
38sed '1,/^EOF/d' < $here/$0 > sigxcpu.c
39mycc -o sigxcpu -Wall -Wextra sigxcpu.c
40rm -f sigxcpu.c
41cd $here
42
43mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint
44mdconfig -l | grep -q md$mdstart &&  mdconfig -d -u $mdstart
45
46mdconfig -a -t swap -s 4g -u $mdstart || exit 1
47bsdlabel -w md$mdstart auto
48
49newfs $newfs_flags md${mdstart}$part > /dev/null
50
51mount /dev/md${mdstart}$part $mntpoint
52chmod 777 $mntpoint
53
54export runRUNTIME=4m
55export RUNDIR=$mntpoint/stressX
56set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'`
57export KBLOCKS=$(($1 / 4))
58export INODES=$(($2 / 4))
59
60su $testuser -c 'ulimit -t 3; cd ..; ./run.sh marcus.cfg' > /dev/null 2>&1 &
61sleep 5
62for i in `jot 10`; do
63	/tmp/sigxcpu $mntpoint
64done
65kill $! > /dev/null 2>&1
66../tools/killall.sh || ../tools/killall.sh
67wait
68
69for i in `jot 6`; do
70	mount | grep -q "on $mntpoint " || break
71	umount $mntpoint && break || sleep 10
72	[ $i -eq 6 ] &&
73	    { echo FATAL; fstat -mf $mntpoint; exit 1; }
74done
75mdconfig -d -u $mdstart
76rm -f /tmp/sigxcpu
77exit 0
78EOF
79#include <sys/param.h>
80#include <err.h>
81#include <errno.h>
82#include <fts.h>
83#include <libutil.h>
84#include <stdint.h>
85#include <stdio.h>
86#include <stdlib.h>
87#include <string.h>
88#include <unistd.h>
89
90static void
91hand(int i __unused) {	/* handler */
92	_exit(1);
93}
94
95int
96test(char *path)
97{
98
99	FTS		*fts;
100	FTSENT		*p;
101	int		ftsoptions;
102	char		*args[2];
103
104	ftsoptions = FTS_PHYSICAL;
105	args[0] = path;
106	args[1] = 0;
107
108	if ((fts = fts_open(args, ftsoptions, NULL)) == NULL)
109		err(1, "fts_open");
110
111	while ((p = fts_read(fts)) != NULL) {
112		switch (p->fts_info) {
113			case FTS_F:			/* Ignore. */
114				break;
115			case FTS_D:			/* Ignore. */
116				break;
117			case FTS_DP:
118				break;
119			case FTS_DC:			/* Ignore. */
120				break;
121			case FTS_SL:			/* Ignore. */
122				break;
123			case FTS_DNR:			/* Warn, continue. */
124			case FTS_ERR:
125			case FTS_NS:
126			case FTS_DEFAULT:
127				break;
128			default:
129				printf("%s: default, %d\n", getprogname(), p->fts_info);
130				break;
131		}
132	}
133
134	if (errno != 0 && errno != ENOENT)
135		err(1, "fts_read");
136	if (fts_close(fts) == -1)
137		err(1, "fts_close()");
138
139	return (0);
140}
141
142int
143main(int argc, char **argv)
144{
145	int i;
146
147	if (argc != 2)
148		errx(1, "Usage: %s <path>", argv[0]);
149	signal(SIGALRM, hand);
150	alarm(20);
151	for (i = 0; i < 100; i++)
152		test(argv[1]);
153
154	return (0);
155}
156