Daniel Campello has uploaded this change for review.

View Change

tests: use MOCK_FD instead of NON_ZERO

With this change the mocks are able to return a non-negative value for
the file descriptor expected from open operations. This avoid issues
with subsequent error checks of the form `if (fd < 0)`

BUG=b:227404721
TEST=./test_build.sh; FEATURES=test emerge-amd64-generic flashrom
BRANCH=none

Signed-off-by: Daniel Campello <campello@chromium.org>
Change-Id: Ib6bac051852aea2465665a6fd669b7f5e3772985
---
M tests/include/test.h
M tests/lifecycle.c
M tests/tests.c
3 files changed, 9 insertions(+), 9 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/93/63193/1
diff --git a/tests/include/test.h b/tests/include/test.h
index bf8c4f7..88ac16d 100644
--- a/tests/include/test.h
+++ b/tests/include/test.h
@@ -29,6 +29,8 @@

#define NON_ZERO (0xf000baaa)

+#define MOCK_FD (0x10ec)
+
/*
* Having this as function allows to set a breakpoint on the address,
* as it has a named symbol associated with the address number.
diff --git a/tests/lifecycle.c b/tests/lifecycle.c
index 282a6b5..c37f3b9 100644
--- a/tests/lifecycle.c
+++ b/tests/lifecycle.c
@@ -370,18 +370,16 @@
#endif
}

-#define REALTEK_MST_MOCK_FD 0x10ec
-
static int realtek_mst_open(void *state, const char *pathname, int flags)
{
assert_string_equal(pathname, "/dev/i2c-254");
assert_int_equal(flags & O_RDWR, O_RDWR);
- return REALTEK_MST_MOCK_FD;
+ return MOCK_FD;
}

static int realtek_mst_ioctl(void *state, int fd, unsigned long request, va_list args)
{
- assert_int_equal(fd, REALTEK_MST_MOCK_FD);
+ assert_int_equal(fd, MOCK_FD);
assert_int_equal(request, I2C_SLAVE);
/* Only access to I2C address 0x4a is expected */
unsigned long addr = va_arg(args, unsigned long);
@@ -392,14 +390,14 @@

static int realtek_mst_read(void *state, int fd, void *buf, size_t sz)
{
- assert_int_equal(fd, REALTEK_MST_MOCK_FD);
+ assert_int_equal(fd, MOCK_FD);
assert_int_equal(sz, 1);
return sz;
}

static int realtek_mst_write(void *state, int fd, const void *buf, size_t sz)
{
- assert_int_equal(fd, REALTEK_MST_MOCK_FD);
+ assert_int_equal(fd, MOCK_FD);
const LargestIntegralType accepted_sizes[] = {1, 2};
assert_in_set(sz, accepted_sizes, ARRAY_SIZE(accepted_sizes));
return sz;
diff --git a/tests/tests.c b/tests/tests.c
index 33b2ea2..f32c14d 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -79,7 +79,7 @@
LOG_ME;
if (get_io() && get_io()->open)
return get_io()->open(get_io()->state, pathname, flags);
- return NON_ZERO;
+ return MOCK_FD;
}

int __wrap_open64(const char *pathname, int flags)
@@ -87,7 +87,7 @@
LOG_ME;
if (get_io() && get_io()->open)
return get_io()->open(get_io()->state, pathname, flags);
- return NON_ZERO;
+ return MOCK_FD;
}

int __wrap___open64_2(const char *pathname, int flags)
@@ -95,7 +95,7 @@
LOG_ME;
if (get_io() && get_io()->open)
return get_io()->open(get_io()->state, pathname, flags);
- return NON_ZERO;
+ return MOCK_FD;
}

int __wrap_ioctl(int fd, unsigned long int request, ...)

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ib6bac051852aea2465665a6fd669b7f5e3772985
Gerrit-Change-Number: 63193
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Campello <campello@chromium.org>
Gerrit-MessageType: newchange