xref: /freebsd/tools/test/stress2/misc/syscall5.sh (revision fd45b686f9d92f583366c75b22c04c7ee49709c0)
1#!/bin/sh
2
3#
4# Copyright (c) 2013 Peter Holm
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# Call syscall4.sh with syscall number as argument.
30# Only run the last ~16 syscalls, if no argument is specified.
31
32[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
33
34. ../default.cfg
35
36syscall=`grep SYS_MAXSYSCALL /usr/include/sys/syscall.h | awk '{print $NF}'`
37syscall=$((syscall - 1))
38esyscall=0
39
40last=/tmp/syscall5.last
41log=/tmp/syscall5.log
42
43while getopts ae:nrs:t:u flag; do
44	case "$flag" in
45	a) all=1 ;;
46	e) esyscall="$OPTARG" ;;
47	n) export noswap=1 ;;
48	r) [ -h $last ] &&
49	       syscall=`ls -l $last | awk '{print $NF}'`
50	       syscall=$((syscall - 1))
51	   ;;
52	s) syscall="$OPTARG" ;;
53	t) sleeptime="$OPTARG"
54	   export sleeptime=$((sleeptime / 10))	;; # used in syscall4.sh
55	u) unnamed=1 ;;
56	*) echo "Usage $0 [-a] [-n] [-r] [-s number] [-e number] "\
57	    "[-t seconds] [-u]"
58	   return 1 ;;
59	esac
60done
61[ $syscall -gt $esyscall ] ||
62    { echo "$syscall must be greater than $esyscall"; exit 1; }
63
64# syscalls with known issues:
65broken="
66swapcontext
67pdfork
68rfork
69pselect
70"
71
72rm -f $log
73n=$syscall
74start=`date '+%s'`
75while [ $n -gt 0 ]; do
76	ps -lUnobody | grep syscall4 | awk '{print $2}' | xargs kill
77	ln -fs $n $last
78	name=`grep -w "$n$" /usr/include/sys/syscall.h | awk '{print $2}' |
79		sed 's/SYS_//'`
80	[ -z "$name" ] && name="unknown"
81	rm -f /tmp/syscall5.name
82	[ -x ../tools/exclude_syscall.sh ] &&
83	    ../tools/exclude_syscall.sh $n &&
84	    { n=$((n - 1)); continue; }
85	[ "$name" = "unknown" ] && [ -f /tmp/syscall5.name ] &&
86	    name=`cat /tmp/syscall5.name`
87	[ -z "$name" -a -n "$unnamed" ] &&
88		{ n=$((n - 1)); continue; }
89	echo "`date '+%T'` syscall $n ($name)"
90	echo "`date '+%T'` syscall $n ($name)"  >> $log
91	printf "`date '+%T'` syscall $n ($name)\r\n" > /dev/console
92	sync; sleep 1
93	echo "$broken" | grep -qw "$name" ||
94		./syscall4.sh $n || break
95	[ $n -le $esyscall ] && break
96	n=$((n - 1))
97	[ -z "$all" -a `date '+%s'` -gt $((start + 1800)) ] && break
98done
99rm -f $log $last
100