mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Add EC_CMD_TEST_PROTOCOL to fake certain responses.
This lets us force the EC to return various error codes, so that we can be sure we're seeing them. BUG=chromium:242706 BRANCH=none TEST=none Trigger various errors like so: ectool test 0 14 ectool test 1 14 ectool test 5 14 ectool test 8 14 ectool test 0 33 Change-Id: Ia951cd7afacdcce6c8ec7d35d3bfb5b113dea694 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/59327 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
ChromeBot
parent
b839e65241
commit
e493e7a013
@@ -525,6 +525,23 @@ DECLARE_HOST_COMMAND(EC_CMD_RESEND_RESPONSE,
|
||||
EC_VER_MASK(0));
|
||||
#endif /* CONFIG_HOST_COMMAND_STATUS */
|
||||
|
||||
/* Returns what we tell it to. */
|
||||
static int host_command_test_protocol(struct host_cmd_handler_args *args)
|
||||
{
|
||||
const struct ec_params_test_protocol *p = args->params;
|
||||
struct ec_response_test_protocol *r = args->response;
|
||||
int copy_len = MIN(p->ret_len, sizeof(r->buf)); /* p,r bufs same size */
|
||||
|
||||
memset(r->buf, 0, sizeof(r->buf));
|
||||
memcpy(r->buf, p->buf, copy_len);
|
||||
args->response_size = p->ret_len;
|
||||
|
||||
return p->ec_result;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_TEST_PROTOCOL,
|
||||
host_command_test_protocol,
|
||||
EC_VER_MASK(0));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Console commands */
|
||||
|
||||
|
||||
@@ -484,6 +484,23 @@ struct ec_response_get_comms_status {
|
||||
uint32_t flags; /* Mask of enum ec_comms_status */
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* Fake a variety of responses, purely for testing purposes.
|
||||
* FIXME: Would be nice to force checksum errors.
|
||||
*/
|
||||
#define EC_CMD_TEST_PROTOCOL 0x0a
|
||||
|
||||
/* Tell the EC what to send back to us. */
|
||||
struct ec_params_test_protocol {
|
||||
uint32_t ec_result;
|
||||
uint32_t ret_len;
|
||||
uint8_t buf[32];
|
||||
} __packed;
|
||||
|
||||
/* Here it comes... */
|
||||
struct ec_response_test_protocol {
|
||||
uint8_t buf[32];
|
||||
} __packed;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Flash commands */
|
||||
|
||||
@@ -24,6 +24,7 @@ static int ec_command_dev(int command, int version,
|
||||
void *indata, int insize)
|
||||
{
|
||||
struct cros_ec_command s_cmd;
|
||||
int r;
|
||||
|
||||
s_cmd.command = command;
|
||||
s_cmd.version = version;
|
||||
@@ -33,8 +34,14 @@ static int ec_command_dev(int command, int version,
|
||||
s_cmd.insize = insize;
|
||||
s_cmd.indata = indata;
|
||||
|
||||
if (ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd))
|
||||
return -1;
|
||||
r = ioctl(fd, CROS_EC_DEV_IOCXCMD, &s_cmd);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "ioctl %d, errno %d (%s), EC result %d\n",
|
||||
r, errno, strerror(errno), s_cmd.result);
|
||||
return r;
|
||||
}
|
||||
if (s_cmd.result != EC_RES_SUCCESS)
|
||||
fprintf(stderr, "EC result %d\n", s_cmd.result);
|
||||
|
||||
return s_cmd.insize;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* @outdata: Outgoing data to EC
|
||||
* @outsize: Outgoing length in bytes
|
||||
* @indata: Where to put the incoming data from EC
|
||||
* @insize: Incoming length in bytes (filled in by EC)
|
||||
* @insize: On call, how much we can accept. On return, how much we got.
|
||||
* @result: EC's response to the command (separate from communication failure)
|
||||
* ioctl returns zero on success, negative on error
|
||||
*/
|
||||
|
||||
@@ -329,6 +329,39 @@ int cmd_hello(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_test(int argc, char *argv[])
|
||||
{
|
||||
struct ec_params_test_protocol p = {
|
||||
.buf = "0123456789abcdef0123456789ABCDEF"
|
||||
};
|
||||
struct ec_response_test_protocol r;
|
||||
int rv;
|
||||
char *e;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: %s result length\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
p.ec_result = strtol(argv[1], &e, 0);
|
||||
if (e && *e) {
|
||||
fprintf(stderr, "invalid param (result)\n");
|
||||
return -1;
|
||||
}
|
||||
p.ret_len = strtol(argv[2], &e, 0);
|
||||
if (e && *e) {
|
||||
fprintf(stderr, "invalid param (length)\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ec_command(EC_CMD_TEST_PROTOCOL, 0, &p, sizeof(p), &r, sizeof(r));
|
||||
printf("rv = %d\n", rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int cmd_cmdversions(int argc, char *argv[])
|
||||
{
|
||||
struct ec_params_get_cmd_versions p;
|
||||
@@ -3067,6 +3100,7 @@ const struct command commands[] = {
|
||||
{"switches", cmd_switches},
|
||||
{"temps", cmd_temperature},
|
||||
{"tempsinfo", cmd_temp_sensor_info},
|
||||
{"test", cmd_test},
|
||||
{"thermalget", cmd_thermal_get_threshold},
|
||||
{"thermalset", cmd_thermal_set_threshold},
|
||||
{"tmp006cal", cmd_tmp006cal},
|
||||
|
||||
Reference in New Issue
Block a user