diff options
Diffstat (limited to 'tests/threads/tests.c')
| -rw-r--r-- | tests/threads/tests.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/threads/tests.c b/tests/threads/tests.c new file mode 100644 index 0000000..af15aee --- /dev/null +++ b/tests/threads/tests.c | |||
| @@ -0,0 +1,102 @@ | |||
| 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-donate-lower", test_priority_donate_lower}, | ||
| 27 | {"priority-donate-chain", test_priority_donate_chain}, | ||
| 28 | {"priority-fifo", test_priority_fifo}, | ||
| 29 | {"priority-preempt", test_priority_preempt}, | ||
| 30 | {"priority-sema", test_priority_sema}, | ||
| 31 | {"priority-condvar", test_priority_condvar}, | ||
| 32 | {"mlfqs-load-1", test_mlfqs_load_1}, | ||
| 33 | {"mlfqs-load-60", test_mlfqs_load_60}, | ||
| 34 | {"mlfqs-load-avg", test_mlfqs_load_avg}, | ||
| 35 | {"mlfqs-recent-1", test_mlfqs_recent_1}, | ||
| 36 | {"mlfqs-fair-2", test_mlfqs_fair_2}, | ||
| 37 | {"mlfqs-fair-20", test_mlfqs_fair_20}, | ||
| 38 | {"mlfqs-nice-2", test_mlfqs_nice_2}, | ||
| 39 | {"mlfqs-nice-10", test_mlfqs_nice_10}, | ||
| 40 | {"mlfqs-block", test_mlfqs_block}, | ||
| 41 | }; | ||
| 42 | |||
| 43 | static const char *test_name; | ||
| 44 | |||
| 45 | /* Runs the test named NAME. */ | ||
| 46 | void | ||
| 47 | run_test (const char *name) | ||
| 48 | { | ||
| 49 | const struct test *t; | ||
| 50 | |||
| 51 | for (t = tests; t < tests + sizeof tests / sizeof *tests; t++) | ||
| 52 | if (!strcmp (name, t->name)) | ||
| 53 | { | ||
| 54 | test_name = name; | ||
| 55 | msg ("begin"); | ||
| 56 | t->function (); | ||
| 57 | msg ("end"); | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | PANIC ("no test named \"%s\"", name); | ||
| 61 | } | ||
| 62 | |||
| 63 | /* Prints FORMAT as if with printf(), | ||
| 64 | prefixing the output by the name of the test | ||
| 65 | and following it with a new-line character. */ | ||
| 66 | void | ||
| 67 | msg (const char *format, ...) | ||
| 68 | { | ||
| 69 | va_list args; | ||
| 70 | |||
| 71 | printf ("(%s) ", test_name); | ||
| 72 | va_start (args, format); | ||
| 73 | vprintf (format, args); | ||
| 74 | va_end (args); | ||
| 75 | putchar ('\n'); | ||
| 76 | } | ||
| 77 | |||
| 78 | /* Prints failure message FORMAT as if with printf(), | ||
| 79 | prefixing the output by the name of the test and FAIL: | ||
| 80 | and following it with a new-line character, | ||
| 81 | and then panics the kernel. */ | ||
| 82 | void | ||
| 83 | fail (const char *format, ...) | ||
| 84 | { | ||
| 85 | va_list args; | ||
| 86 | |||
| 87 | printf ("(%s) FAIL: ", test_name); | ||
| 88 | va_start (args, format); | ||
| 89 | vprintf (format, args); | ||
| 90 | va_end (args); | ||
| 91 | putchar ('\n'); | ||
| 92 | |||
| 93 | PANIC ("test failed"); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* Prints a message indicating the current test passed. */ | ||
| 97 | void | ||
| 98 | pass (void) | ||
| 99 | { | ||
| 100 | printf ("(%s) PASS\n", test_name); | ||
| 101 | } | ||
| 102 | |||
