diff options
| author | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
| commit | b5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch) | |
| tree | 1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/intro/alarm-clock/tests.c | |
| download | progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2 progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip | |
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/intro/alarm-clock/tests.c')
| -rw-r--r-- | pintos-progos/tests/intro/alarm-clock/tests.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/pintos-progos/tests/intro/alarm-clock/tests.c b/pintos-progos/tests/intro/alarm-clock/tests.c new file mode 100644 index 0000000..4a96360 --- /dev/null +++ b/pintos-progos/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 | |||
| 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-zero", test_alarm_zero}, | ||
| 18 | {"alarm-negative", test_alarm_negative}, | ||
| 19 | }; | ||
| 20 | |||
| 21 | static const char *test_name; | ||
| 22 | |||
| 23 | /* Runs the test named NAME. */ | ||
| 24 | void | ||
| 25 | run_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. */ | ||
| 44 | void | ||
| 45 | msg (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. */ | ||
| 60 | void | ||
| 61 | fail (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. */ | ||
| 75 | void | ||
| 76 | pass (void) | ||
| 77 | { | ||
| 78 | printf ("(%s) PASS\n", test_name); | ||
| 79 | } | ||
| 80 | |||
