pthread tests and assert header bugfix
This commit is contained in:
parent
87e3cde79b
commit
9460089573
@ -194,6 +194,7 @@ if env["BOOTDISK"] == "1":
|
|||||||
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
|
Depends(bootdisk, "#build/sbin/ifconfig/ifconfig")
|
||||||
Depends(bootdisk, "#build/sbin/init/init")
|
Depends(bootdisk, "#build/sbin/init/init")
|
||||||
Depends(bootdisk, "#build/sys/castor")
|
Depends(bootdisk, "#build/sys/castor")
|
||||||
|
Depends(bootdisk, "#build/tests/pthreadtest")
|
||||||
Depends(bootdisk, "#build/tests/threadtest")
|
Depends(bootdisk, "#build/tests/threadtest")
|
||||||
env.Alias('bootdisk', '#build/bootdisk.img')
|
env.Alias('bootdisk', '#build/bootdisk.img')
|
||||||
env.Install('$PREFIX/','#build/bootdisk.img')
|
env.Install('$PREFIX/','#build/bootdisk.img')
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
#define assert(_expr)
|
#define assert(_expr) \
|
||||||
|
if (!(_expr)) { \
|
||||||
|
__assert(__func__, __FILE__, __LINE__, #_expr); \
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define assert(_expr) \
|
#define assert(_expr)
|
||||||
if (e) { \
|
|
||||||
__assert(__func__, __FILE__, __LINE__, #e); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ DIR /
|
|||||||
FILE init build/sbin/init/init
|
FILE init build/sbin/init/init
|
||||||
END
|
END
|
||||||
DIR tests
|
DIR tests
|
||||||
|
FILE pthreadtest build/tests/pthreadtest
|
||||||
FILE threadtest build/tests/threadtest
|
FILE threadtest build/tests/threadtest
|
||||||
END
|
END
|
||||||
FILE LICENSE LICENSE
|
FILE LICENSE LICENSE
|
||||||
|
@ -10,4 +10,5 @@ test_env.Append(CPPPATH = ['#build/include'])
|
|||||||
test_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
|
test_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
|
||||||
|
|
||||||
test_env.Program("threadtest", ["threadtest.c"])
|
test_env.Program("threadtest", ["threadtest.c"])
|
||||||
|
test_env.Program("pthreadtest", ["pthreadtest.c"])
|
||||||
|
|
||||||
|
48
tests/pthreadtest.c
Normal file
48
tests/pthreadtest.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user