diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/io_mock.h | 7 | ||||
-rw-r--r-- | tests/tests.c | 37 | ||||
-rw-r--r-- | tests/tests.h | 2 | ||||
-rw-r--r-- | tests/wraps.h | 6 |
4 files changed, 35 insertions, 17 deletions
diff --git a/tests/io_mock.h b/tests/io_mock.h index 935e84b2..020794af 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -49,11 +49,6 @@ struct pci_dev { unsigned int device_id; }; -/* POSIX open() flags, avoiding dependency on fcntl.h */ -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 - /* Linux I2C interface constants, avoiding linux/i2c-dev.h */ #define I2C_SLAVE 0x0703 @@ -107,7 +102,7 @@ struct io_mock { int (*libusb_handle_events_timeout)(void *state, libusb_context *ctx, struct timeval *tv); /* POSIX File I/O */ - int (*iom_open)(void *state, const char *pathname, int flags); + int (*iom_open)(void *state, const char *pathname, int flags, mode_t mode); int (*iom_ioctl)(void *state, int fd, unsigned long request, va_list args); int (*iom_read)(void *state, int fd, void *buf, size_t sz); int (*iom_write)(void *state, int fd, const void *buf, size_t sz); diff --git a/tests/tests.c b/tests/tests.c index abbac643..b517898f 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -75,10 +75,10 @@ uint8_t __wrap_sio_read(uint16_t port, uint8_t reg) return (uint8_t)mock(); } -static int mock_open(const char *pathname, int flags) +static int mock_open(const char *pathname, int flags, mode_t mode) { if (get_io() && get_io()->iom_open) - return get_io()->iom_open(get_io()->state, pathname, flags); + return get_io()->iom_open(get_io()->state, pathname, flags, mode); if (get_io() && get_io()->fallback_open_state) { struct io_mock_fallback_open_state *io_state; @@ -96,22 +96,43 @@ static int mock_open(const char *pathname, int flags) return MOCK_FD; } -int __wrap_open(const char *pathname, int flags) +int __wrap_open(const char *pathname, int flags, ...) { LOG_ME; - return mock_open(pathname, flags); + mode_t mode = 0; + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + return mock_open(pathname, flags, mode); } -int __wrap_open64(const char *pathname, int flags) +int __wrap_open64(const char *pathname, int flags, ...) { LOG_ME; - return mock_open(pathname, flags); + mode_t mode = 0; + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + return mock_open(pathname, flags, mode); } -int __wrap___open64_2(const char *pathname, int flags) +int __wrap___open64_2(const char *pathname, int flags, ...) { LOG_ME; - return mock_open(pathname, flags); + mode_t mode = 0; + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + return mock_open(pathname, flags, mode); } int __wrap_ioctl(int fd, unsigned long int request, ...) diff --git a/tests/tests.h b/tests/tests.h index b36ac70d..6a12fdb0 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -16,6 +16,8 @@ #ifndef TESTS_H #define TESTS_H +#include <fcntl.h> + /* helpers.c */ void address_to_bits_test_success(void **state); void bitcount_test_success(void **state); diff --git a/tests/wraps.h b/tests/wraps.h index f97eaba4..e224d79b 100644 --- a/tests/wraps.h +++ b/tests/wraps.h @@ -28,9 +28,9 @@ struct pci_dev *__wrap_pcidev_init(const struct programmer_cfg *cfg, void *devs, uintptr_t __wrap_pcidev_readbar(void *dev, int bar); void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data); uint8_t __wrap_sio_read(uint16_t port, uint8_t reg); -int __wrap_open(const char *pathname, int flags); -int __wrap_open64(const char *pathname, int flags); -int __wrap___open64_2(const char *pathname, int flags); +int __wrap_open(const char *pathname, int flags, ...); +int __wrap_open64(const char *pathname, int flags, ...); +int __wrap___open64_2(const char *pathname, int flags, ...); int __wrap_ioctl(int fd, unsigned long int request, ...); int __wrap_write(int fd, const void *buf, size_t sz); int __wrap_read(int fd, void *buf, size_t sz); |