Skip to content

Commit

Permalink
Committer: Tamio Vesa Nakajima <[email protected]>
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   README.md
	modified:   run.sh

Basically changed run for finer grained control over sources run
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 19, 2018
1 parent 333533a commit 3bac199
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ problemname | A file that should contain exactly the problem name
timelimit | A file that should contain the time limit, in seconds
lib.sh | A bash library, used for the scripts in this bundle
build\_test.sh | ./build\_test.sh *xxx* will build *problemname*-*xxx*.in with ingen/ingen.bin with configuration incf/*xxx*
run.sh | ./run.sh *xxx* will run src/*xxx* on all the tests
run.sh | ./run.sh -s "s1.cpp s2.cpp" -t "00 01" will run s1.cpp, s2.cpp on 00, 01 -- ommiting -s or -t respectively leads to running all sources / all tests
ingen | Contains files related to input generation
ingen/makefile | A file that needs to make the input generator, ingen/ingen.bin
ingen/ingen.bin | The input generator. When run, a configuration file *problemname*.cf might be made available to it (depending on whether an appropriate file exists in incf). The input should be written to a file *problemname*.in.
Expand Down
175 changes: 113 additions & 62 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/bash
#
# Runs $1.cpp on all tests
# 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.sh
Expand All @@ -13,9 +23,6 @@ if [[ "$OSTYPE" == "darwin"* ]] ; then
timeoutCommand=gtimeout
fi

# Check if timoutCommand is valid
#try "hash $timeoutCommand$" "timeout fail"

# Get the problem name and the time limit
try "problemname=`cat problemname`" "no problemname file"
try "timelimit=`cat timelimit`" "no timelimit file"
Expand All @@ -26,82 +33,126 @@ try "cd eval && make -s && cd .." "evaluator build fail"
# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin

# Copy the source into the stage
try "cp src/$1 stage/$problemname.cpp" "source file missing"
############################
# 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.sh -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

# Create a temporary file to hold the problem binary
binary=`mktemp`
if [ -z "$tests" ] ; then
tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'`
fi

# Build the source
try "g++ stage/$problemname.cpp -std=c++11 -o $binary -O2" "Compile error"

# Make a temporary file to hold the table:
table=`mktemp`
###########################
# EVALUATING
##########################

# $table holds the score table
echo Test Message Time Points > $table
for src in $srcs ; do
# Copy the source into the stage
try "cp src/$src stage/$problemname.cpp" "source file missing"

# Find names of all inputs
tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'`
# Create a temporary file to hold the problem binary
binary=`mktemp`

# For all tests
for testname in $tests ; do
# Output an appropriate messgae
echo -en "Doing $testname\r"
# Build the source
try "g++ stage/$problemname.cpp -std=c++11 -o $binary -O2" "Compile error"

# Clean the stage
rm stage/*
# Make a temporary file to hold the table:
table=`mktemp`

# Copy the executable into the stage
cp $binary stage/$problemname.bin
# $table holds the score table
echo $src > $table
echo Test Message Time Points >> $table

# Copy the input into the stage
cp tests/$testname.in stage/$problemname.in
# For all tests
for testname in $tests ; do
# Output an appropriate messgae
echo -en "Doing $testname\r"

# This string runs the competitor's executable
runExec="./$problemname.bin > /dev/null 2> /dev/null"
# Clean the stage
rm stage/*

# This string runs the competitors executable with an appropriate timeout
runExecWithTimeout="$timeoutCommand $timelimit $runExec"
# Copy the executable into the stage
cp $binary stage/$problemname.bin

# Run the competitors executable with a timeout, and store the time used in timeUsed
timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \
| head -2 \
| awk -F ' ' '{print $2}' \
| awk -F 'm' '{print $2}' \
| awk -F 's' '{print $1}' && cd ..)
# Copy the input into the stage
cp tests/$testname.in stage/$problemname.in

if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then
# Print that this testcase resulted in a TLE
echo $testname TLE $timeUsed 0 >> $table
else
# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin
# This string runs the competitor's executable
runExec="./$problemname.bin > /dev/null 2> /dev/null"

# Copy the ok file into the stage
cp tests/$testname.ok stage/$problemname.ok
# This string runs the competitors executable with an appropriate timeout
runExecWithTimeout="$timeoutCommand $timelimit $runExec"

# Create temporary files to hold the points and the eval message
points=`mktemp`
message=`mktemp`
# Run the competitors executable with a timeout, and store the time used in timeUsed
timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \
| head -2 \
| awk -F ' ' '{print $2}' \
| awk -F 'm' '{print $2}' \
| awk -F 's' '{print $1}' && cd ..)

# Enter the stage and evaluate, storing the results in $points and $message
try "cd stage && ./eval.bin > $points 2> $message && cd .." "eval error"
if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then
# Print that this testcase resulted in a TLE
echo $testname TLE $timeUsed 0 >> $table
else
# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin

# Add the relevant information into the table
echo $testname `cat $message` $timeUsed `cat $points` >> $table
fi
done
# 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
points=`mktemp`
message=`mktemp`

# Enter the stage and evaluate, storing the results in $points and $message
try "cd stage && ./eval.bin > $points 2> $message && cd .." "eval error"

# Add the relevant information into the table
echo $testname `cat $message` $timeUsed `cat $points` >> $table
fi
done

# Output the table
column -t $table
# Clear "Doing test ..."
echo -en " \r"

# Calculate the score
echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table`
# Output the table
column -t $table

# Clear the temporary files
rm $table
rm $binary
# Calculate the score
echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table`

# And the stage
rm stage/*
# Clear the temporary files
rm $table
rm $binary

# And the stage
rm stage/*
done

0 comments on commit 3bac199

Please sign in to comment.