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 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
206 BOX_EXTRAS="$BOX_EXTRAS -i$PROBLEM.in"
208 none) echo "Input file: <none>"
210 *) die "Unknown IN_TYPE $IN_TYPE"
214 file) echo "Output file: $PROBLEM.out"
215 BOX_EXTRAS="$BOX_EXTRAS -o/dev/null"
217 stdio) echo "Output file: <stdout>"
218 BOX_EXTRAS="$BOX_EXTRAS -o$PROBLEM.out"
220 none) echo "Output file: <none>"
222 *) die "Unknown OUT_TYPE $OUT_TYPE"
225 echo "Timeout: $TIME_LIMIT s"
226 echo "Memory: $MEM_LIMIT KB"
228 echo "Sandbox contents before start:"
234 echo "Sandbox contents after exit:"
236 case ${OUT_TYPE:-$IO_TYPE} in
237 file) [ -f $BOXDIR/$PROBLEM.out ] || test-result 0 "No output file."
238 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
240 stdio) [ -f $BOXDIR/$PROBLEM.out ] || test-result 0 "No output file."
241 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
246 # Running of test program with file input/output
248 function test-run-file
252 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS"
253 echo "Sandbox options: $BOXOPTS"
254 if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TMPDIR/exec.out ; then
255 MSG=`head -1 $TMPDIR/exec.out`
262 # Running of interactive test programs
264 function test-run-interactive
268 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS"
269 echo "Sandbox options: $BOXOPTS"
270 ICCMD=`eval echo $IA_CHECK`
271 echo "Interactive checker: $ICCMD"
272 if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TMPDIR/exec.out ; then
273 MSG="`head -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
289 MSG=`head -1 $TMPDIR/exec.out`
290 if [ -z "$MSG" ] ; then MSG="Wrong syntax." ; fi
298 function output-check
300 [ -n "$OUTPUT_CHECK" ] || return 0
302 [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
303 OCHECK=`eval echo $OUTPUT_CHECK`
304 echo "Output check command: $OCHECK"
305 if ! eval $OCHECK 2>$TMPDIR/exec.out ; then
306 MSG=`head -1 $TMPDIR/exec.out`
307 if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi
310 MSG=`head -1 $TMPDIR/exec.out`
311 if [ -z "$MSG" ] ; then MSG="OK" ; fi
312 test-result $POINTS_PER_TEST "$MSG"
315 # Setup of public commands
317 function public-setup
320 PDIR=$MO_PUBLIC/problems/$PROBLEM
324 [ -d $PDIR ] || die "Unknown problem $PROBLEM"
326 pstart "Initializing... "
332 BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
334 pend "OK (see 'log' for details)"
337 # Locate output of open data problem, test case TEST
341 [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST"
342 SRCN=$SDIR/$PROBLEM$TEST.out
343 [ -f $SRCN ] || fatal "Output file $SRCN not found"