this repo has no description
1#!/bin/bash
2# vim: ft=sh ts=4 sw=4 et
3#
4# usage: run-tests <prog> <suffix> [<dirname> ...]
5#
6# Find the test cases in <dirname> ... and subdirectories thereof and run
7# them with 'run-test <prog> <testcase>'. Failing test cases are summarised
8# in a FAILURES.<prog> file.
9#
10# A test case is either <model><suffix> or <model>.<testid>.dzn
11# where there is a corresponding <model><suffix> file.
12#
13# Note that if a model file does not contain a comment of the form
14# 'RUNS ON <prog>' then the test case will be skipped. Ignored test
15# cases are summarised in an IGNORED.<prog> file.
16
17# If the environment variable FORCE_DELAY is set then a small delay
18# will be introduced between each test case. This is useful for
19# avoid resource limits on Mac OS X, usually indicated by the following
20# error message:
21#
22# fork: Resource temporarily unavailable
23
24# Uncomment the next line for debugging:
25# set -x
26
27# The name of this program as invoked.
28#
29THIS=$(basename $0)
30
31THISDIR="$(pwd)"
32
33#
34if [ $# -lt 2 ]
35then
36 echo "usage: $THIS <prog> <suffix> [<dirname> ...]" >&2
37 exit 1
38fi
39
40PROG=$1
41SUFFIX=$2
42shift 2
43DIRS=$@
44[ -z "$DIRS" ] && DIRS=.
45BASEPROG=$(basename $PROG)
46FAILURES="$(pwd)/FAILURES.$BASEPROG"
47IGNORES="$(pwd)/IGNORED.$BASEPROG"
48RUNSONREGEX="\<RUNS *ON *$BASEPROG\>"
49
50# Clear out any old IGNORES and FAILURES files.
51#
52rm -f "$IGNORES" "$FAILURES"
53
54NTESTS=0
55
56# Count number of tests
57for FILENAME in $(find $DIRS -name '*'$SUFFIX -o -name '*.dzn' | sort)
58do
59 # Skip this file if there's a corresponding .dzn file or
60 # it is a .dzn file, but doesn't have the corresponding $SUFFIX file.
61 #
62 case $FILENAME in
63 *.dzn)
64 # Ignore .dzn files that don't have a model file with
65 # the right suffix.
66 MODELNAME=$(echo $FILENAME | sed 's/[.].*//')$SUFFIX
67 if [ ! -e $MODELNAME ]
68 then
69 continue
70 fi
71 ;;
72 *)
73 # Ignore model files that have one or more .dzn files.
74 BASENAME=$(basename $FILENAME $SUFFIX)
75 if ls $BASENAME'*.dzn' >/dev/null 2>&1
76 then
77 continue
78 fi
79 ;;
80 esac
81
82 NTESTS=$((NTESTS+1))
83
84done
85
86echo "<testsuite name=\"$BASEPROG\" tests=\"$NTESTS\">"
87
88NTESTS=0
89NFAIL=0
90
91# Find all applicable test cases.
92#
93for FILENAME in $(find $DIRS -name '*'$SUFFIX -o -name '*.dzn' | sort)
94do
95
96 # Return to the directory where we began.
97 #
98 cd "$THISDIR" >/dev/null 2>&1
99
100 # cd to the directory of the problem file.
101 #
102 DIR=$(dirname $FILENAME)
103 if [ -n "$DIR" ]
104 then
105 cd $DIR >/dev/null 2>&1
106 FILENAME=$(basename $FILENAME)
107 fi
108
109 # Skip this file if there's a corresponding .dzn file or
110 # it is a .dzn file, but doesn't have the corresponding $SUFFIX file.
111 #
112 case $FILENAME in
113 *.dzn)
114 # Ignore .dzn files that don't have a model file with
115 # the right suffix.
116 MODELNAME=$(echo $FILENAME | sed 's/[.].*//')$SUFFIX
117 if [ ! -e $MODELNAME ]
118 then
119 continue
120 fi
121 MODELFILE=$MODELNAME
122 ;;
123 *)
124 # Ignore model files that have one or more .dzn files.
125 BASENAME=$(basename $FILENAME $SUFFIX)
126 if ls $BASENAME'*.dzn' >/dev/null 2>&1
127 then
128 continue
129 fi
130 MODELFILE=$FILENAME
131 ;;
132 esac
133
134 # Ignore model files that don't contain the
135 # string 'RUNS ON $BASEPROG'.
136 if ! grep -q "$RUNSONREGEX" $MODELFILE
137 then
138 echo "$DIR/$FILENAME" >> "$IGNORES"
139 continue
140 fi
141
142 # Run the test.
143 #
144 echo "<testcase name=\"$FILENAME\" classname=\"none\" >"
145 PASSFAIL=fail
146 run-test $PROG $FILENAME >test_stdout 2>&1 && PASSFAIL=pass
147 if [ $PASSFAIL = "fail" ]
148 then
149 echo "<failure message=\"test failed\"></failure>"
150 fi
151 echo "<system-out>"
152 echo "<![CDATA["
153 cat test_stdout
154 echo "]]>"
155 echo "</system-out>"
156 echo "</testcase>"
157
158 NTESTS=$((NTESTS+1))
159
160 if test $FORCE_DELAY
161 then
162 sleep 1
163 fi
164
165 # Return to the directory where we began.
166 #
167 cd "$THISDIR" >/dev/null 2>&1
168
169 if [ $PASSFAIL = "fail" ]
170 then
171 NFAIL=$((NFAIL+1))
172 echo "$DIR/$FILENAME ($PROG)" >> "$FAILURES"
173 fi
174
175done
176
177echo "</testsuite>"