Use runtime options instead of conditional compilation for MLFQS,
[pintos-anon] / grading / threads / priority-donate-multiple.c
1 /* Problem 1-3: Priority Scheduling tests.
2
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>.
7    Modified by arens. */
8
9 #include "threads/test.h"
10 #include <stdio.h>
11 #include "threads/synch.h"
12 #include "threads/thread.h"
13
14 static void test_donate_multiple (void);
15
16 void
17 test (void) 
18 {
19   /* This test does not work with the MLFQS. */
20   ASSERT (!enable_mlfqs);
21
22   /* Make sure our priority is the default. */
23   ASSERT (thread_get_priority () == PRI_DEFAULT);
24
25   test_donate_multiple ();
26 }
27 \f
28 static thread_func a_thread_func;
29 static thread_func b_thread_func;
30
31 static void
32 test_donate_multiple (void) 
33 {
34   struct lock a, b;
35
36   printf ("\n"
37           "Testing multiple priority donation.\n"
38           "If the statements printed below are all true, you pass.\n");
39
40   lock_init (&a, "a");
41   lock_init (&b, "b");
42
43   lock_acquire (&a);
44   lock_acquire (&b);
45
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 ());
49
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 ());
53
54   lock_release (&b);
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 ());
58
59   lock_release (&a);
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");
64 }
65
66 static void
67 a_thread_func (void *lock_) 
68 {
69   struct lock *lock = lock_;
70
71   lock_acquire (lock);
72   printf ("Thread a acquired lock a.\n");
73   lock_release (lock);
74   printf ("Thread a finished.\n");
75 }
76
77 static void
78 b_thread_func (void *lock_) 
79 {
80   struct lock *lock = lock_;
81
82   lock_acquire (lock);
83   printf ("Thread b acquired lock b.\n");
84   lock_release (lock);
85   printf ("Thread b finished.\n");
86 }