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... "
73 PDIR=problems/$PROBLEM
74 SDIR=solutions/$CONTESTANT/$PROBLEM
75 TDIR=testing/$CONTESTANT/$PROBLEM
76 [ -d $PDIR ] || die "Problem $PROBLEM not known"
77 [ -d $SDIR ] || die "Solution of $PROBLEM not found"
82 Testing solution of $PROBLEM by $CONTESTANT
83 Test started at `date`
84 Contestant's solution directory: $SDIR
85 Problem directory: $PDIR
86 Testing directory: $TDIR
92 # Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT
94 function locate-source
96 pstart "Finding source... "
97 for a in $EXTENSIONS ; do
98 if [ -f $SDIR/$PROBLEM.$a ] ; then
99 [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
104 [ -n "$SRCN" ] || die "NOT FOUND"
106 echo "Found source file: $SDIR/$SRCN"
109 # Compilation (compile SDIR/SRCN with PDIR/EXTRAS to EXE=TDIR/PROBLEM)
113 pstart "Compiling... "
114 cp -a $SDIR/$SRCN $TDIR/$SRCN
115 if [ -n "$EXTRAS" ] ; then
116 echo "Extras: $EXTRAS"
117 for a in $EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
120 for a in $SRCN $EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
124 CCMD="`eval echo ${!CCMD}`"
125 COMP_SANDBOX_OPTS="`eval echo $COMP_SANDBOX_OPTS`"
126 echo "Compiler command: $CCMD"
127 echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
129 echo "Compiler input files:"
131 echo "Compiler output:"
132 if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
133 COMPILE_MSG="`cat $TDIR/compile.out`"
134 pend "FAILED: $COMPILE_MSG"
138 cat $TDIR/compile.out
140 echo "Compiler output files:"
142 if [ ! -f $BOXDIR/$PROBLEM ] ; then
143 pend "FAILED: Missing executable file"
144 echo "Missing executable file"
148 cp -a $BOXDIR/$PROBLEM $EXE
149 echo "Compiled OK, result copied to $EXE"
153 # Running of test program with file input/output
159 echo "Executable file: $TDIR/$PROBLEM"
160 cp $TDIR/$PROBLEM $BOXDIR/
161 echo "Input: $TDIR/$PROBLEM"
162 ln $PDIR/$TEST.in $TDIR/$TEST.in
163 cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
168 echo "Timeout: $TIME_LIMIT s"
169 echo "Memory: $MEM_LIMIT KB"
170 BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`"
171 echo "Sandbox options: $BOXOPTS"
172 if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TDIR/exec.out ; then
173 TEST_MSG="`cat $TDIR/exec.out`"
176 echo >>$PTSFILE "0 $TEST_MSG"
183 if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
184 pend "No output file."
185 echo "No output file."
186 echo >>$PTSFILE "0 No output."
189 cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
194 function syntax-check
196 [ -n "$SYNTAX_CHECK" ] || return 0
198 SCHECK="`eval echo $SYNTAX_CHECK`"
199 echo "Syntax check command: $SCHECK"
203 echo >>$PTSFILE "0 Wrong syntax."
209 function output-check
212 ln $PDIR/$TEST.out $TDIR/$TEST.ok
213 OCHECK="`eval echo $OUTPUT_CHECK`"
214 echo "Output check command: $OCHECK"
218 echo >>$PTSFILE "0 Wrong answer."
222 # Setup of public commands
224 function public-setup
226 PDIR=$MO_PUBLIC/problems/$PROBLEM
229 [ -d $PDIR ] || die "Unknown problem $PROBLEM"
231 pstart "Initializing... "
237 BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR"
239 pend "OK (see 'log' for details)"