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_nest (void);
23 /* Make sure our priority is the default. */
24 ASSERT (thread_get_priority () == PRI_DEFAULT);
29 static thread_func medium_thread_func;
30 static thread_func high_thread_func;
39 test_donate_nest (void)
45 "Testing nested priority donation.\n"
46 "If the statements printed below are all true, you pass.\n");
55 thread_create ("medium", PRI_DEFAULT + 1, medium_thread_func, &locks);
57 printf (" 1. Low thread should have priority %d. Actual priority: %d.\n",
58 PRI_DEFAULT + 1, thread_get_priority ());
60 thread_create ("high", PRI_DEFAULT + 2, high_thread_func, &b);
62 printf (" 2. Low thread should have priority %d. Actual priority: %d.\n",
63 PRI_DEFAULT + 2, thread_get_priority ());
67 printf (" 9. Medium thread should just have finished.\n");
68 printf ("10. Low thread should have priority %d. Actual priority: %d.\n",
69 PRI_DEFAULT, thread_get_priority ());
70 printf ("Nested priority priority donation test finished.\n");
74 medium_thread_func (void *locks_)
76 struct locks *locks = locks_;
78 lock_acquire (locks->b);
79 lock_acquire (locks->a);
81 printf (" 3. Medium thread should have priority %d. Actual priority: %d.\n",
82 PRI_DEFAULT + 2, thread_get_priority ());
83 printf (" 4. Medium thread got the lock.\n");
85 lock_release (locks->a);
88 lock_release (locks->b);
91 printf (" 7. High thread should have just finished.\n");
92 printf (" 8. Middle thread finished.\n");
96 high_thread_func (void *lock_)
98 struct lock *lock = lock_;
101 printf (" 5. High thread got the lock.\n");
103 printf (" 6. High thread finished.\n");