summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasia Klimchuk <aklm@chromium.org>2021-10-14 12:21:02 +1100
committerNico Huber <nico.h@gmx.de>2021-10-18 12:22:12 +0000
commitd23613cf6668b677264e5e02d4f4ac02873d307b (patch)
tree8ba56983251ca5e7bcfbde5aa4ff0b87f84f6fbc
parentf42d2f72cccdbcd454a79424fdb998842f7754d6 (diff)
downloadflashrom-d23613cf6668b677264e5e02d4f4ac02873d307b.tar.gz
flashrom-d23613cf6668b677264e5e02d4f4ac02873d307b.tar.bz2
flashrom-d23613cf6668b677264e5e02d4f4ac02873d307b.zip
tests: Add NON_ZERO macro and not_null function instead of MOCK_HANDLE
This patch adds NON_ZERO macro and not_null function into io_mock.h, so that they can be used anywhere in tests. Common usage for not_null is to indicate a valid pointer, where it doesn't matter what the pointer is, only matters it is not null. Common usage of NON_ZERO is to indicate a valid file descriptor, where it only matters the descriptor is non-zero integer. New features replace all usages of previous MOCK_HANDLE. This patch corrects return value from __wrap_ioctl to be successful by default. It used to be MOCK_HANDLE, but should be 0. Included in this patch because this is also a replacement of MOCK_HANDLE. BUG=b:181803212 TEST=builds and ninja test Change-Id: I5ad6ee4aa9091447c6c9108c92bf7f6e755fca48 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/57269 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--tests/include/test.h8
-rw-r--r--tests/init_shutdown.c4
-rw-r--r--tests/tests.c24
3 files changed, 23 insertions, 13 deletions
diff --git a/tests/include/test.h b/tests/include/test.h
index 24fa963b4..ee7b4cf1c 100644
--- a/tests/include/test.h
+++ b/tests/include/test.h
@@ -27,4 +27,12 @@
#include <setjmp.h>
#include <cmocka.h>
+#define NON_ZERO (0xf000baaa)
+
+/*
+ * Having this as function allows to set a breakpoint on the address,
+ * as it has a named symbol associated with the address number.
+ */
+void *not_null(void);
+
#endif /* _TESTS_TEST_H */
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 90bde1e3c..03e888fd5 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -19,8 +19,6 @@
#include "io_mock.h"
#include "programmer.h"
-#define NOT_NULL ((void *)0xf000baaa)
-
static void run_lifecycle(void **state, const struct programmer_entry *prog, const char *param)
{
(void) state; /* unused */
@@ -100,7 +98,7 @@ FILE *linux_mtd_fopen(void *state, const char *pathname, const char *mode)
io_state->fopen_path = strdup(pathname);
- return NOT_NULL;
+ return not_null();
}
size_t linux_mtd_fread(void *state, void *buf, size_t size, size_t len, FILE *fp)
diff --git a/tests/tests.c b/tests/tests.c
index ac5947073..9dadddfec 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -23,7 +23,11 @@
/* redefinitions/wrapping */
#define LOG_ME printf("%s is called\n", __func__)
-#define MOCK_HANDLE 2021
+
+void *not_null(void)
+{
+ return (void *)NON_ZERO;
+}
static const struct io_mock *current_io = NULL;
@@ -54,7 +58,7 @@ void *__wrap_physmap(const char *descr, uintptr_t phys_addr, size_t len)
}
struct pci_dev mock_pci_dev = {
- .device_id = MOCK_HANDLE,
+ .device_id = NON_ZERO,
};
struct pci_dev *__wrap_pcidev_init(void *devs, int bar)
@@ -66,7 +70,7 @@ struct pci_dev *__wrap_pcidev_init(void *devs, int bar)
uintptr_t __wrap_pcidev_readbar(void *dev, int bar)
{
LOG_ME;
- return MOCK_HANDLE;
+ return NON_ZERO;
}
void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data)
@@ -85,7 +89,7 @@ int __wrap_open(const char *pathname, int flags)
LOG_ME;
if (current_io && current_io->open)
return current_io->open(current_io->state, pathname, flags);
- return MOCK_HANDLE;
+ return NON_ZERO;
}
int __wrap_open64(const char *pathname, int flags)
@@ -93,7 +97,7 @@ int __wrap_open64(const char *pathname, int flags)
LOG_ME;
if (current_io && current_io->open)
return current_io->open(current_io->state, pathname, flags);
- return MOCK_HANDLE;
+ return NON_ZERO;
}
int __wrap_ioctl(int fd, unsigned long int request, ...)
@@ -107,7 +111,7 @@ int __wrap_ioctl(int fd, unsigned long int request, ...)
va_end(args);
return out;
}
- return MOCK_HANDLE;
+ return 0;
}
int __wrap_write(int fd, const void *buf, size_t sz)
@@ -131,7 +135,7 @@ FILE *__wrap_fopen(const char *pathname, const char *mode)
LOG_ME;
if (current_io && current_io->fopen)
return current_io->fopen(current_io->state, pathname, mode);
- return (void *)MOCK_HANDLE;
+ return not_null();
}
FILE *__wrap_fopen64(const char *pathname, const char *mode)
@@ -139,7 +143,7 @@ FILE *__wrap_fopen64(const char *pathname, const char *mode)
LOG_ME;
if (current_io && current_io->fopen)
return current_io->fopen(current_io->state, pathname, mode);
- return (void *)MOCK_HANDLE;
+ return not_null();
}
int __wrap_stat(const char *path, void *buf)
@@ -197,7 +201,7 @@ int __wrap_fflush(FILE *fp)
int __wrap_fileno(FILE *fp)
{
LOG_ME;
- return MOCK_HANDLE;
+ return NON_ZERO;
}
int __wrap_fsync(int fd)
@@ -292,7 +296,7 @@ void *__wrap_usb_dev_get_by_vid_pid_number(
libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num)
{
LOG_ME;
- return (void *)MOCK_HANDLE;
+ return not_null();
}
int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config)