Anastasia Klimchuk has uploaded this change for review.

View Change

[WIP] Emulate multithreading env for unit tests on OpenBSD

This patch produces lots of compile errors in pthread.h

Change-Id: I3d65c125183e60037ad07b9d54b8fffdece5a4e8
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
---
M tests/meson.build
M tests/tests.c
2 files changed, 33 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/57/74157/1
diff --git a/tests/meson.build b/tests/meson.build
index df866d7..d8880f8 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -111,6 +111,7 @@
'-Wl,--wrap=libusb_handle_events_timeout',
'-Wl,--wrap=libusb_exit',
'-Wl,--gc-sections',
+ '-lpthread',
]

flashrom_tests = executable('flashrom_unit_tests',
@@ -120,6 +121,7 @@
'-ffunction-sections',
'-fdata-sections',
'-U_FORTIFY_SOURCE',
+ '-Dpthread',
],
export_dynamic : true,
link_args : mocks + link_args,
diff --git a/tests/tests.c b/tests/tests.c
index d296a98..240ad21 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -20,8 +20,11 @@
#include "io_real.h"

#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <stdint.h>
+#include <sys/types.h>
+#include <pthread.h>

void *not_null(void)
{
@@ -385,6 +388,13 @@
return 0;
}

+#if defined(__OpenBSD__)
+static void *doing_nothing(void *vargp) {
+ printf("I am busy multithreading\n");
+ return NULL;
+}
+#endif
+
int main(int argc, char *argv[])
{
int ret = 0;
@@ -405,6 +415,15 @@

cmocka_set_message_output(CM_OUTPUT_STDOUT);

+#if defined(__OpenBSD__)
+ /*
+ * Creating new thread which is doing nothing, to trigger __isthreaded being 1.
+ * This is a workaround for OpenBSD.
+ */
+ pthread_t thread_id;
+ pthread_create(&thread_id, NULL, doing_nothing, NULL);
+#endif
+
const struct CMUnitTest helpers_tests[] = {
cmocka_unit_test(address_to_bits_test_success),
cmocka_unit_test(bitcount_test_success),

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3d65c125183e60037ad07b9d54b8fffdece5a4e8
Gerrit-Change-Number: 74157
Gerrit-PatchSet: 1
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-MessageType: newchange