blob: 5c568787e49656ff79794d0f68b5ad1922abb2db [file] [log] [blame]
Patrick Ventureca97c832018-07-25 08:48:49 -07001#!/bin/bash
2
3# shim system-level operations to allow for unit testing
Patrick Williams5897fcc2022-12-08 06:23:37 -06004function MkDir() { mkdir "$@"; }
5function Mv() { mv "$@"; }
6function Sleep() { sleep "$@"; }
7function SystemCtl() { systemctl "$@"; }
Patrick Ventureca97c832018-07-25 08:48:49 -07008
9# Store commanded rpm as thermal set-point.
10#
11# Arg:
12# rpm - rpm set-point.
Patrick Williams5897fcc2022-12-08 06:23:37 -060013function CommandRpm() {
14 printf '%d\n' "$1" > /etc/thermal.d/set-point
Patrick Ventureca97c832018-07-25 08:48:49 -070015}
16
17# Sweep or step rpm over range.
18#
19# Args:
20# start_rpm: start RPM value
21# stop_rpm: stop RPM value
22# num_steps: number of control steps; i.e., not including start.
23# dwell: dwell time at each point, in seconds
Patrick Williams5897fcc2022-12-08 06:23:37 -060024function RunRpmSteps() {
25 local -i start_rpm=$1
26 local -i stop_rpm=$2
27 local -i num_steps=$3
28 local -i dwell=$4
Patrick Ventureca97c832018-07-25 08:48:49 -070029
Patrick Williams5897fcc2022-12-08 06:23:37 -060030 # Rounding offset when dividing range into num_steps
31 local -i h=$((num_steps / 2))
Patrick Ventureca97c832018-07-25 08:48:49 -070032
Patrick Williams5897fcc2022-12-08 06:23:37 -060033 # To avoid asymmetrical division behavior for negative numbers,
34 # rearrange negative slope to positive slope running backward;
35 # I.e., to run using loop variable p: {num_steps downto 0}.
36 local -i rpm0=$((start_rpm))
37 local -i range=$((stop_rpm - start_rpm))
38 local -i s=1
39 if ((range < 0)); then
40 ((rpm0 = stop_rpm))
41 ((range = -range))
42 ((s = -1))
43 fi
Patrick Ventureca97c832018-07-25 08:48:49 -070044
Patrick Williams5897fcc2022-12-08 06:23:37 -060045 echo "Running RPM from ${start_rpm} to ${stop_rpm} in ${num_steps} steps"
46 CommandRpm "${start_rpm}"
47 SystemCtl start phosphor-pid-control.service
48 Sleep 60
Patrick Ventureca97c832018-07-25 08:48:49 -070049
Patrick Williams5897fcc2022-12-08 06:23:37 -060050 local i
51 for ((i = 0; i <= num_steps; ++i)); do
52 local -i p=$((s < 0 ? num_steps - i : i))
53 local -i rpm=$((rpm0 + (range * p + h) / num_steps))
54 echo "Setting RPM to ${rpm} and sleep ${dwell} seconds"
55 CommandRpm "${rpm}"
56 Sleep "${dwell}"
57 done
Patrick Ventureca97c832018-07-25 08:48:49 -070058
Patrick Williams5897fcc2022-12-08 06:23:37 -060059 SystemCtl stop phosphor-pid-control.service
60 Mv /tmp/swampd.log ~/"${start_rpm}_${stop_rpm}_${num_steps}_${dwell}.csv"
61 echo "Done!!"
Patrick Ventureca97c832018-07-25 08:48:49 -070062}
63
64# Sweep and step fans from min to max and max to min.
65#
66# Args:
67# min_rpm: min RPM for the platform
68# max_rpm: max RPM for the platform
Patrick Williams5897fcc2022-12-08 06:23:37 -060069function main() {
70 local min_rpm=$1
71 local max_rpm=$2
Patrick Ventureca97c832018-07-25 08:48:49 -070072
Patrick Williams5897fcc2022-12-08 06:23:37 -060073 if ((min_rpm < 1 || max_rpm < min_rpm)); then
74 echo "Invalid arguments. Usage: fan_rpm_loop_test.sh <MIN_RPM> <MAX_RPM>"
75 return 1
76 fi
Patrick Ventureca97c832018-07-25 08:48:49 -070077
Patrick Williams5897fcc2022-12-08 06:23:37 -060078 MkDir -p /etc/thermal.d/
79 SystemCtl stop phosphor-pid-control.service
Patrick Ventureca97c832018-07-25 08:48:49 -070080
Patrick Williams5897fcc2022-12-08 06:23:37 -060081 RunRpmSteps "${min_rpm}" "${max_rpm}" 10 30
82 RunRpmSteps "${max_rpm}" "${min_rpm}" 10 30
83 RunRpmSteps "${min_rpm}" "${max_rpm}" 1 30
84 RunRpmSteps "${max_rpm}" "${min_rpm}" 1 30
Patrick Ventureca97c832018-07-25 08:48:49 -070085}
86
Jinliang Wang687d8412023-04-20 15:54:10 -070087if [ "$0" = "${BASH_SOURCE[0]}" ]; then
88 # not sourced, execute main function
89 main "$@"
90fi