From 2f5b87cae60cfbd3e8cd1a335d83bcd2b1af3283 Mon Sep 17 00:00:00 2001 From: Madhav Kumar Date: Tue, 29 Mar 2022 23:38:12 +0530 Subject: [PATCH] added loops for pypy and java --- images/java/evaluate.sh | 65 ++++++++++++++++++++++++---------------- images/pypy3/evaluate.sh | 56 ++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/images/java/evaluate.sh b/images/java/evaluate.sh index 609179d..364b7b9 100644 --- a/images/java/evaluate.sh +++ b/images/java/evaluate.sh @@ -32,36 +32,51 @@ function cleanup() { # # output file = {id} + "-output.txt" -touch $1-code-output.txt - # compile the java file -javac $3/$1_main.$2 +a = 1 +flag = 0 +while [-e "$3/$1-input/input-$a.txt" ] +do + touch $1-code-output.txt + javac $3/$1_main.$2 -if [ $? != 0 ]; then - echo "compile failed" - cleanup $1 $3 - exit -fi + res = $? -cd $3 -# run the code and trap the output -java $1_main < $1-input.txt > ../$1-code-output.txt + if [ $? != 0 ]; then + echo "compile failed" + flag = 1 + cleanup $1 $3 + exit + fi -if [ $? != 0 ]; then - echo "run failed" - cleanup $1 $3 - exit -fi + cd $3 + # run the code and trap the output + java $1_main < $1-input-$a.txt > ../$1-code-output.txt + + if [ $? != 0 ]; then + echo "run failed" + flag = 1 + cleanup $1 $3 + exit + fi + + cd .. -cd .. + # Check if output matches + diff --strip-trailing-cr $1-code-output.txt $3/$1-output-$a.txt > $1-diff-messages.txt + if [ $? != 0 ]; then + echo "wrong output" + flag = 1 + cleanup $1 $3 + exit + fi -# Check if output matches -diff --strip-trailing-cr $1-code-output.txt $3/$1-output.txt > $1-diff-messages.txt -if [ $? != 0 ]; then - echo "wrong output" cleanup $1 $3 - exit -fi + a=$((a+1)) +done + + -cleanup $1 $3 -echo "successfully executed" \ No newline at end of file +if [ $flag -eq 0 ]; then + echo "successfully executed" +fi \ No newline at end of file diff --git a/images/pypy3/evaluate.sh b/images/pypy3/evaluate.sh index 1a48f7f..efd403f 100644 --- a/images/pypy3/evaluate.sh +++ b/images/pypy3/evaluate.sh @@ -25,24 +25,48 @@ function cleanup() { # # output file = {id} + "-output.txt" -touch $1-code-output.txt +a = 1 +flag = 0 +while [-e "$3/$1-input/input-$a.txt" ] +do + touch $1-code-output.txt -# Execute and trap output -pypy3 $3/$1-main.$2 < $3/$1-input.txt &> $1-code-output.txt + # Execute and trap output + timeout $4 pypy3 $3/$1-main.$2 < $3/$1-input-$a.txt &> $1-code-output.txt -if [ $? != 0 ]; then - echo "run failed" - cleanup $1 - exit -fi + res=$? + + if [ $res -eq 124 ]; then + echo "time limit exceeded on test $a" + cleanup $1 + flag=1 + exit + elif [ $res -eq 137 ]; then + echo "memory limit exceeded on test $a" + cleanup $1 + flag=1 + exit + elif [ $res != 0 ]; then + echo "run failed on test $a", $res + cleanup $1 + flag=1 + exit + fi + + # Check if output matches + diff --strip-trailing-cr $1-code-output.txt $3/$1-output/output-$a.txt > $1-diff-messages.txt + if [ $? != 0 ]; then + echo "wrong output on test case $a" + cleanup $1 + flag=1 + exit + fi -# Check if output matches -diff $1-code-output.txt $3/$1-output.txt > $1-diff-messages.txt -if [ $? != 0 ]; then - echo "wrong output" cleanup $1 - exit -fi -cleanup $1 -echo "successfully executed" \ No newline at end of file + a=$((a+1)) +done + +if [ $flag -eq 0 ]; then + echo "successfully executed" +fi \ No newline at end of file