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 #error This test not applicable with MLFQS enabled.
13 #include "threads/test.h"
15 #include "threads/synch.h"
16 #include "threads/thread.h"
18 static void test_donate_return (void);
23 /* Make sure our priority is the default. */
24 ASSERT (thread_get_priority () == PRI_DEFAULT);
26 test_donate_return ();
29 static thread_func acquire1_thread_func;
30 static thread_func acquire2_thread_func;
33 test_donate_return (void)
38 "Testing priority donation.\n"
39 "If the statements printed below are all true, you pass.\n");
41 lock_init (&lock, "donor");
43 thread_create ("acquire1", PRI_DEFAULT + 1, acquire1_thread_func, &lock);
44 printf ("1. This thread should have priority %d. Actual priority: %d.\n",
45 PRI_DEFAULT + 1, thread_get_priority ());
46 thread_create ("acquire2", PRI_DEFAULT + 2, acquire2_thread_func, &lock);
47 printf ("2. This thread should have priority %d. Actual priority: %d.\n",
48 PRI_DEFAULT + 2, thread_get_priority ());
50 printf ("7. acquire2, acquire1 must already have finished, in that order.\n"
51 "8. This should be the last line before finishing this test.\n"
52 "Priority donation test done.\n");
56 acquire1_thread_func (void *lock_)
58 struct lock *lock = lock_;
61 printf ("5. acquire1: got the lock\n");
63 printf ("6. acquire1: done\n");
67 acquire2_thread_func (void *lock_)
69 struct lock *lock = lock_;
72 printf ("3. acquire2: got the lock\n");
74 printf ("4. acquire2: done\n");