diff options
author | Eric van Gyzen <vangyzen@FreeBSD.org> | 2023-04-14 21:11:29 +0000 |
---|---|---|
committer | Eric van Gyzen <vangyzen@FreeBSD.org> | 2023-04-14 21:16:05 +0000 |
commit | 485f783f882ed026cdbfede89aa7bddad3fffdf3 (patch) | |
tree | e69e742a855b9d52f1d11c4d1edfd33cad0fd747 | |
parent | 3cc7b66732808a5f7f703f4b887fe6c60a3e7d4e (diff) | |
download | src-485f783f882ed026cdbfede89aa7bddad3fffdf3.tar.gz src-485f783f882ed026cdbfede89aa7bddad3fffdf3.zip |
limits_test: validate CPU time used, not real time
RLIMIT_CPU applies to CPU time, not real (wall-clock) time.
This test failed in AWS, where the real time was 5-7 seconds.
Sum the user and system CPU time used, and validate that.
While I'm here, don't bother specifying -s exit:0 or -e empty,
since those are checked by default.
MFC after: 1 week
Sponsored by: Dell EMC Isilon
-rwxr-xr-x | usr.bin/limits/tests/limits_test.sh | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/usr.bin/limits/tests/limits_test.sh b/usr.bin/limits/tests/limits_test.sh index 63f60e8eedf5..195813d322a6 100755 --- a/usr.bin/limits/tests/limits_test.sh +++ b/usr.bin/limits/tests/limits_test.sh @@ -31,30 +31,58 @@ # shell interpretation of time(1) TIME=/usr/bin/time -atf_test_case cputime_hard_flag +validate_time_output() +{ + local time_output=$1 + + # RLIMIT_CPU is enforced by a 1-second timer. Allow 3 + 1 + a little. + atf_check awk ' + /^(user|sys) / { + sum += $2 + } + END { + if (sum < 3 || sum >= 4.5) { + print(sum); + exit(1); + } + } + ' < $time_output +} + +atf_test_case cputime_hard_flag cleanup cputime_hard_flag_body() { - atf_check -e empty -o match:'cputime[[:space:]]+3 secs' -s exit:0 \ + atf_check -o match:'cputime[[:space:]]+3 secs' \ limits -H -t 3 limits -H - atf_check -e empty -o match:'cputime[[:space:]]+3 secs' -s exit:0 \ + atf_check -o match:'cputime[[:space:]]+3 secs' \ limits -H -t 3 limits -S - atf_check -e match:'real[[:space:]]+[34]\.[0-9][0-9]' -o empty -s signal:sigkill \ + atf_check -e save:time_output -s signal:sigkill \ limits -H -t 3 $TIME -p sh -c 'while : ; do : ; done' + validate_time_output time_output +} +cputime_hard_flag_cleanup() +{ + rm -f time_output } SIGXCPU=24 # atf_check doesn't know sigxcpu -atf_test_case cputime_soft_flag +atf_test_case cputime_soft_flag cleanup cputime_soft_flag_body() { - atf_check -e empty -o match:'cputime-max[[:space:]]+infinity secs' -s exit:0 \ + atf_check -o match:'cputime-max[[:space:]]+infinity secs' \ limits -S -t 3 limits -H - atf_check -e empty -o match:'cputime-cur[[:space:]]+3 secs' -s exit:0 \ + atf_check -o match:'cputime-cur[[:space:]]+3 secs' \ limits -S -t 3 limits -S - atf_check -e match:'real[[:space:]]+[34]\.[0-9][0-9]' -o empty -s signal:$SIGXCPU \ + atf_check -e save:time_output -s signal:$SIGXCPU \ limits -S -t 3 $TIME -p sh -c 'while : ; do : ; done' + validate_time_output time_output +} +cputime_soft_flag_cleanup() +{ + rm -f time_output } atf_init_test_cases() |