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/$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"
195 if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
196 pend "No output file."
197 echo "No output file."
198 echo >>$PTSFILE "0 No output."
201 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
204 # Running of interactive test programs
206 function test-run-interactive
210 echo "Executable file: $TDIR/$PROBLEM"
211 cp $TDIR/$PROBLEM $BOXDIR/
212 echo "Input: $TDIR/$PROBLEM"
213 ln $PDIR/$TEST.in $TDIR/$TEST.in
214 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
220 echo "Timeout: $TIME_LIMIT s"
221 echo "Memory: $MEM_LIMIT KB"
222 BOXOPTS=`eval echo $TEST_SANDBOX_OPTS`
223 echo "Sandbox options: $BOXOPTS"
224 ICCMD=`eval echo $IA_CHECK`
225 echo "Interactive checker: $ICCMD"
226 if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TDIR/exec.out ; then
227 TEST_MSG="`head -1 $TDIR/exec.out`"
232 echo >>$PTSFILE "0 $TEST_MSG"
241 function syntax-check
243 [ -n "$SYNTAX_CHECK" ] || return 0
245 SCHECK=`eval echo $SYNTAX_CHECK`
246 echo "Syntax check command: $SCHECK"
247 eval $SCHECK && return 0
250 echo >>$PTSFILE "0 Wrong syntax."
256 function output-check
258 [ -n "$OUTPUT_CHECK" ] || return 0
260 [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
261 OCHECK=`eval echo $OUTPUT_CHECK`
262 echo "Output check command: $OCHECK"
263 eval $OCHECK && return 0
266 echo >>$PTSFILE "0 Wrong answer."
270 # Setup of public commands
272 function public-setup
275 PDIR=$MO_PUBLIC/problems/$PROBLEM
278 [ -d $PDIR ] || die "Unknown problem $PROBLEM"
280 pstart "Initializing... "
286 BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
288 pend "OK (see 'log' for details)"
291 # Locate output of open data problem, test case TEST
295 [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST"
296 SRCN=$SDIR/$PROBLEM$TEST.out
297 [ -f $SRCN ] || die "Output file $SRCN not found"