1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# protect against multiple inclusion 5if [ $FILE_MAIN ]; then 6 return 0 7else 8 FILE_MAIN=DONE 9fi 10 11source basic.sh 12 13# amd-pstate-ut only run on x86/x86_64 AMD systems. 14ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/') 15VENDOR=$(cat /proc/cpuinfo | grep -m 1 'vendor_id' | awk '{print $NF}') 16 17FUNC=all 18OUTFILE=selftest 19 20# Kselftest framework requirement - SKIP code is 4. 21ksft_skip=4 22 23# All amd-pstate tests 24amd_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 34help() 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 45parse_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 69prerequisite() 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 97do_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 116pre_clear_dumps() 117{ 118 case "$FUNC" in 119 "all") 120 rm -rf $OUTFILE* 121 ;; 122 123 *) 124 ;; 125 esac 126} 127 128post_clear_dumps() 129{ 130 rm -rf $OUTFILE.log 131} 132 133# Parse arguments 134parse_arguments $@ 135 136# Make sure all requirements are met 137prerequisite 138 139# Run requested functions 140pre_clear_dumps 141do_test | tee -a $OUTFILE.log 142post_clear_dumps 143