Edward O'Callaghan submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved
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 <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56470
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
---
M tests/init_shutdown.c
M tests/io_mock.h
M tests/meson.build
M tests/tests.c
M tests/tests.h
5 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c
index 79918e6..eeea3cc 100644
--- a/tests/init_shutdown.c
+++ b/tests/init_shutdown.c
@@ -89,6 +89,15 @@
#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 72d89c5..5cddca0 100644
--- a/tests/io_mock.h
+++ b/tests/io_mock.h
@@ -37,6 +37,11 @@
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 5776862..9fb86c7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,6 +26,8 @@
'-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 00c987c..ece3e8a 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -53,6 +53,22 @@
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 @@
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 14cfee0..9eacf13 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -43,6 +43,7 @@
/* 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);

To view, visit change 56470. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Iaed14fe1d83c8eb45ec185ebd3f1c97cb81941f4
Gerrit-Change-Number: 56470
Gerrit-PatchSet: 3
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged