Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: amd-pstate: Add test trigger for amd-pstate driver

Add amd-pstate test trigger in kselftest, it will load/unload
amd-pstate-ut module to test some cases etc.

Signed-off-by: Meng Li <li.meng@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Meng Li and committed by
Shuah Khan
e1083a03 14eb1c96

+66
+1
tools/testing/selftests/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 TARGETS += alsa 3 + TARGETS += amd-pstate 3 4 TARGETS += arm64 4 5 TARGETS += bpf 5 6 TARGETS += breakpoints
+9
tools/testing/selftests/amd-pstate/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + # Makefile for amd-pstate/ function selftests 3 + 4 + # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" 5 + all: 6 + 7 + TEST_PROGS := amd-pstate-ut.sh 8 + 9 + include ../lib.mk
+55
tools/testing/selftests/amd-pstate/amd-pstate-ut.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # amd-pstate-ut is a test module for testing the amd-pstate driver. 5 + # It can only run on x86 architectures and current cpufreq driver 6 + # must be amd-pstate. 7 + # (1) It can help all users to verify their processor support 8 + # (SBIOS/Firmware or Hardware). 9 + # (2) Kernel can have a basic function test to avoid the kernel 10 + # regression during the update. 11 + # (3) We can introduce more functional or performance tests to align 12 + # the result together, it will benefit power and performance scale optimization. 13 + 14 + # Kselftest framework requirement - SKIP code is 4. 15 + ksft_skip=4 16 + 17 + # amd-pstate-ut only run on x86/x86_64 AMD systems. 18 + ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/') 19 + VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}') 20 + 21 + if ! echo "$ARCH" | grep -q x86; then 22 + echo "$0 # Skipped: Test can only run on x86 architectures." 23 + exit $ksft_skip 24 + fi 25 + 26 + if ! echo "$VENDOR" | grep -iq amd; then 27 + echo "$0 # Skipped: Test can only run on AMD CPU." 28 + echo "$0 # Current cpu vendor is $VENDOR." 29 + exit $ksft_skip 30 + fi 31 + 32 + scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver) 33 + if [ "$scaling_driver" != "amd-pstate" ]; then 34 + echo "$0 # Skipped: Test can only run on amd-pstate driver." 35 + echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 36 + exit $ksft_skip 37 + fi 38 + 39 + msg="Skip all tests:" 40 + if [ ! -w /dev ]; then 41 + echo $msg please run this as root >&2 42 + exit $ksft_skip 43 + fi 44 + 45 + if ! /sbin/modprobe -q -n amd-pstate-ut; then 46 + echo "amd-pstate-ut: module amd-pstate-ut is not found [SKIP]" 47 + exit $ksft_skip 48 + fi 49 + if /sbin/modprobe -q amd-pstate-ut; then 50 + /sbin/modprobe -q -r amd-pstate-ut 51 + echo "amd-pstate-ut: ok" 52 + else 53 + echo "amd-pstate-ut: [FAIL]" 54 + exit 1 55 + fi
+1
tools/testing/selftests/amd-pstate/config
··· 1 + CONFIG_X86_AMD_PSTATE_UT=m