diff options
| -rw-r--r-- | lib/test_sysctl.c | 13 | ||||
| -rw-r--r-- | tools/testing/selftests/sysctl/sysctl.sh | 89 |
2 files changed, 102 insertions, 0 deletions
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 53db3513ab08..3dd801c1c85b 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c | |||
| @@ -42,6 +42,7 @@ static int i_one_hundred = 100; | |||
| 42 | struct test_sysctl_data { | 42 | struct test_sysctl_data { |
| 43 | int int_0001; | 43 | int int_0001; |
| 44 | int int_0002; | 44 | int int_0002; |
| 45 | int int_0003[4]; | ||
| 45 | 46 | ||
| 46 | unsigned int uint_0001; | 47 | unsigned int uint_0001; |
| 47 | 48 | ||
| @@ -52,6 +53,11 @@ static struct test_sysctl_data test_data = { | |||
| 52 | .int_0001 = 60, | 53 | .int_0001 = 60, |
| 53 | .int_0002 = 1, | 54 | .int_0002 = 1, |
| 54 | 55 | ||
| 56 | .int_0003[0] = 0, | ||
| 57 | .int_0003[1] = 1, | ||
| 58 | .int_0003[2] = 2, | ||
| 59 | .int_0003[3] = 3, | ||
| 60 | |||
| 55 | .uint_0001 = 314, | 61 | .uint_0001 = 314, |
| 56 | 62 | ||
| 57 | .string_0001 = "(none)", | 63 | .string_0001 = "(none)", |
| @@ -76,6 +82,13 @@ static struct ctl_table test_table[] = { | |||
| 76 | .proc_handler = proc_dointvec, | 82 | .proc_handler = proc_dointvec, |
| 77 | }, | 83 | }, |
| 78 | { | 84 | { |
| 85 | .procname = "int_0003", | ||
| 86 | .data = &test_data.int_0003, | ||
| 87 | .maxlen = sizeof(test_data.int_0003), | ||
| 88 | .mode = 0644, | ||
| 89 | .proc_handler = proc_dointvec, | ||
| 90 | }, | ||
| 91 | { | ||
| 79 | .procname = "uint_0001", | 92 | .procname = "uint_0001", |
| 80 | .data = &test_data.uint_0001, | 93 | .data = &test_data.uint_0001, |
| 81 | .maxlen = sizeof(unsigned int), | 94 | .maxlen = sizeof(unsigned int), |
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" | |||
| 33 | ALL_TESTS="$ALL_TESTS 0002:1:1" | 33 | ALL_TESTS="$ALL_TESTS 0002:1:1" |
| 34 | ALL_TESTS="$ALL_TESTS 0003:1:1" | 34 | ALL_TESTS="$ALL_TESTS 0003:1:1" |
| 35 | ALL_TESTS="$ALL_TESTS 0004:1:1" | 35 | ALL_TESTS="$ALL_TESTS 0004:1:1" |
| 36 | ALL_TESTS="$ALL_TESTS 0005:3:1" | ||
| 36 | 37 | ||
| 37 | test_modprobe() | 38 | test_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 | ||
| 113 | function load_req_mod() | 118 | function load_req_mod() |
| @@ -167,6 +172,12 @@ verify() | |||
| 167 | return 0 | 172 | return 0 |
| 168 | } | 173 | } |
| 169 | 174 | ||
| 175 | verify_diff_w() | ||
| 176 | { | ||
| 177 | echo "$TEST_STR" | diff -q -w -u - $1 | ||
| 178 | return $? | ||
| 179 | } | ||
| 180 | |||
| 170 | test_rc() | 181 | test_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 | ||
| 367 | run_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 |
| 356 | run_limit_digit_uint() | 435 | run_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 | ||
| 594 | sysctl_test_0005() | ||
| 595 | { | ||
| 596 | TARGET="${SYSCTL}/int_0003" | ||
| 597 | reset_vals | ||
| 598 | ORIG=$(cat "${TARGET}") | ||
| 599 | |||
| 600 | run_limit_digit_int_array | ||
| 601 | } | ||
| 602 | |||
| 515 | list_tests() | 603 | list_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 | ||
| 529 | test_reqs | 618 | test_reqs |
