Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Apr 2023 20:16:17 GMT
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 485f783f882e - main - limits_test: validate CPU time used, not real time
Message-ID:  <202304142016.33EKGHen000905@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by vangyzen:

URL: https://cgit.FreeBSD.org/src/commit/?id=485f783f882ed026cdbfede89aa7bddad3fffdf3

commit 485f783f882ed026cdbfede89aa7bddad3fffdf3
Author:     Eric van Gyzen <vangyzen@FreeBSD.org>
AuthorDate: 2023-04-14 21:11:29 +0000
Commit:     Eric van Gyzen <vangyzen@FreeBSD.org>
CommitDate: 2023-04-14 21:16:05 +0000

    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
---
 usr.bin/limits/tests/limits_test.sh | 44 ++++++++++++++++++++++++++++++-------
 1 file 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()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304142016.33EKGHen000905>