Use runtime options instead of conditional compilation for MLFQS,
[pintos-anon] / grading / threads / priority-donate-one.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_return (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_return ();
26 }
27 \f
28 static thread_func acquire1_thread_func;
29 static thread_func acquire2_thread_func;
30
31 static void
32 test_donate_return (void) 
33 {
34   struct lock lock;
35
36   printf ("\n"
37           "Testing priority donation.\n"
38           "If the statements printed below are all true, you pass.\n");
39
40   lock_init (&lock, "donor");
41   lock_acquire (&lock);
42   thread_create ("acquire1", PRI_DEFAULT + 1, acquire1_thread_func, &lock);
43   printf ("This thread should have priority %d.  Actual priority: %d.\n",
44           PRI_DEFAULT + 1, thread_get_priority ());
45   thread_create ("acquire2", PRI_DEFAULT + 2, acquire2_thread_func, &lock);
46   printf ("This thread should have priority %d.  Actual priority: %d.\n",
47           PRI_DEFAULT + 2, thread_get_priority ());
48   lock_release (&lock);
49   printf ("acquire2, acquire1 must already have finished, in that order.\n"
50           "This should be the last line before finishing this test.\n"
51           "Priority donation test done.\n");
52 }
53
54 static void
55 acquire1_thread_func (void *lock_) 
56 {
57   struct lock *lock = lock_;
58
59   lock_acquire (lock);
60   printf ("acquire1: got the lock\n");
61   lock_release (lock);
62   printf ("acquire1: done\n");
63 }
64
65 static void
66 acquire2_thread_func (void *lock_) 
67 {
68   struct lock *lock = lock_;
69
70   lock_acquire (lock);
71   printf ("acquire2: got the lock\n");
72   lock_release (lock);
73   printf ("acquire2: done\n");
74 }