c/simple: add create-thread test

This commit is contained in:
Denis Drakhnia 2024-01-13 08:49:00 +02:00
parent 06e246b77f
commit 39d18827f5
2 changed files with 40 additions and 0 deletions

View File

@ -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],

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
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;
}