diff options
| author | manuel <manuel@mausz.at> | 2012-05-11 15:10:44 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-05-11 15:10:44 +0200 |
| commit | ac1525683728d7b3ab644e729e6658d435914d85 (patch) | |
| tree | abc1feac44b687e376d98233dc00a8cd295c32c7 /tests | |
| parent | 29adc36b906ae3be5afc577450136e11c12bc0a0 (diff) | |
| download | progos-ac1525683728d7b3ab644e729e6658d435914d85.tar.gz progos-ac1525683728d7b3ab644e729e6658d435914d85.tar.bz2 progos-ac1525683728d7b3ab644e729e6658d435914d85.zip | |
add new test for priority donation with conditions
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/threads/Make.tests | 3 | ||||
| -rw-r--r-- | tests/threads/priority-donate-condvar.c | 97 | ||||
| -rw-r--r-- | tests/threads/priority-donate-condvar.ck | 18 | ||||
| -rw-r--r-- | tests/threads/tests.c | 1 | ||||
| -rw-r--r-- | tests/threads/tests.h | 1 |
5 files changed, 119 insertions, 1 deletions
diff --git a/tests/threads/Make.tests b/tests/threads/Make.tests index dbdfd0c..a72659b 100644 --- a/tests/threads/Make.tests +++ b/tests/threads/Make.tests | |||
| @@ -7,7 +7,7 @@ alarm-negative priority-change priority-donate-one \ | |||
| 7 | priority-donate-multiple priority-donate-multiple2 \ | 7 | priority-donate-multiple priority-donate-multiple2 \ |
| 8 | priority-donate-nest priority-donate-sema priority-donate-lower \ | 8 | priority-donate-nest priority-donate-sema priority-donate-lower \ |
| 9 | priority-fifo priority-preempt priority-sema priority-condvar \ | 9 | priority-fifo priority-preempt priority-sema priority-condvar \ |
| 10 | priority-donate-chain) | 10 | priority-donate-chain priority-donate-condvar) |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | # Sources for tests. | 13 | # Sources for tests. |
| @@ -29,6 +29,7 @@ tests/threads_SRC += tests/threads/priority-preempt.c | |||
| 29 | tests/threads_SRC += tests/threads/priority-sema.c | 29 | tests/threads_SRC += tests/threads/priority-sema.c |
| 30 | tests/threads_SRC += tests/threads/priority-condvar.c | 30 | tests/threads_SRC += tests/threads/priority-condvar.c |
| 31 | tests/threads_SRC += tests/threads/priority-donate-chain.c | 31 | tests/threads_SRC += tests/threads/priority-donate-chain.c |
| 32 | tests/threads_SRC += tests/threads/priority-donate-condvar.c | ||
| 32 | 33 | ||
| 33 | # Not used in SS 2012 | 34 | # Not used in SS 2012 |
| 34 | MLFQS_TESTS = mlfqs-load-1 mlfqs-load-60 mlfqs-load-avg mlfqs-recent-1 \ | 35 | MLFQS_TESTS = mlfqs-load-1 mlfqs-load-60 mlfqs-load-avg mlfqs-recent-1 \ |
diff --git a/tests/threads/priority-donate-condvar.c b/tests/threads/priority-donate-condvar.c new file mode 100644 index 0000000..321a58a --- /dev/null +++ b/tests/threads/priority-donate-condvar.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* Basically that's the same test as priority-donate-sema but using | ||
| 2 | conditions instead of semaphores. | ||
| 3 | |||
| 4 | Low priority thread L acquires a lock, then blocks waiting for | ||
| 5 | the condition. Medium priority thread M then blocks waiting for | ||
| 6 | the same condition. Next, high priority thread H attempts to | ||
| 7 | acquire the lock, donating its priority to L. | ||
| 8 | |||
| 9 | Next, the main thread signals the condition, waking up L. L | ||
| 10 | releases the lock, which wakes up H. H signals the condition, | ||
| 11 | waking up M. H terminates, then M, then L, and finally the | ||
| 12 | main thread. | ||
| 13 | |||
| 14 | Written by Manuel Mausz <manuel-tuwien@mausz.at>. */ | ||
| 15 | |||
| 16 | #include <stdio.h> | ||
| 17 | #include "tests/threads/tests.h" | ||
| 18 | #include "threads/init.h" | ||
| 19 | #include "threads/synch.h" | ||
| 20 | #include "threads/thread.h" | ||
| 21 | |||
| 22 | struct lock_and_cond | ||
| 23 | { | ||
| 24 | struct lock lock; | ||
| 25 | struct lock lockc; | ||
| 26 | struct condition cond; | ||
| 27 | }; | ||
| 28 | |||
| 29 | static thread_func l_thread_func; | ||
| 30 | static thread_func m_thread_func; | ||
| 31 | static thread_func h_thread_func; | ||
| 32 | |||
| 33 | void | ||
| 34 | test_priority_donate_condvar (void) | ||
| 35 | { | ||
| 36 | struct lock_and_cond ls; | ||
| 37 | |||
| 38 | /* This test does not work with the MLFQS. */ | ||
| 39 | ASSERT (!thread_mlfqs); | ||
| 40 | |||
| 41 | /* Make sure our priority is the default. */ | ||
| 42 | ASSERT (thread_get_priority () == PRI_DEFAULT); | ||
| 43 | |||
| 44 | lock_init (&ls.lock); | ||
| 45 | lock_init (&ls.lockc); | ||
| 46 | cond_init (&ls.cond); | ||
| 47 | thread_create ("low", PRI_DEFAULT + 1, l_thread_func, &ls); | ||
| 48 | thread_create ("med", PRI_DEFAULT + 3, m_thread_func, &ls); | ||
| 49 | thread_create ("high", PRI_DEFAULT + 5, h_thread_func, &ls); | ||
| 50 | lock_acquire (&ls.lockc); | ||
| 51 | msg ("Signaling..."); | ||
| 52 | cond_signal (&ls.cond, &ls.lockc); | ||
| 53 | lock_release (&ls.lockc); | ||
| 54 | msg ("Main thread finished."); | ||
| 55 | } | ||
| 56 | |||
| 57 | static void | ||
| 58 | l_thread_func (void *ls_) | ||
| 59 | { | ||
| 60 | struct lock_and_cond *ls = ls_; | ||
| 61 | |||
| 62 | lock_acquire (&ls->lock); | ||
| 63 | msg ("Thread L acquired lock."); | ||
| 64 | lock_acquire (&ls->lockc); | ||
| 65 | cond_wait (&ls->cond, &ls->lockc); | ||
| 66 | lock_release (&ls->lockc); | ||
| 67 | msg ("Thread L woke up."); | ||
| 68 | lock_release (&ls->lock); | ||
| 69 | msg ("Thread L finished."); | ||
| 70 | } | ||
| 71 | |||
| 72 | static void | ||
| 73 | m_thread_func (void *ls_) | ||
| 74 | { | ||
| 75 | struct lock_and_cond *ls = ls_; | ||
| 76 | |||
| 77 | lock_acquire (&ls->lockc); | ||
| 78 | cond_wait (&ls->cond, &ls->lockc); | ||
| 79 | lock_release (&ls->lockc); | ||
| 80 | msg ("Thread M finished."); | ||
| 81 | } | ||
| 82 | |||
| 83 | static void | ||
| 84 | h_thread_func (void *ls_) | ||
| 85 | { | ||
| 86 | struct lock_and_cond *ls = ls_; | ||
| 87 | |||
| 88 | lock_acquire (&ls->lock); | ||
| 89 | msg ("Thread H acquired lock."); | ||
| 90 | |||
| 91 | lock_acquire (&ls->lockc); | ||
| 92 | msg ("Signaling..."); | ||
| 93 | cond_signal (&ls->cond, &ls->lockc); | ||
| 94 | lock_release (&ls->lockc); | ||
| 95 | lock_release (&ls->lock); | ||
| 96 | msg ("Thread H finished."); | ||
| 97 | } | ||
diff --git a/tests/threads/priority-donate-condvar.ck b/tests/threads/priority-donate-condvar.ck new file mode 100644 index 0000000..3ffe51c --- /dev/null +++ b/tests/threads/priority-donate-condvar.ck | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | # -*- perl -*- | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use tests::tests; | ||
| 5 | check_expected ([<<'EOF']); | ||
| 6 | (priority-donate-condvar) begin | ||
| 7 | (priority-donate-condvar) Thread L acquired lock. | ||
| 8 | (priority-donate-condvar) Signaling... | ||
| 9 | (priority-donate-condvar) Thread L woke up. | ||
| 10 | (priority-donate-condvar) Thread H acquired lock. | ||
| 11 | (priority-donate-condvar) Signaling... | ||
| 12 | (priority-donate-condvar) Thread H finished. | ||
| 13 | (priority-donate-condvar) Thread M finished. | ||
| 14 | (priority-donate-condvar) Thread L finished. | ||
| 15 | (priority-donate-condvar) Main thread finished. | ||
| 16 | (priority-donate-condvar) end | ||
| 17 | EOF | ||
| 18 | pass; | ||
diff --git a/tests/threads/tests.c b/tests/threads/tests.c index af15aee..d19ab24 100644 --- a/tests/threads/tests.c +++ b/tests/threads/tests.c | |||
| @@ -25,6 +25,7 @@ static const struct test tests[] = | |||
| 25 | {"priority-donate-sema", test_priority_donate_sema}, | 25 | {"priority-donate-sema", test_priority_donate_sema}, |
| 26 | {"priority-donate-lower", test_priority_donate_lower}, | 26 | {"priority-donate-lower", test_priority_donate_lower}, |
| 27 | {"priority-donate-chain", test_priority_donate_chain}, | 27 | {"priority-donate-chain", test_priority_donate_chain}, |
| 28 | {"priority-donate-condvar", test_priority_donate_condvar}, | ||
| 28 | {"priority-fifo", test_priority_fifo}, | 29 | {"priority-fifo", test_priority_fifo}, |
| 29 | {"priority-preempt", test_priority_preempt}, | 30 | {"priority-preempt", test_priority_preempt}, |
| 30 | {"priority-sema", test_priority_sema}, | 31 | {"priority-sema", test_priority_sema}, |
diff --git a/tests/threads/tests.h b/tests/threads/tests.h index cd9d489..cc51fc9 100644 --- a/tests/threads/tests.h +++ b/tests/threads/tests.h | |||
| @@ -19,6 +19,7 @@ extern test_func test_priority_donate_sema; | |||
| 19 | extern test_func test_priority_donate_nest; | 19 | extern test_func test_priority_donate_nest; |
| 20 | extern test_func test_priority_donate_lower; | 20 | extern test_func test_priority_donate_lower; |
| 21 | extern test_func test_priority_donate_chain; | 21 | extern test_func test_priority_donate_chain; |
| 22 | extern test_func test_priority_donate_condvar; | ||
| 22 | extern test_func test_priority_fifo; | 23 | extern test_func test_priority_fifo; |
| 23 | extern test_func test_priority_preempt; | 24 | extern test_func test_priority_preempt; |
| 24 | extern test_func test_priority_sema; | 25 | extern test_func test_priority_sema; |
