Anastasia Klimchuk submitted this change.
tests: add probe lifecycle test for ch341a_spi
This test upgrades mocks to simulate a read request. Read buffer
is populated with chip manufacture id and chip model id to emulate
successful probing.
TEST=ninja test
Change-Id: I0a2d5591d097435fc69719e1d9bd153433425821
Signed-off-by: Alexander Goncharov <chat@joursoir.net>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/68755
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
---
M tests/ch341a_spi.c
M tests/tests.c
M tests/tests.h
3 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/tests/ch341a_spi.c b/tests/ch341a_spi.c
index c706171..1cb2652 100644
--- a/tests/ch341a_spi.c
+++ b/tests/ch341a_spi.c
@@ -19,9 +19,15 @@
/* 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;
+ /*
+ * Since the test transfers a data that fits in one CH341 packet, we
+ * don't need an array of these transfers (as is done in the driver code).
+ */
+ struct libusb_transfer *transfer_in;
};
static struct libusb_transfer *ch341a_libusb_alloc_transfer(void *state, int iso_packets)
@@ -39,10 +45,15 @@
{
struct ch341a_spi_io_state *io_state = state;
- assert_true(transfer->endpoint == WRITE_EP);
+ assert_true(transfer->endpoint == WRITE_EP || transfer->endpoint == READ_EP);
- assert_null(io_state->transfer_out);
- io_state->transfer_out = transfer;
+ 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;
}
@@ -67,6 +78,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;
}
@@ -89,6 +111,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,
+ .libusb_handle_events_timeout = &ch341a_libusb_handle_events_timeout,
+ .fallback_open_state = &ch341a_spi_fallback_open_state,
+ };
+
+ 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 2461ff6..fe70204 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -421,6 +421,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);
To view, visit change 68755. To unsubscribe, or for help writing mail filters, visit settings.