1 # The Evaluator -- Shell Function Library
2 # (c) 2001 Martin Mares <mj@ucw.cz>
8 # File handles used: fd1=log, fd2=progress
34 [ -n "$HAVE_LOG" ] && echo "Fatal error: $@"
42 pstart "Preparing sandbox... "
43 [ -n "$TEST_USER" ] || die "TEST_USER not set. Please fix."
44 if [ $TEST_USER == $EVAL_USER ] ; then
45 pcont "running locally (INSECURE), "
50 pcont "used account $TEST_USER, "
51 BOXDIR=$MO_ROOT/eval/$TEST_USER
52 BOXCMD=bin/box-$TEST_USER
54 [ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
55 BOXCMD="$BOXCMD -c$BOXDIR"
56 echo "Sandbox directory: $BOXDIR"
57 echo "Sandbox command: $BOXCMD"
64 [ -n "$BOXCMD" ] || die "box-init not called"
68 # Initialization of testing directories
72 pstart "Initializing... "
74 PDIR=problems/$PROBLEM
75 SDIR=solutions/$CONTESTANT/$PROBLEM
76 TDIR=testing/$CONTESTANT/$PROBLEM
77 [ -d $PDIR ] || die "Problem $PROBLEM not known"
78 [ -d $SDIR ] || die "Solution of $PROBLEM not found"
83 Testing solution of $PROBLEM by $CONTESTANT
84 Test started at `date`
85 Contestant's solution directory: $SDIR
86 Problem directory: $PDIR
87 Testing directory: $TDIR
93 # Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT
95 function locate-source
97 pstart "Finding source... "
99 for a in $EXTENSIONS ; do
100 if [ -f $SDIR/$SBASE.$a ] ; then
101 [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
106 [ -n "$SRCN" ] || die "NOT FOUND"
108 echo "Found source file: $SDIR/$SRCN"
111 # Compilation (compile SDIR/SRCN with PDIR/EXTRAS to EXE=TDIR/PROBLEM)
115 pstart "Compiling... "
116 cp -a $SDIR/$SRCN $TDIR/$SRCN
117 if [ -n "$EXTRAS" ] ; then
118 echo "Extras: $EXTRAS"
119 for a in $EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
122 for a in $SRCN $EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
126 CCMD=`eval echo ${!CCMD}`
127 COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS`
128 echo "Compiler command: $CCMD"
129 echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
130 eval $COMP_SANDBOX_INIT
132 echo "Compiler input files:"
134 echo "Compiler output:"
135 if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
136 COMPILE_MSG="`cat $TDIR/compile.out`"
137 pend "FAILED: $COMPILE_MSG"
141 cat $TDIR/compile.out
143 echo "Compiler output files:"
145 if [ ! -f $BOXDIR/$PROBLEM ] ; then
146 pend "FAILED: Missing executable file"
147 echo "Missing executable file"
151 cp -a $BOXDIR/$PROBLEM $EXE
152 echo "Compiled OK, result copied to $EXE"
156 # Running of test program according to current task type
163 # Running of test program with file input/output
165 function test-run-file
169 echo "Executable file: $TDIR/$PROBLEM"
170 cp $TDIR/$PROBLEM $BOXDIR/
171 echo "Input: $TDIR/$PROBLEM"
172 ln $PDIR/$TEST.in $TDIR/$TEST.in
173 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
179 echo "Timeout: $TIME_LIMIT s"
180 echo "Memory: $MEM_LIMIT KB"
181 BOXOPTS=`eval echo $TEST_SANDBOX_OPTS`
182 echo "Sandbox options: $BOXOPTS"
183 if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TDIR/exec.out ; then
184 TEST_MSG="`head -1 $TDIR/exec.out`"
188 echo >>$PTSFILE "0 $TEST_MSG"
193 test-fetch-output || return 1
196 function test-fetch-output
200 if [ ! -f $BOXDIR/$PROBLEM.out ] ; then
201 pend "No output file."
202 echo "No output file."
203 echo >>$PTSFILE "0 No output."
206 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
209 # Running of interactive test programs
211 function test-run-interactive
215 echo "Executable file: $TDIR/$PROBLEM"
216 cp $TDIR/$PROBLEM $BOXDIR/
217 echo "Input: $TDIR/$PROBLEM"
218 ln $PDIR/$TEST.in $TDIR/$TEST.in
219 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
225 echo "Timeout: $TIME_LIMIT s"
226 echo "Memory: $MEM_LIMIT KB"
227 BOXOPTS=`eval echo $TEST_SANDBOX_OPTS`
228 echo "Sandbox options: $BOXOPTS"
229 ICCMD=`eval echo $IA_CHECK`
230 echo "Interactive checker: $ICCMD"
231 if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TDIR/exec.out ; then
232 TEST_MSG="`head -1 $TDIR/exec.out`"
237 echo >>$PTSFILE "0 $TEST_MSG"
242 [ -z "$OUTPUT_CHECK" ] || test-fetch-output || return 1
247 function syntax-check
249 [ -n "$SYNTAX_CHECK" ] || return 0
251 SCHECK=`eval echo $SYNTAX_CHECK`
252 echo "Syntax check command: $SCHECK"
253 eval $SCHECK && return 0
256 echo >>$PTSFILE "0 Wrong syntax."
262 function output-check
264 [ -n "$OUTPUT_CHECK" ] || return 0
266 [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
267 OCHECK=`eval echo $OUTPUT_CHECK`
268 echo "Output check command: $OCHECK"
269 eval $OCHECK && return 0
272 echo >>$PTSFILE "0 Wrong answer."
276 # Setup of public commands
278 function public-setup
281 PDIR=$MO_PUBLIC/problems/$PROBLEM
284 [ -d $PDIR ] || die "Unknown problem $PROBLEM"
286 pstart "Initializing... "
292 BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
294 pend "OK (see 'log' for details)"
297 # Locate output of open data problem, test case TEST
301 [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST"
302 SRCN=$SDIR/$PROBLEM$TEST.out
303 [ -f $SRCN ] || die "Output file $SRCN not found"