55cd " $( dirname " ${BASH_SOURCE[0]} " ) " || exit 1
66
77RUNGUARD=../runguard
8+ RUNGUARD_OPTIONS=' -u domjudge-run-0'
89LOG1=" $( mktemp) "
910LOG2=" $( mktemp) "
1011# shellcheck disable=SC2154
@@ -66,47 +67,47 @@ test_no_sudo() {
6667}
6768
6869test_ls () {
69- exec_check_success sudo $RUNGUARD -u domjudge-run-0 ls
70+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS ls
7071 expect_stdout " runguard_test.sh"
7172}
7273
7374test_walltime_limit () {
74- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -t 2 sleep 1
75+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -t 2 sleep 1
7576
76- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 2 sleep 3
77+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 2 sleep 3
7778 expect_stderr " timelimit exceeded"
7879 expect_stderr " hard wall time"
7980}
8081
8182test_cputime_limit () {
8283 # 2 threads, ~3s of CPU time, gives ~1.5s of wall time.
83- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -C 3.1 ./threads 2 3
84+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 ./threads 2 3
8485
8586 # Now also limiting wall time to 2s.
86- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -C 3.1 -t 2 ./threads 2 3
87+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 -t 2 ./threads 2 3
8788
8889 # Some failing cases.
89- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -C 2.9 ./threads 2 3
90- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -C 3.1 -t 1.4 ./threads 2 3
90+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -C 2.9 ./threads 2 3
91+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 -t 1.4 ./threads 2 3
9192}
9293
9394test_cputime_pinning () {
9495 # 2 threads, ~3s of CPU time, with one core we are out of luck...
95- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -C 3.1 -t 2 -P 1 ./threads 2 3
96+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 -t 2 -P 1 ./threads 2 3
9697 # ...but with two cores it works.
97- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -C 3.1 -t 2 -P 0-1 ./threads 2 3
98+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 -t 2 -P 0-1 ./threads 2 3
9899}
99100
100101test_streamsize () {
101- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 123 yes DOMjudge
102+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 1 -s 123 yes DOMjudge
102103 expect_stdout " DOMjudge"
103104 limit=$(( 123 * 1024 ))
104105 actual=$( wc -c < " $LOG1 " )
105106 [ $limit -eq $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
106107}
107108
108109test_streamsize_stderr () {
109- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 42 ./fill-stderr.sh
110+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 1 -s 42 ./fill-stderr.sh
110111 expect_stderr " DOMjudge"
111112 # Allow 100 bytes extra, for the runguard time limit message.
112113 limit=$(( 42 * 1024 + 100 ))
@@ -119,15 +120,15 @@ test_redir_stdout() {
119120 chmod go+rwx " $stdout "
120121
121122 # Basic test.
122- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -o " $stdout " echo ' foobar'
123+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -o " $stdout " echo ' foobar'
123124 grep -q " foobar" " $stdout " || fail " did not find expected 'foobar' in redirect stdout"
124-
125+
125126 # Verify that stdout is empty.
126127 actual=$( wc -c < " $LOG1 " )
127128 [ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
128129
129130 # This will fail because of the timeout.
130- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 23 -o " $stdout " yes DOMjudge
131+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 1 -s 23 -o " $stdout " yes DOMjudge
131132 expect_stderr " timelimit exceeded"
132133 expect_stderr " hard wall time"
133134
@@ -149,7 +150,7 @@ test_redir_stderr() {
149150 chmod go+rwx " $stderr "
150151
151152 # This will fail because of the timeout.
152- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 11 -e " $stderr " ./fill-stderr.sh
153+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 1 -s 11 -e " $stderr " ./fill-stderr.sh
153154 expect_stderr " timelimit exceeded"
154155 expect_stderr " hard wall time"
155156
@@ -173,47 +174,47 @@ test_rootdir_changedir() {
173174 cp hello " $almost_empty_dir " /
174175 ln -sf /hello " $almost_empty_dir " /exists/foo
175176
176- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -r " $almost_empty_dir " ./hello
177+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -r " $almost_empty_dir " ./hello
177178 expect_stdout " Hello DOMjudge"
178179
179- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -r " $almost_empty_dir " -d doesnotexist /hello
180+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -r " $almost_empty_dir " -d doesnotexist /hello
180181 expect_stderr " cannot chdir to \` doesnotexist' in chroot"
181182
182- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -r " $almost_empty_dir " -d exists /hello
183+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -r " $almost_empty_dir " -d exists /hello
183184 expect_stdout " Hello DOMjudge"
184185
185- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -r " $almost_empty_dir " -d exists ./foo
186+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -r " $almost_empty_dir " -d exists ./foo
186187 expect_stdout " Hello DOMjudge"
187188
188- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -r " $almost_empty_dir " -d exists /exists/foo
189+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -r " $almost_empty_dir " -d exists /exists/foo
189190 expect_stdout " Hello DOMjudge"
190191}
191192
192193test_memsize () {
193194 # This is slightly over the limit as there is other stuff to be allocated as well.
194- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -m 1024 ./mem $(( 1024 * 1024 ))
195+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -m 1024 ./mem $(( 1024 * 1024 ))
195196
196- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -m 1500 ./mem $(( 1024 * 1024 ))
197+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -m 1500 ./mem $(( 1024 * 1024 ))
197198 expect_stdout " mem = 1048576"
198199
199- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -m $(( 1024 * 1024 )) ./mem $(( 1024 * 1024 * 1024 ))
200- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -m $(( 1024 * 1024 + 10000 )) ./mem $(( 1024 * 1024 * 1024 ))
200+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -m $(( 1024 * 1024 )) ./mem $(( 1024 * 1024 * 1024 ))
201+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -m $(( 1024 * 1024 + 10000 )) ./mem $(( 1024 * 1024 * 1024 ))
201202 expect_stdout " mem = 1073741824"
202203}
203204
204205test_envvars () {
205- exec_check_success sudo $RUNGUARD -u domjudge-run-0 ./print_envvars.py
206+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS ./print_envvars.py
206207 expect_stdout " COUNT: 2."
207208 expect_stdout " PATH="
208209 expect_stdout " LC_CTYPE="
209210 not_expect_stdout " DOMjudge"
210211
211- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -E ./print_envvars.py
212+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -E ./print_envvars.py
212213 expect_stdout " HOME="
213214 expect_stdout " USER="
214215 expect_stdout " SHELL="
215216
216- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -V" DOMjudgeA=A;DOMjudgeB=BB" -V" DOMjudgeC=CCC" ./print_envvars.py
217+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -V" DOMjudgeA=A;DOMjudgeB=BB" -V" DOMjudgeC=CCC" ./print_envvars.py
217218 expect_stdout " COUNT: 5."
218219 expect_stdout " DOMjudgeA=A"
219220 expect_stdout " DOMjudgeB=BB"
@@ -224,18 +225,18 @@ test_envvars() {
224225}
225226
226227test_nprocs () {
227- exec_check_success sudo $RUNGUARD -u domjudge-run-0 ./forky.sh
228+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS ./forky.sh
228229 expect_stdout 31
229230
230- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -p 16 ./forky.sh
231+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -p 16 ./forky.sh
231232 expect_stdout 15
232233 not_expect_stdout 16
233234 not_expect_stdout 31
234235 expect_stderr " fork: retry: Resource temporarily unavailable"
235236}
236237
237238test_meta () {
238- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -t 2 -M " $META " sleep 1
239+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -t 2 -M " $META " sleep 1
239240 expect_meta ' wall-time: 1.0'
240241 expect_meta ' cpu-time: 0.0'
241242 expect_meta ' sys-time: 0.0'
@@ -245,27 +246,27 @@ test_meta() {
245246 expect_meta ' stdout-bytes: 0'
246247 expect_meta ' stderr-bytes: 0'
247248
248- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -M " $META " false
249+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -M " $META " false
249250 expect_meta ' exitcode: 1'
250251
251252 # shellcheck disable=SC2024
252- echo " DOMjudge" | sudo $RUNGUARD -u domjudge-run-0 -t 2 -M " $META " rev > " $LOG1 " 2> " $LOG2 "
253+ echo " DOMjudge" | sudo $RUNGUARD $RUNGUARD_OPTIONS -t 2 -M " $META " rev > " $LOG1 " 2> " $LOG2 "
253254 expect_meta ' wall-time: 0.0'
254255 expect_meta ' stdout-bytes: 9'
255256 expect_stdout " egdujMOD"
256257
257- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -C 3.1 -t 1.4 -M " $META " ./threads 2 3
258+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -C 3.1 -t 1.4 -M " $META " ./threads 2 3
258259 expect_meta ' exitcode: 143'
259260 expect_meta ' signal: 14'
260261 expect_meta ' wall-time: 1.5'
261262 expect_meta ' time-result: hard-timelimit'
262263
263- exec_check_success sudo $RUNGUARD -u domjudge-run-0 -C 1:5 -M " $META " ./threads 2 3
264+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS -C 1:5 -M " $META " ./threads 2 3
264265 expect_meta ' time-used: cpu-time'
265266 expect_meta ' time-result: soft-timelimit'
266267 expect_meta ' exitcode: 0'
267268
268- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 3 -M " $META " ./fill-stderr.sh
269+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -t 1 -s 3 -M " $META " ./fill-stderr.sh
269270 # We expect stderr-bytes to have a non-zero value.
270271 expect_meta ' stderr-bytes: '
271272 grep -q ' stderr-bytes: 0' " $META " && fail " "
0 commit comments