1 /* Problem 1-3: Priority Scheduling tests.
3 Based on a test originally submitted for Stanford's CS 140 in
4 winter 1999 by by Matt Franklin
5 <startled@leland.stanford.edu>, Greg Hutchins
6 <gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>.
10 #include "tests/threads/tests.h"
11 #include "threads/init.h"
12 #include "threads/synch.h"
13 #include "threads/thread.h"
21 static thread_func medium_thread_func;
22 static thread_func high_thread_func;
25 test_priority_donate_nest (void)
30 /* This test does not work with the MLFQS. */
31 ASSERT (!enable_mlfqs);
33 /* Make sure our priority is the default. */
34 ASSERT (thread_get_priority () == PRI_DEFAULT);
43 thread_create ("medium", PRI_DEFAULT - 1, medium_thread_func, &locks);
45 msg ("Low thread should have priority %d. Actual priority: %d.",
46 PRI_DEFAULT - 1, thread_get_priority ());
48 thread_create ("high", PRI_DEFAULT - 2, high_thread_func, &b);
50 msg ("Low thread should have priority %d. Actual priority: %d.",
51 PRI_DEFAULT - 2, thread_get_priority ());
55 msg ("Medium thread should just have finished.");
56 msg ("Low thread should have priority %d. Actual priority: %d.",
57 PRI_DEFAULT, thread_get_priority ());
61 medium_thread_func (void *locks_)
63 struct locks *locks = locks_;
65 lock_acquire (locks->b);
66 lock_acquire (locks->a);
68 msg ("Medium thread should have priority %d. Actual priority: %d.",
69 PRI_DEFAULT - 2, thread_get_priority ());
70 msg ("Medium thread got the lock.");
72 lock_release (locks->a);
75 lock_release (locks->b);
78 msg ("High thread should have just finished.");
79 msg ("Middle thread finished.");
83 high_thread_func (void *lock_)
85 struct lock *lock = lock_;
88 msg ("High thread got the lock.");
90 msg ("High thread finished.");