mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-03 06:53:18 +02:00
tests: Add init-shutdown test for raiden_debug_spi
This patch adds a test for raiden_debug_spi and lots of libusb wraps. libusb.h becomes required for tests to build and run, since new tests are using libusb structs in depth and opaque symbols not sufficient anymore. BUG=b:181803212 TEST=builds and ninja test Change-Id: I880a8637ab02de179df9169c1898230bce4dc1c7 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/57918 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:

committed by
Edward O'Callaghan

parent
421d9133bb
commit
f47ff316ec
@ -54,6 +54,101 @@ void nicrealtek_init_and_shutdown_test_success(void **state)
|
||||
#endif
|
||||
}
|
||||
|
||||
static ssize_t raiden_debug_libusb_get_device_list(void *state, libusb_context *ctx, libusb_device ***list)
|
||||
{
|
||||
*list = calloc(1, sizeof(**list));
|
||||
|
||||
/*
|
||||
* libusb_device is opaque type, it is tossed around between libusb functions but always
|
||||
* stays opaque to the caller.
|
||||
* Given that all libusb functions are mocked in tests, and raiden_debug test is mocking
|
||||
* only one device, we don't need to initialise libusb_device.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void raiden_debug_libusb_free_device_list(void *state, libusb_device **list, int unref_devices)
|
||||
{
|
||||
free(list);
|
||||
}
|
||||
|
||||
static int raiden_debug_libusb_get_device_descriptor(
|
||||
void *state, libusb_device *dev, struct libusb_device_descriptor *desc)
|
||||
{
|
||||
desc->idVendor = 0x18D1; /* GOOGLE_VID */
|
||||
desc->idProduct = 0;
|
||||
desc->bNumConfigurations = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int raiden_debug_libusb_get_config_descriptor(
|
||||
void *state, libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
|
||||
{
|
||||
*config = calloc(1, sizeof(**config));
|
||||
|
||||
struct libusb_endpoint_descriptor *tmp_endpoint = calloc(2, sizeof(*tmp_endpoint));
|
||||
struct libusb_interface_descriptor *tmp_interface_desc = calloc(1, sizeof(*tmp_interface_desc));
|
||||
struct libusb_interface *tmp_interface = calloc(1, sizeof(*tmp_interface));
|
||||
|
||||
/* in endpoint */
|
||||
tmp_endpoint[0].bEndpointAddress = 0x80;
|
||||
tmp_endpoint[0].bmAttributes = 0x2;
|
||||
/* out endpoint */
|
||||
tmp_endpoint[1].bEndpointAddress = 0x0;
|
||||
tmp_endpoint[1].bmAttributes = 0x2;
|
||||
|
||||
tmp_interface_desc->bInterfaceClass = 0xff; /* LIBUSB_CLASS_VENDOR_SPEC */
|
||||
tmp_interface_desc->bInterfaceSubClass = 0x51; /* GOOGLE_RAIDEN_SPI_SUBCLASS */
|
||||
tmp_interface_desc->bInterfaceProtocol = 0x01; /* GOOGLE_RAIDEN_SPI_PROTOCOL_V1 */
|
||||
tmp_interface_desc->bNumEndpoints = 2; /* in_endpoint and out_endpoint */
|
||||
tmp_interface_desc->endpoint = tmp_endpoint;
|
||||
|
||||
tmp_interface->num_altsetting = 1;
|
||||
tmp_interface->altsetting = tmp_interface_desc;
|
||||
|
||||
(*config)->bConfigurationValue = 0;
|
||||
(*config)->bNumInterfaces = 1;
|
||||
(*config)->interface = tmp_interface;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void raiden_debug_libusb_free_config_descriptor(void *state, struct libusb_config_descriptor *config)
|
||||
{
|
||||
free((void *)config->interface->altsetting->endpoint);
|
||||
free((void *)config->interface->altsetting);
|
||||
free((void *)config->interface);
|
||||
free(config);
|
||||
}
|
||||
|
||||
void raiden_debug_init_and_shutdown_test_success(void **state)
|
||||
{
|
||||
#if CONFIG_RAIDEN_DEBUG_SPI == 1
|
||||
const struct io_mock raiden_debug_io = {
|
||||
.libusb_get_device_list = raiden_debug_libusb_get_device_list,
|
||||
.libusb_free_device_list = raiden_debug_libusb_free_device_list,
|
||||
.libusb_get_device_descriptor = raiden_debug_libusb_get_device_descriptor,
|
||||
.libusb_get_config_descriptor = raiden_debug_libusb_get_config_descriptor,
|
||||
.libusb_free_config_descriptor = raiden_debug_libusb_free_config_descriptor,
|
||||
};
|
||||
|
||||
/*
|
||||
* 12 is the length of programmer param string for 3-digit address.
|
||||
* Address can be max 3-digit because it needs to fit into uint8_t.
|
||||
*/
|
||||
char raiden_debug_param[12];
|
||||
snprintf(raiden_debug_param, 12, "address=%d", USB_DEVICE_ADDRESS);
|
||||
|
||||
io_mock_register(&raiden_debug_io);
|
||||
|
||||
run_lifecycle(state, &programmer_raiden_debug_spi, raiden_debug_param);
|
||||
|
||||
io_mock_register(NULL);
|
||||
#else
|
||||
skip();
|
||||
#endif
|
||||
}
|
||||
|
||||
int dediprog_libusb_init(void *state, libusb_context **ctx)
|
||||
{
|
||||
|
Reference in New Issue
Block a user