Files
2026-10-15 20:44:05 -03:00

83 lines
6.2 KiB
Bash
Executable File

#!/bin/bash
# Checks, from the team account in the test VM, the statements of the
# technical notes for the teams (docs/TechNotes.tex) that can be checked on
# the machine: tests/technotes_check.sh -> test_report/technotes_check.txt
cd "$(dirname "$0")/.."
mkdir -p test_report
tests/vssh.sh team 'bash -s' <<'EOF' | tee test_report/technotes_check.txt
set +e
mkdir -p ~/tn && cd ~/tn
pass=0; fail=0
ok(){ echo "PASS $1"; pass=$((pass+1)); }; ko(){ echo "FAIL $1"; fail=$((fail+1)); }
t(){ d=$1; shift; if eval "$@" >/dev/null 2>&1; then ok "$d"; else ko "$d"; fi; }
echo "2 3" > input.txt
cat > base.cpp <<'X'
#include <cstdio>
int main(){int a,b;scanf("%d %d",&a,&b);printf("%d\n",a+b);}
X
for ext in cpp cc C cxx c++; do cp base.cpp "p.$ext"; rm -f a.out
t "C++ extension .$ext: compilecpp, then runcpp < input.txt" "compilecpp p.$ext && [ \"\$(runcpp < input.txt)\" = 5 ]"; done
cat > p.c <<'X'
#include <stdio.h>
int main(void){int a,b;if(scanf("%d %d",&a,&b)!=2)return 1;printf("%d\n",a+b);return 0;}
X
rm -f a.out; t "C: compilec p.c, then runc < input.txt" "compilec p.c && [ \"\$(runc < input.txt)\" = 5 ]"
rm -f a.out; t "compilegcc is another name for compilec" "compilegcc p.c && [ -x a.out ]"
rm -f a.out; t "compileg++ is another name for compilecpp" "compileg++ p.cpp && [ -x a.out ]"
t "programs are linked statically (-static)" "file a.out | grep -q 'statically linked'"
t "compilec runs gcc-15 -g -O2 -o a.out -std=gnu23 -static ... -lm" "grep -q 'gcc-15 -g -O2 -o a.out -std=gnu23 -static' /usr/local/bin/compilec"
t "compilecpp runs the Kattis command" "grep -q 'g++-15 -g -O2 -o a.out -std=gnu++23 -static -lrt -Wl,--whole-archive -lpthread -Wl,--no-whole-archive' /usr/local/bin/compilecpp"
cat > Prog.java <<'X'
import java.util.*;
public class Prog{public static void main(String[] a){Scanner s=new Scanner(System.in);System.out.println(s.nextInt()+s.nextInt());}}
X
t "Java: compilejava Prog.java gives Prog.class, runjava Prog < input.txt" "compilejava Prog.java && [ -f Prog.class ] && [ \"\$(runjava Prog < input.txt)\" = 5 ]"
cat > Mem.java <<'X'
public class Mem{public static void main(String[] a){System.out.println(Runtime.getRuntime().maxMemory()/1048576);}}
X
compilejava Mem.java; m1=$(runjava Mem); m2=$(MEMLIM=1024 runjava Mem)
t "runjava uses 2048 MB (max heap $m1 MB)" "[ $m1 -gt 1900 ] && [ $m1 -le 2048 ]"
t "MEMLIM=1024 runjava uses 1024 MB (max heap $m2 MB)" "[ $m2 -gt 950 ] && [ $m2 -le 1024 ]"
t "java and javac are 25.0.4.1" "java -version 2>&1 | grep -q '\"25.0.4.1\"' && javac -version 2>&1 | grep -q 25.0.4.1"
printf 'a,b=map(int,input().split())\nprint(a+b)\n' > p.py; cp p.py p.py3
t "Python: compilepython3 p.py, then runpython3 p.py < input.txt" "compilepython3 p.py && [ \"\$(runpython3 p.py < input.txt)\" = 5 ]"
t "Python extension .py3 runs" "[ \"\$(runpython3 p.py3 < input.txt)\" = 5 ]"
t "runpython3 runs PyPy 7.3.23 (Python 3.11.15)" "runpython3 -c 'import sys; assert sys.implementation.name==\"pypy\" and sys.pypy_version_info[:3]==(7,3,23) and sys.version_info[:3]==(3,11,15)'"
printf 'print(1/0)\n' > rt.py; t "compilepython3 only checks the syntax (a run time error passes)" "compilepython3 rt.py"
printf 'print(\n' > bad.py; t "compilepython3 reports a syntax error" "! compilepython3 bad.py"
t "python3 is another interpreter, CPython 3.14" "python3 --version | grep -q 'Python 3.14'"
t "gcc-15 and g++-15 are 15.2.0" "[ \$(gcc-15 -dumpfullversion) = 15.2.0 ] && [ \$(g++-15 -dumpfullversion) = 15.2.0 ]"
cat > deep.cpp <<'X'
#include <cstdio>
int f(int n){return n?1+f(n-1):0;}
int main(){printf("%d\n",f(10000000));}
X
t "runcpp: large stack, recursion depth 10 million" "compilecpp deep.cpp && [ \"\$(runcpp)\" = 10000000 ]"
t "man 3 printf works" "man 3 printf | head -5 | grep -qi printf"
t "pypy3 -m pydoc heapq works" "pypy3 -m pydoc heapq | head -3 | grep -q heapq"
t "logged in as team, home /home/team" "[ \"\$(id -un)\" = team ] && [ \"\$HOME\" = /home/team ] && loginctl list-sessions --no-legend | grep -q 'team seat0'"
for app in clion codeblocks Eclipse intellij-idea pycharm com.microsoft.VSCode gvim emacs geany org.kde.kate org.gnome.gedit; do
t "in the Applications menu: $app" "[ -f /usr/share/applications/$app.desktop ]"; done
t "vim and nano are installed" "command -v vim && command -v nano"
t "DevDocs at https://devdocs/ answers" "curl -sk -o /dev/null https://devdocs/"
for d in c cpp openjdk~25 python~3.11; do
t "DevDocs serves the documentation of $d" "[ \$(curl -sk -o /dev/null -w %{http_code} https://devdocs/docs/$d/index.json) = 200 ]"; done
t "DevDocs has no Kotlin documentation" "[ \$(curl -sk -o /dev/null -w %{http_code} https://devdocs/docs/kotlin~2.4/index.json) != 200 ]"
t "offline contest help is readable from the documented menu" "test -r /usr/share/doc/acpc/help/index.html && grep -qx 'Exec=firefox file:///usr/share/doc/acpc/help/index.html' /usr/share/applications/acpc-help.desktop"
t "offline help covers input, judging and every contest language" "python3 -c \"from pathlib import Path;s=Path('/usr/share/doc/acpc/help/index.html').read_text();assert all(x in s for x in ['Reading until EOF','Judgements','C and C++','Java main class','Python 3 and modules'])\""
t "contest site reachable" "curl -s -o /dev/null -m 8 https://atlantic-canada26.kattis.com"
t "Kattis status page reachable" "curl -s -o /dev/null -m 8 https://status.kattis.com"
t "other websites blocked (en.cppreference.com)" "! curl -s -o /dev/null -m 8 https://en.cppreference.com"
t "clock synchronized" "chronyc -n sources | grep -q '^\^\*'"
t "time zone Atlantic (ADT/AST)" "date +%Z | grep -qE 'ADT|AST'"
for source in p.c p.cpp Prog.java p.py; do
t "IDE action acpc-solution builds and runs $source" "acpc-solution run $source < input.txt | tail -1 | grep -qx 5"
done
t "VS Code contest folder and task shortcut exist" "test -d ~/contest && grep -q f6 ~/.config/Code/User/keybindings.json"
t "Eclipse named contest build/run action exists" "test -f ~/eclipse-workspace/.metadata/.plugins/org.eclipse.debug.core/.launches/ACPC\ Build\ and\ run.launch"
t "Geany Java uses runjava for the documented VM options" "grep -q '^EX_00_CM=runjava' /usr/share/geany/filedefs/filetypes.java"
t "CLion includes Python with the PyPy SDK" "grep -q /usr/local/bin/pypy3 ~/.config/JetBrains/CLion*/options/jdk.table.xml"
cd ~ && rm -rf ~/tn
echo; echo "$pass passed, $fail failed"
EOF