Skip to content

Commit

Permalink
Committer: Tamio Vesa Nakajima <[email protected]>
Browse files Browse the repository at this point in the history
On branch master
Your branch is up-to-date with 'origin/master'.
Restructured lib
 Changes to be committed:
	new file:   examples/xxx/eval/makefile
	new file:   examples/xxx/incf/makefile
	new file:   examples/xxx/ingen/makefile
	new file:   examples/xxx/okgen/makefile
	new file:   examples/xxx/problemconfig
	new file:   examples/xxx/src/buildtests
	new file:   examples/xxx/src/compare
	new file:   examples/xxx/src/lib/build_test_number
	new file:   examples/xxx/src/lib/evaluate_src_test
	new file:   examples/xxx/src/lib/run_src_test
	new file:   examples/xxx/src/makefile
	new file:   examples/xxx/src/run
	new file:   examples/xxx/src/todo
	new file:   examples/xxx/testmanifest
	modified:   makeproject
	modified:   src/buildtests
	modified:   src/compare
	deleted:    src/lib
	new file:   src/lib/build_ok_number
	new file:   src/lib/build_test_number
	new file:   src/lib/evaluate_src_test
	new file:   src/lib/run_src_test
	modified:   src/run
	modified:   test/aplusb/ingen/ingen.cpp
	modified:   test/aplusb/src/almost_ok.cpp
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 21, 2018
1 parent f5a720a commit 3787883
Show file tree
Hide file tree
Showing 25 changed files with 591 additions and 187 deletions.
Empty file added examples/xxx/eval/makefile
Empty file.
Empty file added examples/xxx/incf/makefile
Empty file.
Empty file added examples/xxx/ingen/makefile
Empty file.
Empty file added examples/xxx/okgen/makefile
Empty file.
2 changes: 2 additions & 0 deletions examples/xxx/problemconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
problemname=xxx
timelimit=1
89 changes: 89 additions & 0 deletions examples/xxx/src/buildtests
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions examples/xxx/src/compare
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions examples/xxx/src/lib/build_test_number
Original file line number Diff line number Diff line change
@@ -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

}


38 changes: 38 additions & 0 deletions examples/xxx/src/lib/evaluate_src_test
Original file line number Diff line number Diff line change
@@ -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
}
51 changes: 51 additions & 0 deletions examples/xxx/src/lib/run_src_test
Original file line number Diff line number Diff line change
@@ -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 ..)
}


Empty file added examples/xxx/src/makefile
Empty file.
Loading

0 comments on commit 3787883

Please sign in to comment.