aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/sysctl/sysctl.sh
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2017-07-12 17:33:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-12 19:26:00 -0400
commiteb965eda1cabf26e62afc07a06cdf2fd5aaa2906 (patch)
treeb5b38008a45447eefe8450f73de0b441dce11f70 /tools/testing/selftests/sysctl/sysctl.sh
parent1c0357c846452add7c2c863ec372010e3d2ca943 (diff)
test_sysctl: add simple proc_dointvec() case
Test against a simple proc_dointvec() case. While at it, add a test against INT_MAX. Make sure INT_MAX works, and INT_MAX+1 will fail. Also test negative values work. Link: http://lkml.kernel.org/r/20170630224431.17374-5-mcgrof@kernel.org Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/selftests/sysctl/sysctl.sh')
-rw-r--r--tools/testing/selftests/sysctl/sysctl.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
index 6ec807576f7c..7ba3fa2bbd54 100644
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -31,6 +31,7 @@ TEST_FILE=$(mktemp)
31# we have tons of space. 31# we have tons of space.
32ALL_TESTS="0001:1:1" 32ALL_TESTS="0001:1:1"
33ALL_TESTS="$ALL_TESTS 0002:1:1" 33ALL_TESTS="$ALL_TESTS 0002:1:1"
34ALL_TESTS="$ALL_TESTS 0003:1:1"
34 35
35test_modprobe() 36test_modprobe()
36{ 37{
@@ -82,6 +83,9 @@ function check_production_sysctl_writes_strict()
82 if [ -z $MAX_DIGITS ]; then 83 if [ -z $MAX_DIGITS ]; then
83 MAX_DIGITS=$(($PAGE_SIZE/8)) 84 MAX_DIGITS=$(($PAGE_SIZE/8))
84 fi 85 fi
86 if [ -z $INT_MAX ]; then
87 INT_MAX=$(getconf INT_MAX)
88 fi
85} 89}
86 90
87test_reqs() 91test_reqs()
@@ -122,6 +126,9 @@ reset_vals()
122 int_0001) 126 int_0001)
123 VAL="60" 127 VAL="60"
124 ;; 128 ;;
129 int_0002)
130 VAL="1"
131 ;;
125 string_0001) 132 string_0001)
126 VAL="(none)" 133 VAL="(none)"
127 ;; 134 ;;
@@ -296,6 +303,48 @@ run_limit_digit()
296 test_rc 303 test_rc
297} 304}
298 305
306# You are using an int
307run_limit_digit_int()
308{
309 echo -n "Testing INT_MAX works ..."
310 reset_vals
311 TEST_STR="$INT_MAX"
312 echo -n $TEST_STR > $TARGET
313
314 if ! verify "${TARGET}"; then
315 echo "FAIL" >&2
316 rc=1
317 else
318 echo "ok"
319 fi
320 test_rc
321
322 echo -n "Testing INT_MAX + 1 will fail as expected..."
323 reset_vals
324 let TEST_STR=$INT_MAX+1
325 echo -n $TEST_STR > $TARGET 2> /dev/null
326
327 if verify "${TARGET}"; then
328 echo "FAIL" >&2
329 rc=1
330 else
331 echo "ok"
332 fi
333 test_rc
334
335 echo -n "Testing negative values will work as expected..."
336 reset_vals
337 TEST_STR="-3"
338 echo -n $TEST_STR > $TARGET 2> /dev/null
339 if ! verify "${TARGET}"; then
340 echo "FAIL" >&2
341 rc=1
342 else
343 echo "ok"
344 fi
345 test_rc
346}
347
299run_stringtests() 348run_stringtests()
300{ 349{
301 echo -n "Writing entire sysctl in short writes ... " 350 echo -n "Writing entire sysctl in short writes ... "
@@ -389,6 +438,18 @@ sysctl_test_0002()
389 run_stringtests 438 run_stringtests
390} 439}
391 440
441sysctl_test_0003()
442{
443 TARGET="${SYSCTL}/int_0002"
444 reset_vals
445 ORIG=$(cat "${TARGET}")
446 TEST_STR=$(( $ORIG + 1 ))
447
448 run_numerictests
449 run_limit_digit
450 run_limit_digit_int
451}
452
392list_tests() 453list_tests()
393{ 454{
394 echo "Test ID list:" 455 echo "Test ID list:"
@@ -399,6 +460,7 @@ list_tests()
399 echo 460 echo
400 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" 461 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
401 echo "0002 x $(get_test_count 0002) - tests proc_dostring()" 462 echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
463 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
402} 464}
403 465
404test_reqs 466test_reqs