Alexander Goncharov has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/68755 )
Change subject: tests: add probe lifecycle test for ch341a_spi ......................................................................
tests: add probe lifecycle test for ch341a_spi
Change-Id: I0a2d5591d097435fc69719e1d9bd153433425821 Signed-off-by: Alexander Goncharov chat@joursoir.net --- M tests/ch341a_spi.c M tests/tests.c M tests/tests.h 3 files changed, 49 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/55/68755/1
diff --git a/tests/ch341a_spi.c b/tests/ch341a_spi.c index 39eb93b..9fb8588 100644 --- a/tests/ch341a_spi.c +++ b/tests/ch341a_spi.c @@ -19,9 +19,11 @@
/* Same macro as in ch341a_spi.c programmer. */ #define WRITE_EP 0x02 +#define READ_EP 0x82
struct ch341a_spi_io_state { struct libusb_transfer *transfer_out; + struct libusb_transfer *transfer_in; };
static struct libusb_transfer *ch341a_libusb_alloc_transfer(void *state, int iso_packets) @@ -33,11 +35,14 @@ { struct ch341a_spi_io_state *io_state = state;
- assert_true(transfer->endpoint == WRITE_EP); + assert_true(transfer->endpoint == WRITE_EP || transfer->endpoint == READ_EP);
if (transfer->endpoint == WRITE_EP) { assert_null(io_state->transfer_out); io_state->transfer_out = transfer; + } else if (transfer->endpoint == READ_EP) { + assert_null(io_state->transfer_in); + io_state->transfer_in = transfer; }
return 0; @@ -59,6 +64,17 @@ io_state->transfer_out = NULL; }
+ if (io_state->transfer_in) { + io_state->transfer_in->buffer[1] = reverse_byte(0xEF); /* WINBOND_NEX_ID */ + io_state->transfer_in->buffer[2] = reverse_byte(0x40); /* WINBOND_NEX_W25Q128_V left byte */ + io_state->transfer_in->buffer[3] = reverse_byte(0x18); /* WINBOND_NEX_W25Q128_V right byte */ + + io_state->transfer_in->status = LIBUSB_TRANSFER_COMPLETED; + io_state->transfer_in->actual_length = io_state->transfer_in->length; + io_state->transfer_in->callback(io_state->transfer_in); + io_state->transfer_in = NULL; + } + return 0; }
@@ -81,6 +97,26 @@ run_basic_lifecycle(state, &ch341a_spi_io, &programmer_ch341a_spi, ""); }
+void ch341a_spi_probe_lifecycle_test_success(void **state) +{ + struct ch341a_spi_io_state ch341a_spi_io_state = { 0 }; + struct io_mock_fallback_open_state ch341a_spi_fallback_open_state = { + .noc = 0, + .paths = { NULL }, + }; + const struct io_mock ch341a_spi_io = { + .state = &ch341a_spi_io_state, + .libusb_alloc_transfer = &ch341a_libusb_alloc_transfer, + .libusb_submit_transfer = &ch341a_libusb_submit_transfer, + .libusb_free_transfer = &ch341a_libusb_free_transfer, + .fallback_open_state = &ch341a_spi_fallback_open_state, + .libusb_handle_events_timeout = &ch341a_libusb_handle_events_timeout, + }; + + run_probe_lifecycle(state, &ch341a_spi_io, &programmer_ch341a_spi, "", "W25Q128.V"); +} + #else SKIP_TEST(ch341a_spi_basic_lifecycle_test_success) + SKIP_TEST(ch341a_spi_probe_lifecycle_test_success) #endif /* CONFIG_CH341A_SPI */ diff --git a/tests/tests.c b/tests/tests.c index 45d60f9..3bb86ff 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -437,6 +437,7 @@ cmocka_unit_test(realtek_mst_basic_lifecycle_test_success), cmocka_unit_test(realtek_mst_no_allow_brick_test_success), cmocka_unit_test(ch341a_spi_basic_lifecycle_test_success), + cmocka_unit_test(ch341a_spi_probe_lifecycle_test_success), }; ret |= cmocka_run_group_tests_name("lifecycle.c tests", lifecycle_tests, NULL, NULL);
diff --git a/tests/tests.h b/tests/tests.h index 4d91e4d..bcca9e8 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -61,6 +61,7 @@ void realtek_mst_basic_lifecycle_test_success(void **state); void realtek_mst_no_allow_brick_test_success(void **state); void ch341a_spi_basic_lifecycle_test_success(void **state); +void ch341a_spi_probe_lifecycle_test_success(void **state);
/* layout.c */ void included_regions_dont_overlap_test_success(void **state);