Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/62324 )
Change subject: tests/chips.c: Mock out open() for lock file ......................................................................
tests/chips.c: Mock out open() for lock file
Change-Id: I527a266233648b0eef11a89108e82d0a008eeb8d Signed-off-by: Edward O'Callaghan quasisec@google.com --- M tests/chip.c 1 file changed, 105 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/24/62324/1
diff --git a/tests/chip.c b/tests/chip.c index fe12533..51d7011 100644 --- a/tests/chip.c +++ b/tests/chip.c @@ -186,10 +186,41 @@ }, };
+#define DEFAULT_MOCK_FD 0xC0FE + +struct default_io_mock_state { + unsigned int noc; + const char *paths[2]; // no. of subsequent paths to check. + int flags; + int fd; +}; + +static int default_open(void *state, const char *pathname, int flags) +{ + struct default_io_mock_state * io_state = state; + const char *path = io_state->paths[io_state->noc]; + io_state->noc++; // proceed to the next path upon next call. + assert_string_equal(pathname, path); + assert_int_equal(flags & io_state->flags, io_state->flags); + return io_state->fd; +} + void erase_chip_test_success(void **state) { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_8MiB; @@ -208,6 +239,18 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_W25Q128_V; @@ -232,6 +275,18 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_8MiB; @@ -257,6 +312,18 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_W25Q128_V; @@ -287,6 +354,18 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_8MiB; @@ -325,6 +404,18 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; + const struct io_mock chip_io = { + .open = default_open, + .state = &data, + }; + + io_mock_register(&chip_io); + struct flashrom_flashctx flashctx = { 0 }; struct flashrom_layout *layout; struct flashchip mock_chip = chip_W25Q128_V; @@ -367,8 +458,15 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; const struct io_mock verify_chip_io = { .fread = verify_chip_fread, + .open = default_open, + .state = &data, };
io_mock_register(&verify_chip_io); @@ -401,8 +499,15 @@ { (void) state; /* unused */
+ static struct default_io_mock_state data = { + .paths = {"/run/lock/flashrom_lock"}, + .noc = 0, + .fd = DEFAULT_MOCK_FD, + }; const struct io_mock verify_chip_io = { .fread = verify_chip_fread, + .open = default_open, + .state = &data, };
io_mock_register(&verify_chip_io);