From e0ece4a4bb200ed28859419e5349a38a9b02baf1 Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Wed, 21 Jul 2021 14:53:16 +1000 Subject: tests: Add init-shutdown test for nicrealtek This patch adds a test and mocks for two pci functions that nicreltek is using. Main reason for this is to have at least one test for par master (currently there are none), in preparation for a change like CB:56103 but for par masters. BUG=b:181803212 TEST=ninja test Change-Id: Iaed14fe1d83c8eb45ec185ebd3f1c97cb81941f4 Signed-off-by: Anastasia Klimchuk Reviewed-on: https://review.coreboot.org/c/flashrom/+/56470 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan --- tests/init_shutdown.c | 9 +++++++++ tests/io_mock.h | 5 +++++ tests/meson.build | 2 ++ tests/tests.c | 17 +++++++++++++++++ tests/tests.h | 1 + 5 files changed, 34 insertions(+) diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c index 79918e65..eeea3cc1 100644 --- a/tests/init_shutdown.c +++ b/tests/init_shutdown.c @@ -89,6 +89,15 @@ void mec1308_init_and_shutdown_test_success(void **state) #endif } +void nicrealtek_init_and_shutdown_test_success(void **state) +{ +#if CONFIG_NICREALTEK == 1 + run_lifecycle(state, &programmer_nicrealtek, ""); +#else + skip(); +#endif +} + int dediprog_libusb_control_transfer(void *state, libusb_device_handle *devh, uint8_t bmRequestType, diff --git a/tests/io_mock.h b/tests/io_mock.h index 72d89c50..5cddca0d 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -37,6 +37,11 @@ typedef struct libusb_device_handle libusb_device_handle; struct libusb_context; typedef struct libusb_context libusb_context; +/* Define struct pci_dev to avoid dependency on pci.h */ +struct pci_dev { + unsigned int device_id; +}; + struct io_mock { void *state; diff --git a/tests/meson.build b/tests/meson.build index 5776862d..9fb86c71 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -26,6 +26,8 @@ mocks = [ '-Wl,--wrap=strdup', '-Wl,--wrap=physunmap', '-Wl,--wrap=physmap', + '-Wl,--wrap=pcidev_init', + '-Wl,--wrap=pcidev_readbar', '-Wl,--wrap=spi_send_command', '-Wl,--wrap=sio_write', '-Wl,--wrap=sio_read', diff --git a/tests/tests.c b/tests/tests.c index 00c987cd..ece3e8a5 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -53,6 +53,22 @@ void *__wrap_physmap(const char *descr, uintptr_t phys_addr, size_t len) return NULL; } +struct pci_dev mock_pci_dev = { + .device_id = MOCK_HANDLE, +}; + +struct pci_dev *__wrap_pcidev_init(void *devs, int bar) +{ + LOG_ME; + return &mock_pci_dev; +} + +uintptr_t __wrap_pcidev_readbar(void *dev, int bar) +{ + LOG_ME; + return MOCK_HANDLE; +} + void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data) { LOG_ME; @@ -230,6 +246,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(nicrealtek_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 14cfee0a..9eacf13d 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 nicrealtek_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); -- cgit v1.2.3