1 /* Based on a test originally submitted for Stanford's CS 140 in
2 winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
3 Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
4 <yph@cs.stanford.edu>. Modified by arens. */
7 #include "tests/threads/tests.h"
8 #include "threads/init.h"
9 #include "threads/synch.h"
10 #include "threads/thread.h"
18 static thread_func medium_thread_func;
19 static thread_func high_thread_func;
22 test_priority_donate_nest (void)
27 /* This test does not work with the MLFQS. */
28 ASSERT (!enable_mlfqs);
30 /* Make sure our priority is the default. */
31 ASSERT (thread_get_priority () == PRI_DEFAULT);
40 thread_create ("medium", PRI_DEFAULT - 1, medium_thread_func, &locks);
42 msg ("Low thread should have priority %d. Actual priority: %d.",
43 PRI_DEFAULT - 1, thread_get_priority ());
45 thread_create ("high", PRI_DEFAULT - 2, high_thread_func, &b);
47 msg ("Low thread should have priority %d. Actual priority: %d.",
48 PRI_DEFAULT - 2, thread_get_priority ());
52 msg ("Medium thread should just have finished.");
53 msg ("Low thread should have priority %d. Actual priority: %d.",
54 PRI_DEFAULT, thread_get_priority ());
58 medium_thread_func (void *locks_)
60 struct locks *locks = locks_;
62 lock_acquire (locks->b);
63 lock_acquire (locks->a);
65 msg ("Medium thread should have priority %d. Actual priority: %d.",
66 PRI_DEFAULT - 2, thread_get_priority ());
67 msg ("Medium thread got the lock.");
69 lock_release (locks->a);
72 lock_release (locks->b);
75 msg ("High thread should have just finished.");
76 msg ("Middle thread finished.");
80 high_thread_func (void *lock_)
82 struct lock *lock = lock_;
85 msg ("High thread got the lock.");
87 msg ("High thread finished.");