Anastasia Klimchuk has uploaded this change for review.
tests: Add workaround to allow tests mock fileno on FreeBSD
fileno can be a function and a macro in FreeBSD, depending on whether
the environment in multi-threaded or single-threaded. For single
thread, macro is used. Macro is expanded into a inline code which
accesses private field of file descriptor. This is impossible to
mock in tests.
Pretending that environment is multi-threaded makes fileno function
to be called instead of a macro. Function can be mocked for tests.
Change-Id: I3789ea9107a4cf8033cf59bb96d3c82aa58de026
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
---
M tests/chip.c
1 file changed, 35 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/12/67312/1
diff --git a/tests/chip.c b/tests/chip.c
index 6f03172..7b2bd82 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -131,6 +131,17 @@
/* Assignment below normally happens while probing, but this test is not probing. */
flashctx->mst = ®istered_masters[0];
printf("done\n");
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ /*
+ * Pretending to be a multithreaded environment so that `fileno`
+ * is called as a function (and not as a macro).
+ * fileno macro in FreeBSD is expanded into inline access of
+ * private field of file descriptor, which is impossible to mock.
+ * Calling fileno as a function allows the test to mock it.
+ */
+ __isthreaded = 1;
+#endif
}
static void teardown(struct flashrom_layout **layout)
@@ -144,6 +155,11 @@
printf("done\n");
io_mock_register(NULL);
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ /* Restoring the state, see comment in setup_chip. */
+ __isthreaded = 0;
+#endif
}
static const struct flashchip chip_8MiB = {
To view, visit change 67312. To unsubscribe, or for help writing mail filters, visit settings.