]> mj.ucw.cz Git - eval.git/commitdiff
Basically works.
authorMartin Mares <mj@ucw.cz>
Thu, 29 Mar 2001 18:15:15 +0000 (18:15 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 29 Mar 2001 18:15:15 +0000 (18:15 +0000)
TODO
bin/ev
bin/lib
config
examples/problems/sum/config
src/box.c

diff --git a/TODO b/TODO
index fab6f883790b5f9bcafa910ea46f38bca7301f3e..d9fbb8705e98c74b2807d5f549ec7dfc86d6ae6e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,2 +1,4 @@
 submit, compile, test (submit bez odevzdani)
+check pascal
+-static ?
 quotas
diff --git a/bin/ev b/bin/ev
index c25f97a7af9670e9716876efd71adbb68e22a05c..0a462bf40f4a0a56689f85b4641b2847be2c4030 100755 (executable)
--- a/bin/ev
+++ b/bin/ev
@@ -31,21 +31,18 @@ compile
 # Perform the tests
 for TEST in $TESTS ; do
        (
-       pstart "Test $TEST... "
        [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config
        exec >$TDIR/$TEST.log
        PTSFILE=$TDIR/$TEST.pts
+       pstart "Test $TEST ($POINTS_PER_TEST points)... "
        echo "Test $TEST ($POINTS_PER_TEST points)"
-       if [ ! -f $TDIR/compile.out ] ; then
-               echo >$PTSFILE "0 --"
-               die "No source file"
-       fi
        if [ ! -f $TDIR/$PROBLEM ] ; then
-               echo >$PTSFILE "0 CE"
+               echo >$PTSFILE "0 Compile error."
                die "No executable file"
        fi
        $TEST_RUN_METHOD || exit 0
-
+       syntax-check || exit 0
+       output-check || exit 0
        echo "Test completed OK ($POINTS_PER_TEST points)"
        echo >$PTSFILE "$POINTS_PER_TEST OK"
        pend "OK"
diff --git a/bin/lib b/bin/lib
index 090e752a6dd5059cc13ce47cfb9fed0501add962..e61cce29cefe24ecc520ef3a2571ed546349dbb8 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -59,7 +59,6 @@ function box-init
 function box-clean
 {
        [ -n "$BOXCMD" ] || die "box-init not called"
-       # FIXME: Dot files
        rm -rf $BOXDIR/*
 }
 
@@ -133,6 +132,7 @@ function compile
                return 1
        fi
        cat $TDIR/compile.out
+       rm $TDIR/compile.out
        echo "Compiler output files:"
        ls -Al $BOXDIR
        if [ ! -f $BOXDIR/$PROBLEM ] ; then
@@ -168,17 +168,48 @@ function test-run-with-files
                TEST_MSG="`cat $TDIR/exec.out`"
                pend "$TEST_MSG"
                echo "$TEST_MSG"
-               # FIXME: Better recognition of run-time errors
-               echo >$PTSFILE "0 RT"
+               echo >$PTSFILE "0 $TEST_MSG"
                return 1
        fi
+       cat $TDIR/exec.out
+       rm $TDIR/exec.out
        echo "Output files:"
        ls -Al $BOXDIR
-       if [ ! -f $BOXDIR/$PROBLEM.out ] ; then
+       if [ ! -s $BOXDIR/$PROBLEM.out ] ; then
                pend "No output file."
                echo "No output file."
-               echo >$PTSFILE "0 NO"
+               echo >$PTSFILE "0 No output."
                return 1
        fi
-               cp $BOXDIR/$PROBLEM.out $TDIR/$PROBLEM.out
+       cp $BOXDIR/$PROBLEM.out $TDIR/$TEST.out
+}
+
+# Syntax checks
+
+function syntax-check
+{
+       [ -n "$SYNTAX_CHECK" ] || return 0
+       pcont "<syntax> "
+       SCHECK="`eval echo $SYNTAX_CHECK`"
+       echo "Syntax check command: $SCHECK"
+       $SCHECK && return 0
+       pend "Wrong syntax."
+       echo "Wrong syntax."
+       echo >$PTSFILE "0 Wrong syntax."
+       return 1
+}
+
+# Output checks
+
+function output-check
+{
+       pcont "<check> "
+       ln $PDIR/$TEST.out $TDIR/$TEST.ok
+       OCHECK="`eval echo $OUTPUT_CHECK`"
+       echo "Output check command: $OCHECK"
+       $OCHECK && return 0
+       pend "Wrong answer."
+       echo "Wrong answer."
+       echo >$PTSFILE "0 Wrong answer."
+       return 1
 }
diff --git a/config b/config
index 8115ea50e65c3aa1487c3f097defdedcce6c2013..edc6da2a3023c021845404b5545d1d4d99190386 100644 (file)
--- a/config
+++ b/config
@@ -10,15 +10,24 @@ TEST_USERS="mo-test1 mo-test2"
 # Currently used test user
 TEST_USER=mo-eval
 
-# Compilation commands
+### all of the following variables can be overriden in per-task config file
+
+# Known source file extensions
 EXTENSIONS="c C cpp p pas"
+
+# For each source extension, we must give compiler command
 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"
+
+# Sandbox options used when compiling
 COMP_SANDBOX_OPTS='-m65536 -t60 -w -e'
 
-# Testing commands
+# Shell command used to run the tests
 TEST_RUN_METHOD="test-run-with-files"
+
+# Sandbox options used when testing
 TEST_SANDBOX_OPTS='-a2 -f -m$MEM_LIMIT -t$TIME_LIMIT -w'
+# For stdio tasks append '-i$PROBLEM.in -o$PROBLEM.out'
index 6cd4c6dd7911498915f997726f972ca16da9aa06..9bcc2bc2602e6a3e712fc8e8808b4a923ae790f6 100644 (file)
@@ -1,8 +1,23 @@
 # Per-task config
+# All variables can be overriden in test-specific <test>.config
 
+# A list of all tests
 TESTS="1 2"
+
+# Number of points per test
 POINTS_PER_TEST=1
+
+# List of extra files needed for compilation
 EXTRAS="extras.h"
-TEST_EXTRAS="extras.h"
+
+# Time limit in seconds
 TIME_LIMIT=10
+
+# Memory limit in kilobytes
 MEM_LIMIT=16384
+
+# Command used to check output syntax (optional)
+SYNTAX_CHECK='grep -v -- - $TDIR/$TEST.out'
+
+# Command used to check output correctness
+OUTPUT_CHECK='diff -bBu $TDIR/$TEST.ok $TDIR/$TEST.out'
index 2558a3eadea4aff9a4071c7cd2f86318ce45f9fa..b76fd8a06037a8fc8fa34e3d8f9cb6b1cb40fb1c 100644 (file)
--- a/src/box.c
+++ b/src/box.c
@@ -35,6 +35,7 @@ static int use_wall_clock;
 static int file_access;
 static int verbose;
 static int memory_limit;
+static char *redir_stdin, *redir_stdout;
 
 static pid_t box_pid;
 static int is_ptraced;
@@ -419,6 +420,18 @@ box_inside(int argc, char **argv)
 
   memcpy(args, argv, argc * sizeof(char *));
   args[argc] = NULL;
+  if (redir_stdin)
+    {
+      close(0);
+      if (open(redir_stdin, O_RDONLY) != 0)
+       die("open(\"%s\"): %m", redir_stdin);
+    }
+  if (redir_stdout)
+    {
+      close(1);
+      if (open(redir_stdout, O_WRONLY | O_CREAT | O_TRUNC, 0666) != 1)
+       die("open(\"%s\"): %m", redir_stdout);
+    }
   close(2);
   dup(1);
   setpgrp();
@@ -449,7 +462,9 @@ Options:\n\
 -c <dir>\tChange directory to <dir> first\n\
 -e\t\tPass full environment of parent process\n\
 -f\t\tFilter system calls (-ff=very restricted)\n\
+-i <file>\tRedirect stdin from <file>\n\
 -m <size>\tLimit address space to <size> KB\n\
+-o <file>\tRedirect stdout to <file>\n\
 -t <time>\tStop after <time> seconds\n\
 -v\t\tBe verbose\n\
 -w\t\tMeasure wall clock time instead of run time\n\
@@ -464,7 +479,7 @@ main(int argc, char **argv)
   uid_t uid;
   char *cwd = NULL;
 
-  while ((c = getopt(argc, argv, "a:c:efm:t:vw")) >= 0)
+  while ((c = getopt(argc, argv, "a:c:efi:m:o:t:vw")) >= 0)
     switch (c)
       {
       case 'a':
@@ -479,9 +494,15 @@ main(int argc, char **argv)
       case 'f':
        filter_syscalls++;
        break;
+      case 'i':
+       redir_stdin = optarg;
+       break;
       case 'm':
        memory_limit = atol(optarg);
        break;
+      case 'o':
+       redir_stdout = optarg;
+       break;
       case 't':
        timeout = atol(optarg);
        break;