Edward O'Callaghan has uploaded this change for review.

View Change

tests/linux_spi: Validate param file path

BUG=b:217629892,b:215255210
TEST=`ninja test`.

Change-Id: If5d24c65f291c53a35509fea5d2f5b3fdb51c306
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M tests/init_shutdown.c
1 file changed, 23 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/19/62319/1
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 5221a16..4fb93b2 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -36,6 +36,23 @@
free(param_dup);
}

+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 dummy_init_and_shutdown_test_success(void **state)
{
#if CONFIG_DUMMY == 1
@@ -299,8 +316,14 @@
* Specifically, it is reading the buffer size from sysfs.
*/
#if CONFIG_LINUX_SPI == 1
+ static struct default_io_mock_state data = {
+ .paths = {"/dev/null"},
+ .noc = 0,
+ };
const struct io_mock linux_spi_io = {
.fgets = linux_spi_fgets,
+ .open = default_open,
+ .state = &data,
};

io_mock_register(&linux_spi_io);

To view, visit change 62319. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If5d24c65f291c53a35509fea5d2f5b3fdb51c306
Gerrit-Change-Number: 62319
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange