1 # The Evaluator -- Shell Function Library
2 # (c) 2001--2004 Martin Mares <mj@ucw.cz>
8 # File handles used: fd1=log, fd2=progress
33 # Report an internal error
35 [ -n "$HAVE_LOG" ] && echo "Fatal error: $@"
41 # Report a fatal error in the program being tested
43 [ -n "$HAVE_LOG" ] && echo "Fatal error: $@"
51 pstart "Preparing sandbox... "
52 if [ -z "$TEST_USER" -o "$TEST_USER" == $EVAL_USER ] ; then
53 pcont "running locally (INSECURE), "
59 pcont "used account $TEST_USER, "
60 BOXDIR=$MO_ROOT/eval/$TEST_USER
61 BOXCMD=bin/box-$TEST_USER
63 [ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
64 BOXCMD="$BOXCMD -c$BOXDIR"
65 echo "Sandbox directory: $BOXDIR"
66 echo "Sandbox command: $BOXCMD"
73 [ -n "$BOXCMD" ] || die "box-init not called"
77 # Initialization of testing directories
81 pstart "Initializing... "
83 PDIR=problems/$PROBLEM
84 SDIR=solutions/$CONTESTANT/$PROBLEM
85 TDIR=testing/$CONTESTANT/$PROBLEM
87 [ -d $PDIR ] || die "Problem $PROBLEM not known"
88 [ -d $SDIR ] || fatal "Solution of $PROBLEM not found"
89 mkdir -p $TDIR $TMPDIR
91 mkdir -p $TDIR $TMPDIR
93 Testing solution of $PROBLEM by $CONTESTANT
94 Test started at `date`
95 Contestant's solution directory: $SDIR
96 Problem directory: $PDIR
97 Testing directory: $TDIR
102 # Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT
104 function locate-source
106 pstart "Finding source... "
108 for a in $EXTENSIONS ; do
109 if [ -f $SDIR/$SBASE.$a ] ; then
110 [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
115 [ -n "$SRCN" ] || fatal "NOT FOUND"
117 echo "Found source file: $SDIR/$SRCN"
120 # Compilation (compile SDIR/SRCN with PDIR/COMP_EXTRAS to EXE=TDIR/PROBLEM)
124 pstart "Compiling... "
125 cp -a $SDIR/$SRCN $TDIR/$SRCN
126 if [ -n "$COMP_EXTRAS" ] ; then
127 echo "Extras: $COMP_EXTRAS"
128 for a in $COMP_EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
131 for a in $SRCN $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
135 CCMD=`eval echo ${!CCMD}`
136 COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS`
137 echo "Compiler command: $CCMD"
138 echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
139 eval $COMP_SANDBOX_INIT
141 echo "Compiler input files:"
143 echo "Compiler output:"
144 if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
145 COMPILE_MSG="`cat $TDIR/compile.out`"
146 pend "FAILED: $COMPILE_MSG"
150 cat $TDIR/compile.out
152 echo "Compiler output files:"
154 if [ ! -f $BOXDIR/$PROBLEM ] ; then
155 pend "FAILED: Missing executable file"
156 echo "Missing executable file"
160 cp -a $BOXDIR/$PROBLEM $EXE
161 echo "Compiled OK, result copied to $EXE"
165 # Running of test program according to current task type (returns exit code and TEST_MSG)
176 if [ -s $TDIR/$TEST.pts ] ; then
177 P=`cat $TDIR/$TEST.pts`
189 echo "Executable file: $TDIR/$PROBLEM"
190 if [ ! -x $TDIR/$PROBLEM ] ; then
191 test-result 0 "Compile error."
193 cp $TDIR/$PROBLEM $BOXDIR/
195 IN_TYPE=${IN_TYPE:-$IO_TYPE}
196 OUT_TYPE=${OUT_TYPE:-$IO_TYPE}
198 file) echo "Input file: $PROBLEM.in (from $PDIR/$TEST.in)"
199 ln $PDIR/$TEST.in $TDIR/$TEST.in
200 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
201 BOX_EXTRAS="$BOX_EXTRAS -i/dev/null"
203 stdio) echo "Input file: <stdin> (from $PDIR/$TEST.in)"
204 ln $PDIR/$TEST.in $TDIR/$TEST.in
205 BOX_EXTRAS="$BOX_EXTRAS -i$TDIR/$TEST.in"
207 none) echo "Input file: <none>"
209 *) die "Unknown IN_TYPE $IN_TYPE"
213 file) echo "Output file: $PROBLEM.out"
214 BOX_EXTRAS="$BOX_EXTRAS -o/dev/null"
216 stdio) echo "Output file: <stdout>"
217 BOX_EXTRAS="$BOX_EXTRAS -o$TDIR/$TEST.out"
219 none) echo "Output file: <none>"
221 *) die "Unknown OUT_TYPE $OUT_TYPE"
224 echo "Timeout: $TIME_LIMIT s"
225 echo "Memory: $MEM_LIMIT KB"
227 echo "Sandbox contents before start:"
233 echo "Sandbox contents after exit:"
235 case ${OUT_TYPE:-$IO_TYPE} in
236 file) [ -f $BOXDIR/$PROBLEM.out ] || test-result 0 "No output file."
237 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
239 stdio) [ -f $TDIR/$TEST.out ] || test-result 0 "No output file."
244 # Running of test program with file input/output
246 function test-run-file
250 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS"
251 echo "Sandbox options: $BOXOPTS"
252 if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TMPDIR/exec.out ; then
254 MSG=`tail -1 $TMPDIR/exec.out`
261 # Running of interactive test programs
263 function test-run-interactive
267 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS"
268 echo "Sandbox options: $BOXOPTS"
269 ICCMD=`eval echo $IA_CHECK`
270 echo "Interactive checker: $ICCMD"
271 if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TMPDIR/exec.out ; then
273 MSG="`tail -1 $TMPDIR/exec.out`"
282 function syntax-check
284 [ -n "$SYNTAX_CHECK" ] || return 0
286 SCHECK=`eval echo $SYNTAX_CHECK`
287 echo "Syntax check command: $SCHECK"
288 if ! eval $SCHECK 2>$TMPDIR/exec.out ; then
290 MSG=`tail -1 $TMPDIR/exec.out`
291 if [ -z "$MSG" ] ; then MSG="Wrong syntax." ; fi
299 function output-check
301 [ -n "$OUTPUT_CHECK" ] || return 0
303 [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
304 OCHECK=`eval echo $OUTPUT_CHECK`
305 echo "Output check command: $OCHECK"
306 if ! eval $OCHECK 2>$TMPDIR/exec.out ; then
308 MSG=`tail -1 $TMPDIR/exec.out`
309 if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi
313 MSG=`tail -1 $TMPDIR/exec.out`
314 if [ -z "$MSG" ] ; then MSG="OK" ; fi
315 test-result $POINTS_PER_TEST "$MSG"
318 # Setup of public commands
320 function public-setup
323 PDIR=$MO_PUBLIC/problems/$PROBLEM
327 [ -d $PDIR ] || die "Unknown problem $PROBLEM"
329 pstart "Initializing... "
335 BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
337 pend "OK (see 'log' for details)"
340 # Locate output of open data problem, test case TEST
344 [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST"
345 SRCN=$SDIR/$PROBLEM$TEST.out
346 [ -f $SRCN ] || fatal "Output file $SRCN not found"