0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 TEST_NAME="vmalloc"
0013 DRIVER="test_${TEST_NAME}"
0014 NUM_CPUS=`grep -c ^processor /proc/cpuinfo`
0015
0016
0017 exitcode=1
0018
0019
0020 ksft_skip=4
0021
0022
0023
0024
0025
0026 PERF_PARAM="sequential_test_order=1 test_repeat_count=3"
0027 SMOKE_PARAM="test_loop_count=10000 test_repeat_count=10"
0028 STRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20"
0029
0030 check_test_requirements()
0031 {
0032 uid=$(id -u)
0033 if [ $uid -ne 0 ]; then
0034 echo "$0: Must be run as root"
0035 exit $ksft_skip
0036 fi
0037
0038 if ! which modprobe > /dev/null 2>&1; then
0039 echo "$0: You need modprobe installed"
0040 exit $ksft_skip
0041 fi
0042
0043 if ! modinfo $DRIVER > /dev/null 2>&1; then
0044 echo "$0: You must have the following enabled in your kernel:"
0045 echo "CONFIG_TEST_VMALLOC=m"
0046 exit $ksft_skip
0047 fi
0048 }
0049
0050 run_perfformance_check()
0051 {
0052 echo "Run performance tests to evaluate how fast vmalloc allocation is."
0053 echo "It runs all test cases on one single CPU with sequential order."
0054
0055 modprobe $DRIVER $PERF_PARAM > /dev/null 2>&1
0056 echo "Done."
0057 echo "Ccheck the kernel message buffer to see the summary."
0058 }
0059
0060 run_stability_check()
0061 {
0062 echo "Run stability tests. In order to stress vmalloc subsystem all"
0063 echo "available test cases are run by NUM_CPUS workers simultaneously."
0064 echo "It will take time, so be patient."
0065
0066 modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&1
0067 echo "Done."
0068 echo "Check the kernel ring buffer to see the summary."
0069 }
0070
0071 run_smoke_check()
0072 {
0073 echo "Run smoke test. Note, this test provides basic coverage."
0074 echo "Please check $0 output how it can be used"
0075 echo "for deep performance analysis as well as stress testing."
0076
0077 modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&1
0078 echo "Done."
0079 echo "Check the kernel ring buffer to see the summary."
0080 }
0081
0082 usage()
0083 {
0084 echo -n "Usage: $0 [ performance ] | [ stress ] | | [ smoke ] | "
0085 echo "manual parameters"
0086 echo
0087 echo "Valid tests and parameters:"
0088 echo
0089 modinfo $DRIVER
0090 echo
0091 echo "Example usage:"
0092 echo
0093 echo "# Shows help message"
0094 echo "./${DRIVER}.sh"
0095 echo
0096 echo "# Runs 1 test(id_1), repeats it 5 times by NUM_CPUS workers"
0097 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS run_test_mask=1 test_repeat_count=5"
0098 echo
0099 echo -n "# Runs 4 tests(id_1|id_2|id_4|id_16) on one CPU with "
0100 echo "sequential order"
0101 echo -n "./${DRIVER}.sh sequential_test_order=1 "
0102 echo "run_test_mask=23"
0103 echo
0104 echo -n "# Runs all tests by NUM_CPUS workers, shuffled order, repeats "
0105 echo "20 times"
0106 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS test_repeat_count=20"
0107 echo
0108 echo "# Performance analysis"
0109 echo "./${DRIVER}.sh performance"
0110 echo
0111 echo "# Stress testing"
0112 echo "./${DRIVER}.sh stress"
0113 echo
0114 exit 0
0115 }
0116
0117 function validate_passed_args()
0118 {
0119 VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
0120
0121
0122
0123
0124 for passed_arg in $@; do
0125 key=${passed_arg//=*/}
0126 val="${passed_arg:$((${#key}+1))}"
0127 valid=0
0128
0129 for valid_arg in $VALID_ARGS; do
0130 if [[ $key = $valid_arg ]] && [[ $val -gt 0 ]]; then
0131 valid=1
0132 break
0133 fi
0134 done
0135
0136 if [[ $valid -ne 1 ]]; then
0137 echo "Error: key or value is not correct: ${key} $val"
0138 exit $exitcode
0139 fi
0140 done
0141 }
0142
0143 function run_manual_check()
0144 {
0145
0146
0147
0148
0149 validate_passed_args $@
0150
0151 echo "Run the test with following parameters: $@"
0152 modprobe $DRIVER $@ > /dev/null 2>&1
0153 echo "Done."
0154 echo "Check the kernel ring buffer to see the summary."
0155 }
0156
0157 function run_test()
0158 {
0159 if [ $
0160 usage
0161 else
0162 if [[ "$1" = "performance" ]]; then
0163 run_perfformance_check
0164 elif [[ "$1" = "stress" ]]; then
0165 run_stability_check
0166 elif [[ "$1" = "smoke" ]]; then
0167 run_smoke_check
0168 else
0169 run_manual_check $@
0170 fi
0171 fi
0172 }
0173
0174 check_test_requirements
0175 run_test $@
0176
0177 exit 0