From 8fa580d8a0ef5a9e2455c477a296cb0a537e0ba3 Mon Sep 17 00:00:00 2001 From: Bruno Cesar Ribas Date: Tue, 23 Oct 2018 08:56:39 -0300 Subject: Adding kotlin files with problemtemplate Signed-off-by: Bruno Cesar Ribas --- doc/problemexamples/problemtemplate/compare/kt | 97 +++++++++++++++ doc/problemexamples/problemtemplate/compile/kt | 155 ++++++++++++++++++++++++ doc/problemexamples/problemtemplate/limits/kt | 15 +++ doc/problemexamples/problemtemplate/run/kt | 159 +++++++++++++++++++++++++ doc/problemexamples/problemtemplate/tests/kt | 41 +++++++ 5 files changed, 467 insertions(+) create mode 100755 doc/problemexamples/problemtemplate/compare/kt create mode 100755 doc/problemexamples/problemtemplate/compile/kt create mode 100644 doc/problemexamples/problemtemplate/limits/kt create mode 100755 doc/problemexamples/problemtemplate/run/kt create mode 100755 doc/problemexamples/problemtemplate/tests/kt (limited to 'doc/problemexamples/problemtemplate') diff --git a/doc/problemexamples/problemtemplate/compare/kt b/doc/problemexamples/problemtemplate/compare/kt new file mode 100755 index 0000000..4998be3 --- /dev/null +++ b/doc/problemexamples/problemtemplate/compare/kt @@ -0,0 +1,97 @@ +#!/bin/bash +# //////////////////////////////////////////////////////////////////////////////// +# //BOCA Online Contest Administrator +# // Copyright (C) 2003-2012 by BOCA Development Team (bocasystem@gmail.com) +# // +# // This program is free software: you can redistribute it and/or modify +# // it under the terms of the GNU General Public License as published by +# // the Free Software Foundation, either version 3 of the License, or +# // (at your option) any later version. +# // +# // This program is distributed in the hope that it will be useful, +# // but WITHOUT ANY WARRANTY; without even the implied warranty of +# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# // GNU General Public License for more details. +# // You should have received a copy of the GNU General Public License +# // along with this program. If not, see . +# //////////////////////////////////////////////////////////////////////////////// +# // Last modified 21/jul/2012 by cassio@ime.usp.br +# +# This script receives: +# $1 team_output +# $2 sol_output +# $3 problem_input (might be used by some specific checkers, here it is not) +# +# BOCA reads the last line of the standard output +# and pass it to judges +# +if [ ! -r "$1" -o ! -r "$2" ]; then + echo "Parameter problem" + exit 43 +fi + +# Next lines of this script just compares team_output and sol_output, +# although it is possible to change them to more complex evaluations. + +diff -q "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff \"$1\" \"$2\" # files match" + echo "Files match exactly" + exit 4 +fi +diff -q -b "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff -c -b \"$1\" \"$2\" # files match" + echo -e "diff -c \"$1\" \"$2\" # files dont match - see output" + diff -c "$1" "$2" + echo "Files match with differences in the amount of white spaces" + exit 5 +fi +diff -q -b -B "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff -c -b -B \"$1\" \"$2\" # files match" + echo -e "diff -c -b \"$1\" \"$2\" # files dont match - see output" + diff -c -b "$1" "$2" + echo "Files match with differences in the amount of white spaces and blank lines" + exit 5 +fi +diff -q -i -b -B "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff -c -i -b -B \"$1\" \"$2\" # files match" + echo -e "diff -c -b -B \"$1\" \"$2\" # files dont match - see output" + diff -c -b -B "$1" "$2" + echo "Files match if we ignore case and differences in the amount of white spaces and blank lines" + exit 5 +fi +diff -q -b -B -w "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff -c -b -B -w \"$1\" \"$2\" # files match" + echo -e "diff -c -i -b -B \"$1\" \"$2\" # files dont match - see output" + diff -c -i -b -B "$1" "$2" + echo "Files match if we discard all white spaces" + exit 5 +fi +diff -q -i -b -B -w "$1" "$2" >/dev/null 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "diff -c -i -b -B -w \"$1\" \"$2\" # files match" + echo -e "diff -c -b -B -w \"$1\" \"$2\" # files dont match - see output" + diff -c -b -B -w "$1" "$2" + echo "Files match if we ignore case and discard all white spaces" + exit 5 +fi +wd=`which wdiff` +if [ "$wd" != "" ]; then + wdiff \"$1\" \"$2\" >/dev/null 2>/dev/null + if [ "$?" == "0" ]; then + echo -e "wdiff \"$1\" \"$2\" # files match" + echo -e "diff -c -i -b -B -w \"$1\" \"$2\" # files dont match - see output" + diff -c -i -b -B -w "$1" "$2" + echo "BUT Files match if we compare word by word, ignoring everything else, using wdiff" + echo "diff has a bug that, if a line contains a single space, this is not discarded by -w" + exit 5 + fi +fi +echo -e "### files dont match - see output" +diff -c -i -b -B -w "$1" "$2" +echo "Differences found" +exit 6 diff --git a/doc/problemexamples/problemtemplate/compile/kt b/doc/problemexamples/problemtemplate/compile/kt new file mode 100755 index 0000000..45e55d0 --- /dev/null +++ b/doc/problemexamples/problemtemplate/compile/kt @@ -0,0 +1,155 @@ +#!/bin/bash +# //////////////////////////////////////////////////////////////////////////////// +# //BOCA Online Contest Administrator +# // Copyright (C) 2003-2012 by BOCA System (bocasystem@gmail.com) +# // +# // This program is free software: you can redistribute it and/or modify +# // it under the terms of the GNU General Public License as published by +# // the Free Software Foundation, either version 3 of the License, or +# // (at your option) any later version. +# // +# // This program is distributed in the hope that it will be useful, +# // but WITHOUT ANY WARRANTY; without even the implied warranty of +# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# // GNU General Public License for more details. +# // You should have received a copy of the GNU General Public License +# // along with this program. If not, see . +# //////////////////////////////////////////////////////////////////////////////// +#Last modified: 21/july/2012 by cassio@ime.usp.br +# +# parameters are: +# $1 source_file +# $2 exe_file (default run.jar) +# $3 timelimit (optional, limit to run all the repetitions, by default only one repetition) +# $4 maximum allowed memory (in MBytes) +# +# the output of the submission should be directed to the standard output +# +# the return code show what happened (according to safeexec): +# 0 ok +# 1 compile error +# 2 runtime error +# 3 timelimit exceeded +# 4 internal error +# 5 parameter error +# 6 internal error +# 7 memory limit exceeded +# 8 security threat +# 9 runtime error +# other_codes are unknown to boca: in this case BOCA will present the +# last line of standard output to the judge + +umask 0022 +if [ "$1" == "" ]; then + echo "parameter problem" + exit 43 +fi +name="$1" +if [ ! -r "$1" ]; then + echo "$1 not found or it's not readable" + exit 44 +fi +id -u bocajail >/dev/null 2>/dev/null +if [ $? == 0 ]; then + bocau=`id -u bocajail` + bocag=`id -g bocajail` + chown bocajail.nogroup . +else + bocau=`id -u nobody` + bocag=`id -g nobody` + chown nobody.nogroup . +fi +if [ "$bocau" == "" -o "$bocag" == "" ]; then + echo "error finding user to run script" + exit 43 +fi + +mkdir -p src +if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then + unzip "$name" -d src + if [ "${name##*.}" == "zip" ]; then + name=`basename $name .zip` + else + name=`basename $name .ZIP` + fi +else + cp "$name" src +fi +chown -R $bocau src +chmod -R 700 src + +# this script makes use of safeexec to execute the code with less privilegies +# make sure that directories below are correct. +sf=`which safeexec` +[ -x "$sf" ] || sf=/usr/bin/safeexec +if [ ! -x $sf ]; then + echo "$sf not found or it's not executable" + exit 46 +fi + +# setting up the timelimit according to the problem +if [ "$3" == "" ]; then + time=5 +else + time=$3 +fi +let "ttime = $time + 30" + +maxm=1024 +if [ "$4" != "" -a "$4" -gt "1024" ]; then +maxm=$4 +fi + +maxms=100 + +if [ "$2" == "" ]; then + jarfile=run.jar +else + jarfile=$2 +fi + +cdir=`pwd` +echo "Current directory is $cdir" >&2 +mainname=`echo $name | cut -d'.' -f1` +if [ "$mainname" == "" ]; then + mainname=Main +fi + +cat < compileit.sh +#!/bin/bash +kotlinc=/snap/kotlin/24/bin/kotlinc +[ -x "\$kotlinc" ] || kotlinc=/snap/bin/kotlinc +if [ ! -x \$kotlinc ]; then + echo "\$kotlinc not found or it's not executable" + exit 47 +fi +cd src +\$kotlinc -J-Xmx${maxm}M -J-Xss${maxms}M -J-Xms${maxm}M -d ../$jarfile -include-runtime $name +echo \$? > ../compileit.retcode + +exit 0 +EOF +chmod 755 compileit.sh + +echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING" +#$kotlinc "$name" +$sf -r1 -t20 -T32 -istdin0 -F512 -u512 -U$bocau -G$bocag -n0 -C. -d40000000000 -m40000000000 ./compileit.sh +#./compileit.sh +ret=$? +if [ -f "stdout0" ]; then + cat "stdout0" +fi +if [ -f "stderr0" ]; then + cat "stderr0" +fi +#rm -rf src/ +if [ "$ret" != "0" ]; then + echo "Compilation Error: $ret" + exit $ret +fi +ret=`cat compileit.retcode` +if [ "$ret" != "0" ]; then + echo "Compilation Error: $ret" + ret=1 +fi +exit $ret diff --git a/doc/problemexamples/problemtemplate/limits/kt b/doc/problemexamples/problemtemplate/limits/kt new file mode 100644 index 0000000..5701ffc --- /dev/null +++ b/doc/problemexamples/problemtemplate/limits/kt @@ -0,0 +1,15 @@ +#!/bin/bash +# this executable shall output the number of second of timelimit in the first line, for the given problem and with language according to this filename +echo 1 +# and the number of repetitions to run within the given timelimit in the second line +echo 1 +# and the maximum amount of memory per repetition in the third line (in Mbytes) +echo 1024 +# and the maximum file size in the fourth line (in kbytes) +echo 1024 +# and shall return zero to indicate no failure +exit 0 +# the idea is that this file will be executed by the autojudge in the first time the autojudge downloads a problem, so as it will be +# able to decide the proper time limit for the machine where it is running. If one wants to fix a predefined time limit, then it is +# enough to write a script like this one with the desired value. Otherwise, one can build any more sophisticated program that outputs +# the value. diff --git a/doc/problemexamples/problemtemplate/run/kt b/doc/problemexamples/problemtemplate/run/kt new file mode 100755 index 0000000..1b06f48 --- /dev/null +++ b/doc/problemexamples/problemtemplate/run/kt @@ -0,0 +1,159 @@ +#!/bin/bash +# //////////////////////////////////////////////////////////////////////////////// +# //BOCA Online Contest Administrator +# // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com) +# // +# // This program is free software: you can redistribute it and/or modify +# // it under the terms of the GNU General Public License as published by +# // the Free Software Foundation, either version 3 of the License, or +# // (at your option) any later version. +# // +# // This program is distributed in the hope that it will be useful, +# // but WITHOUT ANY WARRANTY; without even the implied warranty of +# // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# // GNU General Public License for more details. +# // You should have received a copy of the GNU General Public License +# // along with this program. If not, see . +# //////////////////////////////////////////////////////////////////////////////// +#Last modified: 04/nov/2014 by cassio@ime.usp.br +# +# parameters are: +# $1 main_class +# $2 input_file +# $3 timelimit (limit to run all the repetitions, by default only one repetition) +# $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit) +# $5 maximum allowed memory (in MBytes) +# $6 maximum allowed output size (in KBytes) +# +# the output of the submission should be directed to the standard output +# +# the return code show what happened (according to safeexec): +# 0 ok +# 1 compile error +# 2 runtime error +# 3 timelimit exceeded +# 4 internal error +# 5 parameter error +# 6 internal error +# 7 memory limit exceeded +# 8 security threat +# 9 runtime error +# other_codes are unknown to boca: in this case BOCA will present the +# last line of standard output to the judge + +umask 0022 +id -u bocajail >/dev/null 2>/dev/null +if [ $? == 0 ]; then + bocau=`id -u bocajail` + bocag=`id -g bocajail` + chown bocajail.nogroup . +else + bocau=`id -u nobody` + bocag=`id -g nobody` + chown nobody.nogroup . +fi +if [ "$bocau" == "" -o "$bocag" == "" ]; then + echo "error finding user to run script" + exit 43 +fi + +# this script makes use of safeexec to execute the code with less privilegies +# make sure that directories below are correct. +sf=`which safeexec` +[ -x "$sf" ] || sf=/usr/bin/safeexec + +if [ "$1" == "" -o "$2" == "" -o "$3" == "" ]; then + echo "parameter problem" + exit 43 +fi +if [ -r run.exe ]; then + rm -f run.jar + cp run.exe run.jar +fi +if [ -r "$1" ]; then + rm -f run.jar + cp "$1" run.jar +fi +if [ ! -r run.jar ]; then + echo "ERROR: file run.jar not found - possible error during compilation" + exit 1 +fi +name=`basename "$1"` +if [ "${name##*.}" == "class" -a "${name##*.}" == "CLASS" ]; then + echo "WARNING: removing .class file extension" +fi +if [ "${name##*.}" == "class" ]; then + name=`basename "$1" .class` +fi +if [ "${name##*.}" == "CLASS" ]; then + name=`basename "$1" .CLASS` +fi +if [ ! -r "$2" ]; then + echo "$2 not found (or is not in the current dir) or it's not readable" + exit 45 +fi +if [ ! -x "$sf" ]; then + echo "$sf not found or it's not executable" + exit 46 +fi + +time=$3 +if [ "$time" -gt "0" ]; then + let "ttime = $time + 30" +else + time=1 + ttime=30 +fi + +nruns=1 +if [ "$4" != "" ]; then + if [ "$4" -gt "0" ]; then + nruns=$4 + fi +fi +maxm=1024000 +if [ "$5" != "" ]; then + if [ "$5" -gt "0" ]; then + maxm=${5}000 + fi +fi +let "maxms = $maxm / 10" +maxf=1024 +if [ "$6" != "" ]; then + if [ "$6" -gt "0" ]; then + maxf=${6} + fi +fi + +rm -f runit.retcode 2>/dev/null +cp "$2" stdin0 2>/dev/null + +cdir=`pwd` +echo "Current directory is $cdir" >&2 +echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2 +echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2 +echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2 +kotlin=/snap/kotlin/24/bin/kotlin +[ -x "$kotlin" ] || kotlin=/usr/bin/kotlin +if [ ! -x "$kotlin" ]; then + echo "$kotlin not found or it's not executable" + exit 47 +fi +"$sf" -r$nruns -t$time -T$ttime -istdin0 -F512 -u512 -U$bocau -G$bocag -ostdout0 -estderr0 -n0 -C. -d40000000000 -m40000000000 -- "$kotlin" -cp run.jar -J-Xmx${maxm}K -J-Xss${maxms}K -J-Xms${maxm}K "$name" +#"$kotlin" -cp run.jar -J-Xmx${maxm}K -J-Xss${maxms}K -J-Xms${maxm}K "$name" +ret=$? +if [ $ret -gt 10 ]; then + if [ -r stderr0 ]; then + grep -q "not find or load main class" stderr0 + if [ $? == 0 ]; then + echo "> > > Nonzero return code - possible class name mismatch - do check < < <" + else + echo "> > > Nonzero return code - possible runtime error - do check < < <" + fi + ret=9 + fi +fi +if [ -f stdout0 ]; then + cat stdout0 +fi +exit $ret diff --git a/doc/problemexamples/problemtemplate/tests/kt b/doc/problemexamples/problemtemplate/tests/kt new file mode 100755 index 0000000..2658715 --- /dev/null +++ b/doc/problemexamples/problemtemplate/tests/kt @@ -0,0 +1,41 @@ +#!/bin/bash +# +# This file performs a test of the autojudge system. It can run whatever you feel important to test the autojudge +# and the script files that are included in the problem package + +mkdir -p testdir +cd testdir + +cat > test.kt <<'EOF' +import java.util.* +fun main(args: Array) { + var scanner = Scanner(System.`in`) + val nTests = scanner.nextInt() + for (i in 1..nTests) { + System.`out`.format("%s%n", scanner.next()) + } +} +EOF +cat > test.in <