diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/init_shutdown.c | 34 | ||||
-rw-r--r-- | tests/io_mock.h | 18 | ||||
-rw-r--r-- | tests/meson.build | 7 | ||||
-rw-r--r-- | tests/tests.c | 54 | ||||
-rw-r--r-- | tests/tests.h | 1 |
5 files changed, 111 insertions, 3 deletions
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c index 48448f8c..84699025 100644 --- a/tests/init_shutdown.c +++ b/tests/init_shutdown.c @@ -85,6 +85,40 @@ void mec1308_init_and_shutdown_test_success(void **state) #endif } +int dediprog_libusb_control_transfer(void *state, + 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) +{ + if (bRequest == 0x08 /* dediprog_cmds CMD_READ_PROG_INFO */) { + /* Provide dediprog Device String into data buffer */ + memcpy(data, "SF600 V:7.2.2 ", wLength); + } + return wLength; +} + +void dediprog_init_and_shutdown_test_success(void **state) +{ +#if CONFIG_DEDIPROG == 1 + const struct io_mock dediprog_io = { + .libusb_control_transfer = dediprog_libusb_control_transfer, + }; + + io_mock_register(&dediprog_io); + + run_lifecycle(state, &programmer_dediprog, "voltage=3.5V"); + + io_mock_register(NULL); +#else + skip(); +#endif +} + struct ene_lpc_io_state { unsigned char outb_val; int pause_cmd; diff --git a/tests/io_mock.h b/tests/io_mock.h index 69045a21..72d89c50 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -31,9 +31,16 @@ #ifndef _IO_MOCK_H_ #define _IO_MOCK_H_ +/* Define libusb symbols to avoid dependency on libusb.h */ +struct libusb_device_handle; +typedef struct libusb_device_handle libusb_device_handle; +struct libusb_context; +typedef struct libusb_context libusb_context; + struct io_mock { void *state; + /* Port I/O */ void (*outb)(void *state, unsigned char value, unsigned short port); unsigned char (*inb)(void *state, unsigned short port); @@ -42,6 +49,17 @@ struct io_mock { void (*outl)(void *state, unsigned int value, unsigned short port); unsigned int (*inl)(void *state, unsigned short port); + + /* USB I/O */ + int (*libusb_control_transfer)(void *state, + 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); }; void io_mock_register(const struct io_mock *io); diff --git a/tests/meson.build b/tests/meson.build index 852fd4c1..a18bc455 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -39,6 +39,13 @@ mocks = [ '-Wl,--wrap=test_inw', '-Wl,--wrap=test_outl', '-Wl,--wrap=test_inl', + '-Wl,--wrap=usb_dev_get_by_vid_pid_number', + '-Wl,--wrap=libusb_set_configuration', + '-Wl,--wrap=libusb_claim_interface', + '-Wl,--wrap=libusb_control_transfer', + '-Wl,--wrap=libusb_release_interface', + '-Wl,--wrap=libusb_close', + '-Wl,--wrap=libusb_exit', '-Wl,--gc-sections', ] 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), }; diff --git a/tests/tests.h b/tests/tests.h index da4f4a97..20076959 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -43,6 +43,7 @@ void probe_spi_st95_test_success(void **state); /* spi95.c */ /* init_shutdown.c */ void dummy_init_and_shutdown_test_success(void **state); void mec1308_init_and_shutdown_test_success(void **state); +void dediprog_init_and_shutdown_test_success(void **state); void ene_lpc_init_and_shutdown_test_success(void **state); void linux_spi_init_and_shutdown_test_success(void **state); |