Add another test that checks priority scheduling in the case of
[pintos-anon] / src / tests / threads / tests.c
1 #include "tests/threads/tests.h"
2 #include <debug.h>
3 #include <string.h>
4 #include <stdio.h>
5
6 struct test 
7   {
8     const char *name;
9     test_func *function;
10   };
11
12 static const struct test tests[] = 
13   {
14     {"alarm-single", test_alarm_single},
15     {"alarm-multiple", test_alarm_multiple},
16     {"alarm-priority", test_alarm_priority},
17     {"alarm-zero", test_alarm_zero},
18     {"alarm-negative", test_alarm_negative},
19     {"priority-change", test_priority_change},
20     {"priority-donate-one", test_priority_donate_one},
21     {"priority-donate-multiple", test_priority_donate_multiple},
22     {"priority-donate-multiple2", test_priority_donate_multiple2},
23     {"priority-donate-nest", test_priority_donate_nest},
24     {"priority-donate-sema", test_priority_donate_sema},
25     {"priority-fifo", test_priority_fifo},
26     {"priority-preempt", test_priority_preempt},
27     {"priority-sema", test_priority_sema},
28     {"priority-condvar", test_priority_condvar},
29     {"mlfqs-load-1", test_mlfqs_load_1},
30     {"mlfqs-load-60", test_mlfqs_load_60},
31     {"mlfqs-load-avg", test_mlfqs_load_avg},
32     {"mlfqs-recent-1", test_mlfqs_recent_1},
33     {"mlfqs-fair-2", test_mlfqs_fair_2},
34     {"mlfqs-fair-20", test_mlfqs_fair_20},
35     {"mlfqs-nice-2", test_mlfqs_nice_2},
36     {"mlfqs-nice-10", test_mlfqs_nice_10},
37   };
38
39 static const char *test_name;
40
41 /* Runs the test named NAME. */
42 void
43 run_test (const char *name) 
44 {
45   const struct test *t;
46
47   for (t = tests; t < tests + sizeof tests / sizeof *tests; t++)
48     if (!strcmp (name, t->name))
49       {
50         test_name = name;
51         msg ("begin");
52         t->function ();
53         msg ("end");
54         return;
55       }
56   PANIC ("no test named \"%s\"", name);
57 }
58
59 /* Prints FORMAT as if with printf(),
60    prefixing the output by the name of the test
61    and following it with a new-line character. */
62 void
63 msg (const char *format, ...) 
64 {
65   va_list args;
66   
67   printf ("(%s) ", test_name);
68   va_start (args, format);
69   vprintf (format, args);
70   va_end (args);
71   putchar ('\n');
72 }
73
74 /* Prints failure message FORMAT as if with printf(),
75    prefixing the output by the name of the test and FAIL:
76    and following it with a new-line character,
77    and then panics the kernel. */
78 void
79 fail (const char *format, ...) 
80 {
81   va_list args;
82   
83   printf ("(%s) FAIL: ", test_name);
84   va_start (args, format);
85   vprintf (format, args);
86   va_end (args);
87   putchar ('\n');
88
89   PANIC ("test failed");
90 }
91
92 /* Prints a message indicating the current test passed. */
93 void
94 pass (void) 
95 {
96   printf ("(%s) PASS\n", test_name);
97 }
98