diff options
author | Tom Hughes <tomhughes@chromium.org> | 2019-08-23 15:06:57 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-03 20:48:41 +0000 |
commit | af51b9ea19c0ba4c6d57cdc4c5f3380647be3034 (patch) | |
tree | 92e5b04103e0342380c510bd632cbc7db43579a5 /test | |
parent | dfbc632cd5b5a856086249253a98bc83d8942a29 (diff) | |
download | chrome-ec-af51b9ea19c0ba4c6d57cdc4c5f3380647be3034.tar.gz |
common: Add uptime host command
This moves the EC_CMD_GET_UPTIME_INFO command from behind the
CONFIG_CMD_AP_RESET_LOG config in chipset.c into the generic
common/uptime.c file, so that all boards in the codebase can use it. If
CONFIG_CMD_AP_RESET_LOG is enabled, the "AP reset stats" will be filled.
Otherwise, ap_reset_stats is a no-op and recent_ap_reset is filled with
zero.
BRANCH=none
BUG=chromium:997314
TEST=cat /sys/kernel/debug/cros_fp/uptime
Change-Id: I3b6f91b2dd22d3d55b707309ec1fdfd26d42fd70
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1769393
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/uptime.c | 73 | ||||
-rw-r--r-- | test/uptime.tasklist | 10 |
3 files changed, 85 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 5868513962..ea0fef7fc1 100644 --- a/test/build.mk +++ b/test/build.mk @@ -66,6 +66,7 @@ test-list-host += static_if_error test-list-host += system test-list-host += thermal test-list-host += timer_dos +test-list-host += uptime test-list-host += usb_pd test-list-host += usb_pd_giveback test-list-host += usb_pd_rev30 @@ -140,6 +141,7 @@ system-y=system.o thermal-y=thermal.o timer_calib-y=timer_calib.o timer_dos-y=timer_dos.o +uptime-y=uptime.o usb_pd-y=usb_pd.o usb_pd_giveback-y=usb_pd.o usb_pd_rev30-y=usb_pd.o diff --git a/test/uptime.c b/test/uptime.c new file mode 100644 index 0000000000..7ff39f98db --- /dev/null +++ b/test/uptime.c @@ -0,0 +1,73 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <stdbool.h> + +#include "common.h" +#include "ec_commands.h" +#include "host_command.h" +#include "test_util.h" +#include "timer.h" +#include "util.h" + +static bool get_ap_reset_stats_should_succeed = true; + +/* Mocks */ + +enum ec_error_list +get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries, + size_t num_reset_log_entries, uint32_t *resets_since_ec_boot) +{ + return get_ap_reset_stats_should_succeed ? EC_SUCCESS : EC_ERROR_INVAL; +} + +timestamp_t get_time(void) +{ + timestamp_t fake_time = { .val = 42 * MSEC }; + return fake_time; +} + +/* Tests */ + +test_static int test_host_uptime_info_command_success(void) +{ + int rv; + struct ec_response_uptime_info resp = { 0 }; + + get_ap_reset_stats_should_succeed = true; + + rv = test_send_host_command(EC_CMD_GET_UPTIME_INFO, 0, NULL, 0, &resp, + sizeof(resp)); + + TEST_ASSERT(rv == EC_RES_SUCCESS); + TEST_ASSERT(resp.time_since_ec_boot_ms == 42); + + return EC_RES_SUCCESS; +} + +test_static int test_host_uptime_info_command_failure(void) +{ + int rv; + struct ec_response_uptime_info resp = { 0 }; + + get_ap_reset_stats_should_succeed = false; + + rv = test_send_host_command(EC_CMD_GET_UPTIME_INFO, 0, NULL, 0, &resp, + sizeof(resp)); + + TEST_ASSERT(rv == EC_RES_ERROR); + + return EC_RES_SUCCESS; +} + +void run_test(void) +{ + test_reset(); + + RUN_TEST(test_host_uptime_info_command_success); + RUN_TEST(test_host_uptime_info_command_failure); + + test_print_result(); +} diff --git a/test/uptime.tasklist b/test/uptime.tasklist new file mode 100644 index 0000000000..9bf1c80c20 --- /dev/null +++ b/test/uptime.tasklist @@ -0,0 +1,10 @@ +/* Copyright 2019 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST + |