1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

tests: Make libusb conditional dependency for unit tests

Unit tests had an unconditional dependency on libusb and this was
a) strictly speaking not needed, b) blocking one build system effort.
This patch is a temporary solution to unblock one build system effort,
specifically CB:63724. It creates a condition so that libusb is only
included when it is required, not always.

This workaround is based on the fact that at the moment only
2 lifecycle unit tests are using libusb symbols: dediprog and
raiden_debug.

BUG=b:237606255
TEST=the following scenarios run tests successfully

1) dediprog and raiden_debug programmers enabled, libusb.h present
result:
all test run and pass

2) dediprog disabled, libusb.h present
result:
dediprog test skipped, all other tests run and pass

3) dediprog and raiden_debug both disabled,
libusb.h changed to libusbabcd.h
result:
dediprog and raiden_debug tests are skipped,
all other tests run and pass

Change-Id: Iec8a1826951fd6ae586e90fde1a55170e7de41a8
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/65627
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Reviewed-by: Thomas Heijligen <src@posteo.de>
This commit is contained in:
Anastasia Klimchuk 2022-07-04 18:38:41 +10:00
parent 94efa44542
commit 06e73a8e61
3 changed files with 64 additions and 6 deletions

View File

@ -34,11 +34,9 @@
/* Required for `FILE *` */ /* Required for `FILE *` */
#include <stdio.h> #include <stdio.h>
/* #include <stdint.h>
* Explicitly including the header because some tests are using libusb structs
* in depth, opaque symbols are not sufficient. #include "usb_unittests.h"
*/
#include <libusb.h>
/* Address value needs fit into uint8_t. */ /* Address value needs fit into uint8_t. */
#define USB_DEVICE_ADDRESS 19 #define USB_DEVICE_ADDRESS 19

View File

@ -16,7 +16,7 @@
#ifndef LIBUSB_WRAPS_H #ifndef LIBUSB_WRAPS_H
#define LIBUSB_WRAPS_H #define LIBUSB_WRAPS_H
#include <libusb.h> #include "usb_unittests.h"
void *__wrap_usb_dev_get_by_vid_pid_number( void *__wrap_usb_dev_get_by_vid_pid_number(
libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num); libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);

60
tests/usb_unittests.h Normal file
View File

@ -0,0 +1,60 @@
/*
* This file is part of the flashrom project.
*
* Copyright 2022 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.
*/
/*
* This header provides a temporary solution to unblock build system
* work. The main goal is to remove unconditional dependency on libusb
* for unit tests. The dependency is still present, but now it is present
* only when it is needed and only when the header is present in the env.
*
* The contents of the file will be modified in a very near future.
*/
#ifndef _USB_UNITTESTS_H_
#define _USB_UNITTESTS_H_
#if CONFIG_RAIDEN_DEBUG_SPI == 1 || CONFIG_DEDIPROG == 1
#include <libusb.h>
#else
struct libusb_context;
typedef struct libusb_context libusb_context;
struct libusb_device_handle;
typedef struct libusb_device_handle libusb_device_handle;
struct libusb_device_descriptor;
typedef struct libusb_device_descriptor libusb_device_descriptor;
struct libusb_device;
typedef struct libusb_device libusb_device;
struct libusb_config_descriptor;
typedef struct libusb_config_descriptor libusb_config_descriptor;
struct libusb_interface;
typedef struct libusb_interface libusb_interface;
struct libusb_interface_descriptor;
typedef struct libusb_interface_descriptor libusb_interface_descriptor;
struct libusb_endpoint_descriptor;
typedef struct libusb_endpoint_descriptor libusb_endpoint_descriptor;
#endif
#endif /* _USB_UNITTESTS_H_ */