Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved
tests: Extract libusb wraps into separate file

In preparation for adding more tests with lots of libusb wraps,
existing wraps are extracted into separate file.

BUG=b:181803212
TEST=builds and ninja test

Change-Id: I17c1cc0189fcb742a99ad1b0fd615ab95504a74a
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/57916
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
---
A tests/libusb_wraps.c
M tests/meson.build
M tests/tests.c
3 files changed, 64 insertions(+), 46 deletions(-)

diff --git a/tests/libusb_wraps.c b/tests/libusb_wraps.c
new file mode 100644
index 0000000..94ef652
--- /dev/null
+++ b/tests/libusb_wraps.c
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright 2021 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <include/test.h>
+#include "io_mock.h"
+
+void *__wrap_usb_dev_get_by_vid_pid_number(
+ libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num)
+{
+ LOG_ME;
+ return not_null();
+}
+
+int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config)
+{
+ LOG_ME;
+ return 0;
+}
+
+int __wrap_libusb_claim_interface(libusb_device_handle *devh, int interface_number)
+{
+ LOG_ME;
+ return 0;
+}
+
+int __wrap_libusb_control_transfer(libusb_device_handle *devh, uint8_t bmRequestType,
+ uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data,
+ uint16_t wLength, unsigned int timeout)
+{
+ LOG_ME;
+ if (get_io() && get_io()->libusb_control_transfer)
+ return get_io()->libusb_control_transfer(get_io()->state,
+ devh, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);
+ return 0;
+}
+
+int __wrap_libusb_release_interface(libusb_device_handle *devh, int interface_number)
+{
+ LOG_ME;
+ return 0;
+}
+
+void __wrap_libusb_close(libusb_device_handle *devh)
+{
+ LOG_ME;
+}
+
+void __wrap_libusb_exit(libusb_context *ctx)
+{
+ LOG_ME;
+}
diff --git a/tests/meson.build b/tests/meson.build
index df56358..c55c5d2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -16,6 +16,7 @@
srcs = [
'io_mock.c',
'tests.c',
+ 'libusb_wraps.c',
'helpers.c',
'flashrom.c',
'spi25.c',
diff --git a/tests/tests.c b/tests/tests.c
index afba5f3..3eb3129 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -282,52 +282,6 @@
return 0;
}

-void *__wrap_usb_dev_get_by_vid_pid_number(
- libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num)
-{
- LOG_ME;
- return not_null();
-}
-
-int __wrap_libusb_set_configuration(libusb_device_handle *devh, int config)
-{
- LOG_ME;
- return 0;
-}
-
-int __wrap_libusb_claim_interface(libusb_device_handle *devh, int interface_number)
-{
- LOG_ME;
- return 0;
-}
-
-int __wrap_libusb_control_transfer(libusb_device_handle *devh, uint8_t bmRequestType,
- uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data,
- uint16_t wLength, unsigned int timeout)
-{
- LOG_ME;
- if (get_io() && get_io()->libusb_control_transfer)
- return get_io()->libusb_control_transfer(get_io()->state,
- devh, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);
- return 0;
-}
-
-int __wrap_libusb_release_interface(libusb_device_handle *devh, int interface_number)
-{
- LOG_ME;
- return 0;
-}
-
-void __wrap_libusb_close(libusb_device_handle *devh)
-{
- LOG_ME;
-}
-
-void __wrap_libusb_exit(libusb_context *ctx)
-{
- LOG_ME;
-}
-
int main(void)
{
int ret = 0;

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

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I17c1cc0189fcb742a99ad1b0fd615ab95504a74a
Gerrit-Change-Number: 57916
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