Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / threads / mlfqs-load-1.c
1 #include <stdio.h>
2 #include "tests/threads/tests.h"
3 #include "threads/init.h"
4 #include "threads/malloc.h"
5 #include "threads/synch.h"
6 #include "threads/thread.h"
7 #include "devices/timer.h"
8
9 void
10 test_mlfqs_load_1 (void) 
11 {
12   int64_t start_time;
13   int elapsed;
14   int load_avg;
15   
16   ASSERT (enable_mlfqs);
17
18   msg ("spinning for up to 45 seconds, please wait...");
19
20   start_time = timer_ticks ();
21   for (;;) 
22     {
23       load_avg = thread_get_load_avg ();
24       ASSERT (load_avg >= 0);
25       elapsed = timer_elapsed (start_time) / TIMER_FREQ;
26       if (load_avg > 50)
27         break;
28       else if (load_avg > 100)
29         fail ("load average is %d.%02d "
30               "but should be between 0 and 1 (after %d seconds)",
31               load_avg / 100, load_avg % 100, elapsed);
32       else if (elapsed > 45)
33         fail ("load average stayed below 0.5 for more than 45 seconds");
34     }
35
36   if (elapsed < 38)
37     fail ("load average took only %d seconds to rise above 0.5", elapsed);
38   msg ("load average rose to 0.5 after %d seconds", elapsed);
39
40   msg ("sleeping for another 10 seconds, please wait...");
41   timer_sleep (TIMER_FREQ * 10);
42
43   load_avg = thread_get_load_avg ();
44   if (load_avg < 0)
45     fail ("load average fell below 0");
46   if (load_avg > 50)
47     fail ("load average stayed above 0.5 for more than 10 seconds");
48   msg ("load average fell back below 0.5 (to %d.%02d)",
49        load_avg / 100, load_avg % 100);
50
51   pass ();
52 }