Lines Matching +full:test +full:- +full:trailing
2 # SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1
7 # Kselftest framework requirement - SKIP code is 4.
19 # TEST_ID: is the test id number
20 # TEST_COUNT: number of times we should run the test
22 # TARGET: test target file required on the test_sysctl module
26 # Once these are enabled please leave them as-is. Write your own test,
43 if [ -z $DIR ]; then
46 if [ -z $DEFAULT_NUM_TESTS ]; then
49 if [ -z $SYSCTL ]; then
52 if [ -z $PROD_SYSCTL ]; then
55 if [ -z $WRITES_STRICT ]; then
62 echo -n "Checking production write strict setting ... "
63 if [ ! -e ${WRITES_STRICT} ]; then
75 if [ -z $PAGE_SIZE ]; then
78 if [ -z $MAX_DIGITS ]; then
81 if [ -z $INT_MAX ]; then
84 if [ -z $UINT_MAX ]; then
91 uid=$(id -u)
92 if [ $uid -ne 0 ]; then
113 if [ ! -d $SYSCTL ]; then
114 if ! modprobe -q -n $TEST_DRIVER; then
120 if [ $? -ne 0 ]; then
150 echo -n $VAL > $TARGET
155 if [ ! -z $TARGET ] && [ ! -z $ORIG ]; then
156 if [ -f ${TARGET} ]; then
186 if ! diff -w -q $TMP_DUMP_FILE $2; then
195 echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null
202 echo "Failed test, return value: $rc" >&2
210 rm -f "${TEST_FILE}"
212 if [ ! -z ${old_strict} ]; then
224 echo -n "Writing test file ... "
233 echo -n "Checking sysctl is not set to test value ... "
241 echo -n "Writing sysctl from shell ... "
250 echo -n "Resetting sysctl to original value ... "
263 echo -n "Writing entire sysctl in single write ... "
273 echo -n "Writing middle of sysctl after synchronized seek ... "
283 echo -n "Writing beyond end of sysctl ... "
293 echo -n "Writing sysctl with multiple long writes ... "
295 (perl -e 'print "A" x 50;'; echo "${TEST_STR}") | \
308 echo -n "Testing that $1 fails as expected ... "
312 echo -n "$TEST_STR" > $TARGET 2> /dev/null
327 # magnitude; here we list the magnitudes we want to test (each of
329 # none of these values fit in 32 bits, writing them to an int- or
330 # uint-typed sysctl should fail.
332 # common boundary-condition values (zero, +1, -1, INT_MIN,
341 # these look like negatives, but without a leading '-' are
343 # despite being zero/+1/-1/INT_MIN/INT_MAX in the lower 32)
351 for sign in '' '-'; do
358 # Your test must accept digits 3 and 4 to use this
361 echo -n "Checking ignoring spaces up to PAGE_SIZE works on write ... "
364 LIMIT=$((MAX_DIGITS -1))
366 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
377 echo -n "Checking passing PAGE_SIZE of spaces fails on write ... "
382 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
397 echo -n "Testing INT_MAX works ... "
400 echo -n $TEST_STR > $TARGET
410 echo -n "Testing INT_MAX + 1 will fail as expected ... "
413 echo -n $TEST_STR > $TARGET 2> /dev/null
423 echo -n "Testing negative values will work as expected ... "
425 TEST_STR="-3"
426 echo -n $TEST_STR > $TARGET 2> /dev/null
439 echo -n "Testing array works as expected ... "
441 echo -n $TEST_STR > $TARGET
451 echo -n "Testing skipping trailing array elements works ... "
452 # Do not reset_vals, carry on the values from the last test.
455 echo -n $TEST_STR > $TARGET
468 echo -n "Testing PAGE_SIZE limit on array works ... "
469 # Do not reset_vals, carry on the values from the last test.
471 # MAX_DIGITS, this is a known limitation. Test limit works.
472 LIMIT=$((MAX_DIGITS -1))
474 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
486 echo -n "Testing exceeding PAGE_SIZE limit fails as expected ... "
487 # Do not reset_vals, carry on the values from the last test.
491 (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
507 echo -n "Testing UINT_MAX works ... "
510 echo -n $TEST_STR > $TARGET
520 echo -n "Testing UINT_MAX + 1 will fail as expected ... "
523 echo -n $TEST_STR > $TARGET 2> /dev/null
533 echo -n "Testing negative values will not work as expected ... "
535 TEST_STR="-3"
536 echo -n $TEST_STR > $TARGET 2> /dev/null
549 echo -n "Writing entire sysctl in short writes ... "
559 echo -n "Writing middle of sysctl after unsynchronized seek ... "
569 echo -n "Checking sysctl maxlen is at least $MAXLEN ... "
571 perl -e 'print "A" x ('"${MAXLEN}"'-2), "B";' | \
573 if ! grep -q B "${TARGET}"; then
580 echo -n "Checking sysctl keeps original string on overflow append ... "
582 perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
583 dd of="${TARGET}" bs=$(( MAXLEN - 1 )) 2>/dev/null
584 if grep -q B "${TARGET}"; then
591 echo -n "Checking sysctl stays NULL terminated on write ... "
593 perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
595 if grep -q B "${TARGET}"; then
602 echo -n "Checking sysctl stays NULL terminated on overwrite ... "
604 perl -e 'print "A" x ('"${MAXLEN}"'-1), "BB";' | \
606 if grep -q B "${TARGET}"; then
621 if [ ! -f ${TARGET} ] ; then
629 # the maximum input size of the test node
639 while [ "${#TEST_STR}" -le "$LENGTH" ]; do
648 if [ "$((RANDOM % 2))" -eq "1" ]; then
650 TEST_STR="${TEST_STR}-${RANGE_END}"
655 echo -n "Checking bitmap handler ... "
657 echo -n "$TEST_STR" > $TEST_FILE
660 if [ $? -ne 0 ]; then
747 echo -n "Testing if $TARGET is set to 1 ... "
749 if [ ! -f $TARGET ]; then
750 echo -e "SKIPPING\n$TARGET is not present"
754 if [ -d $DIR ]; then
755 echo -e "SKIPPING\nTest only possible if sysctl_test is built-in, not module:"
767 if [ ! -f /proc/cmdline ]; then
768 echo -e "SKIPPING\nThere is no /proc/cmdline to check for parameter"
772 FOUND=$(grep -c "sysctl[./]debug[./]test_sysctl[./]boot_int=1" /proc/cmdline)
774 echo -e "FAIL\nKernel param found but $TARGET is not 1." >&2
779 echo -e "SKIPPING\nExpected kernel parameter missing."
787 echo -n "Testing if $TARGET is matched in kernel ... "
789 if [ ! -f $TARGET ]; then
790 echo -e "SKIPPING\n$TARGET is not present"
796 if [ $ORIG_VALUE -ne 1 ]; then
809 echo -n "Testing if $TARGET unregistered correctly ... "
810 if [ -d $TARGET ]; then
823 echo -n "Testing that $TARGET was not created ... "
824 if [ -d $TARGET ]; then
837 echo -n "Testing empty dir handling in ${TARGET} ... "
838 if [ ! -d ${TARGET} ]; then
839 echo -e "FAIL\nCould not create ${TARGET}" >&2
845 if [ ! -d ${TARGET2} ]; then
846 echo -e "FAIL\nCould not create ${TARGET2}" >&2
858 echo -n "Testing u8 range check in sysctl table check in ${TARGET} ... "
859 if [ ! -f ${TARGET} ]; then
860 echo -e "FAIL\nCould not create ${TARGET}" >&2
865 local u8over_msg=$(dmesg | grep "u8_over range value" | wc -l)
866 if [ ! ${u8over_msg} -eq 1 ]; then
867 echo -e "FAIL\nu8 overflow not detected" >&2
872 local u8under_msg=$(dmesg | grep "u8_under range value" | wc -l)
873 if [ ! ${u8under_msg} -eq 1 ]; then
874 echo -e "FAIL\nu8 underflow not detected" >&2
885 echo "Test ID list:"
888 echo "TEST_ID: Test ID"
889 echo "NUM_TESTS: Recommended number of times to run the test"
891 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
892 echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
893 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
894 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
895 echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
896 echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()"
897 echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel boot param"
898 echo "0008 x $(get_test_count 0008) - tests sysctl macro values match"
899 echo "0009 x $(get_test_count 0009) - tests sysct unregister"
900 echo "0010 x $(get_test_count 0010) - tests sysct mount point"
901 echo "0011 x $(get_test_count 0011) - tests empty directories"
902 echo "0012 x $(get_test_count 0012) - tests range check for u8 proc_handler"
907 NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
910 echo "Usage: $0 [ -t <4-number-digit> ] | [ -w <4-number-digit> ] |"
911 echo " [ -s <4-number-digit> ] | [ -c <4-number-digit> <test- count>"
912 echo " [ all ] [ -h | --help ] [ -l ]"
914 echo "Valid tests: 0001-$MAX_TEST"
917 echo " -t Run test ID the recommended number of times"
918 echo " -w Watch test ID run until it runs into an error"
919 echo " -c Run test ID once"
920 echo " -s Run test ID x test-count number of times"
921 echo " -l List all test ID list"
922 echo " -h|--help Help"
925 echo "If you are adding a new test try using -w <test-ID> first to"
926 echo "make sure the test passes a series of tests."
930 echo "$TEST_NAME.sh -- executes all tests"
931 echo "$TEST_NAME.sh -t 0002 -- Executes test ID 0002 the recommended number of times"
932 echo "$TEST_NAME.sh -w 0002 -- Watch test ID 0002 run until an error occurs"
933 echo "$TEST_NAME.sh -s 0002 -- Run test ID 0002 once"
934 echo "$TEST_NAME.sh -c 0002 3 -- Run test ID 0002 three times"
942 re='^[0-9]+$'
957 echo ${TEST_DATA} | awk -F":" '{print $2}'
965 echo ${TEST_DATA} | awk -F":" '{print $3}'
973 echo ${TEST_DATA} | awk -F":" '{print $4}'
981 echo ${TEST_DATA} | awk -F":" '{print $5}'
990 if [[ $TEST_SKIP -eq "1" ]]; then
991 echo "Target $TEST_TARGET for test $TEST_ID does not exist ... SKIPPING"
1006 if [[ $ENABLED -eq "1" ]]; then
1014 if [ $# -ne 3 ]; then
1018 echo "Running test: $2 - run #$1"
1026 if [ $# -eq 1 ]; then
1049 while [ $i -lt $NUM_TESTS ]; do
1060 if [ $# -eq 0 ]; then
1065 elif [[ "$1" = "-w" ]]; then
1068 elif [[ "$1" = "-t" ]]; then
1072 elif [[ "$1" = "-c" ]]; then
1077 elif [[ "$1" = "-s" ]]; then
1080 elif [[ "$1" = "-l" ]]; then
1082 elif [[ "$1" = "-h" || "$1" = "--help" ]]; then