mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
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>
This commit is contained in:
parent
d0fc4e76e1
commit
67e5c6afa4
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user