summaryrefslogtreecommitdiffstats
path: root/tests/lifecycle.c
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-11-30 13:02:41 +1100
committerAnastasia Klimchuk <aklm@chromium.org>2022-03-20 22:41:53 +0000
commit78221212fa06faf82dd799c027e3a9f198354835 (patch)
tree54da7c21dd18a2d4853eaac2e1ba736b36e8f457 /tests/lifecycle.c
parente2f31ca02b2495887185ff4e042b0cf078ceb0b0 (diff)
downloadflashrom-78221212fa06faf82dd799c027e3a9f198354835.tar.gz
flashrom-78221212fa06faf82dd799c027e3a9f198354835.tar.bz2
flashrom-78221212fa06faf82dd799c027e3a9f198354835.zip
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>
Diffstat (limited to 'tests/lifecycle.c')
-rw-r--r--tests/lifecycle.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/lifecycle.c b/tests/lifecycle.c
index e48d94e1e..282a6b5d9 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 @@ void linux_mtd_probe_lifecycle_test_success(void **state)
#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 @@ char *linux_spi_fgets(void *state, char *buf, int len, FILE *fp)
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 @@ void linux_spi_basic_lifecycle_test_success(void **state)
#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