diff options
author | Alexander Goncharov <chat@joursoir.net> | 2022-10-24 12:57:09 +0300 |
---|---|---|
committer | Anastasia Klimchuk <aklm@chromium.org> | 2022-11-29 21:07:43 +0000 |
commit | 67e5c6afa43cbf3a876ae43a77e759d001864757 (patch) | |
tree | 79782c3cc5c3acccc91769fea46f95ca456ae6b7 /tests | |
parent | d0fc4e76e16b6c413519fcfaba9f382afd080407 (diff) | |
download | flashrom-67e5c6afa43cbf3a876ae43a77e759d001864757.tar.gz flashrom-67e5c6afa43cbf3a876ae43a77e759d001864757.tar.bz2 flashrom-67e5c6afa43cbf3a876ae43a77e759d001864757.zip |
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ch341a_spi.c | 48 | ||||
-rw-r--r-- | tests/tests.c | 1 | ||||
-rw-r--r-- | tests/tests.h | 1 |
3 files changed, 47 insertions, 3 deletions
diff --git a/tests/ch341a_spi.c b/tests/ch341a_spi.c index c7061719..1cb26524 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 @@ static int ch341a_libusb_submit_transfer(void *state, struct libusb_transfer *tr { 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 @@ static int ch341a_libusb_handle_events_timeout(void *state, libusb_context *ctx, 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 @@ void ch341a_spi_basic_lifecycle_test_success(void **state) 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 2461ff6e..fe702046 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -421,6 +421,7 @@ int main(int argc, char *argv[]) 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 4d91e4df..bcca9e89 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -61,6 +61,7 @@ void mediatek_i2c_no_allow_brick_test_success(void **state); 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); |