From 39d18827f5b8fcc385cb0c5d6fd534794e52ca71 Mon Sep 17 00:00:00 2001 From: Denis Drakhnia Date: Sat, 13 Jan 2024 08:49:00 +0200 Subject: [PATCH] c/simple: add create-thread test --- tests/c/meson.build | 5 +++++ tests/c/simple/create-thread.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/c/simple/create-thread.c diff --git a/tests/c/meson.build b/tests/c/meson.build index 02b1901..6d5743f 100644 --- a/tests/c/meson.build +++ b/tests/c/meson.build @@ -3,6 +3,7 @@ inc_dir = include_directories('include') asm_tests = { 'simple': { 'hello': {}, + 'create-thread': { 'link_args': ['-lpthread'] }, }, } @@ -18,6 +19,10 @@ foreach suite, tests : asm_tests exe_args += { 'c_args': opts['c_args'] } endif + if 'link_args' in opts + exe_args += { 'link_args': opts['link_args'] } + endif + test_args = { 'timeout': 30, 'suite': [suite], diff --git a/tests/c/simple/create-thread.c b/tests/c/simple/create-thread.c new file mode 100644 index 0000000..317d935 --- /dev/null +++ b/tests/c/simple/create-thread.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +typedef struct { + uint32_t x; +} args_t; + +void *thread_entry(void *arg) { + args_t *args = (args_t *) arg; + args->x = 0xdeadbeef; + return NULL; +} + +int main(int argc, char *argv[]) { + pthread_t th; + args_t args = { 0 }; + int err; + + err = pthread_create(&th, NULL, thread_entry, (void *) &args); + if (err != 0) { + fprintf(stderr, "error: pthread_create %s\n", strerror(err)); + exit(EXIT_FAILURE); + } + + err = pthread_join(th, NULL); + if (err != 0) { + fprintf(stderr, "error: pthread_join %s\n", strerror(err)); + exit(EXIT_FAILURE); + } + + return args.x == 0xdeadbeef ? EXIT_SUCCESS : EXIT_FAILURE; +}