diff options
Diffstat (limited to 'common/scripts/pm-qa/include')
-rw-r--r-- | common/scripts/pm-qa/include/functions.sh | 346 | ||||
-rw-r--r-- | common/scripts/pm-qa/include/suspend_functions.sh | 294 | ||||
-rw-r--r-- | common/scripts/pm-qa/include/thermal_functions.sh | 281 |
3 files changed, 0 insertions, 921 deletions
diff --git a/common/scripts/pm-qa/include/functions.sh b/common/scripts/pm-qa/include/functions.sh deleted file mode 100644 index 874d2d2..0000000 --- a/common/scripts/pm-qa/include/functions.sh +++ /dev/null @@ -1,346 +0,0 @@ -#!/bin/bash -# -# PM-QA validation test suite for the power management on Linux -# -# Copyright (C) 2011, Linaro Limited. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# Contributors: -# Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) -# - initial API and implementation -# - -source ../Switches.sh - -CPU_PATH="/sys/devices/system/cpu" -TEST_NAME=$(basename ${0%.sh}) -PREFIX=$TEST_NAME -INC=0 -CPU= -pass_count=0 -fail_count=0 - -test_status_show() { - echo "-------- total = $(($pass_count + $fail_count))" - echo "-------- pass = $pass_count" - # report failure only if it is there - if [ $fail_count -ne 0 ] ; then - echo "-------- fail = $fail_count" - fi -} - -log_begin() { - printf "%-76s" "$TEST_NAME.$INC$CPU: $@... " - INC=$(($INC+1)) -} - -log_end() { - printf "$*\n" -} - -log_skip() { - log_begin "$@" - log_end "skip" -} - -for_each_cpu() { - - local func=$1 - shift 1 - - cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") - - for cpu in $cpus; do - INC=0 - CPU=/$cpu - $func $cpu $@ - done - - return 0 -} - -for_each_governor() { - - local cpu=$1 - local func=$2 - local dirpath=$CPU_PATH/$cpu/cpufreq - local governors=$(cat $dirpath/scaling_available_governors) - shift 2 - - for governor in $governors; do - $func $cpu $governor $@ - done - - return 0 -} - -for_each_frequency() { - - local cpu=$1 - local func=$2 - local dirpath=$CPU_PATH/$cpu/cpufreq - local frequencies=$(cat $dirpath/scaling_available_frequencies) - shift 2 - - for frequency in $frequencies; do - $func $cpu $frequency $@ - done - - return 0 -} - -set_governor() { - - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor - local newgov=$2 - - echo $newgov > $dirpath -} - -get_governor() { - - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor - - cat $dirpath -} - -wait_latency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq - local latency= - local nrfreq= - - latency=$(cat $dirpath/cpuinfo_transition_latency) - if [ $? != 0 ]; then - return 1 - fi - - nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) - if [ $? != 0 ]; then - return 1 - fi - - nrfreq=$((nrfreq + 1)) - ../utils/nanosleep $(($nrfreq * $latency)) -} - -frequnit() { - local freq=$1 - local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) - local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) - - res=$(echo "($ghz > 1.0)" | bc -l) - if [ "$res" = "1" ]; then - echo $ghz GHz - return 0 - fi - - res=$(echo "($mhz > 1.0)" | bc -l) - if [ "$res" = "1" ];then - echo $mhz MHz - return 0 - fi - - echo $freq KHz -} - -set_frequency() { - - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq - local newfreq=$2 - local setfreqpath=$dirpath/scaling_setspeed - - echo $newfreq > $setfreqpath - wait_latency $cpu -} - -get_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq - cat $dirpath -} - -get_max_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq - cat $dirpath -} - -get_min_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq - cat $dirpath -} - -set_online() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu - - if [ "$cpu" = "cpu0" ]; then - return 0 - fi - - echo 1 > $dirpath/online -} - -set_offline() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu - - if [ "$cpu" = "cpu0" ]; then - return 0 - fi - - echo 0 > $dirpath/online -} - -get_online() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu - - cat $dirpath/online -} - -check() { - - local descr=$1 - local func=$2 - shift 2; - - log_begin "checking $descr" - - $func $@ - if [ $? != 0 ]; then - log_end "Err" - fail_count=$(($fail_count + 1)) - return 1 - fi - - log_end "Ok" - pass_count=$(($pass_count + 1)) - - return 0 -} - -check_file() { - local file=$1 - local dir=$2 - - check "'$file' exists" "test -f" $dir/$file -} - -check_cpufreq_files() { - - local dirpath=$CPU_PATH/$1/cpufreq - shift 1 - - for i in $@; do - check_file $i $dirpath || return 1 - done - - return 0 -} - -check_sched_mc_files() { - - local dirpath=$CPU_PATH - - for i in $@; do - check_file $i $dirpath || return 1 - done - - return 0 -} - -check_topology_files() { - - local dirpath=$CPU_PATH/$1/topology - shift 1 - - for i in $@; do - check_file $i $dirpath || return 1 - done - - return 0 -} - -check_cpuhotplug_files() { - - local dirpath=$CPU_PATH/$1 - shift 1 - - for i in $@; do - check_file $i $dirpath || return 1 - done - - return 0 -} - -save_governors() { - - governors_backup= - local index=0 - - for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do - governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) - index=$((index + 1)) - done -} - -restore_governors() { - - local index=0 - local oldgov= - - for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do - oldgov=${governors_backup[$index]} - echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor - index=$((index + 1)) - done -} - -save_frequencies() { - - frequencies_backup= - local index=0 - local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") - local cpu= - - for cpu in $cpus; do - frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) - index=$((index + 1)) - done -} - -restore_frequencies() { - - local index=0 - local oldfreq= - local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") - - for cpu in $cpus; do - oldfreq=${frequencies_backup[$index]} - echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed - index=$((index + 1)) - done -} - -sigtrap() { - exit 255 -} diff --git a/common/scripts/pm-qa/include/suspend_functions.sh b/common/scripts/pm-qa/include/suspend_functions.sh deleted file mode 100644 index f06689f..0000000 --- a/common/scripts/pm-qa/include/suspend_functions.sh +++ /dev/null @@ -1,294 +0,0 @@ -#!/bin/bash -# -# Script to automate suspend / resume -# -# Copyright (C) 2008-2009 Canonical Ltd. -# -# Authors: -# Michael Frey <michael.frey@canonical.com> -# Andy Whitcroft <apw@canonical.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2, -# as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -# -# Script to automate suspend / resume -# -# We set a RTC alarm that wakes the system back up and then sleep -# for seconds before we go back to sleep. -# -# Changelog: -# -# Version for Linaro PM-QA: -# - this script is edited and integrated into Linaro PM-QA -# - hongbo.zhang@linaro.org, March, 2012 -# - - -LOGDIR='/var/lib/pm-utils' -LOGFILE="$LOGDIR/stress.log" - -# Options Config -dry=0 -auto=1 -pm_trace=1 -timer_sleep=20 - -# root is needed to fiddle with the clock and use the rtc wakeups. -if [ $(id -u) != 0 ]; then - log_skip "run as non-root" - exit 0 -fi - -# Ensure the log directory exists. -mkdir -p "$LOGDIR" - -setup_wakeup_timer () -{ - timeout="$1" - - # Request wakeup from the RTC or ACPI alarm timers. Set the timeout - # at 'now' + $timeout seconds. - ctl='/sys/class/rtc/rtc0/wakealarm' - if [ -f "$ctl" ]; then - # Cancel any outstanding timers. - echo "0" >"$ctl" - # rtcN/wakealarm can use relative time in seconds - echo "+$timeout" >"$ctl" - return 0 - fi - ctl='/proc/acpi/alarm' - if [ -f "$ctl" ]; then - echo `date '+%F %H:%M:%S' -d '+ '$timeout' seconds'` >"$ctl" - return 0 - fi - - echo "no method to awaken machine automatically" 1>&2 - exit 1 -} - -suspend_system () -{ - if [ "$dry" -eq 1 ]; then - echo "DRY-RUN: suspend machine for $timer_sleep" - sleep 1 - return - fi - - setup_wakeup_timer "$timer_sleep" - - dmesg >"$LOGFILE.dmesg.A" - - # Initiate suspend in different ways. - case "$1" in - dbus) - dbus-send --session --type=method_call \ - --dest=org.freedesktop.PowerManagement \ - /org/freedesktop/PowerManagement \ - org.freedesktop.PowerManagement.Suspend \ - >> "$LOGFILE" || { - ECHO "FAILED: dbus suspend failed" 1>&2 - return 1 - } - ;; - pmsuspend) - pm-suspend >> "$LOGFILE" - ;; - mem) - `echo "mem" > /sys/power/state` >> "$LOGFILE" - ;; - esac - - # Wait on the machine coming back up -- pulling the dmesg over. - echo "v---" >>"$LOGFILE" - retry=30 - while [ "$retry" -gt 0 ]; do - let "retry=$retry-1" - - # Accumulate the dmesg delta. - dmesg >"$LOGFILE.dmesg.B" - diff "$LOGFILE.dmesg.A" "$LOGFILE.dmesg.B" | \ - grep '^>' >"$LOGFILE.dmesg" - mv "$LOGFILE.dmesg.B" "$LOGFILE.dmesg.A" - - echo "Waiting for suspend to complete $retry to go ..." \ - >> "$LOGFILE" - cat "$LOGFILE.dmesg" >> "$LOGFILE" - - if [ "`grep -c 'Back to C!' $LOGFILE.dmesg`" -ne 0 ]; then - break; - fi - sleep 1 - done - echo "^---" >>"$LOGFILE" - rm -f "$LOGFILE.dmesg"* - if [ "$retry" -eq 0 ]; then - ECHO "SUSPEND FAILED, did not go to sleep" 1>&2 - return 1 - fi -} - -ECHO () -{ - echo "$@" | tee -a "$LOGFILE" -} - -enable_trace() -{ - if [ -w /sys/power/pm_trace ]; then - echo 1 > '/sys/power/pm_trace' - fi -} - -disable_trace() -{ - if [ -w /sys/power/pm_trace ]; then - echo 0 > '/sys/power/pm_trace' - fi -} - -trace_state=-1 - -save_trace() -{ - if [ -r /sys/power/pm_trace ]; then - trace_state=`cat /sys/power/pm_trace` - fi -} - -restore_trace() -{ - if [ "$trace_state" -ne -1 -a -w /sys/power/pm_trace ]; then - echo "$trace_state" > '/sys/power/pm_trace' - fi -} - -battery_count() -{ - cat /proc/acpi/battery/*/state 2>/dev/null | \ - awk ' - BEGIN { total = 0 } - /present:.*yes/ { total += 1 } - END { print total } - ' -} - -battery_capacity() -{ - cat /proc/acpi/battery/*/state 2>/dev/null | \ - awk ' - BEGIN { total = 0 } - /remaining capacity:/ { total += $3 } - END { print total } - ' -} - -ac_needed=-1 -ac_is=-1 -ac_becomes=-1 - -ac_required() -{ - ac_check - - ac_needed="$1" - ac_becomes="$1" -} - -ac_transitions() -{ - ac_check - - ac_needed="$1" - ac_becomes="$2" -} - -ac_online() -{ - cat /proc/acpi/ac_adapter/*/state 2>/dev/null | \ - awk ' - BEGIN { online = 0; offline = 0 } - /on-line/ { online = 1 } - /off-line/ { offline = 1 } - END { - if (online) { - print "1" - } else if (offline) { - print "0" - } else { - print "-1" - } - } - ' -} - -ac_check() -{ - typeset ac_current=`ac_online` - - if [ "$ac_becomes" -ne -1 -a "$ac_current" -ne -1 -a \ - "$ac_current" -ne "$ac_becomes" ]; then - ECHO "*** WARNING: AC power not in expected state" \ - "($ac_becomes) after test" - fi - ac_is="$ac_becomes" -} - -phase=0 -phase_first=1 -phase_interactive=1 - -phase() -{ - typeset sleep - - let phase="$phase+1" - - if [ "$ac_needed" -ne "$ac_is" ]; then - case "$ac_needed" in - 0) echo "*** please ensure your AC cord is detached" ;; - 1) echo "*** please ensure your AC cord is attached" ;; - esac - ac_is="$ac_needed" - fi - - if [ "$timer_sleep" -gt 60 ]; then - let sleep="$timer_sleep / 60" - sleep="$sleep minutes" - else - sleep="$timer_sleep seconds" - fi - echo "*** machine will suspend for $sleep" - - if [ "$auto" -eq 1 ]; then - : - - elif [ "$phase_interactive" -eq 1 ]; then - echo "*** press return when ready" - read x - - elif [ "$phase_first" -eq 1 ]; then - echo "*** NOTE: there will be no further user interaction from this point" - echo "*** press return when ready" - phase_first=0 - read x - fi -} - -save_trace - -if [ "$pm_trace" -eq 1 ]; then - enable_trace -else - disable_trace -fi - diff --git a/common/scripts/pm-qa/include/thermal_functions.sh b/common/scripts/pm-qa/include/thermal_functions.sh deleted file mode 100644 index 8a4d627..0000000 --- a/common/scripts/pm-qa/include/thermal_functions.sh +++ /dev/null @@ -1,281 +0,0 @@ -#!/bin/bash -# -# PM-QA validation test suite for the power management on Linux -# -# Copyright (C) 2011, Linaro Limited. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -# -# Contributors: -# Amit Daniel <amit.kachhap@linaro.org> (Samsung Electronics) -# - initial API and implementation -# - -THERMAL_PATH="/sys/devices/virtual/thermal" -MAX_ZONE=0-12 -MAX_CDEV=0-50 -ALL_ZONE= -ALL_CDEV= - -check_valid_temp() { - local file=$1 - local zone_name=$2 - local dir=$THERMAL_PATH/$2 - - local temp_file=$dir/$1 - local func=cat - shift 2; - - local temp_val=$($func $temp_file) - local descr="'$zone_name'/'$file' ='$temp_val'" - log_begin "checking $descr" - - if [ $temp_val -gt 0 ]; then - log_end "pass" - return 0 - fi - - log_end "fail" - - return 1 -} - -for_each_thermal_zone() { - - local func=$1 - shift 1 - - zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - - ALL_ZONE=$zone - for zone in $zones; do - INC=0 - $func $zone $@ - done - - return 0 -} - -get_total_trip_point_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 - shift 1 - trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") - for trip in $trips; do - count=$((count + 1)) - done - return $count -} - -for_each_trip_point_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 - local func=$2 - local zone_name=$1 - shift 2 - trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") - for trip in $trips; do - $func $zone_name $count - count=$((count + 1)) - done - return 0 -} - -for_each_binding_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 - local func=$2 - local zone_name=$1 - shift 2 - trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point") - for trip in $trips; do - $func $zone_name $count - count=$((count + 1)) - done - - return 0 - -} - -check_valid_binding() { - local trip_point=$1 - local zone_name=$2 - local dirpath=$THERMAL_PATH/$2 - local temp_file=$2/$1 - local trip_point_val=$(cat $dirpath/$trip_point) - get_total_trip_point_of_zone $zone_name - local trip_point_max=$? - local descr="'$temp_file' valid binding" - shift 2 - - log_begin "checking $descr" - if [ $trip_point_val -ge $trip_point_max ]; then - log_end "fail" - return 1 - fi - - log_end "pass" - return 0 -} - -validate_trip_bindings() { - local zone_name=$1 - local bind_no=$2 - local dirpath=$THERMAL_PATH/$1 - local trip_point=cdev$2_trip_point - shift 2 - - check_file $trip_point $dirpath || return 1 - check_valid_binding $trip_point $zone_name || return 1 -} - -validate_trip_level() { - local zone_name=$1 - local trip_no=$2 - local dirpath=$THERMAL_PATH/$1 - local trip_temp=trip_point_$2_temp - local trip_type=trip_point_$2_type - shift 2 - - check_file $trip_temp $dirpath || return 1 - check_file $trip_type $dirpath || return 1 - check_valid_temp $trip_temp $zone_name || return 1 -} - -for_each_cooling_device() { - - local func=$1 - shift 1 - - devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") - - ALL_DEVICE=$devices - for device in $devices; do - INC=0 - $func $device $@ - done - - return 0 -} -check_scaling_freq() { - - local before_freq_list=$1 - local after_freq_list=$2 - shift 2 - local index=0 - - local flag=0 - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do - if [ $before_freq_list[$index] != $afterf_req_list[$index] ] ; then - flag=1 - fi - index=$((index + 1)) - done - return $flag -} - -store_scaling_maxfreq() { - scale_freq= - local index=0 - - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do - scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) - index=$((index + 1)) - done - return 0 -} - -get_trip_id() { - - local trip_name=$1 - shift 1 - - local id1=$(echo $trip_name|cut -c12) - local id2=$(echo $trip_name|cut -c13) - if [ $id2 != "_" ]; then - id1=$(($id2 + 10*$id1)) - fi - return $id1 -} - -disable_all_thermal_zones() { - - mode_list= - local index=0 - - local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - mode_list[$index]=$(cat $THERMAL_PATH/$zone/mode) - index=$((index + 1)) - echo -n "disabled" > $THERMAL_PATH/$zone/mode - done - return 0 -} - -enable_all_thermal_zones() { - - local index=0 - - local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - echo $mode_list[$index] > $THERMAL_PATH/$zone/mode - index=$((index + 1)) - done - return 0 -} - -GPU_HEAT_BIN=/usr/bin/glmark2 -gpu_pid=0 - -start_glmark2() { - if [ -n "$ANDROID" ]; then - am start org.linaro.glmark2/.Glmark2Activity - return - fi - - if [ -x $GPU_HEAT_BIN ]; then - $GPU_HEAT_BIN & - gpu_pid=$(pidof $GPU_HEAT_BIN) - # Starting X application from serial console needs this - if [ -z "$gpu_pid" ]; then - cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk - echo "autologin-user=root" >> /etc/lightdm/lightdm.conf - export DISPLAY=localhost:0.0 - restart lightdm - sleep 5 - mv /etc/lightdm/lightdm.conf.bk /etc/lightdm/lightdm.conf - $GPU_HEAT_BIN & - gpu_pid=$(pidof $GPU_HEAT_BIN) - fi - test -z "$gpu_pid" && cpu_pid=0 - echo "start gpu heat binary $gpu_pid" - else - echo "glmark2 not found." 1>&2 - fi -} - -kill_glmark2() { - if [ -n "$ANDROID" ]; then - am kill org.linaro.glmark2 - return - fi - - if [ "$gpu_pid" != 0 ]; then - kill -9 $gpu_pid - fi -} |