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_nest (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);
28 static thread_func medium_thread_func;
29 static thread_func high_thread_func;
38 test_donate_nest (void)
44 "Testing nested priority donation.\n"
45 "If the statements printed below are all true, you pass.\n");
54 thread_create ("medium", PRI_DEFAULT + 1, medium_thread_func, &locks);
56 printf ("Low thread should have priority %d. Actual priority: %d.\n",
57 PRI_DEFAULT + 1, thread_get_priority ());
59 thread_create ("high", PRI_DEFAULT + 2, high_thread_func, &b);
61 printf ("Low thread should have priority %d. Actual priority: %d.\n",
62 PRI_DEFAULT + 2, thread_get_priority ());
66 printf ("Medium thread should just have finished.\n");
67 printf ("Low thread should have priority %d. Actual priority: %d.\n",
68 PRI_DEFAULT, thread_get_priority ());
69 printf ("Nested priority priority donation test finished.\n");
73 medium_thread_func (void *locks_)
75 struct locks *locks = locks_;
77 lock_acquire (locks->b);
78 lock_acquire (locks->a);
80 printf ("Medium thread should have priority %d. Actual priority: %d.\n",
81 PRI_DEFAULT + 2, thread_get_priority ());
82 printf ("Medium thread got the lock.\n");
84 lock_release (locks->a);
87 lock_release (locks->b);
90 printf ("High thread should have just finished.\n");
91 printf ("Middle thread finished.\n");
95 high_thread_func (void *lock_)
97 struct lock *lock = lock_;
100 printf ("High thread got the lock.\n");
102 printf ("High thread finished.\n");