diff options
| author | Patrick Venture <venture@google.com> | 2018-07-25 08:48:49 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-07-25 08:53:17 -0700 |
| commit | ca97c83d151ba5d5cca0518420662abc298cce50 (patch) | |
| tree | df6b11e12d6725f304a0b504232676f6a8db79e4 /tools | |
| parent | 7136a5ae2094e3bb8d61b7789768521fb789d80d (diff) | |
| download | phosphor-pid-control-ca97c83d151ba5d5cca0518420662abc298cce50.tar.gz phosphor-pid-control-ca97c83d151ba5d5cca0518420662abc298cce50.zip | |
add fan_rpm_loop script
The script allows running different rpm set-points and verifying whether
the coefficients behave as intended.
Change-Id: I7bc2e5328299ee14349550edb119279c143f4a1b
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/fan_rpm_loop_test.sh | 88 | ||||
| -rwxr-xr-x | tools/fan_rpm_loop_unittest.sh | 48 |
2 files changed, 136 insertions, 0 deletions
diff --git a/tools/fan_rpm_loop_test.sh b/tools/fan_rpm_loop_test.sh new file mode 100755 index 0000000..cbebe24 --- /dev/null +++ b/tools/fan_rpm_loop_test.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# shim system-level operations to allow for unit testing +MkDir() { mkdir "$@"; } +Mv() { mv "$@"; } +Sleep() { sleep "$@"; } +SystemCtl() { systemctl "$@"; } + +# Store commanded rpm as thermal set-point. +# +# Arg: +# rpm - rpm set-point. +CommandRpm() { + printf '%d\n' "$1" > /etc/thermal.d/set-point +} + +# Sweep or step rpm over range. +# +# Args: +# start_rpm: start RPM value +# stop_rpm: stop RPM value +# num_steps: number of control steps; i.e., not including start. +# dwell: dwell time at each point, in seconds +RunRpmSteps() { + local -i start_rpm=$1 + local -i stop_rpm=$2 + local -i num_steps=$3 + local -i dwell=$4 + + # Rounding offset when dividing range into num_steps + local -i h=$((num_steps / 2)) + + # To avoid asymmetrical division behavior for negative numbers, + # rearrange negative slope to positive slope running backward; + # I.e., to run using loop variable p: {num_steps downto 0}. + local -i rpm0=$((start_rpm)) + local -i range=$((stop_rpm - start_rpm)) + local -i s=1 + if ((range < 0)); then + ((rpm0 = stop_rpm)) + ((range = -range)) + ((s = -1)) + fi + + echo "Running RPM from ${start_rpm} to ${stop_rpm} in ${num_steps} steps" + CommandRpm "${start_rpm}" + SystemCtl start swampd.service + Sleep 60 + + local i + for ((i = 0; i <= num_steps; ++i)); do + local -i p=$((s < 0 ? num_steps - i : i)) + local -i rpm=$((rpm0 + (range * p + h) / num_steps)) + echo "Setting RPM to ${rpm} and sleep ${dwell} seconds" + CommandRpm "${rpm}" + Sleep "${dwell}" + done + + SystemCtl stop swampd.service + Mv /tmp/swampd.log ~/"${start_rpm}_${stop_rpm}_${num_steps}_${dwell}.csv" + echo "Done!!" +} + +# Sweep and step fans from min to max and max to min. +# +# Args: +# min_rpm: min RPM for the platform +# max_rpm: max RPM for the platform +main() { + local min_rpm=$1 + local max_rpm=$2 + + if ((min_rpm < 1 || max_rpm < min_rpm)); then + echo "Invalid arguments. Usage: fan_rpm_loop_test.sh <MIN_RPM> <MAX_RPM>" + return 1 + fi + + MkDir -p /etc/thermal.d/ + SystemCtl stop swampd.service + + RunRpmSteps "${min_rpm}" "${max_rpm}" 10 30 + RunRpmSteps "${max_rpm}" "${min_rpm}" 10 30 + RunRpmSteps "${min_rpm}" "${max_rpm}" 1 30 + RunRpmSteps "${max_rpm}" "${min_rpm}" 1 30 +} + +return 0 2>/dev/null +main "$@" diff --git a/tools/fan_rpm_loop_unittest.sh b/tools/fan_rpm_loop_unittest.sh new file mode 100755 index 0000000..2700de1 --- /dev/null +++ b/tools/fan_rpm_loop_unittest.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +SourceModule() { + . fan_rpm_loop_test.sh +} + +SetupShims() { + MkDir() { echo "MkDir $*"; } + Mv() { echo "Mv $*"; } + Sleep() { echo "Sleep $*"; } + SystemCtl() { echo "SystemCtl $*"; } + CommandRpm() { echo "CommandRpm $*"; } +} + +TestRunRpmStepsWorks() { + RunRpmSteps 1000 5000 3 30 || return + RunRpmSteps 5000 1000 3 30 || return + RunRpmSteps 1000 5000 1 30 || return + RunRpmSteps 5000 1000 1 30 || return +} + +TestMainRejectsLowMinAndMax() { + if main 0 0; then + echo "main 0 0 not rejected?" + return 1 + fi + if main 1 0; then + echo "main 1 0 not rejected?" + return 1 + fi +} + +TestMainWorks() { + main 1000 5005 || return +} + +main() { + SourceModule || return + SetupShims || return + TestRunRpmStepsWorks || return + TestMainRejectsLowMinAndMax || return + TestMainWorks || return + echo "All tests completed." +} + +return 0 2>/dev/null +main "$@" + |

