test/fpsensor: Add test for checking protocol info
Note that the "fpsensor_uart_ro" test is broken at this point due to b/171370392 and will be fixed in a followup commit. BRANCH=none BUG=b:171370392 TEST=Using dragonclaw v0.2 and servo_micro: ./test/run_device_tests.py -t fpsensor_uart_ro ./test/run_device_tests.py -t fpsensor_uart_rw ./test/run_device_tests.py -t fpsensor_spi_ro ./test/run_device_tests.py -t fpsensor_spi_rw Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I00cb5dd975fefe577381f1889e88aad000c8ba57 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2508859 Reviewed-by: Bhanu Prakash Maiya <bhanumaiya@google.com>
This commit is contained in:
parent
a6ec60c2f3
commit
8dcad3805d
|
@ -9,7 +9,14 @@ CHIP:=stm32
|
|||
CHIP_FAMILY:=stm32f4
|
||||
CHIP_VARIANT:=stm32f412
|
||||
|
||||
board-y=board.o fpsensor_detect.o
|
||||
board-y=board.o
|
||||
|
||||
# If we're not building a test build, use the real sensor detection. Otherwise,
|
||||
# for test builds, allow the mock version so we can test sensor/transport
|
||||
# permutations in the unit tests.
|
||||
ifeq ($(TEST_BUILD),)
|
||||
board-y+=fpsensor_detect.o
|
||||
endif
|
||||
|
||||
test-list-y=\
|
||||
aes \
|
||||
|
|
|
@ -3,9 +3,30 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "ec_commands.h"
|
||||
#include "mock/fpsensor_detect_mock.h"
|
||||
#include "string.h"
|
||||
#include "test_util.h"
|
||||
#include "common/fpsensor/fpsensor_private.h"
|
||||
|
||||
static const struct ec_response_get_protocol_info expected_info[] = {
|
||||
[FP_TRANSPORT_TYPE_SPI] = {
|
||||
.flags = 1,
|
||||
.max_response_packet_size = 544,
|
||||
.max_request_packet_size = 544,
|
||||
.protocol_versions = 8,
|
||||
},
|
||||
[FP_TRANSPORT_TYPE_UART] = {
|
||||
.flags = 1,
|
||||
.max_response_packet_size = 256,
|
||||
.max_request_packet_size = 544,
|
||||
.protocol_versions = 8,
|
||||
}
|
||||
};
|
||||
|
||||
test_static int test_validate_fp_buffer_offset_success(void)
|
||||
{
|
||||
TEST_EQ(validate_fp_buffer_offset(1, 0, 1), EC_SUCCESS, "%d");
|
||||
|
@ -25,6 +46,44 @@ test_static int test_validate_fp_buffer_offset_failure_overflow(void)
|
|||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
test_static int test_host_command_protocol_info(
|
||||
enum fp_transport_type transport_type,
|
||||
const struct ec_response_get_protocol_info *expected)
|
||||
{
|
||||
struct ec_response_get_protocol_info info;
|
||||
int rv;
|
||||
|
||||
mock_ctrl_fpsensor_detect.get_fp_sensor_type_return =
|
||||
FP_SENSOR_TYPE_FPC;
|
||||
mock_ctrl_fpsensor_detect.get_fp_transport_type_return = transport_type;
|
||||
|
||||
rv = test_send_host_command(EC_CMD_GET_PROTOCOL_INFO, 0, NULL, 0, &info,
|
||||
sizeof(info));
|
||||
|
||||
TEST_EQ(rv, EC_RES_SUCCESS, "%d");
|
||||
|
||||
TEST_EQ(info.flags, expected->flags, "%d");
|
||||
TEST_EQ(info.max_request_packet_size, expected->max_request_packet_size,
|
||||
"%d");
|
||||
TEST_EQ(info.max_response_packet_size,
|
||||
expected->max_response_packet_size, "%d");
|
||||
TEST_EQ(info.protocol_versions, expected->protocol_versions, "%d");
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
test_static int test_host_command_protocol_info_uart(void)
|
||||
{
|
||||
return test_host_command_protocol_info(
|
||||
FP_TRANSPORT_TYPE_UART, &expected_info[FP_TRANSPORT_TYPE_UART]);
|
||||
}
|
||||
|
||||
test_static int test_host_command_protocol_info_spi(void)
|
||||
{
|
||||
return test_host_command_protocol_info(
|
||||
FP_TRANSPORT_TYPE_SPI, &expected_info[FP_TRANSPORT_TYPE_SPI]);
|
||||
}
|
||||
|
||||
void run_test(int argc, char **argv)
|
||||
{
|
||||
if (IS_ENABLED(HAS_TASK_FPSENSOR)) {
|
||||
|
@ -35,7 +94,27 @@ void run_test(int argc, char **argv)
|
|||
RUN_TEST(test_validate_fp_buffer_offset_success);
|
||||
RUN_TEST(test_validate_fp_buffer_offset_failure_no_overflow);
|
||||
RUN_TEST(test_validate_fp_buffer_offset_failure_overflow);
|
||||
}
|
||||
|
||||
/* The tests after this only work on device right now. */
|
||||
if (IS_ENABLED(EMU_BUILD)) {
|
||||
test_print_result();
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
ccprintf("usage: runtest [uart|spi]\n");
|
||||
test_fail();
|
||||
return;
|
||||
}
|
||||
|
||||
/* The transport type is cached in a static variable, so the tests
|
||||
* cannot be run back to back (without reboot).
|
||||
*/
|
||||
if (strncmp(argv[1], "uart", 4) == 0)
|
||||
RUN_TEST(test_host_command_protocol_info_uart);
|
||||
else if (strncmp(argv[1], "spi", 3) == 0)
|
||||
RUN_TEST(test_host_command_protocol_info_spi);
|
||||
|
||||
test_print_result();
|
||||
}
|
||||
|
|
|
@ -11,4 +11,10 @@
|
|||
MOCK(MKBP_EVENTS) \
|
||||
MOCK(ROLLBACK) \
|
||||
MOCK(TIMER)
|
||||
#elif defined(TEST_BUILD)
|
||||
/* Mock the sensor detection on dragonclaw v0.2 dev boards since we can't
|
||||
* otherwise change the detected version in hardware without a rework. See
|
||||
* https://chromium.googlesource.com/chromiumos/platform/ec/+/refs/heads/master/docs/schematics/dragonclaw
|
||||
*/
|
||||
#define CONFIG_TEST_MOCK_LIST MOCK(FPSENSOR_DETECT)
|
||||
#endif /* BOARD_HOST */
|
||||
|
|
|
@ -114,8 +114,16 @@ class AllTests:
|
|||
TestConfig(name='flash_write_protect',
|
||||
image_to_use=ImageType.RO,
|
||||
toggle_power=True, enable_hw_write_protect=True),
|
||||
'fpsensor':
|
||||
TestConfig(name='fpsensor'),
|
||||
'fpsensor_spi_ro':
|
||||
TestConfig(name='fpsensor', image_to_use=ImageType.RO,
|
||||
test_args=['spi']),
|
||||
'fpsensor_spi_rw':
|
||||
TestConfig(name='fpsensor', test_args=['spi']),
|
||||
'fpsensor_uart_ro':
|
||||
TestConfig(name='fpsensor', image_to_use=ImageType.RO,
|
||||
test_args=['uart']),
|
||||
'fpsensor_uart_rw':
|
||||
TestConfig(name='fpsensor', test_args=['uart']),
|
||||
'mpu_ro':
|
||||
TestConfig(name='mpu',
|
||||
image_to_use=ImageType.RO,
|
||||
|
|
Loading…
Reference in New Issue