From 224ce8168791c5914e4289d700ae15f3f9926c8d Mon Sep 17 00:00:00 2001 From: Alexander Goncharov Date: Mon, 21 Nov 2022 14:38:41 +0400 Subject: 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 Change-Id: I5a316687ab39a112d968eeaedb71f7b4b659d8d5 Reviewed-on: https://review.coreboot.org/c/flashrom/+/69873 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk --- tests/io_mock.h | 4 ++++ tests/libusb_wraps.c | 8 ++++++++ 2 files changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/io_mock.h b/tests/io_mock.h index 644da74a..3af5de47 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -99,6 +99,10 @@ struct io_mock { 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 a05cbe9b..be990a12 100644 --- a/tests/libusb_wraps.c +++ b/tests/libusb_wraps.c @@ -188,23 +188,31 @@ void __wrap_libusb_unref_device(libusb_device *dev) 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; } -- cgit v1.2.3