1f08c3bdfSopenharmony_ci#! /bin/sh 2f08c3bdfSopenharmony_ci# 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci# Author: Nageswara R Sastry <nasastry@in.ibm.com> 5f08c3bdfSopenharmony_ci# 6f08c3bdfSopenharmony_ci# This program is free software; you can redistribute it and#or modify 7f08c3bdfSopenharmony_ci# it under the terms of the GNU General Public License as published by 8f08c3bdfSopenharmony_ci# the Free Software Foundation; either version 2 of the License, or 9f08c3bdfSopenharmony_ci# (at your option) any later version. 10f08c3bdfSopenharmony_ci# 11f08c3bdfSopenharmony_ci# This program is distributed in the hope that it will be useful, but 12f08c3bdfSopenharmony_ci# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13f08c3bdfSopenharmony_ci# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14f08c3bdfSopenharmony_ci# for more details. 15f08c3bdfSopenharmony_ci# 16f08c3bdfSopenharmony_ci# You should have received a copy of the GNU General Public License 17f08c3bdfSopenharmony_ci# along with this program; if not, write to the Free Software Foundation, 18f08c3bdfSopenharmony_ci# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19f08c3bdfSopenharmony_ci# 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ciexport TCID="Power_Management03" 22f08c3bdfSopenharmony_ciexport TST_TOTAL=4 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci. test.sh 25f08c3bdfSopenharmony_ci. pm_include.sh 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cicheck_cpufreq_sysfs_files() { 28f08c3bdfSopenharmony_ci total_cpus=`expr $(tst_ncpus) - 1` 29f08c3bdfSopenharmony_ci RC=0 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci for cpu in $(seq 0 "${total_cpus}" ) 32f08c3bdfSopenharmony_ci do 33f08c3bdfSopenharmony_ci cpufiles=$(find /sys/devices/system/cpu/cpu"${cpu}"/cpufreq/ \ 34f08c3bdfSopenharmony_ci -name "*" -type f -perm /400) 35f08c3bdfSopenharmony_ci for files in ${cpufiles} 36f08c3bdfSopenharmony_ci do 37f08c3bdfSopenharmony_ci cat ${files} >/dev/null 2>&1 38f08c3bdfSopenharmony_ci if [ $? -ne 0 ] ; then 39f08c3bdfSopenharmony_ci echo "${0}: FAIL: cat ${files}" 40f08c3bdfSopenharmony_ci RC=1 41f08c3bdfSopenharmony_ci fi 42f08c3bdfSopenharmony_ci done 43f08c3bdfSopenharmony_ci done 44f08c3bdfSopenharmony_ci if [ ${RC} -eq 0 ] ; then 45f08c3bdfSopenharmony_ci echo "${0}: PASS: Checking cpu freq sysfs files" 46f08c3bdfSopenharmony_ci fi 47f08c3bdfSopenharmony_ci return $RC 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cichange_govr() { 51f08c3bdfSopenharmony_ci available_govr=$(get_supporting_govr) 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci total_cpus=`expr $(tst_ncpus) - 1` 54f08c3bdfSopenharmony_ci RC=0 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci for cpu in $(seq 0 "${total_cpus}" ) 57f08c3bdfSopenharmony_ci do 58f08c3bdfSopenharmony_ci for govr in ${available_govr} 59f08c3bdfSopenharmony_ci do 60f08c3bdfSopenharmony_ci echo ${govr} > \ 61f08c3bdfSopenharmony_ci /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor 62f08c3bdfSopenharmony_ci if [ "$?" -ne "0" ] ; then 63f08c3bdfSopenharmony_ci echo "${0}: FAIL: Unable to set" \ 64f08c3bdfSopenharmony_ci "governor -- ${govr} for cpu${cpu}" 65f08c3bdfSopenharmony_ci RC=1 66f08c3bdfSopenharmony_ci fi 67f08c3bdfSopenharmony_ci done 68f08c3bdfSopenharmony_ci done 69f08c3bdfSopenharmony_ci if [ ${RC} -eq 0 ] ; then 70f08c3bdfSopenharmony_ci echo "${0}: PASS: Changing cpu governors" 71f08c3bdfSopenharmony_ci fi 72f08c3bdfSopenharmony_ci return $RC 73f08c3bdfSopenharmony_ci} 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_cichange_freq() { 76f08c3bdfSopenharmony_ci available_freq=$(get_supporting_freq) 77f08c3bdfSopenharmony_ci available_govr=$(get_supporting_govr) 78f08c3bdfSopenharmony_ci RC=0 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_ci total_cpus=`expr $(tst_ncpus) - 1` 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci if ( echo ${available_govr} | grep -i "userspace" \ 83f08c3bdfSopenharmony_ci >/dev/null 2>&1 ); then 84f08c3bdfSopenharmony_ci for cpu in $(seq 0 "${total_cpus}" ) 85f08c3bdfSopenharmony_ci do 86f08c3bdfSopenharmony_ci echo userspace > \ 87f08c3bdfSopenharmony_ci /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor 88f08c3bdfSopenharmony_ci if [ $? -ne 0 ] ; then 89f08c3bdfSopenharmony_ci RC=1 90f08c3bdfSopenharmony_ci fi 91f08c3bdfSopenharmony_ci done 92f08c3bdfSopenharmony_ci if [ ${RC} -ne 1 ] ; then 93f08c3bdfSopenharmony_ci for cpu in $(seq 0 "${total_cpus}" ) 94f08c3bdfSopenharmony_ci do 95f08c3bdfSopenharmony_ci for freq in ${available_freq} 96f08c3bdfSopenharmony_ci do 97f08c3bdfSopenharmony_ci echo ${freq} > \ 98f08c3bdfSopenharmony_ci /sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_setspeed 99f08c3bdfSopenharmony_ci if [ "$?" -ne "0" ] ; then 100f08c3bdfSopenharmony_ci echo "${0}: FAIL: Unable" \ 101f08c3bdfSopenharmony_ci "to set frequency -- ${freq} for cpu${cpu}" 102f08c3bdfSopenharmony_ci RC=1 103f08c3bdfSopenharmony_ci fi 104f08c3bdfSopenharmony_ci done 105f08c3bdfSopenharmony_ci done 106f08c3bdfSopenharmony_ci fi 107f08c3bdfSopenharmony_ci fi 108f08c3bdfSopenharmony_ci if [ ${RC} -eq 0 ] ; then 109f08c3bdfSopenharmony_ci echo "${0}: PASS: Changing cpu frequencies" 110f08c3bdfSopenharmony_ci fi 111f08c3bdfSopenharmony_ci return $RC 112f08c3bdfSopenharmony_ci} 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_cipwkm_load_unload() { 115f08c3bdfSopenharmony_ci RC=0 116f08c3bdfSopenharmony_ci loaded_governor=`cat \ 117f08c3bdfSopenharmony_ci /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor` 118f08c3bdfSopenharmony_ci for module in `modprobe -l | grep cpufreq_ | \ 119f08c3bdfSopenharmony_ci cut -f8 -d"/" | cut -f1 -d"."` 120f08c3bdfSopenharmony_ci do 121f08c3bdfSopenharmony_ci #echo -n "Loading $module ... " 122f08c3bdfSopenharmony_ci if [ $module != "cpufreq_$loaded_governor" ]; then 123f08c3bdfSopenharmony_ci modprobe $module >/dev/null 124f08c3bdfSopenharmony_ci if [ $? -ne 0 ] ; then 125f08c3bdfSopenharmony_ci echo "${0}: FAIL: Loading of module $module" \ 126f08c3bdfSopenharmony_ci "or check whether you compiled as module or not" 127f08c3bdfSopenharmony_ci RC=1 128f08c3bdfSopenharmony_ci fi 129f08c3bdfSopenharmony_ci fi 130f08c3bdfSopenharmony_ci done 131f08c3bdfSopenharmony_ci for module in `modprobe -l | grep cpufreq_ | \ 132f08c3bdfSopenharmony_ci cut -f8 -d"/" | cut -f1 -d"."` 133f08c3bdfSopenharmony_ci do 134f08c3bdfSopenharmony_ci #echo -n "Unloading $module ... " 135f08c3bdfSopenharmony_ci if [ $module != "cpufreq_$loaded_governor" ]; then 136f08c3bdfSopenharmony_ci modprobe -r $module >/dev/null 137f08c3bdfSopenharmony_ci if [ $? -ne 0 ] ; then 138f08c3bdfSopenharmony_ci echo "${0}: FAIL: Loading of module $module" \ 139f08c3bdfSopenharmony_ci "or check whether you compiled as module or not" 140f08c3bdfSopenharmony_ci RC=1 141f08c3bdfSopenharmony_ci fi 142f08c3bdfSopenharmony_ci fi 143f08c3bdfSopenharmony_ci done 144f08c3bdfSopenharmony_ci return $RC 145f08c3bdfSopenharmony_ci} 146f08c3bdfSopenharmony_ci 147f08c3bdfSopenharmony_ci# Checking test environment 148f08c3bdfSopenharmony_cicheck_arch 149f08c3bdfSopenharmony_ci 150f08c3bdfSopenharmony_ci# Checking cpufreq sysfs interface files 151f08c3bdfSopenharmony_ciif [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ] ; then 152f08c3bdfSopenharmony_ci tst_brkm TCONF "Required kernel configuration for CPU_FREQ NOT set" 153f08c3bdfSopenharmony_cifi 154f08c3bdfSopenharmony_ci 155f08c3bdfSopenharmony_ciif check_cpufreq_sysfs_files ; then 156f08c3bdfSopenharmony_ci tst_resm TPASS "CPUFREQ sysfs tests" 157f08c3bdfSopenharmony_cielse 158f08c3bdfSopenharmony_ci tst_resm TFAIL "CPUFREQ sysfs tests" 159f08c3bdfSopenharmony_cifi 160f08c3bdfSopenharmony_ci 161f08c3bdfSopenharmony_ci# Changing governors 162f08c3bdfSopenharmony_ciif change_govr ; then 163f08c3bdfSopenharmony_ci tst_resm TPASS "Changing governors" 164f08c3bdfSopenharmony_cielse 165f08c3bdfSopenharmony_ci tst_resm TFAIL "Changing governors" 166f08c3bdfSopenharmony_cifi 167f08c3bdfSopenharmony_ci 168f08c3bdfSopenharmony_ci# Changing frequencies 169f08c3bdfSopenharmony_ciif change_freq ; then 170f08c3bdfSopenharmony_ci tst_resm TPASS "Changing frequncies" 171f08c3bdfSopenharmony_cielse 172f08c3bdfSopenharmony_ci tst_resm TFAIL "Changing frequncies" 173f08c3bdfSopenharmony_cifi 174f08c3bdfSopenharmony_ci 175f08c3bdfSopenharmony_ci# Loading and Unloading governor related kernel modules 176f08c3bdfSopenharmony_ciif pwkm_load_unload ; then 177f08c3bdfSopenharmony_ci tst_resm TPASS "Loading and Unloading of governor kernel" \ 178f08c3bdfSopenharmony_ci "modules" 179f08c3bdfSopenharmony_cielse 180f08c3bdfSopenharmony_ci tst_resm TFAIL "Loading and Unloading of governor kernel" \ 181f08c3bdfSopenharmony_ci "modules got failed" 182f08c3bdfSopenharmony_cifi 183f08c3bdfSopenharmony_ci 184f08c3bdfSopenharmony_citst_exit 185