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_multiple (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_multiple ();
28 static thread_func a_thread_func;
29 static thread_func b_thread_func;
32 test_donate_multiple (void)
37 "Testing multiple priority donation.\n"
38 "If the statements printed below are all true, you pass.\n");
46 thread_create ("a", PRI_DEFAULT + 1, a_thread_func, &a);
47 printf ("Main thread should have priority %d. Actual priority: %d.\n",
48 PRI_DEFAULT + 1, thread_get_priority ());
50 thread_create ("b", PRI_DEFAULT + 2, b_thread_func, &b);
51 printf ("Main thread should have priority %d. Actual priority: %d.\n",
52 PRI_DEFAULT + 2, thread_get_priority ());
55 printf ("Thread b should have just finished.\n");
56 printf ("Main thread should have priority %d. Actual priority: %d.\n",
57 PRI_DEFAULT + 1, thread_get_priority ());
60 printf ("Thread a should have just finished.\n");
61 printf ("Main thread should have priority %d. Actual priority: %d.\n",
62 PRI_DEFAULT, thread_get_priority ());
63 printf ("Multiple priority priority donation test finished.\n");
67 a_thread_func (void *lock_)
69 struct lock *lock = lock_;
72 printf ("Thread a acquired lock a.\n");
74 printf ("Thread a finished.\n");
78 b_thread_func (void *lock_)
80 struct lock *lock = lock_;
83 printf ("Thread b acquired lock b.\n");
85 printf ("Thread b finished.\n");