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>.
9 #include "threads/test.h"
11 #include "threads/synch.h"
12 #include "threads/thread.h"
14 static void test_donate_return (void);
19 /* This test does not work with the MLFQS. */
20 ASSERT (!enable_mlfqs);
22 /* Make sure our priority is the default. */
23 ASSERT (thread_get_priority () == PRI_DEFAULT);
25 test_donate_return ();
28 static thread_func acquire1_thread_func;
29 static thread_func acquire2_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, acquire1_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, acquire2_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, 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 acquire1_thread_func (void *lock_)
57 struct lock *lock = lock_;
60 printf ("acquire1: got the lock\n");
62 printf ("acquire1: done\n");
66 acquire2_thread_func (void *lock_)
68 struct lock *lock = lock_;
71 printf ("acquire2: got the lock\n");
73 printf ("acquire2: done\n");