diff options
author | Vic Yang <victoryang@chromium.org> | 2012-07-13 16:15:15 +0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-13 02:10:46 -0700 |
commit | dbefb29f028108c6faadb40acebf942dfe51b92c (patch) | |
tree | f1faedf8b99ac05ebb186e9a11cc64f94d3033bb /test | |
parent | 1bd61468929bdd4907d02d56b9144d654b6ad272 (diff) | |
download | chrome-ec-dbefb29f028108c6faadb40acebf942dfe51b92c.tar.gz |
Fix unit tests
Recently, there have been several changes to LPC and host command modules.
This CL fixes unit tests after these changes.
BUG=none
TEST=All test passed.
Change-Id: I263716899af78a61e324fcd0b2636b948617a264
Reviewed-on: https://gerrit.chromium.org/gerrit/27354
Reviewed-by: Rong Chang <rongchang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/charging.tasklist | 1 | ||||
-rw-r--r-- | test/flash.c | 60 | ||||
-rw-r--r-- | test/flash_test_util.py | 29 | ||||
-rw-r--r-- | test/hello.tasklist | 1 | ||||
-rw-r--r-- | test/kb_debounce.tasklist | 1 | ||||
-rw-r--r-- | test/kb_deghost.tasklist | 1 | ||||
-rw-r--r-- | test/mutex.tasklist | 1 | ||||
-rw-r--r-- | test/pingpong.tasklist | 1 | ||||
-rw-r--r-- | test/power_button.tasklist | 1 | ||||
-rw-r--r-- | test/scancode.tasklist | 1 | ||||
-rw-r--r-- | test/thermal.py | 6 | ||||
-rw-r--r-- | test/thermal.tasklist | 1 | ||||
-rw-r--r-- | test/timer_calib.tasklist | 1 | ||||
-rw-r--r-- | test/timer_dos.tasklist | 1 | ||||
-rw-r--r-- | test/timer_jump.py | 11 | ||||
-rw-r--r-- | test/typematic.tasklist | 1 |
16 files changed, 88 insertions, 30 deletions
diff --git a/test/charging.tasklist b/test/charging.tasklist index 4a0d674e91..ae93e63291 100644 --- a/test/charging.tasklist +++ b/test/charging.tasklist @@ -23,4 +23,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/flash.c b/test/flash.c index 6f822d88ec..2ab0b749fb 100644 --- a/test/flash.c +++ b/test/flash.c @@ -22,17 +22,25 @@ DECLARE_CONSOLE_COMMAND(rosize, ro_image_size, "Report size of RO image", NULL); +/* TODO(victoryang@): We should introduce a function to send fake host command + * just like ec_command in ectool. See crosbug/p/11350 */ static int hc_flash_info(int argc, char **argv) { - uint8_t data[EC_PARAM_SIZE]; + uint8_t data[EC_HOST_PARAM_SIZE]; enum ec_status res; - int resp_size; - struct ec_response_flash_info *r = - (struct ec_response_flash_info *)data; - - res = host_command_process(EC_CMD_FLASH_INFO, data, &resp_size); + struct ec_response_flash_info *r; + struct host_cmd_handler_args args = + { .command = EC_CMD_FLASH_INFO, + .version = 0, + .params = NULL, + .params_size = 0, + .response = data, + .response_size = EC_HOST_PARAM_SIZE }; + + res = host_command_process(&args); if (res != EC_RES_SUCCESS) return EC_ERROR_UNKNOWN; + r = (struct ec_response_flash_info *)args.response; uart_printf("flash_size = %d\n", r->flash_size); uart_printf("write_block_size = %d\n", r->write_block_size); uart_printf("erase_block_size = %d\n", r->erase_block_size); @@ -45,13 +53,17 @@ DECLARE_CONSOLE_COMMAND(hcflashinfo, hc_flash_info, static int hc_flash_read(int argc, char **argv) { - uint8_t data[EC_PARAM_SIZE]; + uint8_t data[EC_HOST_PARAM_SIZE]; enum ec_status res; - int resp_size; struct ec_params_flash_read *p = (struct ec_params_flash_read *)data; - struct ec_response_flash_read *r = - (struct ec_response_flash_read *)data; + struct host_cmd_handler_args args = + { .command = EC_CMD_FLASH_READ, + .version = 0, + .params = data, + .params_size = EC_HOST_PARAM_SIZE, + .response = data, + .response_size = EC_HOST_PARAM_SIZE }; char *e; int i, size; @@ -66,11 +78,11 @@ static int hc_flash_read(int argc, char **argv) if (*e) return EC_ERROR_PARAM2; - res = host_command_process(EC_CMD_FLASH_READ, data, &resp_size); + res = host_command_process(&args); if (res != EC_RES_SUCCESS) return EC_ERROR_UNKNOWN; for (i = 0; i < size; ++i) { - uart_printf("%02x", r->data[i]); + uart_printf("%02x", args.response[i]); if ((i & 31) == 31) uart_puts("\n"); } @@ -81,11 +93,17 @@ DECLARE_CONSOLE_COMMAND(hcflashread, hc_flash_read, static int hc_flash_write(int argc, char **argv) { - uint8_t data[EC_PARAM_SIZE]; + uint8_t data[EC_HOST_PARAM_SIZE]; enum ec_status res; - int resp_size; struct ec_params_flash_write *p = (struct ec_params_flash_write *)data; + struct host_cmd_handler_args args = + { .command = EC_CMD_FLASH_WRITE, + .version = 0, + .params = data, + .params_size = EC_HOST_PARAM_SIZE, + .response = data, + .response_size = EC_HOST_PARAM_SIZE }; char *e; int i, size; int seed, mult, add; @@ -115,7 +133,7 @@ static int hc_flash_write(int argc, char **argv) seed = seed * mult + add; } - res = host_command_process(EC_CMD_FLASH_WRITE, data, &resp_size); + res = host_command_process(&args); if (res != EC_RES_SUCCESS) return EC_ERROR_UNKNOWN; return EC_SUCCESS; @@ -125,11 +143,17 @@ DECLARE_CONSOLE_COMMAND(hcflashwrite, hc_flash_write, static int hc_flash_erase(int argc, char **argv) { - uint8_t data[EC_PARAM_SIZE]; + uint8_t data[EC_HOST_PARAM_SIZE]; enum ec_status res; - int resp_size; struct ec_params_flash_erase *p = (struct ec_params_flash_erase *)data; + struct host_cmd_handler_args args = + { .command = EC_CMD_FLASH_ERASE, + .version = 0, + .params = data, + .params_size = EC_HOST_PARAM_SIZE, + .response = data, + .response_size = EC_HOST_PARAM_SIZE }; char *e; int size; @@ -144,7 +168,7 @@ static int hc_flash_erase(int argc, char **argv) if (*e) return EC_ERROR_PARAM2; - res = host_command_process(EC_CMD_FLASH_ERASE, data, &resp_size); + res = host_command_process(&args); if (res != EC_RES_SUCCESS) return EC_ERROR_UNKNOWN; return EC_SUCCESS; diff --git a/test/flash_test_util.py b/test/flash_test_util.py index 476f3b2d09..06eea777da 100644 --- a/test/flash_test_util.py +++ b/test/flash_test_util.py @@ -6,6 +6,7 @@ # import random +import re # Fixed random seed. random.seed(1234) @@ -30,15 +31,29 @@ def test_erase(helper, offset, size): helper.ec_command("hcflasherase %d %d" % (offset, size)) helper.wait_output("Flash erase at %x size %x" % (offset, size)) +def _get_read_ref(helper, offset, size): + ret = [] + retsub = [] + assert size % 4 == 0 + while size > 0: + helper.ec_command("rw %d" % offset) + h = helper.wait_output("read.*=\s+0x(?P<h>[0-9a-f]+)", use_re=True)["h"] + # Change endianess here + retsub.append(re.sub('(..)(..)(..)(..)', r'\4\3\2\1', h)) + if len(retsub) == 8: + ret.append(''.join(retsub)) + retsub = [] + size = size - 4 + offset = offset + 4 + if retsub: + ret.append(''.join(retsub)) + return ret + def test_read(helper, offset, size): + ref = _get_read_ref(helper, offset, size) helper.ec_command("hcflashread %d %d" % (offset, size)) - while size > 0: - cur_size = size if size <= 32 else 32 - expect_str = ''.join([("%02x" % (x & 0xff)) for x in - range(offset, offset + cur_size)]) - helper.wait_output(expect_str) - offset = offset + cur_size - size = size - cur_size + for line in ref: + helper.wait_output(line) def test_write(helper, offset, size, expect_fail=False): seed = random.randint(2, 10000) diff --git a/test/hello.tasklist b/test/hello.tasklist index 43cd7841a5..6c33988331 100644 --- a/test/hello.tasklist +++ b/test/hello.tasklist @@ -16,4 +16,5 @@ #define CONFIG_TASK_LIST \ TASK(WATCHDOG, watchdog_task, NULL) \ TASK(VBOOTHASH, vboot_hash_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/kb_debounce.tasklist b/test/kb_debounce.tasklist index 996cceeacb..253871f365 100644 --- a/test/kb_debounce.tasklist +++ b/test/kb_debounce.tasklist @@ -22,4 +22,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/kb_deghost.tasklist b/test/kb_deghost.tasklist index c949371ae5..3bb24f5eb1 100644 --- a/test/kb_deghost.tasklist +++ b/test/kb_deghost.tasklist @@ -22,4 +22,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/mutex.tasklist b/test/mutex.tasklist index 54ed049101..c617fc5387 100644 --- a/test/mutex.tasklist +++ b/test/mutex.tasklist @@ -7,6 +7,7 @@ #define CONFIG_TASK_LIST \ TASK(WATCHDOG, watchdog_task, NULL) \ TASK(VBOOTHASH, vboot_hash_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) \ TASK(MTX3C, mutex_random_task, NULL) \ TASK(MTX3B, mutex_random_task, NULL) \ diff --git a/test/pingpong.tasklist b/test/pingpong.tasklist index 28cc227280..ce8f7febd9 100644 --- a/test/pingpong.tasklist +++ b/test/pingpong.tasklist @@ -7,6 +7,7 @@ #define CONFIG_TASK_LIST \ TASK(WATCHDOG, watchdog_task, NULL) \ TASK(VBOOTHASH, vboot_hash_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) \ TASK(TESTA, TaskAbc, (void *)'A') \ TASK(TESTB, TaskAbc, (void *)'B') \ diff --git a/test/power_button.tasklist b/test/power_button.tasklist index ac4c48dc2f..b576e38f30 100644 --- a/test/power_button.tasklist +++ b/test/power_button.tasklist @@ -22,4 +22,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/scancode.tasklist b/test/scancode.tasklist index 996cceeacb..253871f365 100644 --- a/test/scancode.tasklist +++ b/test/scancode.tasklist @@ -22,4 +22,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/thermal.py b/test/thermal.py index 30090b6b74..3a0453c3bb 100644 --- a/test/thermal.py +++ b/test/thermal.py @@ -82,7 +82,11 @@ def test(helper): # Set CPU temperature to trigger warning and throttle CPU helper.ec_command("setcputemp %d" % config[CPU]['warning']) helper.wait_output("Throttle CPU.", timeout=11) - helper.wait_output("Host event: 200", timeout=2) + host_event = helper.wait_output("Host event: (?P<h>\d+)", use_re=True, + timeout=2)["h"] + if (int(host_event, 16) & 0x200) == 0: + helper.trace("Fail to get thermal overload event") + return False # Lower CPU temperature and check CPU is not throttled helper.ec_command("setcputemp %d" % (config[CPU]['warning']-5)) diff --git a/test/thermal.tasklist b/test/thermal.tasklist index 56d87219d6..fe620078e8 100644 --- a/test/thermal.tasklist +++ b/test/thermal.tasklist @@ -20,4 +20,5 @@ TASK(THERMAL, thermal_task, NULL) \ TASK(PWM, pwm_task, NULL) \ TASK(X86POWER, x86_power_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/timer_calib.tasklist b/test/timer_calib.tasklist index 012931ab85..b17b961296 100644 --- a/test/timer_calib.tasklist +++ b/test/timer_calib.tasklist @@ -8,4 +8,5 @@ TASK(WATCHDOG, watchdog_task, NULL) \ TASK(VBOOTHASH, vboot_hash_task, NULL) \ TASK(TESTTMR, timer_calib_task, (void *)'T')\ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) diff --git a/test/timer_dos.tasklist b/test/timer_dos.tasklist index 8361010247..1a19829cbb 100644 --- a/test/timer_dos.tasklist +++ b/test/timer_dos.tasklist @@ -7,6 +7,7 @@ #define CONFIG_TASK_LIST \ TASK(WATCHDOG, watchdog_task, NULL) \ TASK(VBOOTHASH, vboot_hash_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) \ TASK(TMRA, TaskTimer, (void *)1234) \ TASK(TMRB, TaskTimer, (void *)5678) \ diff --git a/test/timer_jump.py b/test/timer_jump.py index 2f2302e327..07b67f1793 100644 --- a/test/timer_jump.py +++ b/test/timer_jump.py @@ -11,15 +11,18 @@ DELAY = 5 ERROR_MARGIN = 0.5 def test(helper): - helper.wait_output("Console is enabled") - helper.ec_command("sysjump ro") - helper.wait_output("Console is enabled") + helper.wait_output("idle task started") + helper.ec_command("sysinfo") + copy = helper.wait_output("Copy:\s+(?P<c>\S+)", use_re=True)["c"] + if copy != "RO": + helper.ec_command("sysjump ro") + helper.wait_output("idle task started") helper.ec_command("gettime") ec_start_time = helper.wait_output("Time: 0x[0-9a-f]* = (?P<t>[\d\.]+) s", use_re=True)["t"] time.sleep(DELAY) helper.ec_command("sysjump a") - helper.wait_output("Console is enabled") + helper.wait_output("idle task started") helper.ec_command("gettime") ec_end_time = helper.wait_output("Time: 0x[0-9a-f]* = (?P<t>[\d\.]+) s", use_re=True)["t"] diff --git a/test/typematic.tasklist b/test/typematic.tasklist index 996cceeacb..253871f365 100644 --- a/test/typematic.tasklist +++ b/test/typematic.tasklist @@ -22,4 +22,5 @@ TASK(I8042CMD, i8042_command_task, NULL) \ TASK(KEYSCAN, keyboard_scan_task, NULL) \ TASK(POWERBTN, power_button_task, NULL) \ + TASK(HOSTCMD, host_command_task, NULL) \ TASK(CONSOLE, console_task, NULL) |