selftests: amd-pstate: Add test trigger for amd-pstate driver
[platform/kernel/linux-starfive.git] / 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