1 # The Evaluator -- Shell Function Library
2 # (c) 2001 Martin Mares <mj@ucw.cz>
5 # File handles used: fd1=log, fd2=progress
31 [ -n "$HAVE_LOG" ] && echo "Fatal error: $@"
39 pstart "Preparing sandbox... "
40 [ -n "$TEST_USER" ] || die "TEST_USER not set. Please fix."
41 if [ $TEST_USER == $EVAL_USER ] ; then
42 pcont "running locally (INSECURE), "
47 pcont "used account $TEST_USER, "
48 BOXDIR=$MO_ROOT/$TEST_USER
49 BOXCMD=bin/box-$TEST_USER
51 [ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
52 BOXCMD="$BOXCMD -c$BOXDIR"
53 echo "Sandbox directory: $BOXDIR"
54 echo "Sandbox command: $BOXCMD"
61 [ -n "$BOXCMD" ] || die "box-init not called"
65 # Initialization of testing directories
69 pstart "Initializing... "
70 PDIR=problems/$PROBLEM
71 SDIR=solutions/$CONTESTANT/$PROBLEM
72 TDIR=testing/$CONTESTANT/$PROBLEM
73 [ -d $PDIR ] || die "Problem $PROBLEM not known"
74 [ -d $SDIR ] || die "Solution of $PROBLEM not found"
79 Testing solution of $PROBLEM by $CONTESTANT
80 Test started at `date`
81 Contestant's solution directory: $SDIR
82 Problem directory: $PDIR
83 Testing directory: $TDIR
89 # Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT
91 function locate-source
93 pstart "Locating source... "
94 for a in $EXTENSIONS ; do
95 if [ -f $SDIR/$PROBLEM.$a ] ; then
96 [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
101 [ -n "$SRCN" ] || die "NOT FOUND"
103 echo "Found source file: $SDIR/$SRCN"
106 # Compilation (compile SDIR/SRCN with PDIR/EXTRAS to EXE=TDIR/PROBLEM)
110 pstart "Compiling... "
111 cp -a $SDIR/$SRCN $TDIR/$SRCN
112 if [ -n "$EXTRAS" ] ; then
113 echo "Extras: $EXTRAS"
114 for a in $EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
117 for a in $SRCN $EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
121 CCMD="`eval echo ${!CCMD}`"
122 COMP_SANDBOX_OPTS="`eval echo $COMP_SANDBOX_OPTS`"
123 echo "Compiler command: $CCMD"
124 echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
126 echo "Compiler input files:"
128 if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
129 COMPILE_MSG="`cat $TDIR/compile.out`"
130 pend "FAILED: $COMPILE_MSG"
134 cat $TDIR/compile.out
136 echo "Compiler output files:"
138 if [ ! -f $BOXDIR/$PROBLEM ] ; then
139 pend "FAILED: Missing executable file"
140 echo "Missing executable file"
144 cp -a $BOXDIR/$PROBLEM $EXE
145 echo "Compiled OK, result copied to $EXE"
149 # Running of test program with file input/output
151 function test-run-with-files
155 echo "Executable file: $TDIR/$PROBLEM"
156 cp $TDIR/$PROBLEM $BOXDIR/
157 echo "Input: $TDIR/$PROBLEM"
158 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
163 echo "Timeout: $TIME_LIMIT s"
164 echo "Memory: $MEM_LIMIT KB"
165 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`"
166 echo "Sandbox options: $BOXOPTS"
167 if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TDIR/exec.out ; then
168 TEST_MSG="`cat $TDIR/exec.out`"
171 echo >$PTSFILE "0 $TEST_MSG"
178 if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
179 pend "No output file."
180 echo "No output file."
181 echo >$PTSFILE "0 No output."
184 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
189 function syntax-check
191 [ -n "$SYNTAX_CHECK" ] || return 0
193 SCHECK="`eval echo $SYNTAX_CHECK`"
194 echo "Syntax check command: $SCHECK"
198 echo >$PTSFILE "0 Wrong syntax."
204 function output-check
207 ln $PDIR/$TEST.out $TDIR/$TEST.ok
208 OCHECK="`eval echo $OUTPUT_CHECK`"
209 echo "Output check command: $OCHECK"
213 echo >$PTSFILE "0 Wrong answer."