]> mj.ucw.cz Git - eval.git/commitdiff
...
authorMartin Mares <mj@ucw.cz>
Thu, 29 Mar 2001 14:00:55 +0000 (14:00 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 29 Mar 2001 14:00:55 +0000 (14:00 +0000)
TODO
bin/ev
bin/lib
bin/task-compile [deleted file]
bin/task-init [deleted file]
config
src/box.c

diff --git a/TODO b/TODO
index c62b4d625aabd4158bde4540af1885298cc4e4ac..fab6f883790b5f9bcafa910ea46f38bca7301f3e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +1,2 @@
 submit, compile, test (submit bez odevzdani)
+quotas
diff --git a/bin/ev b/bin/ev
index ed2dc6738f1d5ed68f59ecf950a45472290c2d7a..c25f97a7af9670e9716876efd71adbb68e22a05c 100755 (executable)
--- a/bin/ev
+++ b/bin/ev
@@ -2,39 +2,40 @@
 # (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"
@@ -43,20 +44,7 @@ for TEST in $TESTS ; do
                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"
diff --git a/bin/lib b/bin/lib
index e2caafac5afecb5349ac609c0cf175e29d3912b3..090e752a6dd5059cc13ce47cfb9fed0501add962 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -4,6 +4,12 @@
 # Logging functions.
 # File handles used: fd1=log, fd2=progress
 
+function log-init
+{
+       exec >>$TDIR/log
+       HAVE_LOG=1
+}
+
 function pstart
 {
        echo >&2 -n "$@"
@@ -30,8 +36,149 @@ function die
 
 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
+}
diff --git a/bin/task-compile b/bin/task-compile
deleted file mode 100644 (file)
index 740b6d0..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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"
diff --git a/bin/task-init b/bin/task-init
deleted file mode 100644 (file)
index 63d5da8..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# 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"
diff --git a/config b/config
index 74cfee52ecd7e59f3ccb9bf162451a349715a611..8115ea50e65c3aa1487c3f097defdedcce6c2013 100644 (file)
--- a/config
+++ b/config
@@ -7,11 +7,18 @@ EVAL_USER=mo-eval
 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'
index 12d3eb58b21f81331fdeffdeb336db2d033c68a7..2558a3eadea4aff9a4071c7cd2f86318ce45f9fa 100644 (file)
--- a/src/box.c
+++ b/src/box.c
@@ -201,6 +201,7 @@ valid_syscall(struct user *u)
     case SYS_mmap:
     case SYS_munmap:
     case SYS_ioctl:
+    case SYS_uname:
       return 1;
     case SYS_time:
     case SYS_alarm: