BACKPORT: tests: Rearange CPP guards

This fixes -Werror=unused-function when not all programmer tests are
build.

`run_basic_lifecycle` and `run_probe_lifecycle` need to have a prototype
to not throw a -Werror=unused-function if no programmer needs them.

BUG=none
BRANCH=none
TEST=none

Original-Change-Id: I02880e73996b30df618738e86b8a52126fbe5b3b
Original-Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/64224
Original-Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
(cherry picked from commit f3d09b5997a80a833b4a44ff922a132e8086556f)

Change-Id: I702eac3bdde7fc0d39e498cd7581a832fee81e23
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/3644536
Tested-by: Edward O'Callaghan <quasisec@chromium.org>
Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Evan Benn <evanbenn@chromium.org>
diff --git a/tests/lifecycle.c b/tests/lifecycle.c
index 0738ab1..93ab0aa 100644
--- a/tests/lifecycle.c
+++ b/tests/lifecycle.c
@@ -23,6 +23,9 @@
 #include "programmer.h"
 #include "spi.h"
 
+#define SKIP_TEST(name) \
+	void name (void **state) { skip(); }
+
 static void probe_chip(const struct programmer_entry *prog,
 			struct flashrom_programmer *flashprog,
 			const char *const chip_name)
@@ -65,7 +68,7 @@
 	io_mock_register(NULL);
 }
 
-static void run_basic_lifecycle(void **state, const struct io_mock *io,
+void run_basic_lifecycle(void **state, const struct io_mock *io,
 		const struct programmer_entry *prog, const char *param)
 {
 	/* Basic lifecycle only does init and shutdown,
@@ -73,7 +76,7 @@
 	run_lifecycle(state, io, prog, param, NULL /* chip_name */, NULL /* action */);
 }
 
-static void run_probe_lifecycle(void **state, const struct io_mock *io,
+void run_probe_lifecycle(void **state, const struct io_mock *io,
 		const struct programmer_entry *prog, const char *param, const char *const chip_name)
 {
 	/* Each probe lifecycle should run independently, without cache. */
@@ -81,9 +84,9 @@
 	run_lifecycle(state, io, prog, param, chip_name, &probe_chip);
 }
 
+#if CONFIG_DUMMY == 1
 void dummy_basic_lifecycle_test_success(void **state)
 {
-#if CONFIG_DUMMY == 1
 	static struct io_mock_fallback_open_state dummy_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE },
@@ -93,14 +96,10 @@
 	};
 
 	run_basic_lifecycle(state, &dummy_io, &programmer_dummy, "bus=parallel+lpc+fwh+spi");
-#else
-	skip();
-#endif
 }
 
 void dummy_probe_lifecycle_test_success(void **state)
 {
-#if CONFIG_DUMMY == 1
 	static struct io_mock_fallback_open_state dummy_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE },
@@ -110,14 +109,16 @@
 	};
 
 	run_probe_lifecycle(state, &dummy_io, &programmer_dummy, "bus=spi,emulate=W25Q128FV", "W25Q128.V");
-#else
-	skip();
-#endif
 }
 
+#else
+	SKIP_TEST(dummy_basic_lifecycle_test_success)
+	SKIP_TEST(dummy_probe_lifecycle_test_success)
+#endif /* CONFIG_DUMMY */
+
+#if CONFIG_NICREALTEK == 1
 void nicrealtek_basic_lifecycle_test_success(void **state)
 {
-#if CONFIG_NICREALTEK == 1
 	static struct io_mock_fallback_open_state nicrealtek_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE },
@@ -127,11 +128,12 @@
 	};
 
 	run_basic_lifecycle(state, &nicrealtek_io, &programmer_nicrealtek, "");
-#else
-	skip();
-#endif
 }
+#else
+	SKIP_TEST(nicrealtek_basic_lifecycle_test_success)
+#endif /* CONFIG_NICREALTEK */
 
+#if CONFIG_RAIDEN_DEBUG_SPI == 1
 static ssize_t raiden_debug_libusb_get_device_list(void *state, libusb_context *ctx, libusb_device ***list)
 {
 	*list = calloc(1, sizeof(**list));
@@ -202,7 +204,6 @@
 
 void raiden_debug_basic_lifecycle_test_success(void **state)
 {
-#if CONFIG_RAIDEN_DEBUG_SPI == 1
 	static struct io_mock_fallback_open_state raiden_debug_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE },
@@ -224,10 +225,10 @@
 	snprintf(raiden_debug_param, 12, "address=%d", USB_DEVICE_ADDRESS);
 
 	run_basic_lifecycle(state, &raiden_debug_io, &programmer_raiden_debug_spi, raiden_debug_param);
-#else
-	skip();
-#endif
 }
