1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

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
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69873
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Alexander Goncharov 2022-11-21 14:38:41 +04:00 committed by Anastasia Klimchuk
parent 571a9ac832
commit 224ce81687
2 changed files with 12 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}