From 946008957307b7e7491fc7a45720984c6b082fd0 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 1 Feb 2015 23:56:45 -0800 Subject: [PATCH] pthread tests and assert header bugfix --- SConstruct | 1 + include/assert.h | 10 ++++---- release/bootdisk.manifest | 1 + tests/SConscript | 1 + tests/pthreadtest.c | 48 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tests/pthreadtest.c diff --git a/SConstruct b/SConstruct index 0f202ef..b69d412 100644 --- a/SConstruct +++ b/SConstruct @@ -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') diff --git a/include/assert.h b/include/assert.h index 8146eae..7ce90bb 100644 --- a/include/assert.h +++ b/include/assert.h @@ -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 diff --git a/release/bootdisk.manifest b/release/bootdisk.manifest index a8e687d..04d2346 100644 --- a/release/bootdisk.manifest +++ b/release/bootdisk.manifest @@ -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 diff --git a/tests/SConscript b/tests/SConscript index a73c457..ad064d4 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -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"]) diff --git a/tests/pthreadtest.c b/tests/pthreadtest.c new file mode 100644 index 0000000..fbca42c --- /dev/null +++ b/tests/pthreadtest.c @@ -0,0 +1,48 @@ + +#include +#include +#include +#include + +#include + +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; +} +