This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_one_test.sh
executable file
·110 lines (84 loc) · 1.84 KB
/
run_one_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
bail()
{
if [ "x$tmpdir" != "x" ]; then
rm -rf $tmpdir
fi
exit $1
}
cfg=$(realpath $1)
prog=$(realpath $2)
in=$(realpath $3)
ans=$(realpath $4)
out=$(realpath $5)
source $cfg
# move program into a transient global-accessable directory
tmpdir=$(mktemp -d opojXXXXXXXX -p /tmp)
chmod 711 $tmpdir
if [ "x$mem_limit" = "x" ]; then
# default
mem_limit=1G
fi
if [ "x$out_limit" = "x" ]; then
# default
out_limit=8M
fi
if [ "x$time_limit" = "x" ]; then
echo "time limit must be set in problem configuration file"
bail 1
fi
cmd="sudo systemd-run --wait --collect"
# limit to one core
cmd="$cmd -p CPUQuota=100%"
# memory limit
cmd="$cmd -p MemoryMax=$mem_limit"
cmd="$cmd -p MemorySwapMax=0"
# run time limit
cmd="$cmd -p RuntimeMaxSec=$time_limit"
# do not dump core
cmd="$cmd -p LimitCORE=0"
# output limit
cmd="$cmd -p LimitFSIZE=$out_limit"
# use transient user
cmd="$cmd -p DynamicUser=true"
cmd="$cmd -p BindReadOnlyPaths=$tmpdir"
# set up stdin
cmd="$cmd -p StandardInput=file:$in"
# make a writable file
touch $tmpdir/out.txt
chmod 666 $tmpdir/out.txt
# set up stdout
cmd="$cmd -p StandardOutput=file:$tmpdir/out.txt"
# hack for system("pause")
install -vdm755 $tmpdir/bin
ln -sv /bin/true $tmpdir/bin/pause
cmd="$cmd -p Environment=PATH=$tmpdir/bin:$PATH"
# set up program
install -vm755 $prog $tmpdir/exe
cmd="$cmd $tmpdir/exe"
$cmd 2> $tmpdir/judge_log
# check for JE
if [ "$(cat $tmpdir/judge_log | wc -l)" -lt 2 ]; then
bail 1
fi
# check for TL
if head -n2 $tmpdir/judge_log | tail -n1 | grep timeout > /dev/null; then
echo TL > $out
bail 0
fi
# check for RE
if ! head -n2 $tmpdir/judge_log | tail -n1 | grep success > /dev/null; then
echo RE > $out
bail 0
fi
if [ "x$spj" != x ]; then
diff_cmd="$spj $in"
else
diff_cmd="diff -Z"
fi
if $diff_cmd $tmpdir/out.txt $ans; then
echo AC > $out
bail 0
fi
echo WA > $out
bail 0