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"
15 static thread_func acquire1_thread_func;
16 static thread_func acquire2_thread_func;
19 test_priority_donate_one (void)
23 /* This test does not work with the MLFQS. */
24 ASSERT (!enable_mlfqs);
26 /* Make sure our priority is the default. */
27 ASSERT (thread_get_priority () == PRI_DEFAULT);
31 thread_create ("acquire1", PRI_DEFAULT - 1, acquire1_thread_func, &lock);
32 msg ("This thread should have priority %d. Actual priority: %d.",
33 PRI_DEFAULT - 1, thread_get_priority ());
34 thread_create ("acquire2", PRI_DEFAULT - 2, acquire2_thread_func, &lock);
35 msg ("This thread should have priority %d. Actual priority: %d.",
36 PRI_DEFAULT - 2, thread_get_priority ());
38 msg ("acquire2, acquire1 must already have finished, in that order.");
39 msg ("This should be the last line before finishing this test.");
43 acquire1_thread_func (void *lock_)
45 struct lock *lock = lock_;
48 msg ("acquire1: got the lock");
50 msg ("acquire1: done");
54 acquire2_thread_func (void *lock_)
56 struct lock *lock = lock_;
59 msg ("acquire2: got the lock");
61 msg ("acquire2: done");