Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/59742 )
Change subject: tests: Upgrade linux_spi test to run probe lifecycle ......................................................................
tests: Upgrade linux_spi test to run probe lifecycle
This test adds a mock for linux_spi ioctl and mocks it for read request. Read buffer is populated with chip manufacture id and chip model id to emulate successful probing.
BUG=b:181803212 TEST=ninja test
Change-Id: I32d8e972d99b52c2b18f688aa6aeae75dd170f72 Signed-off-by: Anastasia Klimchuk aklm@chromium.org Reviewed-on: https://review.coreboot.org/c/flashrom/+/59742 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Thomas Heijligen src@posteo.de Reviewed-by: Nico Huber nico.h@gmx.de --- M tests/lifecycle.c M tests/tests.c M tests/tests.h 3 files changed, 30 insertions(+), 4 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Thomas Heijligen: Looks good to me, approved
diff --git a/tests/lifecycle.c b/tests/lifecycle.c index e48d94e..282a6b5 100644 --- a/tests/lifecycle.c +++ b/tests/lifecycle.c @@ -15,6 +15,7 @@
#include <include/test.h> #include <string.h> +#include <linux/spi/spidev.h>
#include "libflashrom.h" #include "io_mock.h" @@ -315,6 +316,30 @@ #endif }
+static int linux_spi_ioctl(void *state, int fd, unsigned long request, va_list args) { + + if (request == SPI_IOC_MESSAGE(2)) { /* ioctl code for read request */ + struct spi_ioc_transfer* msg = va_arg(args, struct spi_ioc_transfer*); + + /* First message has write array and write count */ + unsigned int writecnt = msg[0].len; + unsigned char *writearr = (unsigned char *)msg[0].tx_buf; + /* Second message has read array and read count */ + unsigned int readcnt = msg[1].len; + + /* Detect probing */ + if (writecnt == 1 && writearr[0] == JEDEC_RDID && readcnt == 3) { + /* We need to populate read array. */ + unsigned char *readarr = (unsigned char *)msg[1].rx_buf; + readarr[0] = 0xEF; /* WINBOND_NEX_ID */ + readarr[1] = 0x40; /* WINBOND_NEX_W25Q128_V left byte */ + readarr[2] = 0x18; /* WINBOND_NEX_W25Q128_V right byte */ + } + } + + return 0; +} + char *linux_spi_fgets(void *state, char *buf, int len, FILE *fp) { /* Emulate reading max buffer size from sysfs. */ @@ -323,7 +348,7 @@ return memcpy(buf, max_buf_size, min(len, strlen(max_buf_size) + 1)); }
-void linux_spi_basic_lifecycle_test_success(void **state) +void linux_spi_probe_lifecycle_test_success(void **state) { /* * Current implementation tests a particular path of the init procedure. @@ -332,11 +357,12 @@ #if CONFIG_LINUX_SPI == 1 const struct io_mock linux_spi_io = { .fgets = linux_spi_fgets, + .ioctl = linux_spi_ioctl, };
io_mock_register(&linux_spi_io);
- run_basic_lifecycle(state, &programmer_linux_spi, "dev=/dev/null"); + run_probe_lifecycle(state, &programmer_linux_spi, "dev=/dev/null", "W25Q128.V");
io_mock_register(NULL); #else diff --git a/tests/tests.c b/tests/tests.c index 34c01ea..f1fb3f3 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -369,7 +369,7 @@ cmocka_unit_test(raiden_debug_basic_lifecycle_test_success), cmocka_unit_test(dediprog_basic_lifecycle_test_success), cmocka_unit_test(linux_mtd_probe_lifecycle_test_success), - cmocka_unit_test(linux_spi_basic_lifecycle_test_success), + cmocka_unit_test(linux_spi_probe_lifecycle_test_success), cmocka_unit_test(realtek_mst_basic_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 672ec1f..68f7781 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -47,7 +47,7 @@ void raiden_debug_basic_lifecycle_test_success(void **state); void dediprog_basic_lifecycle_test_success(void **state); void linux_mtd_probe_lifecycle_test_success(void **state); -void linux_spi_basic_lifecycle_test_success(void **state); +void linux_spi_probe_lifecycle_test_success(void **state); void realtek_mst_basic_lifecycle_test_success(void **state);
/* layout.c */
6 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.