^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # under the terms of the GNU General Public License as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # Software Foundation; either version 2 of the License, or at your option any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # later version; or, when distributed separately from the Linux kernel or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # when incorporated into other software packages, subject to the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # license:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # under the terms of copyleft-next (version 0.3.1 or later) as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # at http://copyleft-next.org/.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # This performs a series tests against the proc sysctl interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # Kselftest framework requirement - SKIP code is 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ksft_skip=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) TEST_NAME="sysctl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) TEST_DRIVER="test_${TEST_NAME}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) TEST_DIR=$(dirname $0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) TEST_FILE=$(mktemp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # This represents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) # TEST_ID:TEST_COUNT:ENABLED:TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) # TEST_ID: is the test id number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # TEST_COUNT: number of times we should run the test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) # ENABLED: 1 if enabled, 0 otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) # TARGET: test target file required on the test_sysctl module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) # Once these are enabled please leave them as-is. Write your own test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # we have tons of space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ALL_TESTS="0001:1:1:int_0001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ALL_TESTS="$ALL_TESTS 0002:1:1:string_0001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ALL_TESTS="$ALL_TESTS 0003:1:1:int_0002"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ALL_TESTS="$ALL_TESTS 0004:1:1:uint_0001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ALL_TESTS="$ALL_TESTS 0005:3:1:int_0003"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ALL_TESTS="$ALL_TESTS 0006:50:1:bitmap_0001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ALL_TESTS="$ALL_TESTS 0007:1:1:boot_int"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) function allow_user_defaults()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if [ -z $DIR ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) DIR="/sys/module/test_sysctl/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if [ -z $DEFAULT_NUM_TESTS ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) DEFAULT_NUM_TESTS=50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if [ -z $SYSCTL ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) SYSCTL="/proc/sys/debug/test_sysctl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if [ -z $PROD_SYSCTL ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) PROD_SYSCTL="/proc/sys"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if [ -z $WRITES_STRICT ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) WRITES_STRICT="${PROD_SYSCTL}/kernel/sysctl_writes_strict"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) function check_production_sysctl_writes_strict()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) echo -n "Checking production write strict setting ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if [ ! -e ${WRITES_STRICT} ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) echo "FAIL, but skip in case of old kernel" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) old_strict=$(cat ${WRITES_STRICT})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if [ "$old_strict" = "1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) echo "FAIL, strict value is 0 but force to 1 to continue" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) echo "1" > ${WRITES_STRICT}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if [ -z $PAGE_SIZE ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) PAGE_SIZE=$(getconf PAGESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if [ -z $MAX_DIGITS ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) MAX_DIGITS=$(($PAGE_SIZE/8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if [ -z $INT_MAX ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) INT_MAX=$(getconf INT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if [ -z $UINT_MAX ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) UINT_MAX=$(getconf UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) test_reqs()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) uid=$(id -u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if [ $uid -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) echo $msg must be run as root >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if ! which perl 2> /dev/null > /dev/null; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) echo "$0: You need perl installed"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if ! which getconf 2> /dev/null > /dev/null; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) echo "$0: You need getconf installed"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if ! which diff 2> /dev/null > /dev/null; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) echo "$0: You need diff installed"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) function load_req_mod()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if [ ! -d $SYSCTL ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if ! modprobe -q -n $TEST_DRIVER; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) echo "$0: module $TEST_DRIVER not found [SKIP]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) echo "You must set CONFIG_TEST_SYSCTL=m in your kernel" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) modprobe $TEST_DRIVER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) echo "$0: modprobe $TEST_DRIVER failed."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) reset_vals()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) VAL=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) TRIGGER=$(basename ${TARGET})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) case "$TRIGGER" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int_0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) VAL="60"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int_0002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) VAL="1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) uint_0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) VAL="314"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) string_0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) VAL="(none)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) bitmap_0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) VAL=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) echo -n $VAL > $TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) set_orig()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if [ ! -z $TARGET ] && [ ! -z $ORIG ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if [ -f ${TARGET} ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) echo "${ORIG}" > "${TARGET}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) set_test()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) echo "${TEST_STR}" > "${TARGET}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) verify()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) local seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) seen=$(cat "$1")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if [ "${seen}" != "${TEST_STR}" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) # proc files get read a page at a time, which can confuse diff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) # and get you incorrect results on proc files with long data. To use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) # diff against them you must first extract the output to a file, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) # then compare against that file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) verify_diff_proc_file()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) TMP_DUMP_FILE=$(mktemp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) cat $1 > $TMP_DUMP_FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if ! diff -w -q $TMP_DUMP_FILE $2; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) verify_diff_w()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) echo "$TEST_STR" | diff -q -w -u - $1 > /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return $?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) test_rc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if [[ $rc != 0 ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) echo "Failed test, return value: $rc" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) exit $rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) test_finish()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) rm -f "${TEST_FILE}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if [ ! -z ${old_strict} ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) echo ${old_strict} > ${WRITES_STRICT}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) exit $rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) run_numerictests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) echo "== Testing sysctl behavior against ${TARGET} =="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) rc=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) echo -n "Writing test file ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) echo "${TEST_STR}" > "${TEST_FILE}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if ! verify "${TEST_FILE}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) echo -n "Checking sysctl is not set to test value ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) echo -n "Writing sysctl from shell ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) set_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) echo -n "Resetting sysctl to original value ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) # Now that we've validated the sanity of "set_test" and "set_orig",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) # we can use those functions to set starting states before running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) # specific behavioral tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) echo -n "Writing entire sysctl in single write ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dd if="${TEST_FILE}" of="${TARGET}" bs=4096 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) echo -n "Writing middle of sysctl after synchronized seek ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) set_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 skip=1 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) echo -n "Writing beyond end of sysctl ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dd if="${TEST_FILE}" of="${TARGET}" bs=20 seek=2 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) echo -n "Writing sysctl with multiple long writes ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) (perl -e 'print "A" x 50;'; echo "${TEST_STR}") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) dd of="${TARGET}" bs=50 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) check_failure()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) echo -n "Testing that $1 fails as expected..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) TEST_STR="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) orig="$(cat $TARGET)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) echo -n "$TEST_STR" > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) # write should fail and $TARGET should retain its original value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if [ $? = 0 ] || [ "$(cat $TARGET)" != "$orig" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) run_wideint_tests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) # sysctl conversion functions receive a boolean sign and ulong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) # magnitude; here we list the magnitudes we want to test (each of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) # which will be tested in both positive and negative forms). Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) # none of these values fit in 32 bits, writing them to an int- or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) # uint-typed sysctl should fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) local magnitudes=(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) # common boundary-condition values (zero, +1, -1, INT_MIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) # and INT_MAX respectively) if truncated to lower 32 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) # (potential for being falsely deemed in range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 0x0000000100000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 0x0000000100000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 0x00000001ffffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 0x0000000180000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 0x000000017fffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) # these look like negatives, but without a leading '-' are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) # actually large positives (should be rejected as above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) # despite being zero/+1/-1/INT_MIN/INT_MAX in the lower 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 0xffffffff00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 0xffffffff00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 0xffffffffffffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 0xffffffff80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 0xffffffff7fffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) for sign in '' '-'; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) for mag in "${magnitudes[@]}"; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) check_failure "${sign}${mag}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) # Your test must accept digits 3 and 4 to use this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) run_limit_digit()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) echo -n "Checking ignoring spaces up to PAGE_SIZE works on write ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) LIMIT=$((MAX_DIGITS -1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) TEST_STR="3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dd of="${TARGET}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) echo -n "Checking passing PAGE_SIZE of spaces fails on write ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) LIMIT=$((MAX_DIGITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) TEST_STR="4"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) dd of="${TARGET}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) # You are using an int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) run_limit_digit_int()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) echo -n "Testing INT_MAX works ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) TEST_STR="$INT_MAX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) echo -n $TEST_STR > $TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) echo -n "Testing INT_MAX + 1 will fail as expected..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) let TEST_STR=$INT_MAX+1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) echo -n $TEST_STR > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) echo -n "Testing negative values will work as expected..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) TEST_STR="-3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) echo -n $TEST_STR > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) # You used an int array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) run_limit_digit_int_array()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) echo -n "Testing array works as expected ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) TEST_STR="4 3 2 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) echo -n $TEST_STR > $TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if ! verify_diff_w "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) echo -n "Testing skipping trailing array elements works ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) # Do not reset_vals, carry on the values from the last test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) # If we only echo in two digits the last two are left intact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) TEST_STR="100 101"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) echo -n $TEST_STR > $TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) # After we echo in, to help diff we need to set on TEST_STR what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) # we expect the result to be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) TEST_STR="100 101 2 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if ! verify_diff_w "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) echo -n "Testing PAGE_SIZE limit on array works ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) # Do not reset_vals, carry on the values from the last test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) # Even if you use an int array, you are still restricted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) # MAX_DIGITS, this is a known limitation. Test limit works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) LIMIT=$((MAX_DIGITS -1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) TEST_STR="9"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) dd of="${TARGET}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) TEST_STR="9 101 2 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if ! verify_diff_w "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) echo -n "Testing exceeding PAGE_SIZE limit fails as expected ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) # Do not reset_vals, carry on the values from the last test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) # Now go over limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) LIMIT=$((MAX_DIGITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) TEST_STR="7"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) (perl -e 'print " " x '$LIMIT';'; echo "${TEST_STR}") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) dd of="${TARGET}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) TEST_STR="7 101 2 1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if verify_diff_w "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) # You are using an unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) run_limit_digit_uint()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) echo -n "Testing UINT_MAX works ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) TEST_STR="$UINT_MAX"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) echo -n $TEST_STR > $TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) echo -n "Testing UINT_MAX + 1 will fail as expected..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) TEST_STR=$(($UINT_MAX+1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) echo -n $TEST_STR > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) echo -n "Testing negative values will not work as expected ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) TEST_STR="-3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) echo -n $TEST_STR > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) run_stringtests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) echo -n "Writing entire sysctl in short writes ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if ! verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) echo -n "Writing middle of sysctl after unsynchronized seek ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) set_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if verify "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) echo -n "Checking sysctl maxlen is at least $MAXLEN ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) perl -e 'print "A" x ('"${MAXLEN}"'-2), "B";' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if ! grep -q B "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) echo -n "Checking sysctl keeps original string on overflow append ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) dd of="${TARGET}" bs=$(( MAXLEN - 1 )) 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if grep -q B "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) echo -n "Checking sysctl stays NULL terminated on write ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if grep -q B "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) echo -n "Checking sysctl stays NULL terminated on overwrite ... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) set_orig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) perl -e 'print "A" x ('"${MAXLEN}"'-1), "BB";' | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) dd of="${TARGET}" bs=$(( $MAXLEN + 1 )) 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if grep -q B "${TARGET}"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) target_exists()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) TARGET="${SYSCTL}/$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) TEST_ID="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if [ ! -f ${TARGET} ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) echo "Target for test $TEST_ID: $TARGET not exist, skipping test ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) run_bitmaptest() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) # Total length of bitmaps string to use, a bit under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) # the maximum input size of the test node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) LENGTH=$((RANDOM % 65000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) # First bit to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) BIT=$((RANDOM % 1024))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) # String containing our list of bits to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) TEST_STR=$BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) # build up the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) while [ "${#TEST_STR}" -le "$LENGTH" ]; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) # Make sure next entry is discontiguous,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) # skip ahead at least 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) BIT=$((BIT + $((2 + RANDOM % 10))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) # Add new bit to the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) TEST_STR="${TEST_STR},${BIT}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) # Randomly make it a range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if [ "$((RANDOM % 2))" -eq "1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) RANGE_END=$((BIT + $((1 + RANDOM % 10))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) TEST_STR="${TEST_STR}-${RANGE_END}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) BIT=$RANGE_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) echo -n "Checking bitmap handler... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) TEST_FILE=$(mktemp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) echo -n "$TEST_STR" > $TEST_FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) cat $TEST_FILE > $TARGET 2> /dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if [ $? -ne 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if ! verify_diff_proc_file "$TARGET" "$TEST_FILE"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) echo "FAIL" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) rc=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) sysctl_test_0001()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) TARGET="${SYSCTL}/$(get_test_target 0001)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) TEST_STR=$(( $ORIG + 1 ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) run_numerictests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) run_wideint_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) run_limit_digit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) sysctl_test_0002()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) TARGET="${SYSCTL}/$(get_test_target 0002)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) TEST_STR="Testing sysctl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) # Only string sysctls support seeking/appending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) MAXLEN=65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) run_numerictests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) run_stringtests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) sysctl_test_0003()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) TARGET="${SYSCTL}/$(get_test_target 0003)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) TEST_STR=$(( $ORIG + 1 ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) run_numerictests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) run_wideint_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) run_limit_digit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) run_limit_digit_int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) sysctl_test_0004()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) TARGET="${SYSCTL}/$(get_test_target 0004)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) TEST_STR=$(( $ORIG + 1 ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) run_numerictests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) run_wideint_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) run_limit_digit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) run_limit_digit_uint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) sysctl_test_0005()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) TARGET="${SYSCTL}/$(get_test_target 0005)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) run_limit_digit_int_array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) sysctl_test_0006()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) TARGET="${SYSCTL}/bitmap_0001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) reset_vals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) ORIG=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) run_bitmaptest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) sysctl_test_0007()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) TARGET="${SYSCTL}/boot_int"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if [ ! -f $TARGET ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) echo "Skipping test for $TARGET as it is not present ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if [ -d $DIR ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) echo "Boot param test only possible sysctl_test is built-in, not module:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) cat $TEST_DIR/config >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) echo -n "Testing if $TARGET is set to 1 ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) ORIG=$(cat "${TARGET}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if [ x$ORIG = "x1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) echo "ok"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) echo "FAIL"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) echo "Checking if /proc/cmdline contains setting of the expected parameter ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if [ ! -f /proc/cmdline ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) echo "/proc/cmdline does not exist, test inconclusive"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) FOUND=$(grep -c "sysctl[./]debug[./]test_sysctl[./]boot_int=1" /proc/cmdline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if [ $FOUND = "1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) echo "Kernel param found but $TARGET is not 1, TEST FAILED"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) rc=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) test_rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) echo "Skipping test, expected kernel parameter missing."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) echo "To perform this test, make sure kernel is booted with parameter: sysctl.debug.test_sysctl.boot_int=1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) list_tests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) echo "Test ID list:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) echo "TEST_ID x NUM_TEST"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) echo "TEST_ID: Test ID"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) echo "NUM_TESTS: Number of recommended times to run the test"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) echo "0002 x $(get_test_count 0002) - tests proc_dostring()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) echo "0003 x $(get_test_count 0003) - tests proc_dointvec()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) echo "0004 x $(get_test_count 0004) - tests proc_douintvec()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) echo "0006 x $(get_test_count 0006) - tests proc_do_large_bitmap()"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) echo "0007 x $(get_test_count 0007) - tests setting sysctl from kernel boot param"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) usage()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) let NUM_TESTS=$NUM_TESTS+1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) MAX_TEST=$(printf "%04d\n" $NUM_TESTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) echo "Usage: $0 [ -t <4-number-digit> ] | [ -w <4-number-digit> ] |"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) echo " [ -s <4-number-digit> ] | [ -c <4-number-digit> <test- count>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) echo " [ all ] [ -h | --help ] [ -l ]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) echo ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) echo "Valid tests: 0001-$MAX_TEST"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) echo ""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) echo " all Runs all tests (default)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) echo " -t Run test ID the number amount of times is recommended"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) echo " -w Watch test ID run until it runs into an error"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) echo " -c Run test ID once"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) echo " -s Run test ID x test-count number of times"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) echo " -l List all test ID list"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) echo " -h|--help Help"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) echo "If an error every occurs execution will immediately terminate."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) echo "If you are adding a new test try using -w <test-ID> first to"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) echo "make sure the test passes a series of tests."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) echo Example uses:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) echo "$TEST_NAME.sh -- executes all tests"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) echo "$TEST_NAME.sh -t 0002 -- Executes test ID 0002 number of times is recomended"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) echo "$TEST_NAME.sh -w 0002 -- Watch test ID 0002 run until an error occurs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) echo "$TEST_NAME.sh -s 0002 -- Run test ID 0002 once"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) echo "$TEST_NAME.sh -c 0002 3 -- Run test ID 0002 three times"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) list_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) function test_num()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) re='^[0-9]+$'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if ! [[ $1 =~ $re ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) function get_test_count()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) echo ${TEST_DATA} | awk -F":" '{print $2}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) function get_test_enabled()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) echo ${TEST_DATA} | awk -F":" '{print $3}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) function get_test_target()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) echo ${TEST_DATA} | awk -F":" '{print $4}'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) function run_all_tests()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) for i in $ALL_TESTS ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) TEST_ID=${i%:*:*:*}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) ENABLED=$(get_test_enabled $TEST_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) TEST_COUNT=$(get_test_count $TEST_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) TEST_TARGET=$(get_test_target $TEST_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if target_exists $TEST_TARGET $TEST_ID; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if [[ $ENABLED -eq "1" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) test_case $TEST_ID $TEST_COUNT $TEST_TARGET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) function watch_log()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if [ $# -ne 3 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) date
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) echo "Running test: $2 - run #$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) function watch_case()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) i=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) while [ 1 ]; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if [ $# -eq 1 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) watch_log $i ${TEST_NAME}_test_$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) ${TEST_NAME}_test_$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) watch_log $i all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) run_all_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) let i=$i+1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) function test_case()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) NUM_TESTS=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) i=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if target_exists $3 $1; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) while [ $i -lt $NUM_TESTS ]; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) watch_log $i ${TEST_NAME}_test_$1 noclear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) RUN_TEST=${TEST_NAME}_test_$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) $RUN_TEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) let i=$i+1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) function parse_args()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if [ $# -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) run_all_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if [[ "$1" = "all" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) run_all_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) elif [[ "$1" = "-w" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) watch_case $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) elif [[ "$1" = "-t" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) test_case $1 $(get_test_count $1) $(get_test_target $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) elif [[ "$1" = "-c" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) test_num $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) test_num $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) test_case $1 $2 $(get_test_target $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) elif [[ "$1" = "-s" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) test_case $1 1 $(get_test_target $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) elif [[ "$1" = "-l" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) list_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) elif [[ "$1" = "-h" || "$1" = "--help" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) test_reqs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) allow_user_defaults
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) check_production_sysctl_writes_strict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) load_req_mod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) trap "test_finish" EXIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) parse_args $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) exit 0