diff --git a/examples/xxx/eval/makefile b/examples/xxx/eval/makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/xxx/incf/makefile b/examples/xxx/incf/makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/xxx/ingen/makefile b/examples/xxx/ingen/makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/xxx/okgen/makefile b/examples/xxx/okgen/makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/xxx/problemconfig b/examples/xxx/problemconfig new file mode 100644 index 0000000..35b1076 --- /dev/null +++ b/examples/xxx/problemconfig @@ -0,0 +1,2 @@ +problemname=xxx +timelimit=1 diff --git a/examples/xxx/src/buildtests b/examples/xxx/src/buildtests new file mode 100755 index 0000000..5c912ce --- /dev/null +++ b/examples/xxx/src/buildtests @@ -0,0 +1,89 @@ +#!/bin/bash +# +# This builds all tests using testmanifest +# Tamio-Vesa Nakajima + +# include the library +source lib + +# include the configuration +source problemconfig + +############################ +# ARGUMENT PARSING +############################# + +rebuild_inputs=true + +while getopts "r:ho" opt; do + case $opt in + h) + echo "Usage: ./run -r(estore) [revision to restore]" + exit 0 + ;; + r) + rm -r tests + unzip oldtests/$OPTARG.zip + exit 0 + ;; + o) + rebuild_inputs=false + ;; + esac +done + +read -p "Name of this test revision: " testrevision + +# We will want to remember this: +currtest=0 + +# Loop over lines of +cat testmanifest | while read instr; do + # Parse a line of testmanifest + set $instr + numberoftests=$1 + incf=$2 + totalpoints=$3 + points=$(($totalpoints / $numberoftests)) + + for nr in `seq $currtest $(($currtest + $numberoftests - 1))` ; do + echo $nr + ################# + # Build input: + ################# + + if [ $rebuild_inputs = true ] ; then + ./lib/build_test_number $nr $incf + fi + + ################### + # Build ok + ################### + + # Build ok generator + cd okgen && make -s && cd .. + + # Copy ok generator and input into stage + cp okgen/okgen.bin stage/$problemname.bin + cp tests/$problemname-$nr.in stage/$problemname.in + + # Indicate the number of points in the stage + echo $points > stage/$problemname.points + + # Build ok + cd stage && ./$problemname.bin && cd .. + + # Copy ok from stage into tests + cp stage/$problemname.ok tests/$problemname-$nr.ok + + # Clean stage + rm stage/* + done + + #update currtest + currtest=$(($currtest + $numberoftests)) +done + +if [ -n $testrevision ] ; then + zip -r oldtests/$testrevision.zip tests/* +fi diff --git a/examples/xxx/src/compare b/examples/xxx/src/compare new file mode 100755 index 0000000..6a81689 --- /dev/null +++ b/examples/xxx/src/compare @@ -0,0 +1,90 @@ +#!/bin/bash +# +# compare -s "s1 s2" -s s3 -c "c1 c2" -c c3 compares sources s1, s2, s3 with configurations c1 c2 c3 until they diverge +# Tamio-Vesa Nakajima + +source lib +source problemconfig + +srcs="" +configs="" + +while getopts "hs:c:" opt ; do + case $opt in + h) + echo "Usage: ./compare -s \"source1\" -s \"source2\" -c \"config1\" \"config2\"" + exit 0 + ;; + s) + srcs="$srcs $OPTARG" + ;; + c) + configs="$configs $OPTARG" + ;; + esac +done + +if [ -z "$srcs" ] ; then + echo No sources provided + exit 1 +fi + +if [ -z "$configs" ] ; then + echo No configs provided + exit 1 +fi + +srcs_arr=($srcs) +nr_srcs=${#srcs_arr[@]} +outputs_arr=() +binary_arr=() +input_file=`mktemp` + +for i in `seq 0 $(($nr_srcs-1))` ; do + outputs_arr[$i]=`mktemp` + binary_arr[$i]=`mktemp` +done + +for i in `seq 0 $(($nr_srcs-1))` ; do + g++ src/${srcs_arr[$i]} -std=c++11 -O2 -o ${binary_arr[$i]} +done + +curr_test=0 + +path_to_tests=`realpath tests` +trap "rm $path_to_tests/$problemname-999.in" EXIT + +while : ; do + for conf in $configs ; do + rm stage/* 2> /dev/null + echo -en " \r" + echo Doing test $curr_test + curr_test=$(($curr_test + 1)) + + build_test_number 999 $conf + + hasTle=false + + for i in `seq 0 $(($nr_srcs-1))` ; do + run_src_test ${binary_arr[$i]} $problemname-999 + + if (( $(echo "$timeUsed > $timelimit" | bc -l ) )) ; then + hasTle=true + fi + + cp stage/$problemname.out ${outputs_arr[$i]} + done + if [ $hasTle = true ] || ! diff --from-file ${outputs_arr[*]} > /dev/null ; then + echo -en " \r" + echo Has failed on: + cat tests/$problemname-999.in + echo With outputs: + for i in `seq 0 $(($nr_srcs-1))` ; do + echo ${srcs_arr[$i]}: + cat ${outputs_arr[$i]} + echo + done + exit 0 + fi + done +done diff --git a/examples/xxx/src/lib/build_test_number b/examples/xxx/src/lib/build_test_number new file mode 100755 index 0000000..efd7bfa --- /dev/null +++ b/examples/xxx/src/lib/build_test_number @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Tamio-Vesa Nakajima +# Builds test number $1 with incf $2 +build_test_number () { + source problemconfig + + nr=$1 + incf=$2 + + # Build input generator + cd ingen && make -s && cd .. + + # Copy ingen/ingen.bin and incf/$1 into stage + cp ingen/ingen.bin stage/$problemname.bin + cp incf/$incf stage/$problemname.cf + + # Build input + cd stage && ./$problemname.bin && cp $problemname.in ../tests/$problemname-$nr.in && cd .. + + # Clean stage + rm stage/* 2> /dev/null + +} + + diff --git a/examples/xxx/src/lib/evaluate_src_test b/examples/xxx/src/lib/evaluate_src_test new file mode 100755 index 0000000..fbf4038 --- /dev/null +++ b/examples/xxx/src/lib/evaluate_src_test @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Tamio-Vesa Nakajima + +# Evaluates the binary $1 with test $2, returning the message in $message, the time used in $timeUsed and the points in $points +evaluate_src_test () { + binary=$1 + testname=$2 + + ./lib/run_src_test $binary $testname + if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then + # Set the return values + # timeUsed is already set + message=TLE + points=0 + else + # Make the evaluator + cd eval && make -s && cd .. + + # Copy the evaluator into the stage + cp eval/eval.bin stage/eval.bin + + # Copy the ok file into the stage + cp tests/$testname.ok stage/$problemname.ok + + # Create temporary files to hold the points and the eval message + pointsFile=`mktemp` + messageFile=`mktemp` + + # Enter the stage and evaluate, storing the results in $pointsFile and $messageFile + cd stage && ./eval.bin > $pointsFile 2> $messageFile && cd .. + + # Set the return values + # timeUsed is already set + points=`cat $pointsFile` + message=`cat $messageFile` + fi +} diff --git a/examples/xxx/src/lib/run_src_test b/examples/xxx/src/lib/run_src_test new file mode 100755 index 0000000..488cf7f --- /dev/null +++ b/examples/xxx/src/lib/run_src_test @@ -0,0 +1,51 @@ +#!/bin/bash +# +# Run the binary $1 with test $2, returning the time used in timeUsed, and leaving the output file in stage/$problemname.out +run_src_test () { + binary=$1 + testname=$2 + + # Get an appropriate timeout command + timeoutCommand=timeout + + if [[ "$OSTYPE" == "darwin"* ]] ; then + timeoutCommand=gtimeout + fi + + # Fetch the problem configuration + source problemconfig + + # clear any previous messages + echo -en "\r \r" + + # Output an appropriate messgae + echo -en "Doing $testname\r" + + # Clean the stage + rm stage/* 2> /dev/null + + # Copy the binary into the stage + cp $binary stage/$problemname.bin + + # Copy the input into the stage + cp tests/$testname.in stage/$problemname.in + + # Get the problem config + source problemconfig + + # This string runs the competitor's executable + runExec="./$problemname.bin > /dev/null 2> /dev/null" + + # This string runs the competitors executable with an appropriate timeout + runExecWithTimeout="$timeoutCommand $timelimit $runExec" + + # Run the competitors executable with a timeout, and store the time used in timeUsed + timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \ + | tail -3 \ + | head -1 \ + | awk -F ' ' '{print $2}' \ + | awk -F 'm' '{print $2}' \ + | awk -F 's' '{print $1}' && cd ..) +} + + diff --git a/examples/xxx/src/makefile b/examples/xxx/src/makefile new file mode 100644 index 0000000..e69de29 diff --git a/examples/xxx/src/run b/examples/xxx/src/run new file mode 100755 index 0000000..3e9943e --- /dev/null +++ b/examples/xxx/src/run @@ -0,0 +1,107 @@ +#!/bin/bash +# +# Runs sources on tests +# Tamio-Vesa Nakajima +# +# Use cases: +# ./run.sh -> runs all sources on all tests +# ./run.sh -s "a.cpp b.cpp" -s c.cpp -> runs a,b,c.cpp on all tests +# ./run.sh -t "00 01 02" -> runs all sources on tests 00, 01, 02 +# ./run.sh -s a.cpp -t 00 -> runs a.cpp on 00 + +########################## +# GENERAL SETUP +######################### + +# include the library +source lib + +# include the configuration +source problemconfig + +# make stage (as git deletes it) +mkdir -p stage + +############################ +# ARGUMENT PARSING +############################# + +# default values for used sources and used tests + +srcs="" +tests="" + +while getopts "hs:t:" opt; do + case $opt in + h) + echo "Usage: ./run -s [source] -t [test]" + exit 0 + ;; + s) + for x in $OPTARG ; do + srcs="$srcs $x" + done + ;; + t) + for x in $OPTARG ; do + tests="$tests $problemname-$x" + done + ;; + esac +done + +if [ -z "$srcs" ] ; then + srcs=`ls -1 src | grep .cpp` +fi + +if [ -z "$tests" ] ; then + tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'` +fi + +tests=`echo $tests | sort -t '-' -k 1 -n` + + +########################### +# EVALUATING +########################## + +for src in $srcs ; do + # Copy the source into the stage + cp src/$src stage/$problemname.cpp + + # Create a temporary file to hold the problem binary + binary=`mktemp` + + # Build the source + g++ stage/$problemname.cpp -std=c++11 -o $binary -O2 + + # Make a temporary file to hold the table: + table=`mktemp` + + # $table holds the score table + echo $src > $table + echo Test Message Time Points >> $table + + # For all tests + for testname in $tests ; do + # evaluate $binary on $testname, setting $message, $timeUsed, $points + ./lib/evaluate_src_test $binary $testname + echo $testname.in $message $timeUsed $points >> $table + done + + # Clear "Doing test ..." + echo -en "\r \r" + + # Output the table + column -t $table + + # Calculate the score + echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table` + + # Clear the temporary files + rm $table + rm $binary + + # And the stage + rm stage/* +done diff --git a/examples/xxx/src/todo b/examples/xxx/src/todo new file mode 100644 index 0000000..8f8b63e --- /dev/null +++ b/examples/xxx/src/todo @@ -0,0 +1,9 @@ +TODO: + +- make an evaluator (should read from $problemname.out and $problemname.ok, write the evaluation message to stderr and the # of points to cout +- make an input generator (should read configuration from $problemname.cf and write the input to $problemname.in) +- make an ok generator (should read the # of points from $problemname.points, the input from $problemname.in, and write to ok to $problemname.ok) +- make a testmanifest (each line should contain a group of tests, described by the # of tests, the configuration file, and the # of points for that group) +- call ./buildtests.sh +- add source files to src +- call ./run.sh diff --git a/examples/xxx/testmanifest b/examples/xxx/testmanifest new file mode 100644 index 0000000..e69de29 diff --git a/makeproject b/makeproject index 1515224..d6b617f 100755 --- a/makeproject +++ b/makeproject @@ -15,8 +15,8 @@ mkdir $1/$problemname/incf mkdir $1/$problemname/ingen mkdir $1/$problemname/okgen mkdir $1/$problemname/src -mkdir $1/$problemname/stage mkdir $1/$problemname/tests +mkdir $1/$problemname/stage mkdir $1/$problemname/oldtests touch $1/$problemname/eval/makefile @@ -25,7 +25,7 @@ touch $1/$problemname/ingen/makefile touch $1/$problemname/okgen/makefile touch $1/$problemname/src/makefile -cp src/* $1/$problemname +cp -r ./src/* $1/$problemname touch $1/$problemname/testmanifest diff --git a/src/buildtests b/src/buildtests index c54ff74..35bd0a4 100755 --- a/src/buildtests +++ b/src/buildtests @@ -3,9 +3,6 @@ # This builds all tests using testmanifest # Tamio-Vesa Nakajima -# include the library -source lib - # include the configuration source problemconfig @@ -46,38 +43,16 @@ cat testmanifest | while read instr; do totalpoints=$3 points=$(($totalpoints / $numberoftests)) - for nr in `seq $currtest $(($currtest + $numberoftests - 1))` ; do - echo $nr - ################# - # Build input: - ################# + for nr in `seq $currtest $(($currtest + $numberoftests - 1))` + do + echo $nr >&2 - if [ $rebuild_inputs = true ] ; then - build_test_number $nr $incf + if [ $rebuild_inputs = true ] + then + ./lib/build_test_number $nr $incf fi - ################### - # Build ok - ################### - - # Build ok generator - cd okgen && make -s && cd .. - - # Copy ok generator and input into stage - cp okgen/okgen.bin stage/$problemname.bin - cp tests/$problemname-$nr.in stage/$problemname.in - - # Indicate the number of points in the stage - echo $points > stage/$problemname.points - - # Build ok - cd stage && ./$problemname.bin && cd .. - - # Copy ok from stage into tests - cp stage/$problemname.ok tests/$problemname-$nr.ok - - # Clean stage - rm stage/* + ./lib/build_ok_number $nr $points done #update currtest diff --git a/src/compare b/src/compare index 6a81689..a2afa1d 100755 --- a/src/compare +++ b/src/compare @@ -3,7 +3,6 @@ # compare -s "s1 s2" -s s3 -c "c1 c2" -c c3 compares sources s1, s2, s3 with configurations c1 c2 c3 until they diverge # Tamio-Vesa Nakajima -source lib source problemconfig srcs="" @@ -12,7 +11,7 @@ configs="" while getopts "hs:c:" opt ; do case $opt in h) - echo "Usage: ./compare -s \"source1\" -s \"source2\" -c \"config1\" \"config2\"" + echo "Usage: ./compare -s \"source1\" -s \"source2\" -c \"config1\" \"config2\"" >&2 exit 0 ;; s) @@ -25,12 +24,12 @@ while getopts "hs:c:" opt ; do done if [ -z "$srcs" ] ; then - echo No sources provided + echo No sources provided >&2 exit 1 fi if [ -z "$configs" ] ; then - echo No configs provided + echo No configs provided >&2 exit 1 fi @@ -57,16 +56,16 @@ trap "rm $path_to_tests/$problemname-999.in" EXIT while : ; do for conf in $configs ; do rm stage/* 2> /dev/null - echo -en " \r" - echo Doing test $curr_test + echo -en " \r" >&2 + echo Doing test $curr_test >&2 curr_test=$(($curr_test + 1)) - build_test_number 999 $conf + ./lib/build_test_number 999 $conf hasTle=false for i in `seq 0 $(($nr_srcs-1))` ; do - run_src_test ${binary_arr[$i]} $problemname-999 + timeUsed=$(./lib/run_src_test ${binary_arr[$i]} $problemname-999) if (( $(echo "$timeUsed > $timelimit" | bc -l ) )) ; then hasTle=true @@ -75,14 +74,14 @@ while : ; do cp stage/$problemname.out ${outputs_arr[$i]} done if [ $hasTle = true ] || ! diff --from-file ${outputs_arr[*]} > /dev/null ; then - echo -en " \r" - echo Has failed on: + echo -en " \r" >&2 + echo Has failed on: >&2 cat tests/$problemname-999.in - echo With outputs: + echo With outputs: >&2 for i in `seq 0 $(($nr_srcs-1))` ; do - echo ${srcs_arr[$i]}: + echo ${srcs_arr[$i]}: >&2 cat ${outputs_arr[$i]} - echo + echo >&2 done exit 0 fi diff --git a/src/lib b/src/lib deleted file mode 100644 index e8bf9c7..0000000 --- a/src/lib +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/bash -# -# Bash library for this project -# Tamio-Vesa Nakajima - -# Tries to execute $1 ; if this succeeds, do nothing -# otherwise, output $2 -try () { - if eval $1 ; then - : - else - echo $2 - exit 1 - fi -} - -# Tries to copy $1 to $2 ; if $1 doesn't exist, creates an empty $2 -maybecp () { - if [ -f $1 ] ; then - cp $1 $2 - else - touch $2 - fi -} - -# Builds test number $1 with incf $2 -build_test_number () { - source problemconfig - - nr=$1 - incf=$2 - - # Build input generator - cd ingen && make -s && cd .. - - # Copy ingen/ingen.bin and incf/$1 into stage - cp ingen/ingen.bin stage/$problemname.bin - cp incf/$incf stage/$problemname.cf - - # Build input - cd stage && ./$problemname.bin && cp $problemname.in ../tests/$problemname-$nr.in && cd .. - - # Clean stage - rm stage/* 2> /dev/null - -} - -# Run the binary $1 with test $2, returning the time used in timeUsed, and leaving the output file in stage/$problemname.out -run_src_test () { - binary=$1 - testname=$2 - - # Get an appropriate timeout command - timeoutCommand=timeout - - if [[ "$OSTYPE" == "darwin"* ]] ; then - timeoutCommand=gtimeout - fi - - # Fetch the problem configuration - source problemconfig - - # clear any previous messages - echo -en "\r \r" - - # Output an appropriate messgae - echo -en "Doing $testname\r" - - # Clean the stage - rm stage/* 2> /dev/null - - # Copy the binary into the stage - cp $binary stage/$problemname.bin - - # Copy the input into the stage - cp tests/$testname.in stage/$problemname.in - - # Get the problem config - source problemconfig - - # This string runs the competitor's executable - runExec="./$problemname.bin > /dev/null 2> /dev/null" - - # This string runs the competitors executable with an appropriate timeout - runExecWithTimeout="$timeoutCommand $timelimit $runExec" - - # Run the competitors executable with a timeout, and store the time used in timeUsed - timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \ - | tail -3 \ - | head -1 \ - | awk -F ' ' '{print $2}' \ - | awk -F 'm' '{print $2}' \ - | awk -F 's' '{print $1}' && cd ..) -} - -# Evaluates the binary $1 with test $2, returning the message in $message, the time used in $timeUsed and the points in $points -evaluate_src_test () { - binary=$1 - testname=$2 - - run_src_test $binary $testname - if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then - # Set the return values - # timeUsed is already set - message=TLE - points=0 - else - # Make the evaluator - try "cd eval && make -s && cd .." "evaluator build fail" - - # Copy the evaluator into the stage - cp eval/eval.bin stage/eval.bin - - # Copy the ok file into the stage - cp tests/$testname.ok stage/$problemname.ok - - # Create temporary files to hold the points and the eval message - pointsFile=`mktemp` - messageFile=`mktemp` - - # Enter the stage and evaluate, storing the results in $pointsFile and $messageFile - try "cd stage && ./eval.bin > $pointsFile 2> $messageFile && cd .." "eval error" - - # Set the return values - # timeUsed is already set - points=`cat $pointsFile` - message=`cat $messageFile` - fi -} diff --git a/src/lib/build_ok_number b/src/lib/build_ok_number new file mode 100755 index 0000000..ed487cc --- /dev/null +++ b/src/lib/build_ok_number @@ -0,0 +1,30 @@ +#!/bin/bash +# + +source problemconfig + +nr=$1 +points=$2 + +# Build ok generator +cd okgen && make -s && cd .. + +# make a stage +stage=$(mktemp -d) + +# Copy ok generator and input into stage +cp okgen/okgen.bin $stage/$problemname.bin +cp tests/$problemname-$nr.in $stage/$problemname.in + +# Indicate the number of points in the stage +echo $points > $stage/$problemname.points + +# Build ok +currdir=$PWD +cd $stage && ./$problemname.bin && cd $currdir + +# Copy ok from stage into tests +cp $stage/$problemname.ok tests/$problemname-$nr.ok + +# Clean stage +rm -rf $stage diff --git a/src/lib/build_test_number b/src/lib/build_test_number new file mode 100755 index 0000000..5e91634 --- /dev/null +++ b/src/lib/build_test_number @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Tamio-Vesa Nakajima +# Builds test number $1 with incf $2 +source problemconfig + +nr=$1 +incf=$2 + +# Build input generator +cd ingen && make -s && cd .. + +# Make a stage +stage=$(mktemp -d) + +# Copy ingen/ingen.bin and incf/$1 into stage +cp ingen/ingen.bin $stage/$problemname.bin +cp incf/$incf $stage/$problemname.cf + +# Build input +currdir=$PWD +cd $stage && ./$problemname.bin && cp $problemname.in $currdir/tests/$problemname-$nr.in && cd $currdir + +# Clean stage +rm -rf $stage diff --git a/src/lib/evaluate_src_test b/src/lib/evaluate_src_test new file mode 100755 index 0000000..c1f2848 --- /dev/null +++ b/src/lib/evaluate_src_test @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Tamio-Vesa Nakajima + +source problemconfig + +# Evaluates the binary $1 with test $2, returning the message in $message, the time used in $timeUsed and the points in $points +binary=$1 +testname=$2 +timeUsed=$(./lib/run_src_test $binary $testname) + + +if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then + # Set the return values + # timeUsed is already set + message=TLE + points=0 +else + # Make the evaluator + cd eval && make -s && cd .. + + # Copy the evaluator into the stage + cp eval/eval.bin stage/eval.bin + + # Copy the ok file into the stage + cp tests/$testname.ok stage/$problemname.ok + + # Create temporary files to hold the points and the eval message + pointsFile=`mktemp` + messageFile=`mktemp` + + # Enter the stage and evaluate, storing the results in $pointsFile and $messageFile + cd stage && ./eval.bin > $pointsFile 2> $messageFile && cd .. + + # Set the return values + # timeUsed is already set + points=`cat $pointsFile` + message=`cat $messageFile` +fi + +echo $message $timeUsed $points diff --git a/src/lib/run_src_test b/src/lib/run_src_test new file mode 100755 index 0000000..5df2b0b --- /dev/null +++ b/src/lib/run_src_test @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Run the binary $1 with test $2, returning the time used stdout, and leaving the output file in stage/$problemname.out +binary=$1 +testname=$2 + +# Get an appropriate timeout command +timeoutCommand=timeout + +if [[ "$OSTYPE" == "darwin"* ]] ; then + timeoutCommand=gtimeout +fi + +# Fetch the problem configuration +source problemconfig + +# clear any previous messages +echo -en "\r \r" >&2 + +# Output an appropriate messgae +echo -en "Doing $testname\r" >&2 + +# Clean the stage +rm stage/* 2> /dev/null + +# Copy the binary into the stage +cp $binary stage/$problemname.bin + +# Copy the input into the stage +cp tests/$testname.in stage/$problemname.in + +# Get the problem config +source problemconfig + +# This string runs the competitor's executable +runExec="./$problemname.bin > /dev/null 2> /dev/null" + +# This string runs the competitors executable with an appropriate timeout +runExecWithTimeout="$timeoutCommand $timelimit $runExec" + +# Run the competitors executable with a timeout, and store the time used in timeUsed +timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \ + | tail -3 \ + | head -1 \ + | awk -F ' ' '{print $2}' \ + | awk -F 'm' '{print $2}' \ + | awk -F 's' '{print $1}' && cd ..) + +echo $timeUsed diff --git a/src/run b/src/run index 1289837..24847dd 100755 --- a/src/run +++ b/src/run @@ -13,9 +13,6 @@ # GENERAL SETUP ######################### -# include the library -source lib - # include the configuration source problemconfig @@ -34,7 +31,7 @@ tests="" while getopts "hs:t:" opt; do case $opt in h) - echo "Usage: ./run -s [source] -t [test]" + echo "Usage: ./run -s [source] -t [test]" >&2 exit 0 ;; s) @@ -67,13 +64,13 @@ tests=`echo $tests | sort -t '-' -k 1 -n` for src in $srcs ; do # Copy the source into the stage - try "cp src/$src stage/$problemname.cpp" "source file missing" + cp src/$src stage/$problemname.cpp # Create a temporary file to hold the problem binary binary=`mktemp` # Build the source - try "g++ stage/$problemname.cpp -std=c++11 -o $binary -O2" "Compile error" + g++ stage/$problemname.cpp -std=c++11 -o $binary -O2 # Make a temporary file to hold the table: table=`mktemp` @@ -85,18 +82,22 @@ for src in $srcs ; do # For all tests for testname in $tests ; do # evaluate $binary on $testname, setting $message, $timeUsed, $points - evaluate_src_test $binary $testname + set "$(./lib/evaluate_src_test $binary $testname)" + message=$1 + timeUsed=$2 + points=$3 + echo $testname.in $message $timeUsed $points >> $table done # Clear "Doing test ..." - echo -en "\r \r" + echo -en "\r \r" >&2 # Output the table column -t $table # Calculate the score - echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table` + echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table` >&2 # Clear the temporary files rm $table diff --git a/test/aplusb/ingen/ingen.cpp b/test/aplusb/ingen/ingen.cpp index 0d04686..800845e 100644 --- a/test/aplusb/ingen/ingen.cpp +++ b/test/aplusb/ingen/ingen.cpp @@ -11,6 +11,7 @@ int main(){ if(fixed) g << x << ' ' << y << endl; else{ - srand(time(nullptr)); + unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count(); + srand(seed1); g << rand() << ' ' << rand() << endl; } return 0; } diff --git a/test/aplusb/src/almost_ok.cpp b/test/aplusb/src/almost_ok.cpp index 475adf6..9464e09 100644 --- a/test/aplusb/src/almost_ok.cpp +++ b/test/aplusb/src/almost_ok.cpp @@ -6,6 +6,6 @@ int main(){ ofstream g("aplusb.out"); long long x, y; f >> x >> y; - if((x+y)%10 == 0) g << -1 << endl; + if((x+y)%100 == 0) g << -1 << endl; else g << x+y << endl; return 0; }