From 283214723416710aaf5d94b9c1e3527fa6f1208e Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 28 Mar 2001 15:04:16 +0000 Subject: [PATCH] A lot of work... --- Makefile | 11 +++--- TODO | 1 + bin/clean | 11 ++++++ bin/ev | 65 ++++++++++++++++++++++++++++++++++ bin/lib | 37 +++++++++++++++++++ bin/mo-install | 47 ++++++++++++++++++++++++ bin/profile | 12 +++++++ bin/task-compile | 58 ++++++++++++++++++++++++++++++ bin/task-init | 18 ++++++++++ config | 17 +++++++++ examples/problems/sum/1.config | 1 + examples/problems/sum/1.in | 1 + examples/problems/sum/1.out | 1 + examples/problems/sum/2.in | 1 + examples/problems/sum/2.out | 1 + examples/problems/sum/config | 8 +++++ examples/problems/sum/extras.h | 1 + src/box.c | 10 +++++- 18 files changed, 294 insertions(+), 7 deletions(-) create mode 100644 TODO create mode 100644 bin/clean create mode 100755 bin/ev create mode 100644 bin/lib create mode 100755 bin/mo-install create mode 100644 bin/profile create mode 100644 bin/task-compile create mode 100644 bin/task-init create mode 100644 config create mode 100644 examples/problems/sum/1.config create mode 100644 examples/problems/sum/1.in create mode 100644 examples/problems/sum/1.out create mode 100644 examples/problems/sum/2.in create mode 100644 examples/problems/sum/2.out create mode 100644 examples/problems/sum/config create mode 100644 examples/problems/sum/extras.h diff --git a/Makefile b/Makefile index a66efde..9d2b0e2 100644 --- 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 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 index 0000000..15461e2 --- /dev/null +++ b/bin/clean @@ -0,0 +1,11 @@ +# The Evaluator -- Directory Cleanup +# (c) 2001 Martin Mares + +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 " \ No newline at end of file diff --git a/bin/ev b/bin/ev new file mode 100755 index 0000000..ed2dc67 --- /dev/null +++ b/bin/ev @@ -0,0 +1,65 @@ +# The Evaluator -- Master Control Script +# (c) 2001 Martin Mares + +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 " +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 " " + 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 " " + + 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 index 0000000..e2caafa --- /dev/null +++ b/bin/lib @@ -0,0 +1,37 @@ +# The Evaluator -- Shell Function Library +# (c) 2001 Martin Mares + +# 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 index 0000000..e362614 --- /dev/null +++ b/bin/mo-install @@ -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 index 0000000..404cecb --- /dev/null +++ b/bin/profile @@ -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 index 0000000..740b6d0 --- /dev/null +++ b/bin/task-compile @@ -0,0 +1,58 @@ +# The Evaluator -- Compile a Solution +# (c) 2001 Martin Mares + +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 index 0000000..63d5da8 --- /dev/null +++ b/bin/task-init @@ -0,0 +1,18 @@ +# The Evaluator -- Initialize Task Directory +# (c) 2001 Martin Mares + +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 <$TDIR/points +pend "OK" diff --git a/config b/config new file mode 100644 index 0000000..74cfee5 --- /dev/null +++ b/config @@ -0,0 +1,17 @@ +# Configuration file for MO Evaluator +# (c) 2001 Martin Mares + +# 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 index 0000000..ce36b74 --- /dev/null +++ b/examples/problems/sum/1.config @@ -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 index 0000000..b85905e --- /dev/null +++ b/examples/problems/sum/1.in @@ -0,0 +1 @@ +1 2 3 diff --git a/examples/problems/sum/1.out b/examples/problems/sum/1.out new file mode 100644 index 0000000..1e8b314 --- /dev/null +++ b/examples/problems/sum/1.out @@ -0,0 +1 @@ +6 diff --git a/examples/problems/sum/2.in b/examples/problems/sum/2.in new file mode 100644 index 0000000..aacb595 --- /dev/null +++ b/examples/problems/sum/2.in @@ -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 index 0000000..60d3b2f --- /dev/null +++ b/examples/problems/sum/2.out @@ -0,0 +1 @@ +15 diff --git a/examples/problems/sum/config b/examples/problems/sum/config new file mode 100644 index 0000000..6cd4c6d --- /dev/null +++ b/examples/problems/sum/config @@ -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 index 0000000..b3ff325 --- /dev/null +++ b/examples/problems/sum/extras.h @@ -0,0 +1 @@ +/* Dummy header we're testing */ diff --git a/src/box.c b/src/box.c index cd5b8c4..12d3eb5 100644 --- a/src/box.c +++ b/src/box.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,7 @@ Usage: box [] -- \n\ \n\ Options:\n\ -a \tSet file access level (0=none, 1=cwd, 2=/etc,/lib,..., 3=whole fs, 9=no checks; needs -f)\n\ +-c \tChange directory to first\n\ -e\t\tPass full environment of parent process\n\ -f\t\tFilter system calls (-ff=very restricted)\n\ -m \tLimit address space to 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"); -- 2.39.2