aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/spi25.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/tests/spi25.c b/tests/spi25.c
index 942fe6e5..251c98c0 100644
--- a/tests/spi25.c
+++ b/tests/spi25.c
@@ -20,10 +20,39 @@
#include "chipdrivers.h"
#include "spi.h"
+struct flashchip mock_chip = {
+ .vendor = "Generic",
+ .name = "unknown SPI chip (RDID)",
+ .bustype = BUS_SPI,
+ .manufacture_id = GENERIC_MANUF_ID,
+ .model_id = GENERIC_DEVICE_ID,
+ .total_size = 0,
+ .page_size = 256,
+ .tested = TEST_BAD_PREW,
+ .probe = probe_spi_rdid,
+ .write = NULL,
+};
+
+/*
+ * This declaration is needed for visibility, so that wrap below could
+ * redirect to real function.
+ */
+int __real_spi_send_command(const struct flashctx *flash,
+ unsigned int writecnt, unsigned int readcnt,
+ const unsigned char *writearr, unsigned char *readarr);
+
int __wrap_spi_send_command(const struct flashctx *flash,
unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{
+ if (flash->chip != &mock_chip)
+ /*
+ * Caller is some other test, redirecting to real function.
+ * This test is the only one which uses wrap of spi_send_command,
+ * all other tests use real function.
+ */
+ return __real_spi_send_command(flash, writecnt, readcnt, writearr, readarr);
+
check_expected_ptr(flash);
assert_int_equal(writecnt, mock_type(int));
assert_int_equal(writearr[0], mock_type(int));
@@ -36,19 +65,6 @@ int __wrap_spi_send_command(const struct flashctx *flash,
return 0;
}
-struct flashchip mock_chip = {
- .vendor = "Generic",
- .name = "unknown SPI chip (RDID)",
- .bustype = BUS_SPI,
- .manufacture_id = GENERIC_MANUF_ID,
- .model_id = GENERIC_DEVICE_ID,
- .total_size = 0,
- .page_size = 256,
- .tested = TEST_BAD_PREW,
- .probe = probe_spi_rdid,
- .write = NULL,
-};
-
void spi_write_enable_test_success(void **state)
{
(void) state; /* unused */