diff options
author | Vic Yang <victoryang@chromium.org> | 2013-07-04 15:21:16 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-11 04:26:14 -0700 |
commit | 4d270c1507040e1ba45b597310167c172e915ef6 (patch) | |
tree | 7ed98de429cc2fdcfa78ecd51baa79da84752d73 /test | |
parent | 62f2a33ff2ff37ad8226fd854712206f3ccd745e (diff) | |
download | chrome-ec-4d270c1507040e1ba45b597310167c172e915ef6.tar.gz |
Add thermal host and console command test
This checks the functionality of thermal engine related host and
console commands.
BUG=chrome-os-partner:19236
TEST=Pass all tests.
BRANCH=None
Change-Id: I604ed3bfed3549b2573fac65da83450acd3f2797
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60964
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/thermal.c | 193 |
1 files changed, 192 insertions, 1 deletions
diff --git a/test/thermal.c b/test/thermal.c index 7af14038ed..e047a64486 100644 --- a/test/thermal.c +++ b/test/thermal.c @@ -10,6 +10,7 @@ #include "console.h" #include "hooks.h" #include "host_command.h" +#include "printf.h" #include "temp_sensor.h" #include "test_util.h" #include "thermal.h" @@ -18,6 +19,7 @@ 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; @@ -39,7 +41,7 @@ int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr) void pwm_set_fan_rpm_mode(int rpm_mode) { - /* Do nothing */ + fan_rpm_mode = rpm_mode; } void pwm_set_fan_target_rpm(int rpm) @@ -183,6 +185,9 @@ static int test_safety(void) TEST_ASSERT(host_get_events() & EC_HOST_EVENT_MASK(EC_HOST_EVENT_THERMAL_SHUTDOWN)); + mock_temp[T_CPU] = 0; + cpu_down = 0; + return EC_SUCCESS; } @@ -205,6 +210,187 @@ static int test_sensor_failure(void) return EC_SUCCESS; } +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, ¶ms, 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); + } + + params.id = TEMP_SENSOR_COUNT; + TEST_ASSERT(test_send_host_command( + EC_CMD_TEMP_SENSOR_GET_INFO, + 0, ¶ms, sizeof(params), + &resp, sizeof(resp)) != EC_RES_SUCCESS); + + return EC_SUCCESS; +} + +static int set_threshold(int type, int threshold_id, int val) +{ + struct ec_params_thermal_set_threshold params; + + params.sensor_type = type; + params.threshold_id = threshold_id; + params.value = val; + + return test_send_host_command(EC_CMD_THERMAL_SET_THRESHOLD, 0, ¶ms, + sizeof(params), NULL, 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; + + params.sensor_type = type; + params.threshold_id = threshold_id; + + rv = test_send_host_command(EC_CMD_THERMAL_GET_THRESHOLD, 0, ¶ms, + sizeof(params), &resp, sizeof(resp)); + if (rv != EC_RES_SUCCESS) + return rv; + + *val = resp.value; + return EC_RES_SUCCESS; +} + +static int verify_threshold(int type, int threshold_id, int val) +{ + int actual_val; + + if (get_threshold(type, threshold_id, &actual_val) != EC_RES_SUCCESS) + return 0; + return val == actual_val; +} + +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; + + return EC_SUCCESS; +} + +static int test_threshold_console_cmd(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)); + + return EC_SUCCESS; +} + +static int test_invalid_hostcmd(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); + + return EC_SUCCESS; +} + +static int test_auto_fan_ctrl(void) +{ + reset_mock_temp(); + + /* Disable fan control */ + pwm_set_fan_rpm_mode(0); + thermal_control_fan(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)); + + /* 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)); + + /* Disable fan control */ + pwm_set_fan_rpm_mode(0); + thermal_control_fan(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)); + + /* 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)); + + + return EC_SUCCESS; +} + static int check_assumption(void) { TEST_ASSERT((int)TEMP_SENSOR_CPU == (int)TEMP_SENSOR_TYPE_CPU); @@ -231,6 +417,11 @@ void run_test(void) /* 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); test_print_result(); } |