5
5
cd " $( dirname " ${BASH_SOURCE[0]} " ) " || exit 1
6
6
7
7
RUNGUARD=../runguard
8
+ RUNGUARD_OPTIONS=' -u domjudge-run-0'
8
9
LOG1=" $( mktemp) "
9
10
LOG2=" $( mktemp) "
10
11
# shellcheck disable=SC2154
@@ -66,47 +67,47 @@ test_no_sudo() {
66
67
}
67
68
68
69
test_ls () {
69
- exec_check_success sudo $RUNGUARD -u domjudge-run-0 ls
70
+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS ls
70
71
expect_stdout " runguard_test.sh"
71
72
}
72
73
73
74
test_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
75
76
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
77
78
expect_stderr " timelimit exceeded"
78
79
expect_stderr " hard wall time"
79
80
}
80
81
81
82
test_cputime_limit () {
82
83
# 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
84
85
85
86
# 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
87
88
88
89
# 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
91
92
}
92
93
93
94
test_cputime_pinning () {
94
95
# 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
96
97
# ...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
98
99
}
99
100
100
101
test_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
102
103
expect_stdout " DOMjudge"
103
104
limit=$(( 123 * 1024 ))
104
105
actual=$( wc -c < " $LOG1 " )
105
106
[ $limit -eq $actual ] || fail " stdout not limited to ${limit} B, but wrote ${actual} B"
106
107
}
107
108
108
109
test_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
110
111
expect_stderr " DOMjudge"
111
112
# Allow 100 bytes extra, for the runguard time limit message.
112
113
limit=$(( 42 * 1024 + 100 ))
@@ -119,15 +120,15 @@ test_redir_stdout() {
119
120
chmod go+rwx " $stdout "
120
121
121
122
# 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'
123
124
grep -q " foobar" " $stdout " || fail " did not find expected 'foobar' in redirect stdout"
124
-
125
+
125
126
# Verify that stdout is empty.
126
127
actual=$( wc -c < " $LOG1 " )
127
128
[ $actual -eq 0 ] || fail " stdout should be empty, but contains ${actual} B"
128
129
129
130
# 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
131
132
expect_stderr " timelimit exceeded"
132
133
expect_stderr " hard wall time"
133
134
@@ -149,7 +150,7 @@ test_redir_stderr() {
149
150
chmod go+rwx " $stderr "
150
151
151
152
# 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
153
154
expect_stderr " timelimit exceeded"
154
155
expect_stderr " hard wall time"
155
156
@@ -173,47 +174,47 @@ test_rootdir_changedir() {
173
174
cp hello " $almost_empty_dir " /
174
175
ln -sf /hello " $almost_empty_dir " /exists/foo
175
176
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
177
178
expect_stdout " Hello DOMjudge"
178
179
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
180
181
expect_stderr " cannot chdir to \` doesnotexist' in chroot"
181
182
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
183
184
expect_stdout " Hello DOMjudge"
184
185
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
186
187
expect_stdout " Hello DOMjudge"
187
188
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
189
190
expect_stdout " Hello DOMjudge"
190
191
}
191
192
192
193
test_memsize () {
193
194
# 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 ))
195
196
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 ))
197
198
expect_stdout " mem = 1048576"
198
199
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 ))
201
202
expect_stdout " mem = 1073741824"
202
203
}
203
204
204
205
test_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
206
207
expect_stdout " COUNT: 2."
207
208
expect_stdout " PATH="
208
209
expect_stdout " LC_CTYPE="
209
210
not_expect_stdout " DOMjudge"
210
211
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
212
213
expect_stdout " HOME="
213
214
expect_stdout " USER="
214
215
expect_stdout " SHELL="
215
216
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
217
218
expect_stdout " COUNT: 5."
218
219
expect_stdout " DOMjudgeA=A"
219
220
expect_stdout " DOMjudgeB=BB"
@@ -224,18 +225,18 @@ test_envvars() {
224
225
}
225
226
226
227
test_nprocs () {
227
- exec_check_success sudo $RUNGUARD -u domjudge-run-0 ./forky.sh
228
+ exec_check_success sudo $RUNGUARD $RUNGUARD_OPTIONS ./forky.sh
228
229
expect_stdout 31
229
230
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
231
232
expect_stdout 15
232
233
not_expect_stdout 16
233
234
not_expect_stdout 31
234
235
expect_stderr " fork: retry: Resource temporarily unavailable"
235
236
}
236
237
237
238
test_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
239
240
expect_meta ' wall-time: 1.0'
240
241
expect_meta ' cpu-time: 0.0'
241
242
expect_meta ' sys-time: 0.0'
@@ -245,27 +246,27 @@ test_meta() {
245
246
expect_meta ' stdout-bytes: 0'
246
247
expect_meta ' stderr-bytes: 0'
247
248
248
- exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -M " $META " false
249
+ exec_check_fail sudo $RUNGUARD $RUNGUARD_OPTIONS -M " $META " false
249
250
expect_meta ' exitcode: 1'
250
251
251
252
# 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 "
253
254
expect_meta ' wall-time: 0.0'
254
255
expect_meta ' stdout-bytes: 9'
255
256
expect_stdout " egdujMOD"
256
257
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
258
259
expect_meta ' exitcode: 143'
259
260
expect_meta ' signal: 14'
260
261
expect_meta ' wall-time: 1.5'
261
262
expect_meta ' time-result: hard-timelimit'
262
263
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
264
265
expect_meta ' time-used: cpu-time'
265
266
expect_meta ' time-result: soft-timelimit'
266
267
expect_meta ' exitcode: 0'
267
268
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
269
270
# We expect stderr-bytes to have a non-zero value.
270
271
expect_meta ' stderr-bytes: '
271
272
grep -q ' stderr-bytes: 0' " $META " && fail " "
0 commit comments