Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/74157 )
Change subject: tests: Emulate multithreading environment for unit tests
......................................................................
tests: Emulate multithreading environment for unit tests
The main purpose of this patch is to run unit tests on BSD family
of OSes. The root cause is `fileno` syscall which is a macro that
can be expanded to either a function call (for multi-threaded
environment) or to inline code (for single-threaded environment).
Said inline code accesses private field of file descriptor, and
this construction is impossible to mock in unit tests. Multi-
threaded environment has `fileno` as a function, which can be
mocked in unit tests.
On other OSes the patch just creates a thread which is doing nothing.
We avoid adding pre-processor conditionals since the cost is small.
Tested on
FreeBSD 13.1-RELEASE-p6 GENERIC amd64
NetBSD 9.2 (GENERIC) amd64
OpenBSD 7.2 GENERIC#7 amd64
DragonFly v6.4.0-RELEASE x86_64
Ubuntu 22.04.1 x86_64
Change-Id: I3d65c125183e60037ad07b9d54b8fffdece5a4e8
Signed-off-by: Anastasia Klimchuk <aklm(a)chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/74157
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Peter Marheine <pmarheine(a)chromium.org>
Reviewed-by: Thomas Heijligen <src(a)posteo.de>
---
M tests/meson.build
M tests/tests.c
2 files changed, 54 insertions(+), 12 deletions(-)
Approvals:
build bot (Jenkins): Verified
Thomas Heijligen: Looks good to me, approved
Peter Marheine: Looks good to me, approved
diff --git a/tests/meson.build b/tests/meson.build
index df866d7..94f60e2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -113,6 +113,8 @@
'-Wl,--gc-sections',
]
+threads_dep = dependency('threads')
+
flashrom_tests = executable('flashrom_unit_tests',
test_srcs,
c_args : [
@@ -123,7 +125,7 @@
],
export_dynamic : true,
link_args : mocks + link_args,
- dependencies : [cmocka_dep, flashrom_test_dep],
+ dependencies : [cmocka_dep, flashrom_test_dep, threads_dep],
)
test('cmocka test flashrom', flashrom_tests)
diff --git a/tests/tests.c b/tests/tests.c
index 159b79f..8b4ad03 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <pthread.h>
void *not_null(void)
{
@@ -385,26 +386,32 @@
return 0;
}
+static void *doing_nothing(void *vargp) {
+ return NULL;
+}
+
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]);
cmocka_set_message_output(CM_OUTPUT_STDOUT);
+ /*
+ * Creating new thread which is doing nothing, to trigger __isthreaded being 1.
+ * This is a workaround for BSD family. In multi-threaded environment fileno
+ * macro is expanded into a function which is possible to mock in unit tests.
+ * Without this workaround, on a single-thread environment, fileno macro is
+ * expanded into an inline access of a private field of a file descriptor,
+ * which is impossible to mock.
+ *
+ * In other OSes this is just creating a thread which is doing nothing.
+ */
+ pthread_t thread_id;
+ pthread_create(&thread_id, NULL, doing_nothing, NULL);
+
const struct CMUnitTest helpers_tests[] = {
cmocka_unit_test(address_to_bits_test_success),
cmocka_unit_test(bitcount_test_success),
--
To view, visit https://review.coreboot.org/c/flashrom/+/74157
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3d65c125183e60037ad07b9d54b8fffdece5a4e8
Gerrit-Change-Number: 74157
Gerrit-PatchSet: 7
Gerrit-Owner: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Peter Marheine <pmarheine(a)chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Idwer Vollering <vidwer(a)gmail.com>
Gerrit-MessageType: merged
Attention is currently required from: Anastasia Klimchuk, Alexander Goncharov.
Miklós Márton has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/72160 )
Change subject: ni845x_spi: refactor singleton states into reentrant pattern
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS3:
> Oh! do you think it was broken by the patch, or at some point earlier? […]
No it got broken earlier. Or maybe something on the mingw make had been changed, it looks that it has issues with the spaces in the linker/include path (which is C:\Program Files\-...)
I think I am going to remove the auto detection at all (still keeping it optional), as I doubt that NI will ever change the installation path/method and keep the current path "hardcoded".
--
To view, visit https://review.coreboot.org/c/flashrom/+/72160
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I45fcb8e20582cb0c532c4a9f0c78543a25f8d484
Gerrit-Change-Number: 72160
Gerrit-PatchSet: 3
Gerrit-Owner: Alexander Goncharov <chat(a)joursoir.net>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Attention: Alexander Goncharov <chat(a)joursoir.net>
Gerrit-Comment-Date: Tue, 25 Apr 2023 13:24:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Miklós Márton <martonmiklosqdev(a)gmail.com>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Miklós Márton, Alexander Goncharov.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/72160 )
Change subject: ni845x_spi: refactor singleton states into reentrant pattern
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS3:
> Well I need to make a few patches before testing it: the NI-845x detection looks to be broken and so […]
Oh! do you think it was broken by the patch, or at some point earlier?
Also, you said you made few patches to fix the situation: probably send them to Gerrit? can I help with anything? Thank you so much!
--
To view, visit https://review.coreboot.org/c/flashrom/+/72160
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I45fcb8e20582cb0c532c4a9f0c78543a25f8d484
Gerrit-Change-Number: 72160
Gerrit-PatchSet: 3
Gerrit-Owner: Alexander Goncharov <chat(a)joursoir.net>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Miklós Márton <martonmiklosqdev(a)gmail.com>
Gerrit-Attention: Alexander Goncharov <chat(a)joursoir.net>
Gerrit-Comment-Date: Tue, 25 Apr 2023 13:08:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Miklós Márton <martonmiklosqdev(a)gmail.com>
Comment-In-Reply-To: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-MessageType: comment
Attention is currently required from: Thomas Heijligen, Angel Pons, Steve Markgraf.
Anastasia Klimchuk has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/71801 )
Change subject: programmer: Add bitbanging programmer driver for Linux libgpiod
......................................................................
Patch Set 6:
(1 comment)
Patchset:
PS6:
Hello Steve! We have some comments on the patch, but it looks like maybe you don't have much time at the moment. I was wondering how we can complete this work, I really don't want your work to be lost.
Do you have any time to resolve the comments?
If not, we can wait for you to come back and resolve later.
Another option can be: someone else (maybe me :D ) resolves the comments and uploads new patchset. Would you be able to do the final testing on the hardware in this case?
Thank you!
--
To view, visit https://review.coreboot.org/c/flashrom/+/71801
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Icad3eb7764f28feaea51bda3a7893da724c86d06
Gerrit-Change-Number: 71801
Gerrit-PatchSet: 6
Gerrit-Owner: Steve Markgraf <steve(a)steve-m.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Attention: Steve Markgraf <steve(a)steve-m.de>
Gerrit-Comment-Date: Mon, 24 Apr 2023 13:48:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment