summaryrefslogtreecommitdiffstats
path: root/tests/intro/alarm-clock/tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/intro/alarm-clock/tests.c')
-rw-r--r--tests/intro/alarm-clock/tests.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/intro/alarm-clock/tests.c b/tests/intro/alarm-clock/tests.c
new file mode 100644
index 0000000..4a96360
--- /dev/null
+++ b/tests/intro/alarm-clock/tests.c
@@ -0,0 +1,80 @@
1#include "tests/threads/tests.h"
2#include <debug.h>
3#include <string.h>
4#include <stdio.h>
5
6struct test
7 {
8 const char *name;
9 test_func *function;
10 };
11
12static 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-zero", test_alarm_zero},
18 {"alarm-negative", test_alarm_negative},
19 };
20
21static const char *test_name;
22
23/* Runs the test named NAME. */
24void
25run_test (const char *name)
26{
27 const struct test *t;
28
29 for (t = tests; t < tests + sizeof tests / sizeof *tests; t++)
30 if (!strcmp (name, t->name))
31 {
32 test_name = name;
33 msg ("begin");
34 t->function ();
35 msg ("end");
36 return;
37 }
38 PANIC ("no test named \"%s\"", name);
39}
40
41/* Prints FORMAT as if with printf(),
42 prefixing the output by the name of the test
43 and following it with a new-line character. */
44void
45msg (const char *format, ...)
46{
47 va_list args;
48
49 printf ("(%s) ", test_name);
50 va_start (args, format);
51 vprintf (format, args);
52 va_end (args);
53 putchar ('\n');
54}
55
56/* Prints failure message FORMAT as if with printf(),
57 prefixing the output by the name of the test and FAIL:
58 and following it with a new-line character,
59 and then panics the kernel. */
60void
61fail (const char *format, ...)
62{
63 va_list args;
64
65 printf ("(%s) FAIL: ", test_name);
66 va_start (args, format);
67 vprintf (format, args);
68 va_end (args);
69 putchar ('\n');
70
71 PANIC ("test failed");
72}
73
74/* Prints a message indicating the current test passed. */
75void
76pass (void)
77{
78 printf ("(%s) PASS\n", test_name);
79}
80