Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
tests: Add wrap for libusb_init and use it in dediprog test

Missing wrap for libusb_init has been discovered while working
on the test for raiden_debug_spi. Both dediprog (existing test) and
raiden_debug_spi (new test, see later in this chain) are using
libusb_init, so it definitely needs to be wrapped and added to io_mock.

Why tests worked before, without the wrap: my understanding is that
real libusb_init was called for dediprog test? Given that tests
definitely should not call any real libusb functions, wrap is needed.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I51c9cb96db1afb3298f4d098df96509d3cb3c046
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57917
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
---
M tests/init_shutdown.c
M tests/io_mock.h
M tests/libusb_wraps.c
M tests/meson.build
4 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 03e888f..e64e58c 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -54,6 +54,13 @@
#endif
}

+
+int dediprog_libusb_init(void *state, libusb_context **ctx)
+{
+ *ctx = not_null();
+ return 0;
+}
+
int dediprog_libusb_control_transfer(void *state,
libusb_device_handle *devh,
uint8_t bmRequestType,
@@ -75,6 +82,7 @@
{
#if CONFIG_DEDIPROG == 1
const struct io_mock dediprog_io = {
+ .libusb_init = dediprog_libusb_init,
.libusb_control_transfer = dediprog_libusb_control_transfer,
};

diff --git a/tests/io_mock.h b/tests/io_mock.h
index 7c235d8..0bee6ca 100644
--- a/tests/io_mock.h
+++ b/tests/io_mock.h
@@ -70,6 +70,7 @@
unsigned int (*inl)(void *state, unsigned short port);

/* USB I/O */
+ int (*libusb_init)(void *state, libusb_context **ctx);
int (*libusb_control_transfer)(void *state,
libusb_device_handle *devh,
uint8_t bmRequestType,
diff --git a/tests/libusb_wraps.c b/tests/libusb_wraps.c
index 94ef652..978108e 100644
--- a/tests/libusb_wraps.c
+++ b/tests/libusb_wraps.c
@@ -23,6 +23,14 @@
return not_null();
}

+int __wrap_libusb_init(libusb_context **ctx)
+{
+ LOG_ME;
+ if (get_io() && get_io()->libusb_init)
+ return get_io()->libusb_init(get_io()->state, ctx);
+ return 0;
+}
+
int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config)
{
LOG_ME;
diff --git a/tests/meson.build b/tests/meson.build
index c55c5d2..30b1e78 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -64,6 +64,7 @@
'-Wl,--wrap=test_outl',
'-Wl,--wrap=test_inl',
'-Wl,--wrap=usb_dev_get_by_vid_pid_number',
+ '-Wl,--wrap=libusb_init',
'-Wl,--wrap=libusb_set_configuration',
'-Wl,--wrap=libusb_claim_interface',
'-Wl,--wrap=libusb_control_transfer',

4 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.

To view, visit change 57917. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I51c9cb96db1afb3298f4d098df96509d3cb3c046
Gerrit-Change-Number: 57917
Gerrit-PatchSet: 6
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged