1 /* Problem 1-3: Priority Scheduling tests.
3 Based on a test originally submitted for Stanford's CS 140 in
4 winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
5 Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
6 <yph@cs.stanford.edu>. Modified by arens. */
9 #include "tests/threads/tests.h"
10 #include "threads/init.h"
11 #include "threads/synch.h"
12 #include "threads/thread.h"
20 static thread_func medium_thread_func;
21 static thread_func high_thread_func;
24 test_priority_donate_nest (void)
29 /* This test does not work with the MLFQS. */
30 ASSERT (!enable_mlfqs);
32 /* Make sure our priority is the default. */
33 ASSERT (thread_get_priority () == PRI_DEFAULT);
42 thread_create ("medium", PRI_DEFAULT - 1, medium_thread_func, &locks);
44 msg ("Low thread should have priority %d. Actual priority: %d.",
45 PRI_DEFAULT - 1, thread_get_priority ());
47 thread_create ("high", PRI_DEFAULT - 2, high_thread_func, &b);
49 msg ("Low thread should have priority %d. Actual priority: %d.",
50 PRI_DEFAULT - 2, thread_get_priority ());
54 msg ("Medium thread should just have finished.");
55 msg ("Low thread should have priority %d. Actual priority: %d.",
56 PRI_DEFAULT, thread_get_priority ());
60 medium_thread_func (void *locks_)
62 struct locks *locks = locks_;
64 lock_acquire (locks->b);
65 lock_acquire (locks->a);
67 msg ("Medium thread should have priority %d. Actual priority: %d.",
68 PRI_DEFAULT - 2, thread_get_priority ());
69 msg ("Medium thread got the lock.");
71 lock_release (locks->a);
74 lock_release (locks->b);
77 msg ("High thread should have just finished.");
78 msg ("Middle thread finished.");
82 high_thread_func (void *lock_)
84 struct lock *lock = lock_;
87 msg ("High thread got the lock.");
89 msg ("High thread finished.");