mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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>
This commit is contained in:
@@ -6,24 +6,26 @@
|
||||
/* Mock LPC module for Chrome EC */
|
||||
|
||||
#include "board.h"
|
||||
#include "common.h"
|
||||
#include "ec_commands.h"
|
||||
#include "lpc.h"
|
||||
#include "registers.h"
|
||||
#include "uart.h"
|
||||
|
||||
void lpc_set_host_events(uint32_t mask)
|
||||
void lpc_set_host_event_state(uint32_t mask)
|
||||
{
|
||||
uart_printf("Host event: %x\n", mask);
|
||||
}
|
||||
|
||||
|
||||
uint32_t lpc_get_host_events(void)
|
||||
uint32_t lpc_get_host_event_state(void)
|
||||
{
|
||||
/* Not implemented */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void lpc_clear_host_events(uint32_t mask)
|
||||
void lpc_clear_host_event_state(uint32_t mask)
|
||||
{
|
||||
uart_printf("Clear host event: %x\n", mask);
|
||||
}
|
||||
@@ -61,3 +63,22 @@ void lpc_comx_put_char(int c)
|
||||
/* Not implemented */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void host_send_response(enum ec_status result, const uint8_t *data, int size)
|
||||
{
|
||||
/* Not implemented */
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint8_t *lpc_get_memmap_range(void)
|
||||
{
|
||||
return (uint8_t *)LPC_POOL_CMD_DATA + EC_HOST_PARAM_SIZE * 2;
|
||||
}
|
||||
|
||||
|
||||
uint8_t *host_get_buffer(void)
|
||||
{
|
||||
return (uint8_t *)LPC_POOL_CMD_DATA;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
58
test/flash.c
58
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;
|
||||
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(EC_CMD_FLASH_INFO, data, &resp_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;
|
||||
|
||||
@@ -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 test_read(helper, offset, size):
|
||||
helper.ec_command("hcflashread %d %d" % (offset, size))
|
||||
def _get_read_ref(helper, offset, size):
|
||||
ret = []
|
||||
retsub = []
|
||||
assert size % 4 == 0
|
||||
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
|
||||
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))
|
||||
for line in ref:
|
||||
helper.wait_output(line)
|
||||
|
||||
def test_write(helper, offset, size, expect_fail=False):
|
||||
seed = random.randint(2, 10000)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -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') \
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user