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

selftests: amd-pstate: Split basic.sh into run.sh and basic.sh.

Split basic.sh into run.sh and basic.sh.
The modification makes basic.sh more pure, just for test basic kernel
functions. The file of run.sh mainly contains functions such as test
entry, parameter check, prerequisite and log clearing etc.
Then you can specify test case in kselftest/amd-pstate, for example:
sudo ./run.sh -c basic. The detail please run the below script.
./run.sh --help

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

authored by

Meng Li and committed by
Shuah Khan
e5df3268 a2fa60ee

+167 -42
+2 -1
tools/testing/selftests/amd-pstate/Makefile
··· 4 4 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" 5 5 all: 6 6 7 - TEST_PROGS := basic.sh 7 + TEST_PROGS := run.sh 8 + TEST_FILES := basic.sh 8 9 9 10 include ../lib.mk
+23 -41
tools/testing/selftests/amd-pstate/basic.sh
··· 11 11 # (3) We can introduce more functional or performance tests to align 12 12 # the result together, it will benefit power and performance scale optimization. 13 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 # Please set X86_AMD_PSTATE enabled." 36 - echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 37 - exit $ksft_skip 38 - fi 39 - 40 - msg="Skip all tests:" 41 - if [ ! -w /dev ]; then 42 - echo $msg please run this as root >&2 43 - exit $ksft_skip 44 - fi 45 - 46 - if ! /sbin/modprobe -q -n amd-pstate-ut; then 47 - echo "amd-pstate-ut: module amd-pstate-ut is not found [SKIP]" 48 - exit $ksft_skip 49 - fi 50 - if /sbin/modprobe -q amd-pstate-ut; then 51 - /sbin/modprobe -q -r amd-pstate-ut 52 - echo "amd-pstate-ut: ok" 14 + # protect against multiple inclusion 15 + if [ $FILE_BASIC ]; then 16 + return 0 53 17 else 54 - echo "amd-pstate-ut: [FAIL]" 55 - exit 1 18 + FILE_BASIC=DONE 56 19 fi 20 + 21 + amd_pstate_basic() 22 + { 23 + printf "\n---------------------------------------------\n" 24 + printf "*** Running AMD P-state ut ***" 25 + printf "\n---------------------------------------------\n" 26 + 27 + if ! /sbin/modprobe -q -n amd-pstate-ut; then 28 + echo "amd-pstate-ut: module amd-pstate-ut is not found [SKIP]" 29 + exit $ksft_skip 30 + fi 31 + if /sbin/modprobe -q amd-pstate-ut; then 32 + /sbin/modprobe -q -r amd-pstate-ut 33 + echo "amd-pstate-basic: ok" 34 + else 35 + echo "amd-pstate-basic: [FAIL]" 36 + exit 1 37 + fi 38 + }
+142
tools/testing/selftests/amd-pstate/run.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # protect against multiple inclusion 5 + if [ $FILE_MAIN ]; then 6 + return 0 7 + else 8 + FILE_MAIN=DONE 9 + fi 10 + 11 + source basic.sh 12 + 13 + # amd-pstate-ut only run on x86/x86_64 AMD systems. 14 + ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/') 15 + VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}') 16 + 17 + FUNC=all 18 + OUTFILE=selftest 19 + 20 + # Kselftest framework requirement - SKIP code is 4. 21 + ksft_skip=4 22 + 23 + # All amd-pstate tests 24 + amd_pstate_all() 25 + { 26 + printf "\n=============================================\n" 27 + printf "***** Running AMD P-state Sanity Tests *****\n" 28 + printf "=============================================\n\n" 29 + 30 + # unit test for amd-pstate kernel driver 31 + amd_pstate_basic 32 + } 33 + 34 + help() 35 + { 36 + printf "Usage: $0 [OPTION...] 37 + [-h <help>] 38 + [-o <output-file-for-dump>] 39 + [-c <all: All testing, 40 + basic: Basic testing.>] 41 + \n" 42 + exit 2 43 + } 44 + 45 + parse_arguments() 46 + { 47 + while getopts ho:c: arg 48 + do 49 + case $arg in 50 + h) # --help 51 + help 52 + ;; 53 + 54 + c) # --func_type (Function to perform: basic (default: all)) 55 + FUNC=$OPTARG 56 + ;; 57 + 58 + o) # --output-file (Output file to store dumps) 59 + OUTFILE=$OPTARG 60 + ;; 61 + 62 + *) 63 + help 64 + ;; 65 + esac 66 + done 67 + } 68 + 69 + prerequisite() 70 + { 71 + if ! echo "$ARCH" | grep -q x86; then 72 + echo "$0 # Skipped: Test can only run on x86 architectures." 73 + exit $ksft_skip 74 + fi 75 + 76 + if ! echo "$VENDOR" | grep -iq amd; then 77 + echo "$0 # Skipped: Test can only run on AMD CPU." 78 + echo "$0 # Current cpu vendor is $VENDOR." 79 + exit $ksft_skip 80 + fi 81 + 82 + scaling_driver=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_driver) 83 + if [ "$scaling_driver" != "amd-pstate" ]; then 84 + echo "$0 # Skipped: Test can only run on amd-pstate driver." 85 + echo "$0 # Please set X86_AMD_PSTATE enabled." 86 + echo "$0 # Current cpufreq scaling drvier is $scaling_driver." 87 + exit $ksft_skip 88 + fi 89 + 90 + msg="Skip all tests:" 91 + if [ ! -w /dev ]; then 92 + echo $msg please run this as root >&2 93 + exit $ksft_skip 94 + fi 95 + } 96 + 97 + do_test() 98 + { 99 + case "$FUNC" in 100 + "all") 101 + amd_pstate_all 102 + ;; 103 + 104 + "basic") 105 + amd_pstate_basic 106 + ;; 107 + 108 + *) 109 + echo "Invalid [-f] function type" 110 + help 111 + ;; 112 + esac 113 + } 114 + 115 + # clear dumps 116 + pre_clear_dumps() 117 + { 118 + case "$FUNC" in 119 + "all") 120 + rm -rf $OUTFILE* 121 + ;; 122 + 123 + *) 124 + ;; 125 + esac 126 + } 127 + 128 + post_clear_dumps() 129 + { 130 + rm -rf $OUTFILE.log 131 + } 132 + 133 + # Parse arguments 134 + parse_arguments $@ 135 + 136 + # Make sure all requirements are met 137 + prerequisite 138 + 139 + # Run requested functions 140 + pre_clear_dumps 141 + do_test | tee -a $OUTFILE.log 142 + post_clear_dumps