2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright (C) 2018 Uladzislau Rezki (Sony) <urezki@gmail.com>
6 # This is a test script for the kernel test driver to analyse vmalloc
7 # allocator. Therefore it is just a kernel module loader. You can specify
8 # and pass different parameters in order to:
9 # a) analyse performance of vmalloc allocations;
10 # b) stressing and stability check of vmalloc subsystem.
13 DRIVER="test_${TEST_NAME}"
14 NUM_CPUS=`grep -c ^processor /proc/cpuinfo`
19 # Kselftest framework requirement - SKIP code is 4.
23 # Static templates for performance, stressing and smoke tests.
24 # Also it is possible to pass any supported parameters manualy.
26 PERF_PARAM="sequential_test_order=1 test_repeat_count=3"
27 SMOKE_PARAM="test_loop_count=10000 test_repeat_count=10"
28 STRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20"
30 check_test_requirements()
33 if [ $uid -ne 0 ]; then
34 echo "$0: Must be run as root"
38 if ! which modprobe > /dev/null 2>&1; then
39 echo "$0: You need modprobe installed"
43 if ! modinfo $DRIVER > /dev/null 2>&1; then
44 echo "$0: You must have the following enabled in your kernel:"
45 echo "CONFIG_TEST_VMALLOC=m"
50 run_perfformance_check()
52 echo "Run performance tests to evaluate how fast vmalloc allocation is."
53 echo "It runs all test cases on one single CPU with sequential order."
55 modprobe $DRIVER $PERF_PARAM > /dev/null 2>&1
57 echo "Ccheck the kernel message buffer to see the summary."
62 echo "Run stability tests. In order to stress vmalloc subsystem all"
63 echo "available test cases are run by NUM_CPUS workers simultaneously."
64 echo "It will take time, so be patient."
66 modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&1
68 echo "Check the kernel ring buffer to see the summary."
73 echo "Run smoke test. Note, this test provides basic coverage."
74 echo "Please check $0 output how it can be used"
75 echo "for deep performance analysis as well as stress testing."
77 modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&1
79 echo "Check the kernel ring buffer to see the summary."
84 echo -n "Usage: $0 [ performance ] | [ stress ] | | [ smoke ] | "
85 echo "manual parameters"
87 echo "Valid tests and parameters:"
93 echo "# Shows help message"
96 echo "# Runs 1 test(id_1), repeats it 5 times by NUM_CPUS workers"
97 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS run_test_mask=1 test_repeat_count=5"
99 echo -n "# Runs 4 tests(id_1|id_2|id_4|id_16) on one CPU with "
100 echo "sequential order"
101 echo -n "./${DRIVER}.sh sequential_test_order=1 "
102 echo "run_test_mask=23"
104 echo -n "# Runs all tests by NUM_CPUS workers, shuffled order, repeats "
106 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS test_repeat_count=20"
108 echo "# Performance analysis"
109 echo "./${DRIVER}.sh performance"
111 echo "# Stress testing"
112 echo "./${DRIVER}.sh stress"
117 function validate_passed_args()
119 VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
122 # Something has been passed, check it.
124 for passed_arg in $@; do
125 key=${passed_arg//=*/}
126 val="${passed_arg:$((${#key}+1))}"
129 for valid_arg in $VALID_ARGS; do
130 if [[ $key = $valid_arg ]] && [[ $val -gt 0 ]]; then
136 if [[ $valid -ne 1 ]]; then
137 echo "Error: key or value is not correct: ${key} $val"
143 function run_manual_check()
146 # Validate passed parameters. If there is wrong one,
147 # the script exists and does not execute further.
149 validate_passed_args $@
151 echo "Run the test with following parameters: $@"
152 modprobe $DRIVER $@ > /dev/null 2>&1
154 echo "Check the kernel ring buffer to see the summary."
159 if [ $# -eq 0 ]; then
162 if [[ "$1" = "performance" ]]; then
163 run_perfformance_check
164 elif [[ "$1" = "stress" ]]; then
166 elif [[ "$1" = "smoke" ]]; then
174 check_test_requirements