sysctl.sh (a0edef79685c508fde517e6defac23b3ba60c422) sysctl.sh (2ea622b887e74497ce5aac5bfe247502b5786f56)
1#!/bin/bash
2# Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the Free
6# Software Foundation; either version 2 of the License, or at your option any
7# later version; or, when distributed separately from the Linux kernel or
8# when incorporated into other software packages, subject to the following

--- 24 unchanged lines hidden (view full) ---

33#
34# Once these are enabled please leave them as-is. Write your own test,
35# we have tons of space.
36ALL_TESTS="0001:1:1:int_0001"
37ALL_TESTS="$ALL_TESTS 0002:1:1:string_0001"
38ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002"
39ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001"
40ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003"
1#!/bin/bash
2# Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the Free
6# Software Foundation; either version 2 of the License, or at your option any
7# later version; or, when distributed separately from the Linux kernel or
8# when incorporated into other software packages, subject to the following

--- 24 unchanged lines hidden (view full) ---

33#
34# Once these are enabled please leave them as-is. Write your own test,
35# we have tons of space.
36ALL_TESTS="0001:1:1:int_0001"
37ALL_TESTS="$ALL_TESTS 0002:1:1:string_0001"
38ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002"
39ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001"
40ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003"
41ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001"
41
42test_modprobe()
43{
44 if [ ! -d $DIR ]; then
45 echo "$0: $DIR not present" >&2
46 echo "You must have the following enabled in your kernel:" >&2
47 cat $TEST_DIR/config >&2
48 exit $ksft_skip

--- 96 unchanged lines hidden (view full) ---

145 VAL="1"
146 ;;
147 uint_0001)
148 VAL="314"
149 ;;
150 string_0001)
151 VAL="(none)"
152 ;;
42
43test_modprobe()
44{
45 if [ ! -d $DIR ]; then
46 echo "$0: $DIR not present" >&2
47 echo "You must have the following enabled in your kernel:" >&2
48 cat $TEST_DIR/config >&2
49 exit $ksft_skip

--- 96 unchanged lines hidden (view full) ---

146 VAL="1"
147 ;;
148 uint_0001)
149 VAL="314"
150 ;;
151 string_0001)
152 VAL="(none)"
153 ;;
154 bitmap_0001)
155 VAL=""
156 ;;
153 *)
154 ;;
155 esac
156 echo -n $VAL > $TARGET
157}
158
159set_orig()
160{

--- 14 unchanged lines hidden (view full) ---

175 local seen
176 seen=$(cat "$1")
177 if [ "${seen}" != "${TEST_STR}" ]; then
178 return 1
179 fi
180 return 0
181}
182
157 *)
158 ;;
159 esac
160 echo -n $VAL > $TARGET
161}
162
163set_orig()
164{

--- 14 unchanged lines hidden (view full) ---

179 local seen
180 seen=$(cat "$1")
181 if [ "${seen}" != "${TEST_STR}" ]; then
182 return 1
183 fi
184 return 0
185}
186
187# proc files get read a page at a time, which can confuse diff,
188# and get you incorrect results on proc files with long data. To use
189# diff against them you must first extract the output to a file, and
190# then compare against that file.
191verify_diff_proc_file()
192{
193 TMP_DUMP_FILE=$(mktemp)
194 cat $1 > $TMP_DUMP_FILE
195
196 if ! diff -w -q $TMP_DUMP_FILE $2; then
197 return 1
198 else
199 return 0
200 fi
201}
202
183verify_diff_w()
184{
185 echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null
186 return $?
187}
188
189test_rc()
190{

--- 419 unchanged lines hidden (view full) ---

610
611 if [ ! -f ${TARGET} ] ; then
612 echo "Target for test $TEST_ID: $TARGET not exist, skipping test ..."
613 return 0
614 fi
615 return 1
616}
617
203verify_diff_w()
204{
205 echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null
206 return $?
207}
208
209test_rc()
210{

--- 419 unchanged lines hidden (view full) ---

630
631 if [ ! -f ${TARGET} ] ; then
632 echo "Target for test $TEST_ID: $TARGET not exist, skipping test ..."
633 return 0
634 fi
635 return 1
636}
637
638run_bitmaptest() {
639 # Total length of bitmaps string to use, a bit under
640 # the maximum input size of the test node
641 LENGTH=$((RANDOM % 65000))
642
643 # First bit to set
644 BIT=$((RANDOM % 1024))
645
646 # String containing our list of bits to set
647 TEST_STR=$BIT
648
649 # build up the string
650 while [ "${#TEST_STR}" -le "$LENGTH" ]; do
651 # Make sure next entry is discontiguous,
652 # skip ahead at least 2
653 BIT=$((BIT + $((2 + RANDOM % 10))))
654
655 # Add new bit to the list
656 TEST_STR="${TEST_STR},${BIT}"
657
658 # Randomly make it a range
659 if [ "$((RANDOM % 2))" -eq "1" ]; then
660 RANGE_END=$((BIT + $((1 + RANDOM % 10))))
661 TEST_STR="${TEST_STR}-${RANGE_END}"
662 BIT=$RANGE_END
663 fi
664 done
665
666 echo -n "Checking bitmap handler... "
667 TEST_FILE=$(mktemp)
668 echo -n "$TEST_STR" > $TEST_FILE
669
670 cat $TEST_FILE > $TARGET 2> /dev/null
671 if [ $? -ne 0 ]; then
672 echo "FAIL" >&2
673 rc=1
674 test_rc
675 fi
676
677 if ! verify_diff_proc_file "$TARGET" "$TEST_FILE"; then
678 echo "FAIL" >&2
679 rc=1
680 else
681 echo "ok"
682 rc=0
683 fi
684 test_rc
685}
686
618sysctl_test_0001()
619{
620 TARGET="${SYSCTL}/$(get_test_target 0001)"
621 reset_vals
622 ORIG=$(cat "${TARGET}")
623 TEST_STR=$(( $ORIG + 1 ))
624
625 run_numerictests

--- 44 unchanged lines hidden (view full) ---

670{
671 TARGET="${SYSCTL}/$(get_test_target 0005)"
672 reset_vals
673 ORIG=$(cat "${TARGET}")
674
675 run_limit_digit_int_array
676}
677
687sysctl_test_0001()
688{
689 TARGET="${SYSCTL}/$(get_test_target 0001)"
690 reset_vals
691 ORIG=$(cat "${TARGET}")
692 TEST_STR=$(( $ORIG + 1 ))
693
694 run_numerictests

--- 44 unchanged lines hidden (view full) ---

739{
740 TARGET="${SYSCTL}/$(get_test_target 0005)"
741 reset_vals
742 ORIG=$(cat "${TARGET}")
743
744 run_limit_digit_int_array
745}
746
747sysctl_test_0006()
748{
749 TARGET="${SYSCTL}/bitmap_0001"
750 reset_vals
751 ORIG=""
752 run_bitmaptest
753}
754
678list_tests()
679{
680 echo "Test ID list:"
681 echo
682 echo "TEST_ID x NUM_TEST"
683 echo "TEST_ID: Test ID"
684 echo "NUM_TESTS: Number of recommended times to run the test"
685 echo
686 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
687 echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
688 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
689 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
690 echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
755list_tests()
756{
757 echo "Test ID list:"
758 echo
759 echo "TEST_ID x NUM_TEST"
760 echo "TEST_ID: Test ID"
761 echo "NUM_TESTS: Number of recommended times to run the test"
762 echo
763 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
764 echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
765 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
766 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
767 echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
768 echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()"
691}
692
693usage()
694{
695 NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
696 let NUM_TESTS=$NUM_TESTS+1
697 MAX_TEST=$(printf "%04d\n" $NUM_TESTS)
698 echo "Usage: $0 [ -t <4-number-digit> ] | [ -w <4-number-digit> ] |"

--- 57 unchanged lines hidden (view full) ---

756
757function run_all_tests()
758{
759 for i in $ALL_TESTS ; do
760 TEST_ID=${i%:*:*:*}
761 ENABLED=$(get_test_enabled $TEST_ID)
762 TEST_COUNT=$(get_test_count $TEST_ID)
763 TEST_TARGET=$(get_test_target $TEST_ID)
769}
770
771usage()
772{
773 NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
774 let NUM_TESTS=$NUM_TESTS+1
775 MAX_TEST=$(printf "%04d\n" $NUM_TESTS)
776 echo "Usage: $0 [ -t <4-number-digit> ] | [ -w <4-number-digit> ] |"

--- 57 unchanged lines hidden (view full) ---

834
835function run_all_tests()
836{
837 for i in $ALL_TESTS ; do
838 TEST_ID=${i%:*:*:*}
839 ENABLED=$(get_test_enabled $TEST_ID)
840 TEST_COUNT=$(get_test_count $TEST_ID)
841 TEST_TARGET=$(get_test_target $TEST_ID)
764 target_exists $TEST_TARGET $TEST_ID
765 if [ $? -ne 1 ]; then
842 if target_exists $TEST_TARGET $TEST_ID; then
766 continue
767 fi
768 if [[ $ENABLED -eq "1" ]]; then
769 test_case $TEST_ID $TEST_COUNT $TEST_TARGET
770 fi
771 done
772}
773

--- 88 unchanged lines hidden ---
843 continue
844 fi
845 if [[ $ENABLED -eq "1" ]]; then
846 test_case $TEST_ID $TEST_COUNT $TEST_TARGET
847 fi
848 done
849}
850

--- 88 unchanged lines hidden ---