summaryrefslogtreecommitdiff
path: root/test/thermal.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2013-08-07 15:34:04 -0700
committerChromeBot <chrome-bot@google.com>2013-08-23 10:38:36 -0700
commitfcce7223a5493e512e77d9f7b758d874ac502df5 (patch)
tree3cfc90b9f4d16b1937f9927b48a80abc2035c48c /test/thermal.c
parent0e024b2bae085f12ec4df33000799339aef38809 (diff)
downloadchrome-ec-fcce7223a5493e512e77d9f7b758d874ac502df5.tar.gz
Completely new thermal/fan implementation
Problems with existing thermal control loop: * Not multi-board friendly. thermal.c only supports Link and needs refactoring. Temp thresholds and fan speeds are hard-coded. * Only the PECI temp is used to determine the fan speed. Other temp sensors are ignored. * Has confusing data structures. Values in the CPU temp thresholds array mix ACPI thresholds with fan step values. With this change, the thermal task monitors all temp sensors in order to perform two completely independent functions: Function one: Determine if the host needs to be throttled by or informed of any thermal events. For thermal events, each temp sensor will have three threshold levels. TEMP_HOST_WARN * When any sensor goes above this level, host_throttle_cpu(1) will be called to ask the CPU to slow itself down. * When all sensors drop below this level, host_throttle_cpu(0) will be called. * Exactly AT this level, nothing happens (this provides hysteresis). TEMP_HOST_HIGH * When any sensor goes above this level, chipset_throttle_cpu(1) will be called to slow the CPU down whether it wants to or not. * When all sensors drop below this level, chipset_throttle_cpu(0) will be called. * Exactly AT this level, nothing happens (this provides hysteresis). TEMP_HOST_SHUTDOWN * When any sensor is above this level, chipset_force_shutdown() will be called to halt the CPU. * Nothing turns the CPU back on again - the user just has to wait for things to cool off. Pressing the power button too soon will just trigger shutdown again as soon as the EC can read the host temp. Function two: Determine the amount of fan cooling needed For fan cooling, each temp sensor will have two levels. TEMP_FAN_OFF * At or below this temperature, no active cooling is needed. TEMP_FAN_MAX * At or above this temperature, active cooling should be running at maximum. The highest level of all temp sensors will be used to request the amount of active cooling needed. The function pwm_fan_percent_to_rpm() is invoked to convert the amount of cooling to the target fan RPM. The default pwm_fan_percent_to_rpm() function converts smoothly between the configured CONFIG_PWM_FAN_RPM_MIN and CONFIG_PWM_FAN_RPM_MAX for percentages between 1 and 100. 0% means "off". The default function probably provide the smoothest and quietest behavior, but individual boards can provide their own pwm_fan_percent_to_rpm() to implement whatever curves, hysteresis, feedback, or other hackery they wish. BUG=chrome-os-partner:20805 BRANCH=none TEST=manual Compile-time test with make BOARD=falco runtests On the EC console, the existing fan commands should work correctly: faninfo - display the fan state fanduty NUM - force the fan PWM to the specified percentage (0-100) fanset RPM - force the fan to the specified RPM fanset NUM% - force the fan to the specified percentage (0-100) between its configured minimum and maximum speeds from board.h (CONFIG_PWM_FAN_RPM_MIN and CONFIG_PWM_FAN_RPM_MAX) fanauto - let the EC control the fan automatically You can test the default pwm_fan_percent_to_rpm() with fanset 1% faninfo The fan should be turning at CONFIG_PWM_FAN_RPM_MIN. Let the EC control it automatically again with fanauto Also on the EC console, the thermal settings can be examined or changed: > temps PECI : 327 K = 54 C ECInternal : 320 K = 47 C G781Internal : 319 K = 46 C G781External : 318 K = 45 C > > thermalget sensor warn high shutdown fan_off fan_max name 0 373 387 383 333 363 PECI 1 0 0 0 0 0 ECInternal 2 0 0 0 0 0 G781Internal 3 0 0 0 0 0 G781External > > help thermalset Usage: thermalset sensor warn [high [shutdown [fan_off [fan_max]]]] set thermal parameters (-1 to skip) > > thermalset 2 -1 -1 999 sensor warn high shutdown fan_off fan_max name 0 373 387 383 333 363 PECI 1 0 0 0 0 0 ECInternal 2 0 0 999 0 0 G781Internal 3 0 0 0 0 0 G781External > From the host, ectool can be used to get and set these parameters with nearly identical commands: ectool thermalget ectool thermalset 2 -1 -1 999 Change-Id: Idb27977278f766826045fb7d41929953ec6b1cca Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/66688 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'test/thermal.c')
-rw-r--r--test/thermal.c656
1 files changed, 363 insertions, 293 deletions
diff --git a/test/thermal.c b/test/thermal.c
index 485e19bfb5..7b2e3f9976 100644
--- a/test/thermal.c
+++ b/test/thermal.c
@@ -7,6 +7,7 @@
#include "common.h"
#include "console.h"
+#include "fan.h"
#include "hooks.h"
#include "host_command.h"
#include "printf.h"
@@ -16,41 +17,39 @@
#include "timer.h"
#include "util.h"
-static int mock_temp[TEMP_SENSOR_COUNT];
-static int fan_rpm;
-static int fan_rpm_mode = 1;
-static int cpu_throttled;
-static int cpu_down;
-extern struct thermal_config_t thermal_config[TEMP_SENSOR_TYPE_COUNT];
-extern const int fan_speed[THERMAL_FAN_STEPS + 1];
+/*****************************************************************************/
+/* Exported data */
+
+struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT];
+
+/* The tests below make some assumptions. */
+BUILD_ASSERT(TEMP_SENSOR_COUNT == 4);
+BUILD_ASSERT(EC_TEMP_THRESH_COUNT == 3);
/*****************************************************************************/
/* Mock functions */
+static int mock_temp[TEMP_SENSOR_COUNT];
+static int host_throttled;
+static int cpu_throttled;
+static int cpu_shutdown;
+static int fan_pct;
+static int no_temps_read;
+
int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr)
{
if (mock_temp[id] >= 0) {
*temp_ptr = mock_temp[id];
return EC_SUCCESS;
- } else {
- return -mock_temp[id];
}
-}
-void pwm_set_fan_rpm_mode(int rpm_mode)
-{
- fan_rpm_mode = rpm_mode;
-}
-
-void pwm_set_fan_target_rpm(int rpm)
-{
- fan_rpm = rpm;
+ return EC_ERROR_NOT_POWERED;
}
void chipset_force_shutdown(void)
{
- cpu_down = 1;
+ cpu_shutdown = 1;
}
void chipset_throttle_cpu(int throttled)
@@ -58,369 +57,440 @@ void chipset_throttle_cpu(int throttled)
cpu_throttled = throttled;
}
-/*****************************************************************************/
-/* Test utilities */
-
-/* Test shorthands */
-#define T_CPU TEMP_SENSOR_CPU
-#define T_BOARD TEMP_SENSOR_BOARD
-#define T_CASE TEMP_SENSOR_CASE
-#define THRESHOLD(x, y) (thermal_config[x].thresholds[y])
-#define FAN_THRESHOLD(x, y) THRESHOLD(x, THRESHOLD_COUNT + (y))
-
-static void reset_mock_temp(void)
+void host_throttle_cpu(int throttled)
{
- int i;
- enum temp_sensor_type type;
- for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
- type = temp_sensors[i].type;
- mock_temp[i] = FAN_THRESHOLD(type, 0) - 1;
- }
+ host_throttled = throttled;
}
-static int wait_fan_rpm(int rpm, int timeout_secs)
+void pwm_fan_set_percent_needed(int pct)
{
- do {
- if (fan_rpm == rpm)
- return 1;
- usleep(SECOND);
- } while (timeout_secs--);
-
- return 0;
+ fan_pct = pct;
}
-static int wait_value(int *v, int target, int timeout_secs)
+void smi_sensor_failure_warning(void)
{
- do {
- if (*v == target)
- return 1;
- usleep(SECOND);
- } while (timeout_secs--);
+ no_temps_read = 1;
+}
- return 0;
+/*****************************************************************************/
+/* Test utilities */
+
+static void set_temps(int t0, int t1, int t2, int t3)
+{
+ mock_temp[0] = t0;
+ mock_temp[1] = t1;
+ mock_temp[2] = t2;
+ mock_temp[3] = t3;
}
-static int wait_set(int *v, int timeout_secs)
+static void all_temps(int t)
{
- return wait_value(v, 1, timeout_secs);
+ set_temps(t, t, t, t);
}
-static int wait_clear(int *v, int timeout_secs)
+static void reset_mocks(void)
{
- return wait_value(v, 0, timeout_secs);
+ /* Ignore all sensors */
+ memset(thermal_params, 0, sizeof(thermal_params));
+
+ /* All sensors report error anyway */
+ set_temps(-1, -1 , -1, -1);
+
+ /* Reset expectations */
+ host_throttled = 0;
+ cpu_throttled = 0;
+ cpu_shutdown = 0;
+ fan_pct = 0;
+ no_temps_read = 0;
}
+
/*****************************************************************************/
/* Tests */
static int test_init_val(void)
{
- /* Initial mock temperature values are all zero. */
+ reset_mocks();
+ sleep(2);
+
+ TEST_ASSERT(host_throttled == 0);
TEST_ASSERT(cpu_throttled == 0);
- TEST_ASSERT(cpu_down == 0);
- TEST_ASSERT(!(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_OVERLOAD)));
- TEST_ASSERT(!(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN)));
+ TEST_ASSERT(cpu_shutdown == 0);
+ TEST_ASSERT(fan_pct == 0);
+ TEST_ASSERT(no_temps_read);
- return EC_SUCCESS;
-}
+ sleep(2);
-static int test_cpu_fan(void)
-{
- reset_mock_temp();
-
- /*
- * Increase CPU temperature to first fan step and check if
- * the fan comes up.
- */
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 0);
- TEST_ASSERT(wait_fan_rpm(fan_speed[1], 11));
-
- /* Increase CPU temperature to second fan step */
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 1);
- TEST_ASSERT(wait_fan_rpm(fan_speed[2], 11));
-
- /* Test threshold hysteresis */
- mock_temp[T_CPU]--;
- usleep(15 * SECOND);
- TEST_ASSERT(fan_rpm == fan_speed[2]);
-
- /* Test action delay */
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 4);
- usleep((temp_sensors[T_CPU].action_delay_sec - 1) * SECOND);
- TEST_ASSERT(fan_rpm == fan_speed[2]);
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 0);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+ TEST_ASSERT(fan_pct == 0);
+ TEST_ASSERT(no_temps_read);
return EC_SUCCESS;
}
-static int test_safety(void)
+static int test_sensors_can_be_read(void)
{
- reset_mock_temp();
+ reset_mocks();
+ mock_temp[2] = 100;
- /* Trigger CPU throttling */
- mock_temp[T_CPU] = THRESHOLD(T_CPU, THRESHOLD_WARNING);
- TEST_ASSERT(wait_set(&cpu_throttled, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_OVERLOAD));
+ sleep(2);
- /* Lower temperature. CPU not throttled anymore. */
- mock_temp[T_CPU] = THRESHOLD(T_CPU, THRESHOLD_WARNING) - 5;
- TEST_ASSERT(wait_clear(&cpu_throttled, 2));
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+ TEST_ASSERT(fan_pct == 0);
+ TEST_ASSERT(no_temps_read == 0);
- /* Thermal shutdown */
- mock_temp[T_CPU] = THRESHOLD(T_CPU, THRESHOLD_CPU_DOWN);
- TEST_ASSERT(wait_set(&cpu_down, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN));
+ return EC_SUCCESS;
+}
- mock_temp[T_CPU] = 0;
- usleep(SECOND);
- cpu_down = 0;
- mock_temp[T_CPU] = THRESHOLD(T_CPU, THRESHOLD_POWER_DOWN);
- TEST_ASSERT(wait_set(&cpu_down, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN));
+static int test_one_fan(void)
+{
+ reset_mocks();
+ thermal_params[2].temp_fan_off = 100;
+ thermal_params[2].temp_fan_max = 200;
- mock_temp[T_CPU] = 0;
- cpu_down = 0;
+ all_temps(50);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
- return EC_SUCCESS;
-}
+ all_temps(100);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
-static int test_sensor_failure(void)
-{
- reset_mock_temp();
+ all_temps(101);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 1);
- /* Failure due to sensor not powered should be ignored */
- mock_temp[T_CPU] = -EC_ERROR_NOT_POWERED;
- usleep(5 * SECOND);
- TEST_ASSERT(!(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL)));
+ all_temps(130);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 30);
- /* Other failure should be pumped up to host */
- mock_temp[T_CPU] = -EC_ERROR_UNKNOWN;
- usleep(5 * SECOND);
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL));
+ all_temps(150);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
- return EC_SUCCESS;
-}
+ all_temps(170);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 70);
-static int test_sensor_info(void)
-{
- struct ec_params_temp_sensor_get_info params;
- struct ec_response_temp_sensor_get_info resp;
- int i;
-
- for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
- params.id = i;
- TEST_ASSERT(test_send_host_command(
- EC_CMD_TEMP_SENSOR_GET_INFO,
- 0, &params, sizeof(params),
- &resp, sizeof(resp)) == EC_RES_SUCCESS);
- TEST_ASSERT_ARRAY_EQ(resp.sensor_name,
- temp_sensors[i].name,
- strlen(resp.sensor_name));
- TEST_ASSERT(resp.sensor_type == temp_sensors[i].type);
- }
+ all_temps(200);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
- params.id = TEMP_SENSOR_COUNT;
- TEST_ASSERT(test_send_host_command(
- EC_CMD_TEMP_SENSOR_GET_INFO,
- 0, &params, sizeof(params),
- &resp, sizeof(resp)) != EC_RES_SUCCESS);
+ all_temps(300);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
return EC_SUCCESS;
}
-static int set_threshold(int type, int threshold_id, int val)
+static int test_two_fans(void)
{
- struct ec_params_thermal_set_threshold params;
+ reset_mocks();
- params.sensor_type = type;
- params.threshold_id = threshold_id;
- params.value = val;
+ thermal_params[1].temp_fan_off = 120;
+ thermal_params[1].temp_fan_max = 160;
+ thermal_params[2].temp_fan_off = 100;
+ thermal_params[2].temp_fan_max = 200;
- return test_send_host_command(EC_CMD_THERMAL_SET_THRESHOLD, 0, &params,
- sizeof(params), NULL, 0);
-}
+ all_temps(50);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
-static int get_threshold(int type, int threshold_id, int *val)
-{
- struct ec_params_thermal_get_threshold params;
- struct ec_response_thermal_get_threshold resp;
- int rv;
+ all_temps(100);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
- params.sensor_type = type;
- params.threshold_id = threshold_id;
+ all_temps(101);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 1);
- rv = test_send_host_command(EC_CMD_THERMAL_GET_THRESHOLD, 0, &params,
- sizeof(params), &resp, sizeof(resp));
- if (rv != EC_RES_SUCCESS)
- return rv;
+ all_temps(130);
+ sleep(2);
+ /* fan 2 is still higher */
+ TEST_ASSERT(fan_pct == 30);
- *val = resp.value;
- return EC_RES_SUCCESS;
-}
+ all_temps(150);
+ sleep(2);
+ /* now fan 1 is higher: 150 = 75% of [120-160] */
+ TEST_ASSERT(fan_pct == 75);
-static int verify_threshold(int type, int threshold_id, int val)
-{
- int actual_val;
+ all_temps(170);
+ sleep(2);
+ /* fan 1 is maxed now */
+ TEST_ASSERT(fan_pct == 100);
- if (get_threshold(type, threshold_id, &actual_val) != EC_RES_SUCCESS)
- return 0;
- return val == actual_val;
-}
+ all_temps(200);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
-static int test_threshold_hostcmd(void)
-{
- reset_mock_temp();
-
- /* Verify thresholds */
- TEST_ASSERT(verify_threshold(T_CPU, THRESHOLD_WARNING,
- THRESHOLD(T_CPU, THRESHOLD_WARNING)));
- TEST_ASSERT(verify_threshold(T_BOARD, THRESHOLD_WARNING,
- THRESHOLD(T_BOARD, THRESHOLD_WARNING)));
- TEST_ASSERT(verify_threshold(T_CPU, THRESHOLD_CPU_DOWN,
- THRESHOLD(T_CPU, THRESHOLD_CPU_DOWN)));
-
- /* Lower CPU throttling threshold and trigger */
- TEST_ASSERT(set_threshold(T_CPU, THRESHOLD_WARNING, 350) ==
- EC_RES_SUCCESS);
- mock_temp[T_CPU] = 355;
- TEST_ASSERT(wait_set(&cpu_throttled, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_OVERLOAD));
-
- /* Lower thermal shutdown threshold */
- TEST_ASSERT(set_threshold(T_CPU, THRESHOLD_CPU_DOWN, 353) ==
- EC_RES_SUCCESS);
- TEST_ASSERT(wait_set(&cpu_down, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN));
-
- /* Clear */
- mock_temp[T_CPU] = 0;
- TEST_ASSERT(wait_clear(&cpu_throttled, 2));
- cpu_down = 0;
+ all_temps(300);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
return EC_SUCCESS;
}
-static int test_threshold_console_cmd(void)
+static int test_all_fans(void)
{
- char buf[100];
-
- reset_mock_temp();
-
- /* Lower CPU threshold and trigger */
- snprintf(buf, 100, "thermalconf %d %d 330\n", T_CPU, THRESHOLD_WARNING);
- UART_INJECT(buf);
- msleep(100);
- mock_temp[T_CPU] = 335;
- TEST_ASSERT(wait_set(&cpu_throttled, 11));
- TEST_ASSERT(host_get_events() &
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_OVERLOAD));
-
- /* Set first fan step to 280 K */
- snprintf(buf, 100, "thermalfan %d 0 280\n", T_CPU);
- UART_INJECT(buf);
- msleep(100);
- mock_temp[T_CPU] = 280;
- TEST_ASSERT(wait_fan_rpm(fan_speed[1], 11));
+ reset_mocks();
+
+ thermal_params[0].temp_fan_off = 20;
+ thermal_params[0].temp_fan_max = 60;
+ thermal_params[1].temp_fan_off = 120;
+ thermal_params[1].temp_fan_max = 160;
+ thermal_params[2].temp_fan_off = 100;
+ thermal_params[2].temp_fan_max = 200;
+ thermal_params[3].temp_fan_off = 300;
+ thermal_params[3].temp_fan_max = 500;
+
+ set_temps(1, 1, 1, 1);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
+
+ /* Each sensor has its own range */
+ set_temps(40, 0, 0, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
+
+ set_temps(0, 140, 0, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
+
+ set_temps(0, 0, 150, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
+
+ set_temps(0, 0, 0, 400);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
+
+ set_temps(60, 0, 0, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
+
+ set_temps(0, 160, 0, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
+
+ set_temps(0, 0, 200, 0);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
+
+ set_temps(0, 0, 0, 500);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
+
+ /* But sensor 0 needs the most cooling */
+ all_temps(20);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 0);
+
+ all_temps(21);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 2);
+
+ all_temps(30);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 25);
+
+ all_temps(40);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 50);
+
+ all_temps(50);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 75);
+
+ all_temps(60);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
+
+ all_temps(65);
+ sleep(2);
+ TEST_ASSERT(fan_pct == 100);
return EC_SUCCESS;
}
-static int test_invalid_hostcmd(void)
+static int test_one_limit(void)
{
- int dummy;
-
- TEST_ASSERT(set_threshold(TEMP_SENSOR_TYPE_COUNT, THRESHOLD_WARNING,
- 100) != EC_RES_SUCCESS);
- TEST_ASSERT(set_threshold(T_CPU, THRESHOLD_COUNT + THERMAL_FAN_STEPS,
- 100) != EC_RES_SUCCESS);
- TEST_ASSERT(get_threshold(TEMP_SENSOR_TYPE_COUNT, THRESHOLD_WARNING,
- &dummy) != EC_RES_SUCCESS);
- TEST_ASSERT(get_threshold(T_CPU, THRESHOLD_COUNT + THERMAL_FAN_STEPS,
- &dummy) != EC_RES_SUCCESS);
+ reset_mocks();
+ thermal_params[2].temp_host[EC_TEMP_THRESH_WARN] = 100;
+ thermal_params[2].temp_host[EC_TEMP_THRESH_HIGH] = 200;
+ thermal_params[2].temp_host[EC_TEMP_THRESH_HALT] = 300;
+
+ all_temps(50);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- return EC_SUCCESS;
-}
+ all_temps(100);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
-static int test_auto_fan_ctrl(void)
-{
- reset_mock_temp();
+ all_temps(101);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /* Disable fan control */
- pwm_set_fan_rpm_mode(0);
- thermal_control_fan(0);
+ all_temps(100);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /*
- * Increase CPU temperature to first fan step and check the fan
- * doesn't come up.
- */
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 0);
- TEST_ASSERT(!wait_fan_rpm(fan_speed[1], 11));
+ all_temps(99);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /* Enable fan control */
- TEST_ASSERT(test_send_host_command(EC_CMD_THERMAL_AUTO_FAN_CTRL, 0,
- NULL, 0, NULL, 0) == EC_RES_SUCCESS);
- TEST_ASSERT(fan_rpm_mode == 1);
- TEST_ASSERT(wait_fan_rpm(fan_speed[1], 11));
+ all_temps(199);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /* Disable fan control */
- pwm_set_fan_rpm_mode(0);
- thermal_control_fan(0);
+ all_temps(200);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ all_temps(201);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ all_temps(200);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ all_temps(199);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /* Increase CPU temperature to second fan step */
- mock_temp[T_CPU] = FAN_THRESHOLD(T_CPU, 1);
- TEST_ASSERT(!wait_fan_rpm(fan_speed[2], 11));
+ all_temps(99);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
- /* Enable fan control by console command */
- UART_INJECT("autofan\n");
- msleep(100);
- TEST_ASSERT(fan_rpm_mode == 1);
- TEST_ASSERT(wait_fan_rpm(fan_speed[2], 11));
+ all_temps(201);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 0);
+ all_temps(99);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ all_temps(301);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 1);
+
+ /* We probably won't be able to read the CPU temp while shutdown,
+ * so nothing will change. */
+ all_temps(-1);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ /* cpu_shutdown is only set for testing purposes. The thermal task
+ * doesn't do anything that could clear it. */
+
+ all_temps(50);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
return EC_SUCCESS;
}
-static int check_assumption(void)
+static int test_several_limits(void)
{
- TEST_ASSERT((int)TEMP_SENSOR_CPU == (int)TEMP_SENSOR_TYPE_CPU);
- TEST_ASSERT((int)TEMP_SENSOR_BOARD == (int)TEMP_SENSOR_TYPE_BOARD);
- TEST_ASSERT((int)TEMP_SENSOR_CASE == (int)TEMP_SENSOR_TYPE_CASE);
+ reset_mocks();
+
+ thermal_params[1].temp_host[EC_TEMP_THRESH_WARN] = 150;
+ thermal_params[1].temp_host[EC_TEMP_THRESH_HIGH] = 200;
+ thermal_params[1].temp_host[EC_TEMP_THRESH_HALT] = 250;
+
+ thermal_params[2].temp_host[EC_TEMP_THRESH_WARN] = 100;
+ thermal_params[2].temp_host[EC_TEMP_THRESH_HIGH] = 200;
+ thermal_params[2].temp_host[EC_TEMP_THRESH_HALT] = 300;
- TEST_ASSERT(temp_sensors[T_CPU].action_delay_sec != 0);
+ thermal_params[3].temp_host[EC_TEMP_THRESH_WARN] = 20;
+ thermal_params[3].temp_host[EC_TEMP_THRESH_HIGH] = 30;
+ thermal_params[3].temp_host[EC_TEMP_THRESH_HALT] = 40;
+
+ set_temps(500, 100, 150, 10);
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1); /* 1=low, 2=warn, 3=low */
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ set_temps(500, 50, -1, 10); /* 1=low, 2=X, 3=low */
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ set_temps(500, 170, 210, 10); /* 1=warn, 2=high, 3=low */
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ set_temps(500, 100, 50, 40); /* 1=low, 2=low, 3=high */
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 0);
+
+ set_temps(500, 100, 50, 41); /* 1=low, 2=low, 3=shutdown */
+ sleep(2);
+ TEST_ASSERT(host_throttled == 1);
+ TEST_ASSERT(cpu_throttled == 1);
+ TEST_ASSERT(cpu_shutdown == 1);
+
+ all_temps(0); /* reset from shutdown */
+ sleep(2);
+ TEST_ASSERT(host_throttled == 0);
+ TEST_ASSERT(cpu_throttled == 0);
- TEST_ASSERT(thermal_config[T_CPU].config_flags &
- THERMAL_CONFIG_WARNING_ON_FAIL);
return EC_SUCCESS;
}
+
void run_test(void)
{
- test_reset();
-
- /* Test assumptions */
- RUN_TEST(check_assumption);
-
RUN_TEST(test_init_val);
- RUN_TEST(test_cpu_fan);
- /* No tests for board and case temp sensors as they are ignored. */
- RUN_TEST(test_safety);
- RUN_TEST(test_sensor_failure);
- RUN_TEST(test_auto_fan_ctrl);
- RUN_TEST(test_sensor_info);
- RUN_TEST(test_threshold_hostcmd);
- RUN_TEST(test_invalid_hostcmd);
- RUN_TEST(test_threshold_console_cmd);
+ RUN_TEST(test_sensors_can_be_read);
+ RUN_TEST(test_one_fan);
+ RUN_TEST(test_two_fans);
+ RUN_TEST(test_all_fans);
+
+ RUN_TEST(test_one_limit);
+ RUN_TEST(test_several_limits);
test_print_result();
}