Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / 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 <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 acquire1_thread_func;
16 static thread_func acquire2_thread_func;
17
18 void
19 test_priority_donate_one (void) 
20 {
21   struct lock lock;
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 (&lock);
30   lock_acquire (&lock);
31   thread_create ("acquire1", PRI_DEFAULT - 1, acquire1_thread_func, &lock);
32   msg ("This thread should have priority %d.  Actual priority: %d.",
33        PRI_DEFAULT - 1, thread_get_priority ());
34   thread_create ("acquire2", PRI_DEFAULT - 2, acquire2_thread_func, &lock);
35   msg ("This thread should have priority %d.  Actual priority: %d.",
36        PRI_DEFAULT - 2, thread_get_priority ());
37   lock_release (&lock);
38   msg ("acquire2, acquire1 must already have finished, in that order.");
39   msg ("This should be the last line before finishing this test.");
40 }
41
42 static void
43 acquire1_thread_func (void *lock_) 
44 {
45   struct lock *lock = lock_;
46
47   lock_acquire (lock);
48   msg ("acquire1: got the lock");
49   lock_release (lock);
50   msg ("acquire1: done");
51 }
52
53 static void
54 acquire2_thread_func (void *lock_) 
55 {
56   struct lock *lock = lock_;
57
58   lock_acquire (lock);
59   msg ("acquire2: got the lock");
60   lock_release (lock);
61   msg ("acquire2: done");
62 }