metal-cos/tests/pthreadtest.c

51 lines
920 B
C

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <stdbool.h>
#include <core/mutex.h>
void *
thread_simple(void *arg)
{
printf("thread_simple %p!\n", arg);
return arg;
}
int
main(int argc, const char *argv[])
{
int status;
pthread_t thr;
void *result;
printf("PThread Test\n");
// Simple thread test
printf("simple test\n");
status = pthread_create(&thr, NULL, thread_simple, NULL);
assert(status == 0);
status = pthread_join(thr, &result);
assert(status == 0);
assert(result == NULL);
// Return value test
printf("return value test\n");
status = pthread_create(&thr, NULL, thread_simple, (void *)1);
assert(status == 0);
status = pthread_join(thr, &result);
assert(status == 0);
assert(result == (void *)1);
// Mutex test
printf("Success!\n");
return 0;
}