diff options
author | zhanghongbo <hongbo.zhang@stericsson.com> | 2012-08-17 18:47:56 +0800 |
---|---|---|
committer | hongbo.zhang <hongbo.zhang@linaro.com> | 2012-11-28 17:11:30 +0800 |
commit | ea9b7f31710abcabd44fb8deeea77d013de4a8a8 (patch) | |
tree | 59e025e22b5641d41c9a1757fe0e029d7a1ac9f4 | |
parent | a3719a1d42046ff448a7a0c91e04eb72e58ef2e0 (diff) |
Suspend function updated.
Remove unnecessary stress test for PM-QA;
Add more condition checkings before taking actions.
Signed-off-by: hongbo.zhang <hongbo.zhang@linaro.com>
-rwxr-xr-x | include/suspend_functions.sh (renamed from include/suspend.sh) | 199 | ||||
-rwxr-xr-x | suspend/suspend_01.sh | 22 | ||||
-rwxr-xr-x | suspend/suspend_02.sh | 15 | ||||
-rwxr-xr-x | suspend/suspend_03.sh | 34 | ||||
-rw-r--r-- | suspend/suspend_03.txt | 2 | ||||
-rwxr-xr-x | suspend/suspend_04.sh | 77 | ||||
-rw-r--r-- | suspend/suspend_04.txt | 2 | ||||
-rwxr-xr-x | suspend/suspend_05.sh | 73 | ||||
-rw-r--r-- | suspend/suspend_05.txt | 2 | ||||
-rwxr-xr-x | suspend/suspend_06.sh | 56 | ||||
-rw-r--r-- | suspend/suspend_06.txt | 1 |
11 files changed, 162 insertions, 321 deletions
diff --git a/include/suspend.sh b/include/suspend_functions.sh index 3d6ce60..6c085db 100755 --- a/include/suspend.sh +++ b/include/suspend_functions.sh @@ -32,85 +32,31 @@ # - this script is edited and integrated into Linaro PM-QA # - hongbo.zhang@linaro.org, March, 2012 # -# V8: -# - add a new suspend battery drain test -# - track batteries disabling tests which require them automatically -# - disable dbus tests when we have no primary user -# - include the new power drain test in --full -# - handle AC transitions better -# - use minutes in messages where appropriate -# - report AC transition failures -# - only mention AC when we have batteries -# - report results at the bottom for easy posting -# -# V7: -# - add a --dry-run mode to simplify developement -# - add a automation mode for checkbox integration -# - add a new pm-suspend test -# - record and restore timer_delay around the variable time test. -# -# V6: -# - move an --enable/--disable interface for tests -# - add --set to allow setting of approved parameters -# - fix up prompting for interactive and non-interactive tests -# - supply a sensible default for testing on servers (apw, kirkland) -# -# V5: -# - send dbus messages as the original user -# - stop clearing the dmesg as we go -# - stop using trace generally as this affects the wakeups -# - do a single dbus test then move to pm-suspend to avoid screensaver -# - timeout waiting for a suspend to complete catching failure to go down -# -# V4: -# - update the help output -# - add --comprehensive to do AC related tests -# - add --extensive to do a range of time related tests -# - add --full to enable all harder tests -# - add fallback to pm-suspend for Kbuntu -# - collect dmesg output -# - remove hwclock update -# -# V3: -# - fix typo in fallback acpi interface -# - when recording the RTC clock do not go direct -# - pmi is now deprecated suspend using dbus -# -# V2: -# - support newer rtc sysfs wakealarm interface -# - move to using pmi action suspend -# - allow the user to specify the number of iterations -# - ensure we are running as root -# - report the iterations to the user -# - clean up the output and put it in a standard logfile -# - add a descriptive warning and allow user cancel -# - add tracing enable/disable -# - fix logfile location -# - add a failure cleanup mode -# - make time sleep time and delay time configurable -# - ensure the log directory exists -# - clock will be fixed automatically on network connect -# - default sleep before wakeup to 20s -# - do not use dates after we have corrupted the clock -# - sort out the copyright information -# - we do not have any failure cleanup currently -# -# V1: -# - add the suspend test scripts -# -P="test-suspend" + LOGDIR='/var/lib/pm-utils' LOGFILE="$LOGDIR/stress.log" +# Options Config +dry=0 +auto=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. @@ -141,19 +87,25 @@ suspend_system () dmesg >"$LOGFILE.dmesg.A" - # Send a dbus message to initiate Suspend. - if [ "$suspend_dbus" -eq 1 ]; then - sudo -u $SUDO_USER dbus-send --session --type=method_call \ + # 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 "$P FAILED: dbus suspend failed" 1>&2 + ECHO "FAILED: dbus suspend failed" 1>&2 return 1 } - else - pm-suspend >> "$LOGFILE" - fi + ;; + pmsuspend) + pm-suspend >> "$LOGFILE" + ;; + mem) + echo "mem" > /sys/power/state + ;; + esac # Wait on the machine coming back up -- pulling the dmesg over. echo "v---" >>"$LOGFILE" @@ -179,32 +131,16 @@ suspend_system () echo "^---" >>"$LOGFILE" rm -f "$LOGFILE.dmesg"* if [ "$retry" -eq 0 ]; then - ECHO "$P SUSPEND FAILED, did not go to sleep" 1>&2 + ECHO "SUSPEND FAILED, did not go to sleep" 1>&2 return 1 fi } -delay_system () -{ - if [ "$dry" -eq 1 ]; then - echo "DRY-RUN: stay awake for $timer_delay" - sleep 1 - return - fi - - # - # wait for $timer_delay seconds after system resume from S3 - # - ECHO "wait for $timer_delay seconds..." - sleep $timer_delay -} - ECHO () { echo "$@" | tee -a "$LOGFILE" } - enable_trace() { echo 1 > '/sys/power/pm_trace' @@ -215,7 +151,6 @@ disable_trace() echo 0 > '/sys/power/pm_trace' } -# Battery battery_count() { cat /proc/acpi/battery/*/state 2>/dev/null | \ @@ -225,6 +160,7 @@ battery_count() END { print total } ' } + battery_capacity() { cat /proc/acpi/battery/*/state 2>/dev/null | \ @@ -235,74 +171,10 @@ battery_capacity() ' } - -# Options helpers. -chk_test () -{ - if ! declare -p "test_$1" 2>/dev/null 1>&2; then - echo "$P: $1: test unknown" 1>&2 - exit 1 - fi -} -handle_set () -{ - stmt=`echo "$1" | sed -e 's/\./_/g'` - - test="${stmt%%_*}" - var="${stmt%%=*}" - - chk_test "$test" - if ! declare -p "args_$var" 2>/dev/null 1>&2; then - echo "$P: $var: test variable unknown" 1>&2 - exit 1 - fi - - RET="args_$stmt" -} -chk_number() { - eval "val=\"\$$1\"" - let num="0+$val" - if [ "$val" != "$num" ]; then - name=`echo "$1" | sed -e 's/args_//' -e 's/_/./'` - echo "$P: $name: $val: non-numeric value" 1>&2 - exit 1 - fi -} - -# Options handling. -dry=0 -auto=0 -timer_sleep=20 -timer_delay=10 - -test_dbus=0 -test_pmsuspend=0 -test_ac=0 -test_timed=0 -test_repeat=0 -args_repeat_iterations=10 -test_power=0 -args_power_sleep=600 - -chk_number "args_repeat_iterations" -chk_number "args_power_sleep" - -battery_count=`battery_count` - -suspend_dbus=0 - -# Check we are running as root as we are going to fiddle with the clock -# and use the rtc wakeups. -id=`id -u` -if [ "$id" -ne 0 ]; then - echo "ERROR: must be run as root to perform this test, use sudo:" 1>&2 - echo " sudo $0 $@" 1>&2 - exit 1 -fi - ac_needed=-1 ac_is=-1 ac_becomes=-1 + ac_required() { ac_check @@ -310,6 +182,7 @@ ac_required() ac_needed="$1" ac_becomes="$1" } + ac_transitions() { ac_check @@ -317,6 +190,7 @@ ac_transitions() ac_needed="$1" ac_becomes="$2" } + ac_online() { cat /proc/acpi/ac_adapter/*/state 2>/dev/null | \ @@ -335,6 +209,7 @@ ac_online() } ' } + ac_check() { typeset ac_current=`ac_online` @@ -350,13 +225,14 @@ ac_check() phase=0 phase_first=1 phase_interactive=1 + phase() { typeset sleep let phase="$phase+1" - if [ "$battery_count" -ne 0 -a "$ac_needed" -ne "$ac_is" ]; then + 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" ;; @@ -387,6 +263,3 @@ phase() fi } -# Ensure the log directory exists. -mkdir -p "$LOGDIR" - diff --git a/suspend/suspend_01.sh b/suspend/suspend_01.sh index 2b79c67..0149c70 100755 --- a/suspend/suspend_01.sh +++ b/suspend/suspend_01.sh @@ -27,23 +27,23 @@ source ../include/functions.sh -source ../include/suspend.sh +source ../include/suspend_functions.sh # test_dbus: switch on/off this test -test_dbus=1 -auto=1 +test_dbus=0 -if [ "$test_dbus" -eq 1 -a \ - \( "$SUDO_USER" = "" -o "$SUDO_USER" = "root" \) ]; then - ECHO "*** no primary user (via sudo) dbus tests skipped ..." -elif [ "$test_dbus" -eq 1 ]; then - ac_required 1 - suspend_dbus=1 +if [ "$test_dbus" -eq 0 ]; then + log_skip "dbus message suspend test not enabled" + exit 0 +fi + +if [ -x /usr/bin/dbus-send ]; then phase - check "suspend via dbus message" suspend_system + check "suspend by dbus message" suspend_system "dbus" if [ $? -eq 0 ]; then rm -f "$LOGFILE" fi - suspend_dbus=0 +else + log_skip "dbus-send command not exist" fi diff --git a/suspend/suspend_02.sh b/suspend/suspend_02.sh index 591e0cb..cb15801 100755 --- a/suspend/suspend_02.sh +++ b/suspend/suspend_02.sh @@ -27,18 +27,23 @@ source ../include/functions.sh -source ../include/suspend.sh +source ../include/suspend_functions.sh # test_pmsuspend: switch on/off this test test_pmsuspend=1 -auto=1 -if [ "$test_pmsuspend" -eq 1 ]; then - ac_required 1 +if [ "$test_pmsuspend" -eq 0 ]; then + log_skip "pm-suspend test not enabled" + exit 0 +fi + +if [ -x /usr/sbin/pm-suspend ]; then phase - check "suspend via pm-suspend" suspend_system + check "suspend via pm-suspend" suspend_system "pmsuspend" if [ $? -eq 0 ]; then rm -f "$LOGFILE" fi +else + log_skip "pm-suspend command not exist" fi diff --git a/suspend/suspend_03.sh b/suspend/suspend_03.sh index 0c40451..a782061 100755 --- a/suspend/suspend_03.sh +++ b/suspend/suspend_03.sh @@ -27,34 +27,24 @@ source ../include/functions.sh -source ../include/suspend.sh +source ../include/suspend_functions.sh -# test_ac: switch on/off this test -test_ac=0 -auto=1 +# test_mem: switch on/off this test +test_mem=0 -if [ "$test_ac" -eq 1 -a "$battery_count" -eq 0 ]; then - ECHO "*** no BATTERY detected ac tests skipped ..." -elif [ "$test_ac" -eq 1 ]; then - ac_required 0 - phase - check "suspend with AC disconnected" suspend_system - - ac_required 1 - phase - check "suspend with AC connected" suspend_system - - ac_transitions 1 0 - echo "*** please remove the AC cord while the machine is suspended" - phase - check "loss of AC while suspended" suspend_system +if [ "$test_mem" -eq 0 ]; then + log_skip "suspend to ram via sysfs not enabled" + exit 0 +fi - ac_transitions 0 1 - echo "*** please insert the AC cord while the machine is suspended" +supported=$(cat /sys/power/state | grep "mem") +if [ -n "$supported" ]; then phase - check "return of AC while suspended" suspend_system + check "suspend to ram via sysfs" suspend_system "mem" if [ $? -eq 0 ]; then rm -f "$LOGFILE" fi +else + log_skip "suspend to ram via sysfs not supported" fi diff --git a/suspend/suspend_03.txt b/suspend/suspend_03.txt index d9b682f..48daa6a 100644 --- a/suspend/suspend_03.txt +++ b/suspend/suspend_03.txt @@ -1 +1 @@ -perform tests involving removing ac power +perform a suspend to ram test via sysfs diff --git a/suspend/suspend_04.sh b/suspend/suspend_04.sh index 13c639a..ed8a580 100755 --- a/suspend/suspend_04.sh +++ b/suspend/suspend_04.sh @@ -27,57 +27,48 @@ source ../include/functions.sh -source ../include/suspend.sh +source ../include/suspend_functions.sh -# test_power: switch on/off this test -test_power=0 -auto=1 -args_power_sleep=60 +# test_ac: switch on/off this test +test_ac=0 -if [ "$test_power" -eq 1 -a "$battery_count" -eq 0 ]; then - ECHO "*** no BATTERY detected power test skipped ..." -elif [ "$test_power" -eq 1 ]; then - save_timer_sleep="$timer_sleep" - let timer_sleep="$args_power_sleep" +if [ "$test_ac" -eq 0 ]; then + log_skip "suspend test involving ac power remove" + exit 0 +fi + +if [ ! -d /proc/acpi/battery/ ]; then + log_skip "acpi interface is not there" + exit 0 +fi +battery_count=`battery_count` +if [ "$battery_count" -eq 0 ]; then + log_skip "no BATTERY detected for ac tests" +else ac_required 0 phase + sleep 2 + check "suspend with AC disconnected" suspend_system "mem" - # get start values - date_before=`date +%s` - bat_before=`battery_capacity` - - # Suspend - check "battery drain during suspend" suspend_system - if [ $? -eq 0 ]; then - rm -f "$LOGFILE" - fi - - # get end values - date_after=`date +%s` - bat_after=`battery_capacity` - - # do the calculations - let consumed="$bat_before - $bat_after" - let elapsed="$date_after - $date_before" - let usage="($consumed * 60*60) / $elapsed" + ac_required 1 + phase + sleep 2 + check "suspend with AC connected" suspend_system "mem" - # output the results - ECHO "before: $bat_before mWh" - ECHO "after: $bat_after mWh" - ECHO "consumed: $consumed mW" - ECHO "sleep seconds: $elapsed sec" - ECHO "overall usage: $usage mW" - - report_battery="$usage mW" + ac_transitions 1 0 + echo "*** please remove the AC cord while the machine is suspended" + phase + sleep 2 + check "loss of AC while suspended" suspend_system "mem" - if [ $elapsed -lt 600 ] - then - ECHO "WARNING: the suspend was less than 10 minutes" - ECHO " to get reliable numbers increase the sleep time" - report_battery="$report_battery (unreliable)" + ac_transitions 0 1 + echo "*** please insert the AC cord while the machine is suspended" + phase + sleep 2 + check "return of AC while suspended" suspend_system "mem" + if [ $? -eq 0 ]; then + rm -f "$LOGFILE" fi - - timer_sleep="$save_timer_sleep" fi diff --git a/suspend/suspend_04.txt b/suspend/suspend_04.txt index 1ade451..d9b682f 100644 --- a/suspend/suspend_04.txt +++ b/suspend/suspend_04.txt @@ -1 +1 @@ -perform a battery consumption test +perform tests involving removing ac power diff --git a/suspend/suspend_05.sh b/suspend/suspend_05.sh index 661adf4..767eec1 100755 --- a/suspend/suspend_05.sh +++ b/suspend/suspend_05.sh @@ -27,28 +27,67 @@ source ../include/functions.sh -source ../include/suspend.sh +source ../include/suspend_functions.sh -# test_timed: switch on/off this test -test_timed=1 -auto=1 +# test_power: switch on/off this test +test_power=0 +args_power_sleep=60 -if [ "$test_timed" -eq 1 ]; then - save_timer_delay="$timer_delay" - timer_delay=20 - sus_number=0 +if [ "$test_power" -eq 0 ]; then + log_skip "battery consumption test while suspend" + exit 0 +fi + +if [ ! -d /proc/acpi/battery/ ]; then + log_skip "acpi interface is not there" + exit 0 +fi + +battery_count=`battery_count` +if [ "$battery_count" -eq 0 ]; then + log_skip "no BATTERY detected for power test" +else + save_timer_sleep="$timer_sleep" + let timer_sleep="$args_power_sleep" - ac_required 1 + ac_required 0 phase - while [ "$timer_delay" -gt 0 ]; do - check "iteration variable delay suspend/resume" suspend_system - delay_system - let timer_delay="$timer_delay - 5" - let sus_number="sus_number + 1" - done - if [ $? -eq 0 ]; then + + # get start values + date_before=`date +%s` + bat_before=`battery_capacity` + + # Suspend + check "battery drain during suspend" suspend_system "mem" + if [ $? -eq 0 ]; then rm -f "$LOGFILE" fi - timer_delay="$save_timer_delay" + + # get end values + date_after=`date +%s` + bat_after=`battery_capacity` + + # do the calculations + let consumed="$bat_before - $bat_after" + let elapsed="$date_after - $date_before" + let usage="($consumed * 60*60) / $elapsed" + + # output the results + ECHO "before: $bat_before mWh" + ECHO "after: $bat_after mWh" + ECHO "consumed: $consumed mW" + ECHO "sleep seconds: $elapsed sec" + ECHO "overall usage: $usage mW" + + report_battery="$usage mW" + + if [ $elapsed -lt 600 ] + then + ECHO "WARNING: the suspend was less than 10 minutes" + ECHO " to get reliable numbers increase the sleep time" + report_battery="$report_battery (unreliable)" + fi + + timer_sleep="$save_timer_sleep" fi diff --git a/suspend/suspend_05.txt b/suspend/suspend_05.txt index 4735d94..1ade451 100644 --- a/suspend/suspend_05.txt +++ b/suspend/suspend_05.txt @@ -1 +1 @@ -perform a variable delay suspend/resume test +perform a battery consumption test diff --git a/suspend/suspend_06.sh b/suspend/suspend_06.sh deleted file mode 100755 index 59cc7ec..0000000 --- a/suspend/suspend_06.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# -# PM-QA validation test suite for the power management on Linux -# -# Copyright (C) 2012, 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: -# Hongbo ZHANG <hongbo.zhang@linaro.org> (ST-Ericsson Corporation) -# - initial API and implementation -# - -# URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#suspend_06 - - -source ../include/functions.sh -source ../include/suspend.sh - -# test_repeat: switch on/off this test -test_repeat=1 -auto=1 -args_repeat_iterations=5 - -if [ "$test_repeat" -eq 1 ]; then - ac_required 1 - - CNT=1 - TOTAL=$args_repeat_iterations - - phase - while [ "$CNT" -le "$TOTAL" ] - do - ECHO "Suspend iteration $CNT of $TOTAL" - check "iteration suspend/resume stress test" suspend_system - delay_system - - (( CNT++ )) - done - if [ $? -eq 0 ]; then - rm -f "$LOGFILE" - fi -fi - diff --git a/suspend/suspend_06.txt b/suspend/suspend_06.txt deleted file mode 100644 index 6511c23..0000000 --- a/suspend/suspend_06.txt +++ /dev/null @@ -1 +0,0 @@ -perform a longer repeat suspend/resume test |