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 acquire_thread_func;
32 test_donate_return (void)
37 "Testing priority donation.\n"
38 "If the statements printed below are all true, you pass.\n");
40 lock_init (&lock, "donor");
42 thread_create ("acquire1", PRI_DEFAULT + 1, acquire_thread_func, &lock);
43 printf ("This thread should have priority %d. Actual priority: %d.\n",
44 PRI_DEFAULT + 1, thread_get_priority ());
45 thread_create ("acquire2", PRI_DEFAULT + 2, acquire_thread_func, &lock);
46 printf ("This thread should have priority %d. Actual priority: %d.\n",
47 PRI_DEFAULT + 2, thread_get_priority ());
49 printf ("acquire2 and acquire1 must already have finished, in that order.\n"
50 "This should be the last line before finishing this test.\n"
51 "Priority donation test done.\n");
55 acquire_thread_func (void *lock_)
57 struct lock *lock = lock_;
60 printf ("%s: got the lock\n", thread_name ());
62 printf ("%s: done\n", thread_name ());