pthread tests and assert header bugfix

This commit is contained in:
Ali Mashtizadeh 2015-02-01 23:56:45 -08:00
parent 87e3cde79b
commit 9460089573
5 changed files with 56 additions and 5 deletions

View File

@ -194,6 +194,7 @@ if env["BOOTDISK"] == "1":
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
Depends(bootdisk, "#build/sbin/init/init")
Depends(bootdisk, "#build/sys/castor")
Depends(bootdisk, "#build/tests/pthreadtest")
Depends(bootdisk, "#build/tests/threadtest")
env.Alias('bootdisk', '#build/bootdisk.img')
env.Install('$PREFIX/','#build/bootdisk.img')

View File

@ -4,14 +4,14 @@
#ifndef NDEBUG
#define assert(_expr)
#define assert(_expr) \
if (!(_expr)) { \
__assert(__func__, __FILE__, __LINE__, #_expr); \
}
#else
#define assert(_expr) \
if (e) { \
__assert(__func__, __FILE__, __LINE__, #e); \
}
#define assert(_expr)
#endif

View File

@ -14,6 +14,7 @@ DIR /
FILE init build/sbin/init/init
END
DIR tests
FILE pthreadtest build/tests/pthreadtest
FILE threadtest build/tests/threadtest
END
FILE LICENSE LICENSE

View File

@ -10,4 +10,5 @@ test_env.Append(CPPPATH = ['#build/include'])
test_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
test_env.Program("threadtest", ["threadtest.c"])
test_env.Program("pthreadtest", ["pthreadtest.c"])

48
tests/pthreadtest.c Normal file
View File

@ -0,0 +1,48 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.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);
printf("status %d\n", status);
assert(status == 0);
status = pthread_join(thr, &result);
printf("status %d\n", status);
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);
printf("Success!\n");
return 0;
}