]> mj.ucw.cz Git - moe.git/commitdiff
A lot of work...
authorMartin Mares <mj@ucw.cz>
Wed, 28 Mar 2001 15:04:16 +0000 (15:04 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 28 Mar 2001 15:04:16 +0000 (15:04 +0000)
18 files changed:
Makefile
TODO [new file with mode: 0644]
bin/clean [new file with mode: 0644]
bin/ev [new file with mode: 0755]
bin/lib [new file with mode: 0644]
bin/mo-install [new file with mode: 0755]
bin/profile [new file with mode: 0644]
bin/task-compile [new file with mode: 0644]
bin/task-init [new file with mode: 0644]
config [new file with mode: 0644]
examples/problems/sum/1.config [new file with mode: 0644]
examples/problems/sum/1.in [new file with mode: 0644]
examples/problems/sum/1.out [new file with mode: 0644]
examples/problems/sum/2.in [new file with mode: 0644]
examples/problems/sum/2.out [new file with mode: 0644]
examples/problems/sum/config [new file with mode: 0644]
examples/problems/sum/extras.h [new file with mode: 0644]
src/box.c

index a66efdee7dc5722971cd9d06526e82422d49ce6f..9d2b0e2dabeacb7a20e907934ce0adbe4ae17733 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,11 @@
-# Makefile for the ywho toolkit
-
-DEBUG=-ggdb
+#DEBUG=-ggdb
 CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline $(DEBUG)
 
-all: box
+all: bin/box
 
-box.o: box.c
+bin/box: src/box.o
+       $(CC) $(LDFLAGS) -o $@ $<
 
 clean:
        rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core`
-       rm -f box
+       rm -f bin/box
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..c62b4d6
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+submit, compile, test (submit bez odevzdani)
diff --git a/bin/clean b/bin/clean
new file mode 100644 (file)
index 0000000..15461e2
--- /dev/null
+++ b/bin/clean
@@ -0,0 +1,11 @@
+# The Evaluator -- Directory Cleanup
+# (c) 2001 Martin Mares <mj@ucw.cz>
+
+if [ -z "$MO_ROOT" ] ; then
+       set -e -a
+       cd
+       [ -f config ] || ( echo "Missing config file. Please fix the installation." ; exit 1 )
+       . config
+       fi
+if [ -z "$CT" ] ; then
+       [ -n "$1" ] || ( echo "Usage: clean <contestant> <task>"
\ No newline at end of file
diff --git a/bin/ev b/bin/ev
new file mode 100755 (executable)
index 0000000..ed2dc67
--- /dev/null
+++ b/bin/ev
@@ -0,0 +1,65 @@
+# The Evaluator -- Master Control Script
+# (c) 2001 Martin Mares <mj@ucw.cz>
+
+set -e
+cd
+. 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."
+[ -n "$2" ] || die "Usage: ev <contestant> <problem>"
+CT=$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
+. $PDIR/config
+
+# Set up logging
+exec >>$TDIR/log
+HAVE_LOG=1
+
+# Compile the solution
+( . bin/task-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
+       if [ ! -f $TDIR/compile.out ] ; then
+               echo >$PTSFILE "0 --"
+               die "No source file"
+       fi
+       if [ ! -f $TDIR/$PROBLEM ] ; then
+               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> "
+
+       echo "Test completed OK ($POINTS_PER_TEST points)"
+       echo >$PTSFILE "$POINTS_PER_TEST OK"
+       pend "OK"
+       )
+done
diff --git a/bin/lib b/bin/lib
new file mode 100644 (file)
index 0000000..e2caafa
--- /dev/null
+++ b/bin/lib
@@ -0,0 +1,37 @@
+# The Evaluator -- Shell Function Library
+# (c) 2001 Martin Mares <mj@ucw.cz>
+
+# Logging functions.
+# File handles used: fd1=log, fd2=progress
+
+function pstart
+{
+       echo >&2 -n "$@"
+}
+
+function pcont
+{
+       echo >&2 -n "$@"
+}
+
+function pend
+{
+       echo >&2 "$@"
+}
+
+function die
+{
+       echo >&2 "$@"
+       [ -n "$HAVE_LOG" ] && echo "Fatal error: $@"
+       exit 1
+}
+
+# Sandbox subroutines
+
+function box-init
+{
+       BOXDIR=$MO_ROOT/$TEST_USER
+       BOXCMD=bin/box-$TEST_USER
+       [ -d $BOXDIR -a -f $BOXCMD ] || die "Sandbox set up incorrectly"
+       rm -rf $BOXDIR/*
+}
diff --git a/bin/mo-install b/bin/mo-install
new file mode 100755 (executable)
index 0000000..e362614
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+[ -f config ] || ( echo "Missing config file, check cwd." ; exit 1 )
+set -e
+. config
+
+H=`pwd`
+cd $MO_ROOT
+
+# mo-eval home
+echo "Creating $EVAL_USER"
+rm -rf ./$EVAL_USER
+mkdir $EVAL_USER
+cd $EVAL_USER
+cp -a $H/* .
+mv bin/profile .profile
+chmod +x bin/*
+cd ..
+chown -R $EVAL_USER.$EVAL_GROUP $EVAL_USER
+chmod 700 $EVAL_USER
+
+# mo-test home
+for u in $TEST_USERS ; do
+       echo "Creating $u"
+       rm -rf ./$u
+       mkdir $u
+       chown $u.$EVAL_GROUP $u
+       chmod 770 $u
+       cp $EVAL_USER/bin/box $EVAL_USER/bin/box-$u
+       chown $u.$EVAL_GROUP $EVAL_USER/bin/box-$u
+       chmod 4550 $EVAL_USER/bin/box-$u
+       done
+
+# common
+echo "Creating common"
+rm -rf common
+mkdir common
+cd common
+cd ..
+chown -R $EVAL_USER.$EVAL_GROUP common
+chmod 750 $EVAL_USER
+
+# SSH keys (FIXME)
+echo "Copying SSH keys"
+mkdir $EVAL_USER/.ssh
+cp ~mj/.ssh/authorized_keys $EVAL_USER/.ssh/
+chown -R $EVAL_USER $EVAL_USER/.ssh
diff --git a/bin/profile b/bin/profile
new file mode 100644 (file)
index 0000000..404cecb
--- /dev/null
@@ -0,0 +1,12 @@
+# Profile for eval user
+
+PATH="$PATH:~/bin"
+
+#echo -n "User to use for testing: "
+#read TEST_USER
+
+# FIXME
+echo "Setting TEST_USER=mo-test1"
+TEST_USER=mo-test1
+
+export TEST_USER
diff --git a/bin/task-compile b/bin/task-compile
new file mode 100644 (file)
index 0000000..740b6d0
--- /dev/null
@@ -0,0 +1,58 @@
+# 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
new file mode 100644 (file)
index 0000000..63d5da8
--- /dev/null
@@ -0,0 +1,18 @@
+# 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
new file mode 100644 (file)
index 0000000..74cfee5
--- /dev/null
+++ b/config
@@ -0,0 +1,17 @@
+# Configuration file for MO Evaluator
+# (c) 2001 Martin Mares <mj@ucw.cz>
+
+# Directories and users
+MO_ROOT=/aux/mo
+EVAL_USER=mo-eval
+EVAL_GROUP=mo-eval
+TEST_USERS="mo-test1 mo-test2"
+
+# 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'
+
+# Testing commands
+TEST_SANDBOX_OPTS='-a2 -c$BOXDIR -f -m$MEM_LIMIT -t$TIME_LIMIT -w'
diff --git a/examples/problems/sum/1.config b/examples/problems/sum/1.config
new file mode 100644 (file)
index 0000000..ce36b74
--- /dev/null
@@ -0,0 +1 @@
+POINTS_PER_TEST=2
diff --git a/examples/problems/sum/1.in b/examples/problems/sum/1.in
new file mode 100644 (file)
index 0000000..b85905e
--- /dev/null
@@ -0,0 +1 @@
+1 2 3
diff --git a/examples/problems/sum/1.out b/examples/problems/sum/1.out
new file mode 100644 (file)
index 0000000..1e8b314
--- /dev/null
@@ -0,0 +1 @@
+6
diff --git a/examples/problems/sum/2.in b/examples/problems/sum/2.in
new file mode 100644 (file)
index 0000000..aacb595
--- /dev/null
@@ -0,0 +1 @@
+1 2 3 4 5
diff --git a/examples/problems/sum/2.out b/examples/problems/sum/2.out
new file mode 100644 (file)
index 0000000..60d3b2f
--- /dev/null
@@ -0,0 +1 @@
+15
diff --git a/examples/problems/sum/config b/examples/problems/sum/config
new file mode 100644 (file)
index 0000000..6cd4c6d
--- /dev/null
@@ -0,0 +1,8 @@
+# Per-task config
+
+TESTS="1 2"
+POINTS_PER_TEST=1
+EXTRAS="extras.h"
+TEST_EXTRAS="extras.h"
+TIME_LIMIT=10
+MEM_LIMIT=16384
diff --git a/examples/problems/sum/extras.h b/examples/problems/sum/extras.h
new file mode 100644 (file)
index 0000000..b3ff325
--- /dev/null
@@ -0,0 +1 @@
+/* Dummy header we're testing */
index cd5b8c4ac0c8df4b52ddb23a319bb236e753d095..12d3eb58b21f81331fdeffdeb336db2d033c68a7 100644 (file)
--- a/src/box.c
+++ b/src/box.c
@@ -15,6 +15,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <getopt.h>
+#include <time.h>
 #include <sys/wait.h>
 #include <sys/user.h>
 #include <sys/time.h>
@@ -444,6 +445,7 @@ Usage: box [<options>] -- <command> <arguments>\n\
 \n\
 Options:\n\
 -a <level>\tSet file access level (0=none, 1=cwd, 2=/etc,/lib,..., 3=whole fs, 9=no checks; needs -f)\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\
 -m <size>\tLimit address space to <size> KB\n\
@@ -459,13 +461,17 @@ main(int argc, char **argv)
 {
   int c;
   uid_t uid;
+  char *cwd = NULL;
 
-  while ((c = getopt(argc, argv, "a:efm:t:vw")) >= 0)
+  while ((c = getopt(argc, argv, "a:c:efm:t:vw")) >= 0)
     switch (c)
       {
       case 'a':
        file_access = atol(optarg);
        break;
+      case 'c':
+       cwd = optarg;
+       break;
       case 'e':
        pass_environ = 1;
        break;
@@ -493,6 +499,8 @@ main(int argc, char **argv)
   uid = geteuid();
   if (setreuid(uid, uid) < 0)
     die("setreuid: %m");
+  if (cwd && chdir(cwd))
+    die("chdir: %m");
   box_pid = fork();
   if (box_pid < 0)
     die("fork: %m");