c/simple: add create-thread test
This commit is contained in:
parent
06e246b77f
commit
39d18827f5
@ -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],
|
||||
|
35
tests/c/simple/create-thread.c
Normal file
35
tests/c/simple/create-thread.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user