diff options
-rw-r--r-- | zephyr/test/drivers/include/test/drivers/utils.h | 17 | ||||
-rw-r--r-- | zephyr/test/drivers/src/host_cmd/motion_sense.c | 82 | ||||
-rw-r--r-- | zephyr/test/drivers/src/utils.c | 25 |
3 files changed, 121 insertions, 3 deletions
diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index d653d54938..4e89bf7292 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -403,6 +403,23 @@ int host_cmd_motion_sense_int_enable(int8_t enable, struct ec_response_motion_sense *response); /** + * @brief Call the spoof motion_sense subcommand + * + * @param sensor_num The sensor index in motion_sensors + * @param enable The enable field, for normal operations this will be one of + * enum motionsense_spoof_mode + * @param values0 The X value to set if using custom mode + * @param values1 The Y value to set if using custom mode + * @param values2 The Z value to set if using custom mode + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, + int16_t values0, int16_t values1, + int16_t values2, + struct ec_response_motion_sense *response); + +/** * Run the host command to get the PD discovery responses. * * @param port The USB-C port number diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c index fbb22d4789..07952ed285 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -80,6 +80,7 @@ static void host_cmd_motion_sense_after(void *fixture) motion_sensors[0].drv = this->sensor_0_drv; host_cmd_motion_sense_int_enable(0, &response); + motion_sensors[0].flags &= ~MOTIONSENSE_FLAG_IN_SPOOF_MODE; } ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, @@ -761,3 +762,84 @@ ZTEST(host_cmd_motion_sense, test_int_enable) NULL); zassert_equal(0, response.fifo_int_enable.ret, NULL); } + +ZTEST(host_cmd_motion_sense, test_spoof_invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_spoof(0xff, 0, 0, 0, 0, &response), + NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_disable) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].flags |= MOTIONSENSE_FLAG_IN_SPOOF_MODE; + zassert_ok(host_cmd_motion_sense_spoof(0, + MOTIONSENSE_SPOOF_MODE_DISABLE, + 0, 0, 0, &response), + NULL); + zassert_equal(0, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_false(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_custom) +{ + struct ec_response_motion_sense response; + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_CUSTOM, + -8, 16, -32, &response), + NULL); + zassert_equal(MOTIONSENSE_FLAG_IN_SPOOF_MODE, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + zassert_equal(-8, motion_sensors[0].spoof_xyz[0], NULL); + zassert_equal(16, motion_sensors[0].spoof_xyz[1], NULL); + zassert_equal(-32, motion_sensors[0].spoof_xyz[2], NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_true(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_lock_current) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].raw_xyz[0] = 64; + motion_sensors[0].raw_xyz[1] = 48; + motion_sensors[0].raw_xyz[2] = 32; + zassert_ok(host_cmd_motion_sense_spoof( + 0, MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, 0, 0, 0, + &response), + NULL); + zassert_equal(MOTIONSENSE_FLAG_IN_SPOOF_MODE, + motion_sensors[0].flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE, + NULL); + zassert_equal(64, motion_sensors[0].spoof_xyz[0], NULL); + zassert_equal(48, motion_sensors[0].spoof_xyz[1], NULL); + zassert_equal(32, motion_sensors[0].spoof_xyz[2], NULL); + + zassert_ok(host_cmd_motion_sense_spoof(0, MOTIONSENSE_SPOOF_MODE_QUERY, + 0, 0, 0, &response), + NULL); + zassert_true(response.spoof.ret, NULL); +} + +ZTEST(host_cmd_motion_sense, test_spoof_invalid_mode) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_spoof(0, 0xff, 0, 0, 0, &response), + NULL); +} diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index c5e6b8148d..a0c79ad036 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -196,7 +196,7 @@ int host_cmd_motion_sense_range(uint8_t sensor_num, int32_t range, int host_cmd_motion_sense_offset(uint8_t sensor_num, uint16_t flags, int16_t temperature, int16_t offset_x, int16_t offset_y, int16_t offset_z, - struct ec_response_motion_sense *response) + struct ec_response_motion_sense *response) { struct ec_params_motion_sense params = { .cmd = MOTIONSENSE_CMD_SENSOR_OFFSET, @@ -214,8 +214,8 @@ int host_cmd_motion_sense_offset(uint8_t sensor_num, uint16_t flags, } int host_cmd_motion_sense_scale(uint8_t sensor_num, uint16_t flags, - int16_t temperature, int16_t scale_x, - int16_t scale_y, int16_t scale_z, + int16_t temperature, int16_t scale_x, + int16_t scale_y, int16_t scale_z, struct ec_response_motion_sense *response) { struct ec_params_motion_sense params = { @@ -305,6 +305,25 @@ int host_cmd_motion_sense_int_enable(int8_t enable, return host_command_process(&args); } +int host_cmd_motion_sense_spoof(uint8_t sensor_num, uint8_t enable, + int16_t values0, int16_t values1, + int16_t values2, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_SPOOF, + .spoof = { + .sensor_id = sensor_num, + .spoof_enable = enable, + .components = { values0, values1, values2 }, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + void host_cmd_typec_discovery(int port, enum typec_partner_type partner_type, void *response, size_t response_size) { |