00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdio.h>
00010 #include "tests/threads/tests.h"
00011 #include "threads/init.h"
00012 #include "threads/malloc.h"
00013 #include "threads/synch.h"
00014 #include "threads/thread.h"
00015 #include "devices/timer.h"
00016
00017 void
00018 test_mlfqs_load_1 (void)
00019 {
00020 int64_t start_time;
00021 int elapsed;
00022 int load_avg;
00023
00024 ASSERT (thread_mlfqs);
00025
00026 msg ("spinning for up to 45 seconds, please wait...");
00027
00028 start_time = timer_ticks ();
00029 for (;;)
00030 {
00031 load_avg = thread_get_load_avg ();
00032 ASSERT (load_avg >= 0);
00033 elapsed = timer_elapsed (start_time) / TIMER_FREQ;
00034 if (load_avg > 100)
00035 fail ("load average is %d.%02d "
00036 "but should be between 0 and 1 (after %d seconds)",
00037 load_avg / 100, load_avg % 100, elapsed);
00038 else if (load_avg > 50)
00039 break;
00040 else if (elapsed > 45)
00041 fail ("load average stayed below 0.5 for more than 45 seconds");
00042 }
00043
00044 if (elapsed < 38)
00045 fail ("load average took only %d seconds to rise above 0.5", elapsed);
00046 msg ("load average rose to 0.5 after %d seconds", elapsed);
00047
00048 msg ("sleeping for another 10 seconds, please wait...");
00049 timer_sleep (TIMER_FREQ * 10);
00050
00051 load_avg = thread_get_load_avg ();
00052 if (load_avg < 0)
00053 fail ("load average fell below 0");
00054 if (load_avg > 50)
00055 fail ("load average stayed above 0.5 for more than 10 seconds");
00056 msg ("load average fell back below 0.5 (to %d.%02d)",
00057 load_avg / 100, load_avg % 100);
00058
00059 pass ();
00060 }