-# 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
--- /dev/null
+submit, compile, test (submit bez odevzdani)
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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/*
+}
--- /dev/null
+#!/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
--- /dev/null
+# 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
--- /dev/null
+# 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"
--- /dev/null
+# 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"
--- /dev/null
+# 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'
--- /dev/null
+POINTS_PER_TEST=2
--- /dev/null
+# Per-task config
+
+TESTS="1 2"
+POINTS_PER_TEST=1
+EXTRAS="extras.h"
+TEST_EXTRAS="extras.h"
+TIME_LIMIT=10
+MEM_LIMIT=16384
--- /dev/null
+/* Dummy header we're testing */
#include <stdarg.h>
#include <unistd.h>
#include <getopt.h>
+#include <time.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <sys/time.h>
\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\
{
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;
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");