xref: /openbmc/linux/tools/testing/selftests/mm/test_vmalloc.sh (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1*baa489faSSeongJae Park#!/bin/bash
2*baa489faSSeongJae Park# SPDX-License-Identifier: GPL-2.0
3*baa489faSSeongJae Park#
4*baa489faSSeongJae Park# Copyright (C) 2018 Uladzislau Rezki (Sony) <urezki@gmail.com>
5*baa489faSSeongJae Park#
6*baa489faSSeongJae Park# This is a test script for the kernel test driver to analyse vmalloc
7*baa489faSSeongJae Park# allocator. Therefore it is just a kernel module loader. You can specify
8*baa489faSSeongJae Park# and pass different parameters in order to:
9*baa489faSSeongJae Park#     a) analyse performance of vmalloc allocations;
10*baa489faSSeongJae Park#     b) stressing and stability check of vmalloc subsystem.
11*baa489faSSeongJae Park
12*baa489faSSeongJae ParkTEST_NAME="vmalloc"
13*baa489faSSeongJae ParkDRIVER="test_${TEST_NAME}"
14*baa489faSSeongJae ParkNUM_CPUS=`grep -c ^processor /proc/cpuinfo`
15*baa489faSSeongJae Park
16*baa489faSSeongJae Park# 1 if fails
17*baa489faSSeongJae Parkexitcode=1
18*baa489faSSeongJae Park
19*baa489faSSeongJae Park# Kselftest framework requirement - SKIP code is 4.
20*baa489faSSeongJae Parkksft_skip=4
21*baa489faSSeongJae Park
22*baa489faSSeongJae Park#
23*baa489faSSeongJae Park# Static templates for performance, stressing and smoke tests.
24*baa489faSSeongJae Park# Also it is possible to pass any supported parameters manualy.
25*baa489faSSeongJae Park#
26*baa489faSSeongJae ParkPERF_PARAM="sequential_test_order=1 test_repeat_count=3"
27*baa489faSSeongJae ParkSMOKE_PARAM="test_loop_count=10000 test_repeat_count=10"
28*baa489faSSeongJae ParkSTRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20"
29*baa489faSSeongJae Park
30*baa489faSSeongJae Parkcheck_test_requirements()
31*baa489faSSeongJae Park{
32*baa489faSSeongJae Park	uid=$(id -u)
33*baa489faSSeongJae Park	if [ $uid -ne 0 ]; then
34*baa489faSSeongJae Park		echo "$0: Must be run as root"
35*baa489faSSeongJae Park		exit $ksft_skip
36*baa489faSSeongJae Park	fi
37*baa489faSSeongJae Park
38*baa489faSSeongJae Park	if ! which modprobe > /dev/null 2>&1; then
39*baa489faSSeongJae Park		echo "$0: You need modprobe installed"
40*baa489faSSeongJae Park		exit $ksft_skip
41*baa489faSSeongJae Park	fi
42*baa489faSSeongJae Park
43*baa489faSSeongJae Park	if ! modinfo $DRIVER > /dev/null 2>&1; then
44*baa489faSSeongJae Park		echo "$0: You must have the following enabled in your kernel:"
45*baa489faSSeongJae Park		echo "CONFIG_TEST_VMALLOC=m"
46*baa489faSSeongJae Park		exit $ksft_skip
47*baa489faSSeongJae Park	fi
48*baa489faSSeongJae Park}
49*baa489faSSeongJae Park
50*baa489faSSeongJae Parkrun_perfformance_check()
51*baa489faSSeongJae Park{
52*baa489faSSeongJae Park	echo "Run performance tests to evaluate how fast vmalloc allocation is."
53*baa489faSSeongJae Park	echo "It runs all test cases on one single CPU with sequential order."
54*baa489faSSeongJae Park
55*baa489faSSeongJae Park	modprobe $DRIVER $PERF_PARAM > /dev/null 2>&1
56*baa489faSSeongJae Park	echo "Done."
57*baa489faSSeongJae Park	echo "Ccheck the kernel message buffer to see the summary."
58*baa489faSSeongJae Park}
59*baa489faSSeongJae Park
60*baa489faSSeongJae Parkrun_stability_check()
61*baa489faSSeongJae Park{
62*baa489faSSeongJae Park	echo "Run stability tests. In order to stress vmalloc subsystem all"
63*baa489faSSeongJae Park	echo "available test cases are run by NUM_CPUS workers simultaneously."
64*baa489faSSeongJae Park	echo "It will take time, so be patient."
65*baa489faSSeongJae Park
66*baa489faSSeongJae Park	modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&1
67*baa489faSSeongJae Park	echo "Done."
68*baa489faSSeongJae Park	echo "Check the kernel ring buffer to see the summary."
69*baa489faSSeongJae Park}
70*baa489faSSeongJae Park
71*baa489faSSeongJae Parkrun_smoke_check()
72*baa489faSSeongJae Park{
73*baa489faSSeongJae Park	echo "Run smoke test. Note, this test provides basic coverage."
74*baa489faSSeongJae Park	echo "Please check $0 output how it can be used"
75*baa489faSSeongJae Park	echo "for deep performance analysis as well as stress testing."
76*baa489faSSeongJae Park
77*baa489faSSeongJae Park	modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&1
78*baa489faSSeongJae Park	echo "Done."
79*baa489faSSeongJae Park	echo "Check the kernel ring buffer to see the summary."
80*baa489faSSeongJae Park}
81*baa489faSSeongJae Park
82*baa489faSSeongJae Parkusage()
83*baa489faSSeongJae Park{
84*baa489faSSeongJae Park	echo -n "Usage: $0 [ performance ] | [ stress ] | | [ smoke ] | "
85*baa489faSSeongJae Park	echo "manual parameters"
86*baa489faSSeongJae Park	echo
87*baa489faSSeongJae Park	echo "Valid tests and parameters:"
88*baa489faSSeongJae Park	echo
89*baa489faSSeongJae Park	modinfo $DRIVER
90*baa489faSSeongJae Park	echo
91*baa489faSSeongJae Park	echo "Example usage:"
92*baa489faSSeongJae Park	echo
93*baa489faSSeongJae Park	echo "# Shows help message"
94*baa489faSSeongJae Park	echo "./${DRIVER}.sh"
95*baa489faSSeongJae Park	echo
96*baa489faSSeongJae Park	echo "# Runs 1 test(id_1), repeats it 5 times by NUM_CPUS workers"
97*baa489faSSeongJae Park	echo "./${DRIVER}.sh nr_threads=$NUM_CPUS run_test_mask=1 test_repeat_count=5"
98*baa489faSSeongJae Park	echo
99*baa489faSSeongJae Park	echo -n "# Runs 4 tests(id_1|id_2|id_4|id_16) on one CPU with "
100*baa489faSSeongJae Park	echo "sequential order"
101*baa489faSSeongJae Park	echo -n "./${DRIVER}.sh sequential_test_order=1 "
102*baa489faSSeongJae Park	echo "run_test_mask=23"
103*baa489faSSeongJae Park	echo
104*baa489faSSeongJae Park	echo -n "# Runs all tests by NUM_CPUS workers, shuffled order, repeats "
105*baa489faSSeongJae Park	echo "20 times"
106*baa489faSSeongJae Park	echo "./${DRIVER}.sh nr_threads=$NUM_CPUS test_repeat_count=20"
107*baa489faSSeongJae Park	echo
108*baa489faSSeongJae Park	echo "# Performance analysis"
109*baa489faSSeongJae Park	echo "./${DRIVER}.sh performance"
110*baa489faSSeongJae Park	echo
111*baa489faSSeongJae Park	echo "# Stress testing"
112*baa489faSSeongJae Park	echo "./${DRIVER}.sh stress"
113*baa489faSSeongJae Park	echo
114*baa489faSSeongJae Park	exit 0
115*baa489faSSeongJae Park}
116*baa489faSSeongJae Park
117*baa489faSSeongJae Parkfunction validate_passed_args()
118*baa489faSSeongJae Park{
119*baa489faSSeongJae Park	VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`
120*baa489faSSeongJae Park
121*baa489faSSeongJae Park	#
122*baa489faSSeongJae Park	# Something has been passed, check it.
123*baa489faSSeongJae Park	#
124*baa489faSSeongJae Park	for passed_arg in $@; do
125*baa489faSSeongJae Park		key=${passed_arg//=*/}
126*baa489faSSeongJae Park		val="${passed_arg:$((${#key}+1))}"
127*baa489faSSeongJae Park		valid=0
128*baa489faSSeongJae Park
129*baa489faSSeongJae Park		for valid_arg in $VALID_ARGS; do
130*baa489faSSeongJae Park			if [[ $key = $valid_arg ]] && [[ $val -gt 0 ]]; then
131*baa489faSSeongJae Park				valid=1
132*baa489faSSeongJae Park				break
133*baa489faSSeongJae Park			fi
134*baa489faSSeongJae Park		done
135*baa489faSSeongJae Park
136*baa489faSSeongJae Park		if [[ $valid -ne 1 ]]; then
137*baa489faSSeongJae Park			echo "Error: key or value is not correct: ${key} $val"
138*baa489faSSeongJae Park			exit $exitcode
139*baa489faSSeongJae Park		fi
140*baa489faSSeongJae Park	done
141*baa489faSSeongJae Park}
142*baa489faSSeongJae Park
143*baa489faSSeongJae Parkfunction run_manual_check()
144*baa489faSSeongJae Park{
145*baa489faSSeongJae Park	#
146*baa489faSSeongJae Park	# Validate passed parameters. If there is wrong one,
147*baa489faSSeongJae Park	# the script exists and does not execute further.
148*baa489faSSeongJae Park	#
149*baa489faSSeongJae Park	validate_passed_args $@
150*baa489faSSeongJae Park
151*baa489faSSeongJae Park	echo "Run the test with following parameters: $@"
152*baa489faSSeongJae Park	modprobe $DRIVER $@ > /dev/null 2>&1
153*baa489faSSeongJae Park	echo "Done."
154*baa489faSSeongJae Park	echo "Check the kernel ring buffer to see the summary."
155*baa489faSSeongJae Park}
156*baa489faSSeongJae Park
157*baa489faSSeongJae Parkfunction run_test()
158*baa489faSSeongJae Park{
159*baa489faSSeongJae Park	if [ $# -eq 0 ]; then
160*baa489faSSeongJae Park		usage
161*baa489faSSeongJae Park	else
162*baa489faSSeongJae Park		if [[ "$1" = "performance" ]]; then
163*baa489faSSeongJae Park			run_perfformance_check
164*baa489faSSeongJae Park		elif [[ "$1" = "stress" ]]; then
165*baa489faSSeongJae Park			run_stability_check
166*baa489faSSeongJae Park		elif [[ "$1" = "smoke" ]]; then
167*baa489faSSeongJae Park			run_smoke_check
168*baa489faSSeongJae Park		else
169*baa489faSSeongJae Park			run_manual_check $@
170*baa489faSSeongJae Park		fi
171*baa489faSSeongJae Park	fi
172*baa489faSSeongJae Park}
173*baa489faSSeongJae Park
174*baa489faSSeongJae Parkcheck_test_requirements
175*baa489faSSeongJae Parkrun_test $@
176*baa489faSSeongJae Park
177*baa489faSSeongJae Parkexit 0
178