]> mj.ucw.cz Git - moe.git/blobdiff - bin/lib
Added.
[moe.git] / bin / lib
diff --git a/bin/lib b/bin/lib
index aa7b4cfff04b88da71420a6d4910033cd0c1fe08..537bf58764c8d81ed514e65bf49d1c71b3967c97 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -48,7 +48,7 @@ function box-init
                mkdir -p box
        else
                pcont "used account $TEST_USER, "
-               BOXDIR=$MO_ROOT/$TEST_USER
+               BOXDIR=$MO_ROOT/eval/$TEST_USER
                BOXCMD=bin/box-$TEST_USER
        fi
        [ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
@@ -70,6 +70,7 @@ function box-clean
 function dir-init
 {
        pstart "Initializing... "
+       HDIR=.
        PDIR=problems/$PROBLEM
        SDIR=solutions/$CONTESTANT/$PROBLEM
        TDIR=testing/$CONTESTANT/$PROBLEM
@@ -122,10 +123,11 @@ function compile
        SRC=$SRCN
        EXE=$PROBLEM
        CCMD=COMP_$SRCEXT
-       CCMD="`eval echo ${!CCMD}`"
-       COMP_SANDBOX_OPTS="`eval echo $COMP_SANDBOX_OPTS`"
+       CCMD=`eval echo ${!CCMD}`
+       COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS`
        echo "Compiler command: $CCMD"
        echo "Compiler sandbox options: $COMP_SANDBOX_OPTS"
+       eval $COMP_SANDBOX_INIT
 
        echo "Compiler input files:"
        ls -Al $BOXDIR
@@ -151,9 +153,16 @@ function compile
        pend "OK"
 }
 
-# Running of test program with file input/output
+# Running of test program according to current task type
 
 function test-run
+{
+       test-run-$TASK_TYPE
+}
+
+# Running of test program with file input/output
+
+function test-run-file
 {
        pcont "<init> "
        box-clean
@@ -162,26 +171,33 @@ function test-run
        echo "Input: $TDIR/$PROBLEM"
        ln $PDIR/$TEST.in $TDIR/$TEST.in
        cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
+       eval $SANDBOX_INIT
        echo "Input files:"
        ls -Al $BOXDIR
 
        pcont "<run> "
        echo "Timeout: $TIME_LIMIT s"
        echo "Memory: $MEM_LIMIT KB"
-       BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`"
+       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`"
+               TEST_MSG="`head -1 $TDIR/exec.out`"
                pend "$TEST_MSG"
-               echo "$TEST_MSG"
+               cat $TDIR/exec.out
+               rm $TDIR/exec.out
                echo >>$PTSFILE "0 $TEST_MSG"
                return 1
        fi
        cat $TDIR/exec.out
        rm $TDIR/exec.out
+       test-fetch-output || return 1
+}
+
+function test-fetch-output
+{
        echo "Output files:"
        ls -Al $BOXDIR
-       if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
+       if [ ! -f $BOXDIR/$PROBLEM.out ] ; then
                pend "No output file."
                echo "No output file."
                echo >>$PTSFILE "0 No output."
@@ -190,15 +206,51 @@ function test-run
        cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
 }
 
+# Running of interactive test programs
+
+function test-run-interactive
+{
+       pcont "<init> "
+       box-clean
+       echo "Executable file: $TDIR/$PROBLEM"
+       cp $TDIR/$PROBLEM $BOXDIR/
+       echo "Input: $TDIR/$PROBLEM"
+       ln $PDIR/$TEST.in $TDIR/$TEST.in
+       cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in
+       eval $SANDBOX_INIT
+       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"
+       ICCMD=`eval echo $IA_CHECK`
+       echo "Interactive checker: $ICCMD"
+       if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TDIR/exec.out ; then
+               TEST_MSG="`head -1 $TDIR/exec.out`"
+               pend "$TEST_MSG"
+               cat $TDIR/exec.out
+               rm $TDIR/exec.out
+               echo "$TEST_MSG"
+               echo >>$PTSFILE "0 $TEST_MSG"
+               return 1
+       fi
+       cat $TDIR/exec.out
+       rm $TDIR/exec.out
+       [ -z "$OUTPUT_CHECK" ] || test-fetch-output || return 1
+}
+
 # Syntax checks
 
 function syntax-check
 {
        [ -n "$SYNTAX_CHECK" ] || return 0
        pcont "<syntax> "
-       SCHECK="`eval echo $SYNTAX_CHECK`"
+       SCHECK=`eval echo $SYNTAX_CHECK`
        echo "Syntax check command: $SCHECK"
-       $SCHECK && return 0
+       eval $SCHECK && return 0
        pend "Wrong syntax."
        echo "Wrong syntax."
        echo >>$PTSFILE "0 Wrong syntax."
@@ -209,11 +261,12 @@ function syntax-check
 
 function output-check
 {
+       [ -n "$OUTPUT_CHECK" ] || return 0
        pcont "<check> "
-       ln $PDIR/$TEST.out $TDIR/$TEST.ok
-       OCHECK="`eval echo $OUTPUT_CHECK`"
+       [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok
+       OCHECK=`eval echo $OUTPUT_CHECK`
        echo "Output check command: $OCHECK"
-       $OCHECK && return 0
+       eval $OCHECK && return 0
        pend "Wrong answer."
        echo "Wrong answer."
        echo >>$PTSFILE "0 Wrong answer."
@@ -224,6 +277,7 @@ function output-check
 
 function public-setup
 {
+       HDIR=$MO_PUBLIC
        PDIR=$MO_PUBLIC/problems/$PROBLEM
        SDIR=.
        TDIR=~/.test
@@ -239,3 +293,12 @@ function public-setup
        exec >log
        pend "OK  (see 'log' for details)"
 }
+
+# Locate output of open data problem, test case TEST
+
+function open-locate
+{
+       [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST"
+       SRCN=$SDIR/$PROBLEM$TEST.out
+       [ -f $SRCN ] || die "Output file $SRCN not found"
+}