this repo has no description
1#!/bin/bash 2# vim: ft=sh ts=4 sw=4 et 3# 4# usage: run-test <prog> <filename> 5# 6# Ralph Becket <rafe@csse.unimelb.edu.au> 7# 8# 9# Run program <prog> on <filename> and compare the results against the 10# expected outputs. The solver is run with default time and memory limits 11# which an be configured by setting TIMELIMIT (default 30 seconds) and 12# MEMLIMIT (default 1000 megabytes). 13# 14# If G12PATH is set and $G12PATH/<prog> is executable then this file is 15# run, otherwise PATH is used. 16# 17# <filename> should end in 18# - .fzn for FlatZinc tests 19# - .mzn for MiniZinc tests 20# - .zinc for Zinc tests 21# - .dzn for Zinc or MiniZinc tests (the prefix of <filename> up to 22# the first '.' is used to identify the corresponding .mzn or .zinc model). 23# 24# 25# TEST CASES 26# 27# A test case consists of the following: 28# 29# - a <model>.zinc or <model>.mzn or <model>.fzn file; 30# 31# - zero or more <model>.<testid>.dzn files (as an option for .zinc and .mzn 32# tests which separate the data from the model); 33# 34# - an optional <model>.opt file containing command line options to be 35# passed to <prog> for <model>; 36# 37# - an optional <model>.<prog>.opt file containing command line options 38# specific to <prog> for <model>; 39# 40# - [where a test is not specified as a .dzn file] one or more <model>*.exp* 41# or <model>*.err_exp* files specifying the expected output or error report 42# 43# - [where a test is specified as a .dzn file] one or more; 44# <model>.<testid>*.exp* or <model>.<testid>*.err_exp* files specifying the 45# expected output or error report. 46# 47# 48# HOW TEST CASES ARE RUN 49# 50# The contents of any <model>.opts and <model>.<prog>.opts files are 51# collected in $OPTS. 52# 53# Where a test is specified as a <model>.[fzn|mzn|zinc] file: 54# $OUT is defined as <model>.<prog>.out 55# $ERR is defined as <model>.<prog>.err 56# The test is run under time-and-mem-limit as: 57# <prog> $OPTS <model>.[fzn|mzn|zinc] >$OUT 2>$ERR 58# 59# Where a test is specified as a <model>.<testid>.dzn file: 60# $OUT is defined as <model>.<testid>.<prog>.out 61# $ERR is defined as <model>.<testid>.<prog>.err 62# The test is run under time-and-mem-limit as: 63# <prog> $OPTS -d <model>.<testid>.dzn <model>.[mzn|zinc] >$OUT 2>$ERR 64# 65# If the $OUT file matches a <model>*.exp* or <model>.<testid>.*exp* file 66# or the $ERR file matches a <model>*.err_exp* or <model>.<testid>.*err_exp* 67# file then the test is deemed to have passed and $OUT and $ERR are deleted. 68# Otherwise an error message is printed and $OUT and $ERR are left for later 69# review. 70 71 72 73# Uncomment the next line for debugging: 74# set -x 75 76# Set default time and memory limits (seconds and megabytes respectively). 77# 78TIMELIMIT=${TIMELIMIT:-30} 79MEMLIMIT=${MEMLIMIT:-8000} 80 81# The name of this program as invoked. 82# 83THIS=$(basename $0) 84 85# Parse the command line. 86# 87if [ $# -ne 2 ] 88then 89 echo "usage: $THIS <prog> <filename>" >&2 90 echo " <filename> must be either " >&2 91 echo " <model>.<testid>.dzn " >&2 92 echo " or <model>.mzn" >&2 93 echo " or <model>.fzn" >&2 94 echo " or <model>.zinc" >&2 95 echo " Environmnent vars TIMELIMIT (default $TIMELIMIT seconds)" >&2 96 echo " and MEMLIMIT (default $MEMLIMIT megabytes) are recognised." >&2 97 exit 1 98fi 99 100PROG=$1 101FILENAME=$2 102 103if test "$G12PATH" -a -x "$G12PATH/$PROG"; then 104 PROG_EXEC="$G12PATH/$PROG" 105else 106 PROG_EXEC="$PROG" 107fi 108 109# cd to the directory of the problem file if it is not present in the 110# current working directory. 111# 112DIR=$(dirname $FILENAME) 113if [ -n "$DIR" ] 114then 115 cd $DIR >/dev/null 2>&1 116 FILENAME=$(basename $FILENAME) 117fi 118 119# get_exp_out_err_files X sets the OPTS, EXPS, ERREXPS, OUT and ERR variables 120# for problem X. If no expected output files are found then exit. 121# 122function get_exp_out_err_files () { 123 124 X=$1 125 126 # Find the .exp files. 127 # 128 EXPS=$(find . -maxdepth 1 -name $X'*.exp*') 129 ERREXPS=$(find . -maxdepth 1 -name $X'*.err_exp*') 130 131 # If no .exp file exists for this model then do nothing. 132 # 133 if [ -z "$EXPS" -a -z "$ERREXPS" ] 134 then 135 echo "$THIS: skipping $FILENAME since it has no .exp files" >&2 136 exit 0 137 fi 138 139 # Read any special options for this model. 140 # 141 [ -e $X.opt ] && OPTS=$(cat $X.opt) 142 [ -e $X.$PROG.opt ] && OPTS=$OPTS" "$(cat $X.$PROG.opt) 143 144 # Construct the command to run the solver. 145 # 146 OUT=$X.$PROG.out 147 ERR=$X.$PROG.err 148 149} 150 151# Decide what to do with the given file. 152# 153case "$FILENAME" in 154 155 *.fzn) 156 X=$(basename $FILENAME .fzn) 157 FZN=$X.fzn 158 159 get_exp_out_err_files $X 160 161 # Construct the command to run the solver. 162 # 163 CMD="$PROG_EXEC $OPTS $FZN" 164 165 ;; 166 167 *.mzn) 168 X=$(basename $FILENAME .mzn) 169 MZN=$X.mzn 170 171 # If a .dzn file exists for this model then do nothing. 172 # 173 if ls $X*.dzn >/dev/null 2>&1 174 then 175 exit 0 176 fi 177 178 get_exp_out_err_files $X 179 180 # Construct the command to run the solver. 181 # 182 CMD="$PROG_EXEC $OPTS $MZN" 183 184 ;; 185 186 *.zinc) 187 X=$(basename $FILENAME .zinc) 188 ZINC=$X.zinc 189 190 # If a .dzn file exists for this model then do nothing. 191 # 192 if ls $X*.dzn >/dev/null 2>&1 193 then 194 exit 0 195 fi 196 197 get_exp_out_err_files $X 198 199 # Construct the command to run the solver. 200 # 201 CMD="$PROG_EXEC $OPTS $ZINC" 202 203 ;; 204 205 *.dzn) 206 X=$(basename $FILENAME .dzn) 207 DZN=$X.dzn 208 MZN=$(echo $X | sed 's/[.].*//').mzn 209 ZINC=$(echo $X | sed 's/[.].*//').zinc 210 211 # Find the corresponding .mzn or .zinc file. Report an error if it 212 # doesn't exist. 213 # 214 MODEL="" 215 [ -e $MZN ] && MODEL=$MZN 216 [ -e $ZINC ] && MODEL=$ZINC 217 if [ -z $MODEL ] 218 then 219 echo "$THIS: no .mzn or .zinc file corresponding to $DZN" >&2 220 exit 1 221 fi 222 223 get_exp_out_err_files $X 224 225 # Construct the command to run the solver (give priority to 226 # zinc models). 227 # 228 CMD="$PROG_EXEC $OPTS -d $DZN $MODEL" 229 230 ;; 231 232 *) 233 # Don't recognise this file, just ignore it. 234 # 235 echo "$THIS: ignoring unrecognised file $FILENAME" >&2 236 exit 1 237 238 ;; 239 240esac 241 242# Run the solver and generate the .out and .err files. 243# 244echo -n "$THIS: $CMD" 245time-and-mem-limit $TIMELIMIT $MEMLIMIT $CMD >$OUT 2>$ERR 246#ulimit -d $MEMLIMITKB -m $MEMLIMITKB -v $MEMLIMITKB -t $TIMELIMIT 247#$CMD >$OUT 2>$ERR 248 249# Compare the solver output against the expected output. 250# 251PASSFAIL=fail 252 253if [ -n "$EXPS" ] 254then 255 for EXP in $EXPS 256 do 257 if diff --brief --ignore-all-space \ 258 -I 'minizinc.exe: flattening killed by signal.*' \ 259 $OUT $EXP >/dev/null 2>&1 260 then 261 PASSFAIL=pass 262 break 263 fi 264 done 265fi 266 267if [ -n "$ERREXPS" ] 268then 269 for ERREXP in $ERREXPS 270 do 271 if diff -I "^\(IBM \)\?ILOG.*CPLEX.*" --brief --ignore-all-space \ 272 -I 'minizinc.exe: flattening killed by signal.*' \ 273 $ERR $ERREXP >/dev/null 2>&1 274 then 275 PASSFAIL=pass 276 break 277 fi 278 done 279fi 280 281# Clean up after success or report failure. 282# 283if [ "$PASSFAIL" = "pass" ] 284then 285 echo " ... passed" 286 rm -f $OUT $ERR 287else 288 echo " ... failed" 289 echo "$THIS: no match against expected outputs" 290 echo "$THIS: ---- $OUT ----" 291 cat $OUT 292 echo "$THIS: ---- $ERR ----" 293 cat $ERR 294 echo "$THIS: ---- end of output ----" 295 exit 1 296fi 297