+#else
+	SKIP_TEST(raiden_debug_basic_lifecycle_test_success)
+#endif /* CONFIG_RAIDEN_DEBUG_SPI */
 
 #if CONFIG_DEDIPROG == 1
 static int dediprog_libusb_init(void *state, libusb_context **ctx)
@@ -252,11 +253,9 @@
 	}
 	return wLength;
 }
-#endif /* CONFIG_DEDIPROG == 1 */
 
 void dediprog_basic_lifecycle_test_success(void **state)
 {
-#if CONFIG_DEDIPROG == 1
 	static struct io_mock_fallback_open_state dediprog_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE },
@@ -268,11 +267,12 @@
 	};
 
 	run_basic_lifecycle(state, &dediprog_io, &programmer_dediprog, "voltage=3.5V");
-#else
-	skip();
-#endif
 }
+#else
+	SKIP_TEST(dediprog_basic_lifecycle_test_success)
+#endif /* CONFIG_DEDIPROG */
 
+#if CONFIG_LINUX_MTD == 1
 struct linux_mtd_io_state {
 	char *fopen_path;
 };
@@ -331,7 +331,6 @@
 
 void linux_mtd_probe_lifecycle_test_success(void **state)
 {
-#if CONFIG_LINUX_MTD == 1
 	struct linux_mtd_io_state linux_mtd_io_state = { NULL };
 	static struct io_mock_fallback_open_state linux_mtd_fallback_open_state = {
 		.noc = 0,
@@ -346,11 +345,12 @@
 	};
 
 	run_probe_lifecycle(state, &linux_mtd_io, &programmer_linux_mtd, "", "Opaque flash chip");
-#else
-	skip();
-#endif
 }
+#else
+	SKIP_TEST(linux_mtd_probe_lifecycle_test_success)
+#endif /* CONFIG_LINUX_MTD */
 
+#if CONFIG_LINUX_SPI == 1
 static int linux_spi_ioctl(void *state, int fd, unsigned long request, va_list args) {
 
 	if (request == SPI_IOC_MESSAGE(2)) { /* ioctl code for read request */
@@ -389,7 +389,6 @@
 	 * Current implementation tests a particular path of the init procedure.
 	 * Specifically, it is reading the buffer size from sysfs.
 	 */
-#if CONFIG_LINUX_SPI == 1
 	static struct io_mock_fallback_open_state linux_spi_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE, "/dev/null", NULL },
@@ -402,11 +401,12 @@
 	};
 
 	run_probe_lifecycle(state, &linux_spi_io, &programmer_linux_spi, "dev=/dev/null", "W25Q128.V");
-#else
-	skip();
-#endif
 }
+#else
+	SKIP_TEST(linux_spi_probe_lifecycle_test_success)
+#endif /* CONFIG_LINUX_SPI */
 
+#if CONFIG_REALTEK_MST_I2C_SPI == 1
 static int realtek_mst_ioctl(void *state, int fd, unsigned long request, va_list args)
 {
 	assert_int_equal(fd, MOCK_FD);
@@ -435,7 +435,6 @@
 
 void realtek_mst_basic_lifecycle_test_success(void **state)
 {
-#if CONFIG_REALTEK_MST_I2C_SPI == 1
 	static struct io_mock_fallback_open_state realtek_mst_fallback_open_state = {
 		.noc = 0,
 		.paths = { LOCK_FILE, "/dev/i2c-254", NULL },
@@ -449,7 +448,7 @@
 	};
 
 	run_basic_lifecycle(state, &realtek_mst_io, &programmer_realtek_mst_i2c_spi, "bus=254,enter-isp=0");
-#else
-	skip();
-#endif /* CONFIG_REALTEK_I2C_SPI */
 }
+#else
+	SKIP_TEST(realtek_mst_basic_lifecycle_test_success)
+#endif /* CONFIG_REALTEK_I2C_SPI */
diff --git a/tests/tests.h b/tests/tests.h
index 68f7781..6fa3c14 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -41,6 +41,13 @@
 void probe_spi_st95_test_success(void **state); /* spi95.c */
 
 /* lifecycle.c */
+struct io_mock;
+struct programmer_entry;
+void run_basic_lifecycle(void **state, const struct io_mock *io,
+		const struct programmer_entry *prog, const char *param);
+void run_probe_lifecycle(void **state, const struct io_mock *io,
+		const struct programmer_entry *prog, const char *param, const char *chip_name);
+
 void dummy_basic_lifecycle_test_success(void **state);
 void dummy_probe_lifecycle_test_success(void **state);
 void nicrealtek_basic_lifecycle_test_success(void **state);