Alexander Goncharov has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/69873 )
Change subject: tests: add mocks for libusb's asynchronous API ......................................................................
tests: add mocks for libusb's asynchronous API
This patch adds mocks for several libusb functions are introduced in one of the previous commits.
Signed-off-by: Alexander Goncharov chat@joursoir.net Change-Id: I5a316687ab39a112d968eeaedb71f7b4b659d8d5 --- M tests/io_mock.h M tests/libusb_wraps.c 2 files changed, 25 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/73/69873/1
diff --git a/tests/io_mock.h b/tests/io_mock.h index 644da74..3af5de4 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -99,6 +99,10 @@ uint8_t config_index, struct libusb_config_descriptor **); void (*libusb_free_config_descriptor)(void *state, struct libusb_config_descriptor *); + struct libusb_transfer* (*libusb_alloc_transfer)(void *state, int iso_packets); + int (*libusb_submit_transfer)(void *state, struct libusb_transfer *transfer); + void (*libusb_free_transfer)(void *state, struct libusb_transfer *transfer); + 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); diff --git a/tests/libusb_wraps.c b/tests/libusb_wraps.c index a05cbe9..be990a1 100644 --- a/tests/libusb_wraps.c +++ b/tests/libusb_wraps.c @@ -188,23 +188,31 @@ struct libusb_transfer *__wrap_libusb_alloc_transfer(int iso_packets) { LOG_ME; + if (get_io() && get_io()->libusb_alloc_transfer) + return get_io()->libusb_alloc_transfer(get_io()->state, iso_packets); return not_null(); }
int __wrap_libusb_submit_transfer(struct libusb_transfer *transfer) { LOG_ME; + if (get_io() && get_io()->libusb_submit_transfer) + return get_io()->libusb_submit_transfer(get_io()->state, transfer); return 0; }
void __wrap_libusb_free_transfer(struct libusb_transfer *transfer) { LOG_ME; + if (get_io() && get_io()->libusb_free_transfer) + get_io()->libusb_free_transfer(get_io()->state, transfer); }
int __wrap_libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv) { LOG_ME; + if (get_io() && get_io()->libusb_handle_events_timeout) + get_io()->libusb_handle_events_timeout(get_io()->state, ctx, tv); return 0; }