xref: /freebsd/tools/test/stress2/run.sh (revision 2008043f386721d58158e37e0d7e50df8095942d)
1#!/bin/sh
2
3#
4# Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
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# Run 1) with no argument: the default test cases
30#     2) with the "-a" arguments all the *.cfg test variations
31#     3) with one argument: that specific test case
32
33while getopts a name; do
34   case $name in
35   a) aflag=1;;
36   ?) printf "Usage: %s: [-a] [arg]\n" $0
37      exit 2;;
38   esac
39done
40shift $(($OPTIND - 1))
41
42[ -x ./testcases/run/run ] ||
43    { echo "Please run \"make\" first." && exit 1; }
44[ `basename ${stress2origin:-X}` != misc ] &&
45    echo "Note: all.sh in stress2/misc is the preferred test to run." \
46    1>&2
47find ./testcases -perm -1 \( -name "*.debug" -o -name "*.full" \) -delete \
48    2>/dev/null
49if [ ! -z "$aflag" ]; then
50   . ./default.cfg
51   export runRUNTIME=5m
52   t1=`date '+%s'`
53   while true;do
54      for i in `ls *.cfg | grep -v default`; do
55         t2=`date '+%s'`
56         e=` date -u -j -f '%s' '+%T' $((t2 - t1))`
57         echo "`date '+%Y%m%d %T'` $i, elapsed $e"
58         echo "`date '+%Y%m%d %T'` $i, elapsed $e" >> /tmp/all.log
59         logger "Starting test $i"
60         [ -w /dev/console ] &&
61            printf "`date '+%Y%m%d %T'` run $i\r\n" > /dev/console
62         $0 $i
63      done
64   done
65else
66   CONFIG=./default.cfg
67   if [ $# -eq 1 ]; then
68      [ ! -r $1 ] && echo "$0: $1 not found!" && exit 1
69      CONFIG=$1
70   fi
71   . $CONFIG
72
73   [ -z "$RUNDIR" ] && echo "$0: RUNDIR is unset!" && exit 1
74   [ `basename $RUNDIR` != stressX ] && \
75      echo "$0: Basename of RUNDIR must be stressX!" && exit 2
76   [ -d "$RUNDIR" ] && (cd $RUNDIR && find . -delete)
77
78   [ -z "$EXCLUDETESTS" ] && EXCLUDETESTS=DuMmY
79
80   [ -z "$TESTPROGS" ] && \
81      TESTPROGS=`find testcases/ -perm -1 -type f | \
82          egrep -v "/run/|$EXCLUDETESTS|\.full|\.debug"`
83   ./testcases/run/run $TESTPROGS
84fi
85