From 869f3f7b2cf0864e193a198f0423919fedde7765 Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Fri, 2 Sep 2022 17:30:00 +1000 Subject: 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. BUG=b:237606255 TEST=ninja test tests pass on two environments: 1) FreeBSD 13.1-RELEASE-p2 GENERIC amd64 2) Debian 5.17.11 x86_64 GNU/Linux Change-Id: I3789ea9107a4cf8033cf59bb96d3c82aa58de026 TICKET: https://ticket.coreboot.org/issues/411 Signed-off-by: Anastasia Klimchuk Reviewed-on: https://review.coreboot.org/c/flashrom/+/67312 Tested-by: build bot (Jenkins) Reviewed-by: Thomas Heijligen Reviewed-by: Peter Marheine --- tests/tests.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/tests.c b/tests/tests.c index 8e3fdde0c..7f20069f9 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -370,6 +370,17 @@ int main(int argc, char *argv[]) { int ret = 0; +#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 + if (argc > 1) cmocka_set_test_filter(argv[1]); -- cgit v1.2.3