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