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