Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / 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 <stdio.h>
10 #include "tests/threads/tests.h"
11 #include "threads/init.h"
12 #include "threads/synch.h"
13 #include "threads/thread.h"
14
15 static thread_func a_thread_func;
16 static thread_func b_thread_func;
17
18 void
19 test_priority_donate_multiple (void) 
20 {
21   struct lock a, b;
22
23   /* This test does not work with the MLFQS. */
24   ASSERT (!enable_mlfqs);
25
26   /* Make sure our priority is the default. */
27   ASSERT (thread_get_priority () == PRI_DEFAULT);
28
29   lock_init (&a);
30   lock_init (&b);
31
32   lock_acquire (&a);
33   lock_acquire (&b);
34
35   thread_create ("a", PRI_DEFAULT - 1, a_thread_func, &a);
36   msg ("Main thread should have priority %d.  Actual priority: %d.",
37        PRI_DEFAULT - 1, thread_get_priority ());
38
39   thread_create ("b", PRI_DEFAULT - 2, b_thread_func, &b);
40   msg ("Main thread should have priority %d.  Actual priority: %d.",
41        PRI_DEFAULT - 2, thread_get_priority ());
42
43   lock_release (&b);
44   msg ("Thread b should have just finished.");
45   msg ("Main thread should have priority %d.  Actual priority: %d.",
46        PRI_DEFAULT - 1, thread_get_priority ());
47
48   lock_release (&a);
49   msg ("Thread a should have just finished.");
50   msg ("Main thread should have priority %d.  Actual priority: %d.",
51        PRI_DEFAULT, thread_get_priority ());
52 }
53
54 static void
55 a_thread_func (void *lock_) 
56 {
57   struct lock *lock = lock_;
58
59   lock_acquire (lock);
60   msg ("Thread a acquired lock a.");
61   lock_release (lock);
62   msg ("Thread a finished.");
63 }
64
65 static void
66 b_thread_func (void *lock_) 
67 {
68   struct lock *lock = lock_;
69
70   lock_acquire (lock);
71   msg ("Thread b acquired lock b.");
72   lock_release (lock);
73   msg ("Thread b finished.");
74 }