Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/57269 )
Change subject: tests: Add NOT_ZERO and NOT_NULL macros to the header file ......................................................................
tests: Add NOT_ZERO and NOT_NULL macros to the header file
This patch adds two macros into io_mock.h, so that they can be used anywhere in tests. Common usage is to indicate a valid pointer, where it doesn't matter what the pointer is, only matters it is not null. Another case is to indicate a valid file descriptor, where it only matters the descriptor is not zero integer.
New macros replace existing 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.
BUG=b:181803212 TEST=builds and ninja test
Change-Id: I5ad6ee4aa9091447c6c9108c92bf7f6e755fca48 Signed-off-by: Anastasia Klimchuk aklm@chromium.org --- M tests/init_shutdown.c M tests/io_mock.h M tests/tests.c 3 files changed, 11 insertions(+), 11 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/69/57269/1
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c index 3236b22..d1e99cb 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 */ diff --git a/tests/io_mock.h b/tests/io_mock.h index adb5f3b..18eaac8 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -34,6 +34,9 @@ /* Required for `FILE *` */ #include <stdio.h>
+#define NOT_ZERO (0xf000baaa) +#define NOT_NULL ((void *)NOT_ZERO) + /* Define libusb symbols to avoid dependency on libusb.h */ struct libusb_device_handle; typedef struct libusb_device_handle libusb_device_handle; diff --git a/tests/tests.c b/tests/tests.c index 4965fe1..cd50bdf 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -23,7 +23,6 @@
/* redefinitions/wrapping */ #define LOG_ME printf("%s is called\n", __func__) -#define MOCK_HANDLE 2021
static const struct io_mock *current_io = NULL;
@@ -54,7 +53,7 @@ }
struct pci_dev mock_pci_dev = { - .device_id = MOCK_HANDLE, + .device_id = NOT_ZERO, };
struct pci_dev *__wrap_pcidev_init(void *devs, int bar) @@ -66,7 +65,7 @@ uintptr_t __wrap_pcidev_readbar(void *dev, int bar) { LOG_ME; - return MOCK_HANDLE; + return NOT_ZERO; }
void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data) @@ -85,7 +84,7 @@ LOG_ME; if (current_io && current_io->open) return current_io->open(current_io->state, pathname, flags); - return MOCK_HANDLE; + return NOT_ZERO; }
int __wrap_open64(const char *pathname, int flags) @@ -93,7 +92,7 @@ LOG_ME; if (current_io && current_io->open) return current_io->open(current_io->state, pathname, flags); - return MOCK_HANDLE; + return NOT_ZERO; }
int __wrap_ioctl(int fd, unsigned long int request, ...) @@ -107,7 +106,7 @@ va_end(args); return out; } - return MOCK_HANDLE; + return 0; }
int __wrap_write(int fd, const void *buf, size_t sz) @@ -131,7 +130,7 @@ 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 +138,7 @@ 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) @@ -256,7 +255,7 @@ 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)