Use runtime options instead of conditional compilation for MLFQS,
[pintos-anon] / grading / threads / priority-preempt.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_preempt (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_preempt ();
26 }
27 \f
28 static thread_func simple_thread_func;
29
30 static void
31 test_preempt (void) 
32 {
33   printf ("\n"
34           "Testing priority preemption.\n");
35   thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
36   printf ("The high-priority thread should have already completed.\n"
37           "Priority preemption test done.\n");
38 }
39
40 static void 
41 simple_thread_func (void *aux UNUSED) 
42 {
43   int i;
44   
45   for (i = 0; i < 5; i++) 
46     {
47       printf ("Thread %s iteration %d\n", thread_name (), i);
48       thread_yield ();
49     }
50   printf ("Thread %s done!\n", thread_name ());
51 }