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'.

 Changes to be committed:
	modified:   README.md
	new file:   buildtests.sh
	deleted:    incf/00
	deleted:    incf/01
	deleted:    incf/02
	new file:   incf/fixed
	new file:   incf/random
	modified:   ingen/ingen.bin
	modified:   ingen/ingen.cpp
	modified:   lib.sh
	modified:   okgen/okgen.bin
	modified:   okgen/okgen.cpp
	modified:   run.sh
	new file:   testmanifest

Basically made ./buildtests work with testmanifest rather than test by test
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 20, 2018
1 parent 9326159 commit 9490935
Show file tree
Hide file tree
Showing 56 changed files with 167 additions and 73 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ README.md | This readme
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 -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
buildtests.sh | ./buildtests.sh will build all tests following testmanifest
testmanifest | describes the structure of the 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.
incf | Holds various configuration files
ingen/ingen.bin | The input generator. When run, a configuration file *problemname*.cf will be made available to it. Output the input to *problemname*.in
incf | Holds various input configuration files
okgen | Contains files related to ok generation
okgen/makefile | A file that needs to make the ok generator, okgen/okgen.bin
okgen/okgen.bin | A file that needs to make ok's. It will read the input from *problemname*.in and write the ok to *problemname*.ok
okgen/okgen.bin | A file that needs to make ok's. It will read the input from *problemname*.in and write the ok to *problemname*.ok. The number of points for this test will be found in *problemname*.points
eval | Contains files related to evaluation
eval/makefile | A file that needs to make the evaluator, eval/eval.bin
eval/eval.bin | A file that evaluates. It will read the input file from *problemname*.in, the output file from *problemname*.out, the ok file from *problemname*.ok. It will write the score to *stdout* and the evaluation message to *stderr*.
tests | Holds tests
stage | Where evaluation happens

testmanifest format:

Groups of tests will appear, each described on a column ; first the number of tests "like this", second the number of points for the group, third the name of the incf.
73 changes: 73 additions & 0 deletions buildtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#
# This builds all tests using testmanifest
# Tamio-Vesa Nakajima

# include the library
source lib.sh

# Get problem name
problemname=`cat problemname`

# Make stage (as git deletes it)
mkdir -p stage

# 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:
#################

# Build input generator
try "cd ingen && make -s && cd .." "input generator build fail"

# Copy ingen/ingen.bin and incf/$1 into stage
cp ingen/ingen.bin stage/$problemname.bin
try "cp incf/$incf stage/$problemname.cf" "incf/$incf doesn't exist"

# Build input
try "cd stage && ./$problemname.bin > ../tests/$problemname-$nr.in && cd .." "input generation fail"

# Clean stage
rm stage/*

###################
# Build ok
###################

# Build ok generator
try "cd okgen && make -s && cd .." "ok generator build fil"

# 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
try "cd stage && ./$problemname.bin && cd .." "ok generation fail"

# 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
1 change: 0 additions & 1 deletion incf/00

This file was deleted.

1 change: 0 additions & 1 deletion incf/01

This file was deleted.

1 change: 0 additions & 1 deletion incf/02

This file was deleted.

1 change: 1 addition & 0 deletions incf/fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 0 1
1 change: 1 addition & 0 deletions incf/random
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 0
Binary file modified ingen/ingen.bin
Binary file not shown.
14 changes: 8 additions & 6 deletions ingen/ingen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ using namespace std;

int main(){
ifstream f("aplusb.cf");
if(!f){
ofstream g("aplusb.in");
bool fixed;
int x, y;
f >> fixed >> x >> y;

if(fixed) g << x << ' ' << y << endl;
else{
srand(time(nullptr));
cout << rand() << ' ' << rand() << endl; }
else {
int x;
f >> x;
cout << x << ' ' << x << endl; }
g << rand() << ' ' << rand() << endl; }
return 0; }
53 changes: 53 additions & 0 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,56 @@ maybecp () {
touch $2
fi
}

# Evaluates whatever is in the stage, and returns: the time used in $1, the evaluation result in $2, the points in $3
evaluate_stage () {
# Get an appropriate timeout command
timeoutCommand=timeout

if [[ "$OSTYPE" == "darwin"* ]] ; then
timeoutCommand=gtimeout
fi

# Get the problem name and the time limit
try "problemname=`cat problemname`" "no problemname file"
try "timelimit=`cat timelimit`" "no timelimit file"

# 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 ..)

if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then
# Set the return values
eval $1=$timeUsed
eval $2=TLE
eval $3=0
else
# 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
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"

# Set the return values
eval "$1="$timeUsed""
eval "$2=`cat $message`"
eval "$3=`cat $points`"
fi
}
Binary file modified okgen/okgen.bin
Binary file not shown.
9 changes: 6 additions & 3 deletions okgen/okgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
using namespace std;

int main(){
ifstream points("aplusb.points");
ifstream f("aplusb.in");
ofstream g("aplusb.out");
long long x, y;
ofstream g("aplusb.ok");

long long p, x, y;
f >> x >> y;
g << 5 << endl;
points >> p;
g << p << endl;
g << x+y << endl;
return 0; }
45 changes: 12 additions & 33 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
source lib.sh

# make stage (as git deletes it)
mkdir stage
mkdir -p stage

# Get an appropriate timeout command
timeoutCommand=timeout
Expand Down Expand Up @@ -72,6 +72,8 @@ if [ -z "$tests" ] ; then
tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'`
fi

tests=`echo $tests | sort -t '-' -k 1 -n`


###########################
# EVALUATING
Expand All @@ -96,6 +98,9 @@ for src in $srcs ; do

# For all tests
for testname in $tests ; do
# clear any previous messages
echo -en " \r"

# Output an appropriate messgae
echo -en "Doing $testname\r"

Expand All @@ -107,40 +112,14 @@ for src in $srcs ; do

# Copy the input into the stage
cp tests/$testname.in stage/$problemname.in

#timeUsed=""
#message=""
#points=""

# 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 \
| head -2 \
| awk -F ' ' '{print $2}' \
| awk -F 'm' '{print $2}' \
| awk -F 's' '{print $1}' && cd ..)

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

# 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"
evaluate_stage timeUsed message points

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

# Clear "Doing test ..."
Expand Down
2 changes: 2 additions & 0 deletions testmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 fixed 10
18 random 90
Empty file added tests/aplusb-0.in
Empty file.
2 changes: 2 additions & 0 deletions tests/aplusb-0.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10
0
1 change: 0 additions & 1 deletion tests/aplusb-00.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-01.in

This file was deleted.

2 changes: 0 additions & 2 deletions tests/aplusb-01.ok

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-02.in

This file was deleted.

2 changes: 0 additions & 2 deletions tests/aplusb-02.ok

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-03.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-04.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-05.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-06.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-07.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-08.in

This file was deleted.

1 change: 0 additions & 1 deletion tests/aplusb-09.in

This file was deleted.

Empty file added tests/aplusb-1.in
Empty file.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/aplusb-10.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-11.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-12.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-13.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-14.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-15.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-16.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-17.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-18.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
0 0
1 change: 0 additions & 1 deletion tests/aplusb-19.in

This file was deleted.

Empty file added tests/aplusb-2.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-3.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-4.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-5.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-6.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-7.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-8.in
Empty file.
File renamed without changes.
Empty file added tests/aplusb-9.in
Empty file.
File renamed without changes.

0 comments on commit 9490935

Please sign in to comment.