Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / threads / priority-lower.c
1 #include <stdio.h>
2 #include "tests/threads/tests.h"
3 #include "threads/init.h"
4 #include "threads/synch.h"
5 #include "threads/thread.h"
6
7 static thread_func acquire1_thread_func;
8 static thread_func acquire2_thread_func;
9
10 void
11 test_priority_donate_one (void) 
12 {
13   struct lock lock;
14
15   /* This test does not work with the MLFQS. */
16   ASSERT (!enable_mlfqs);
17
18   /* Make sure our priority is the default. */
19   ASSERT (thread_get_priority () == PRI_DEFAULT);
20
21   lock_init (&lock);
22   lock_acquire (&lock);
23   thread_create ("acquire1", PRI_DEFAULT - 1, acquire1_thread_func, &lock);
24   msg ("This thread should have priority %d.  Actual priority: %d.",
25        PRI_DEFAULT - 1, thread_get_priority ());
26   thread_create ("acquire2", PRI_DEFAULT - 2, acquire2_thread_func, &lock);
27   msg ("This thread should have priority %d.  Actual priority: %d.",
28        PRI_DEFAULT - 2, thread_get_priority ());
29   lock_release (&lock);
30   msg ("acquire2, acquire1 must already have finished, in that order.");
31   msg ("This should be the last line before finishing this test.");
32 }
33
34 static void
35 acquire1_thread_func (void *lock_) 
36 {
37   struct lock *lock = lock_;
38
39   lock_acquire (lock);
40   msg ("acquire1: got the lock");
41   lock_release (lock);
42   msg ("acquire1: done");
43 }
44
45 static void
46 acquire2_thread_func (void *lock_) 
47 {
48   struct lock *lock = lock_;
49
50   lock_acquire (lock);
51   msg ("acquire2: got the lock");
52   lock_release (lock);
53   msg ("acquire2: done");
54 }