submit, compile, test (submit bez odevzdani)
+quotas
# (c) 2001 Martin Mares <mj@ucw.cz>
set -e
-cd
+if [ ! -f config -o ! -f bin/lib ] ; then
+ echo "Unable to find evaluator files!"
+ exit 1
+fi
. bin/lib
. config
-[ -n "$TEST_USER" ] || die "TEST_USER not set. Please fix."
-[ -d $MO_ROOT/$TEST_USER ] || die "TEST_USER set incorrectly. Please fix."
+
+# Set up environment:
+# PDIR problem specific data
+# SDIR contestant's solution
+# TDIR test results
+# BOXDIR sandbox
+# PROBLEM problem we're evaluating
+
[ -n "$2" ] || die "Usage: ev <contestant> <problem>"
-CT=$1
+CONTESTANT=$1
PROBLEM=$2
-. bin/lib
-
-# Initialize the testing directory
-echo >&2 "Testing contestant $CT, problem $PROBLEM"
-echo >&2
-PDIR=problems/$PROBLEM
-SDIR=solutions/$CT/$PROBLEM
-TDIR=testing/$CT/$PROBLEM
-. bin/task-init
+dir-init
+log-init
. $PDIR/config
+box-init
-# Set up logging
-exec >>$TDIR/log
-HAVE_LOG=1
-
-# Compile the solution
-( . bin/task-compile )
+# Compile the program
+locate-source
+compile
# Perform the tests
for TEST in $TESTS ; do
(
- pstart "Test $TEST: "
+ pstart "Test $TEST... "
[ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
exec >$TDIR/$TEST.log
PTSFILE=$TDIR/$TEST.pts
+ echo "Test $TEST ($POINTS_PER_TEST points)"
if [ ! -f $TDIR/compile.out ] ; then
echo >$PTSFILE "0 --"
die "No source file"
echo >$PTSFILE "0 CE"
die "No executable file"
fi
- pcont "<init> "
- box-init
- echo "Executable file: $TDIR/$PROBLEM"
- cp $TDIR/$PROBLEM $BOXDIR/
- echo "Input: $TDIR/$PROBLEM"
- cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
- echo "Input files:"
- ls -Al $BOXDIR
- echo "Timeout: $TIME_LIMIT s"
- echo "Memory: $MEM_LIMIT KB"
- BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`"
- echo "Sandbox options: $BOXOPTS"
-
- pcont "<run> "
+ $TEST_RUN_METHOD || exit 0
echo "Test completed OK ($POINTS_PER_TEST points)"
echo >$PTSFILE "$POINTS_PER_TEST OK"
# Logging functions.
# File handles used: fd1=log, fd2=progress
+function log-init
+{
+ exec >>$TDIR/log
+ HAVE_LOG=1
+}
+
function pstart
{
echo >&2 -n "$@"
function box-init
{
- BOXDIR=$MO_ROOT/$TEST_USER
- BOXCMD=bin/box-$TEST_USER
+ pstart "Preparing sandbox... "
+ [ -n "$TEST_USER" ] || die "TEST_USER not set. Please fix."
+ if [ $TEST_USER == $EVAL_USER ] ; then
+ pcont "running locally (INSECURE), "
+ BOXDIR=box
+ BOXCMD=bin/box
+ mkdir -p box
+ else
+ pcont "used account $TEST_USER, "
+ BOXDIR=$MO_ROOT/$TEST_USER
+ BOXCMD=bin/box-$TEST_USER
+ fi
[ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
+ BOXCMD="$BOXCMD -c$BOXDIR"
+ echo "Sandbox directory: $BOXDIR"
+ echo "Sandbox command: $BOXCMD"
+ box-clean
+ pend "OK"
+}
+
+function box-clean
+{
+ [ -n "$BOXCMD" ] || die "box-init not called"
+ # FIXME: Dot files
rm -rf $BOXDIR/*
}
+
+# Initialization of testing directories
+
+function dir-init
+{
+ pstart "Initializing... "
+ PDIR=problems/$PROBLEM
+ SDIR=solutions/$CONTESTANT/$PROBLEM
+ TDIR=testing/$CONTESTANT/$PROBLEM
+ [ -d $PDIR ] || die "Problem $PROBLEM not known"
+ [ -d $SDIR ] || die "Solution of $PROBLEM not found"
+ mkdir -p $TDIR
+ rm -rf $TDIR
+ cp -a $SDIR $TDIR
+ cat >$TDIR/log <<EOF
+Testing solution of $PROBLEM by $CONTESTANT
+Test started at `date`
+Contestant's solution directory: $SDIR
+Problem directory: $PDIR
+Testing directory: $TDIR
+EOF
+ >$TDIR/points
+ pend "OK"
+}
+
+# Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT
+
+function locate-source
+{
+ pstart "Locating source... "
+ for a in $EXTENSIONS ; do
+ if [ -f $SDIR/$PROBLEM.$a ] ; then
+ [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix."
+ SRCN=$PROBLEM.$a
+ SRCEXT=$a
+ fi
+ done
+ [ -n "$SRCN" ] || die "NOT FOUND"
+ pend $SRCN
+ echo "Found source file: $SDIR/$SRCN"
+}
+
+# Compilation (compile SDIR/SRCN with PDIR/EXTRAS to EXE=TDIR/PROBLEM)
+
+function compile
+{
+ pstart "Compiling... "
+ cp -a $SDIR/$SRCN $TDIR/$SRCN
+ if [ -n "$EXTRAS" ] ; then
+ echo "Extras: $EXTRAS"
+ for a in $EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
+ fi
+ box-clean
+ for a in $SRCN $EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
+ SRC=$SRCN
+ EXE=$PROBLEM
+ CCMD=COMP_$SRCEXT
+ CCMD="`eval echo ${!CCMD}`"
+ COMP_SANDBOX_OPTS="`eval echo $COMP_SANDBOX_OPTS`"
+ echo "Compiler command: $CCMD"
+ echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
+
+ echo "Compiler input files:"
+ ls -Al $BOXDIR
+ if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
+ COMPILE_MSG="`cat $TDIR/compile.out`"
+ pend "FAILED: $COMPILE_MSG"
+ echo "$COMPILE_MSG"
+ return 1
+ fi
+ cat $TDIR/compile.out
+ echo "Compiler output files:"
+ ls -Al $BOXDIR
+ if [ ! -f $BOXDIR/$PROBLEM ] ; then
+ pend "FAILED: Missing executable file"
+ echo "Missing executable file"
+ return 1
+ fi
+ EXE=$TDIR/$PROBLEM
+ cp -a $BOXDIR/$PROBLEM $EXE
+ echo "Compiled OK, result copied to $EXE"
+ pend "OK"
+}
+
+# Running of test program with file input/output
+
+function test-run-with-files
+{
+ pcont "<init> "
+ box-clean
+ echo "Executable file: $TDIR/$PROBLEM"
+ cp $TDIR/$PROBLEM $BOXDIR/
+ echo "Input: $TDIR/$PROBLEM"
+ cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
+ echo "Input files:"
+ ls -Al $BOXDIR
+
+ pcont "<run> "
+ echo "Timeout: $TIME_LIMIT s"
+ echo "Memory: $MEM_LIMIT KB"
+ BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`"
+ echo "Sandbox options: $BOXOPTS"
+ if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TDIR/exec.out ; then
+ TEST_MSG="`cat $TDIR/exec.out`"
+ pend "$TEST_MSG"
+ echo "$TEST_MSG"
+ # FIXME: Better recognition of run-time errors
+ echo >$PTSFILE "0 RT"
+ return 1
+ fi
+ echo "Output files:"
+ ls -Al $BOXDIR
+ if [ ! -f $BOXDIR/$PROBLEM.out ] ; then
+ pend "No output file."
+ echo "No output file."
+ echo >$PTSFILE "0 NO"
+ return 1
+ fi
+ cp $BOXDIR/$PROBLEM.out $TDIR/$PROBLEM.out
+}
+++ /dev/null
-# The Evaluator -- Compile a Solution
-# (c) 2001 Martin Mares <mj@ucw.cz>
-
-pstart "Locating source... "
-if [ -f $SDIR/$PROBLEM.c ] ; then
- SRCN=$PROBLEM.c
- LANG=C
-elif [ -f $SDIR/$PROBLEM.cc ] ; then
- SRCN=$PROBLEM.cc
- LANG=CXX
-elif [ -f $SDIR/$PROBLEM.p ] ; then
- SRCN=$PROBLEM.p
- LANG=P
-else
- pend "NOT FOUND"
- echo "Source not found."
- exit 0
-fi
-box-init
-echo "Source file: $TDIR/$SRCN copied from $SDIR/$SRCN"
-
-cp $SDIR/$SRCN $TDIR/$SRCN
-if [ -n "$EXTRAS" ] ; then
- echo "Extras: $EXTRAS"
- for a in $EXTRAS ; do cp $PDIR/$a $TDIR/ ; done
-fi
-for a in $SRCN $EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done
-echo "Language: $LANG"
-SRC=$SRCN
-EXE=$PROBLEM
-CCMD=COMP_$LANG
-CCMD="`eval echo ${!CCMD}`"
-COMP_SANDBOX_OPTS="`eval echo $COMP_SANDBOX_OPTS`"
-echo "Compiler command: $CCMD"
-echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
-pend "$SRC ($LANG)"
-
-pstart "Compiling... "
-echo "Pre-compile:"
-ls -Al $BOXDIR
-if ! $BOXCMD $COMP_SANDBOX_OPTS -- $CCMD 2>$TDIR/compile.out ; then
- COMPILE_MSG=`cat $TDIR/compile.out`
- pend "FAILED: $COMPILE_MSG"
- echo "$COMPILE_MSG"
- exit 0
-fi
-cat $TDIR/compile.out
-if [ ! -f $BOXDIR/$PROBLEM ] ; then
- pend "FAILED: Missing executable file"
- echo "Missing executable file"
- exit 0
-fi
-EXE=$TDIR/$PROBLEM
-cp -a $BOXDIR/$PROBLEM $EXE
-echo "Compiled OK."
-ls -Al $BOXDIR
-echo "Executable file: $EXE"
-pend "OK"
+++ /dev/null
-# The Evaluator -- Initialize Task Directory
-# (c) 2001 Martin Mares <mj@ucw.cz>
-
-pstart "Initializing... "
-[ -d $PDIR ] || die "Problem not found"
-[ -d $SDIR ] || die "Solution not found"
-mkdir -p $TDIR
-rm -rf $TDIR
-cp -a $SDIR $TDIR
-cat >$TDIR/log <<EOF
-Contestant: $CT
-Problem: $PROBLEM
-Contestant's solution directory: $SDIR
-Problem directory: $PDIR
-Testing directory: $TDIR
-EOF
->$TDIR/points
-pend "OK"
EVAL_GROUP=mo-eval
TEST_USERS="mo-test1 mo-test2"
+# Currently used test user
+TEST_USER=mo-eval
+
# Compilation commands
-COMP_C='/usr/bin/gcc -o $EXE $SRC'
-COMP_CXX='/usr/bin/g++ -o $EXE $SRC'
-COMP_P='/usr/bin/fpc -o $EXE $SRC'
-COMP_SANDBOX_OPTS='-c$BOXDIR -m65536 -t60 -w -e'
+EXTENSIONS="c C cpp p pas"
+COMP_c='/usr/bin/gcc -o $EXE $SRC'
+COMP_C='/usr/bin/g++ -o $EXE $SRC'
+COMP_cpp="$COMP_C"
+COMP_p='/usr/bin/fpc -o $EXE $SRC'
+COMP_pas="$COMP_p"
+COMP_SANDBOX_OPTS='-m65536 -t60 -w -e'
# Testing commands
-TEST_SANDBOX_OPTS='-a2 -c$BOXDIR -f -m$MEM_LIMIT -t$TIME_LIMIT -w'
+TEST_RUN_METHOD="test-run-with-files"
+TEST_SANDBOX_OPTS='-a2 -f -m$MEM_LIMIT -t$TIME_LIMIT -w'
case SYS_mmap:
case SYS_munmap:
case SYS_ioctl:
+ case SYS_uname:
return 1;
case SYS_time:
case SYS_alarm: