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