diff options
author | Anastasia Klimchuk <aklm@chromium.org> | 2021-06-30 09:26:59 +1000 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2021-07-19 03:23:04 +0000 |
commit | 02bc0b2c53d1c20d676ac11bbfa84f42d2fb070c (patch) | |
tree | 0848b8d031d5973a367b467b0cb0977afb47546b /tests/tests.c | |
parent | 942004398632e8e71e2b29ee476233be569615ba (diff) | |
download | flashrom-02bc0b2c53d1c20d676ac11bbfa84f42d2fb070c.tar.gz flashrom-02bc0b2c53d1c20d676ac11bbfa84f42d2fb070c.tar.bz2 flashrom-02bc0b2c53d1c20d676ac11bbfa84f42d2fb070c.zip |
dediprog: Init-shutdown test for dediprog
This patch adds mocks for libusb functions. To avoid dependency on
libusb.h, libusb symbols for context and device handle are redefined.
Real libusb functions are never called in tests anyway, cmocka wraps
work with this without complaints.
BUG=b:181803212
TEST=builds and ninja test
Change-Id: I38508dfb6d7c24d42522f22fcae0c5e410c5f7ea
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55934
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'tests/tests.c')
-rw-r--r-- | tests/tests.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/tests/tests.c b/tests/tests.c index dcbd5afc..cde696f4 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -22,6 +22,7 @@ /* redefinitions/wrapping */ #define LOG_ME printf("%s is called\n", __func__) +#define MOCK_HANDLE 2021 static const struct io_mock *current_io = NULL; @@ -55,19 +56,19 @@ uint8_t __wrap_sio_read(uint16_t port, uint8_t reg) int __wrap_open(const char *pathname, int flags) { LOG_ME; - return 2021; + return MOCK_HANDLE; } int __wrap_open64(const char *pathname, int flags) { LOG_ME; - return 2021; + return MOCK_HANDLE; } int __wrap_ioctl(int fd, unsigned long int request, ...) { LOG_ME; - return 2021; + return MOCK_HANDLE; } FILE *__wrap_fopen(const char *pathname, const char *mode) @@ -133,6 +134,52 @@ unsigned int __wrap_test_inl(unsigned short port) 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 (void *)MOCK_HANDLE; +} + +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 (current_io && current_io->libusb_control_transfer) + return current_io->libusb_control_transfer(current_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; @@ -172,6 +219,7 @@ int main(void) const struct CMUnitTest init_shutdown_tests[] = { cmocka_unit_test(dummy_init_and_shutdown_test_success), cmocka_unit_test(mec1308_init_and_shutdown_test_success), + cmocka_unit_test(dediprog_init_and_shutdown_test_success), cmocka_unit_test(ene_lpc_init_and_shutdown_test_success), cmocka_unit_test(linux_spi_init_and_shutdown_test_success), }; |