aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Geiselbrecht <geist@foobox.com>2013-05-18 16:35:31 -0700
committerTravis Geiselbrecht <geist@foobox.com>2013-05-25 11:35:07 -0700
commit5e87468584dbaf6757631c82005e3e656619adcb (patch)
tree89d1888cc5b755650b902b687312d42f8bcd02b2
parentdc37d8b764b9832864025e96610525ba0c642de7 (diff)
downloadlk-5e87468584dbaf6757631c82005e3e656619adcb.tar.gz
[app][thread_tests] add a few tests for the static initializers
-rw-r--r--app/tests/thread_tests.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/app/tests/thread_tests.c b/app/tests/thread_tests.c
index cbd1fb3a..7ebcd525 100644
--- a/app/tests/thread_tests.c
+++ b/app/tests/thread_tests.c
@@ -88,8 +88,12 @@ static int semaphore_consumer()
return 0;
}
-static int semaphore_test()
+static int semaphore_test(void)
{
+ static semaphore_t isem = SEMAPHORE_INITIAL_VALUE(isem, 99);
+ printf("preinitialized sempahore:\n");
+ hexdump(&isem, sizeof(isem));
+
sem_init(&sem, sem_start_value);
mutex_init(&sem_test_mutex);
@@ -122,19 +126,19 @@ static int semaphore_test()
return 0;
}
-
-static volatile int shared = 0;
-static mutex_t m;
-
static int mutex_thread(void *arg)
{
int i;
- const int iterations = 10000;
+ const int iterations = 50000;
+
+ static volatile int shared = 0;
+
+ mutex_t *m = (mutex_t *)arg;
printf("mutex tester thread %p starting up, will go for %d iterations\n", current_thread, iterations);
for (i = 0; i < iterations; i++) {
- mutex_acquire(&m);
+ mutex_acquire(m);
if (shared != 0)
panic("someone else has messed with the shared data\n");
@@ -143,7 +147,7 @@ static int mutex_thread(void *arg)
thread_yield();
shared = 0;
- mutex_release(&m);
+ mutex_release(m);
thread_yield();
}
@@ -182,12 +186,17 @@ static int mutex_zerotimeout_thread(void *arg)
int mutex_test(void)
{
+ static mutex_t imutex = MUTEX_INITIAL_VALUE(imutex);
+ printf("preinitialized mutex:\n");
+ hexdump(&imutex, sizeof(imutex));
+
+ mutex_t m;
mutex_init(&m);
thread_t *threads[5];
for (uint i=0; i < countof(threads); i++) {
- threads[i] = thread_create("mutex tester", &mutex_thread, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
+ threads[i] = thread_create("mutex tester", &mutex_thread, &m, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
thread_resume(threads[i]);
}
@@ -269,6 +278,10 @@ void event_test(void)
{
thread_t *threads[5];
+ static event_t ievent = EVENT_INITIAL_VALUE(ievent, true, 0x1234);
+ printf("preinitialized event:\n");
+ hexdump(&ievent, sizeof(ievent));
+
printf("event tests starting\n");
/* make sure signalling the event wakes up all the threads */