aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2017-07-12 17:33:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-12 19:26:00 -0400
commit7c43a657a4beadeb6d2fe1a00732261e313a807f (patch)
tree136df4cf9e16868c81d502ca8b6f3284546c81c6 /tools/testing
parent2920fad3a5d394b66011c7f35c7b05278354055e (diff)
test_sysctl: test against int proc_dointvec() array support
Add a few initial respective tests for an array: o Echoing values separated by spaces works o Echoing only first elements will set first elements o Confirm PAGE_SIZE limit still applies even if an array is used Link: http://lkml.kernel.org/r/20170630224431.17374-7-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')
-rw-r--r--tools/testing/selftests/sysctl/sysctl.sh89
1 files changed, 89 insertions, 0 deletions
diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
index abeef675a884..ec232c3cfcaa 100644
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -33,6 +33,7 @@ ALL_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" 34ALL_TESTS="$ALL_TESTS 0003:1:1"
35ALL_TESTS="$ALL_TESTS 0004:1:1" 35ALL_TESTS="$ALL_TESTS 0004:1:1"
36ALL_TESTS="$ALL_TESTS 0005:3:1"
36 37
37test_modprobe() 38test_modprobe()
38{ 39{
@@ -108,6 +109,10 @@ test_reqs()
108 echo "$0: You need getconf installed" 109 echo "$0: You need getconf installed"
109 exit 1 110 exit 1
110 fi 111 fi
112 if ! which diff 2> /dev/null > /dev/null; then
113 echo "$0: You need diff installed"
114 exit 1
115 fi
111} 116}
112 117
113function load_req_mod() 118function load_req_mod()
@@ -167,6 +172,12 @@ verify()
167 return 0 172 return 0
168} 173}
169 174
175verify_diff_w()
176{
177 echo "$TEST_STR" | diff -q -w -u - $1
178 return $?
179}
180
170test_rc() 181test_rc()
171{ 182{
172 if [[ $rc != 0 ]]; then 183 if [[ $rc != 0 ]]; then
@@ -352,6 +363,74 @@ run_limit_digit_int()
352 test_rc 363 test_rc
353} 364}
354 365
366# You used an int array
367run_limit_digit_int_array()
368{
369 echo -n "Testing array works as expected ... "
370 TEST_STR="4 3 2 1"
371 echo -n $TEST_STR > $TARGET
372
373 if ! verify_diff_w "${TARGET}"; then
374 echo "FAIL" >&2
375 rc=1
376 else
377 echo "ok"
378 fi
379 test_rc
380
381 echo -n "Testing skipping trailing array elements works ... "
382 # Do not reset_vals, carry on the values from the last test.
383 # If we only echo in two digits the last two are left intact
384 TEST_STR="100 101"
385 echo -n $TEST_STR > $TARGET
386 # After we echo in, to help diff we need to set on TEST_STR what
387 # we expect the result to be.
388 TEST_STR="100 101 2 1"
389
390 if ! verify_diff_w "${TARGET}"; then
391 echo "FAIL" >&2
392 rc=1
393 else
394 echo "ok"
395 fi
396 test_rc
397
398 echo -n "Testing PAGE_SIZE limit on array works ... "
399 # Do not reset_vals, carry on the values from the last test.
400 # Even if you use an int array, you are still restricted to
401 # MAX_DIGITS, this is a known limitation. Test limit works.
402 LIMIT=$((MAX_DIGITS -1))
403 TEST_STR="9"
404 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
405 dd of="${TARGET}" 2>/dev/null
406
407 TEST_STR="9 101 2 1"
408 if ! verify_diff_w "${TARGET}"; then
409 echo "FAIL" >&2
410 rc=1
411 else
412 echo "ok"
413 fi
414 test_rc
415
416 echo -n "Testing exceeding PAGE_SIZE limit fails as expected ... "
417 # Do not reset_vals, carry on the values from the last test.
418 # Now go over limit.
419 LIMIT=$((MAX_DIGITS))
420 TEST_STR="7"
421 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
422 dd of="${TARGET}" 2>/dev/null
423
424 TEST_STR="7 101 2 1"
425 if verify_diff_w "${TARGET}"; then
426 echo "FAIL" >&2
427 rc=1
428 else
429 echo "ok"
430 fi
431 test_rc
432}
433
355# You are using an unsigned int 434# You are using an unsigned int
356run_limit_digit_uint() 435run_limit_digit_uint()
357{ 436{
@@ -512,6 +591,15 @@ sysctl_test_0004()
512 run_limit_digit_uint 591 run_limit_digit_uint
513} 592}
514 593
594sysctl_test_0005()
595{
596 TARGET="${SYSCTL}/int_0003"
597 reset_vals
598 ORIG=$(cat "${TARGET}")
599
600 run_limit_digit_int_array
601}
602
515list_tests() 603list_tests()
516{ 604{
517 echo "Test ID list:" 605 echo "Test ID list:"
@@ -524,6 +612,7 @@ list_tests()
524 echo "0002 x $(get_test_count 0002) - tests proc_dostring()" 612 echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
525 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" 613 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
526 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()" 614 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
615 echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
527} 616}
528 617
529test_reqs 618test_reqs