PKUOS - Pintos
Pintos source browser for PKU Operating System course
tests.c
Go to the documentation of this file.
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-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
43static const char *test_name;
44
45/** Runs the test named NAME. */
46void
47run_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 {
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. */
66void
67msg (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. */
82void
83fail (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. */
97void
98pass (void)
99{
100 printf ("(%s) PASS\n", test_name);
101}
102
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
Definition: debug.h:14
char * name[]
Definition: insult.c:47
int vprintf(const char *format, va_list args)
The standard vprintf() function, which is like printf() but uses a va_list.
Definition: console.c:126
int putchar(int c)
Writes C to the vga display and serial port.
Definition: console.c:163
int printf(const char *format,...)
Writes formatted output to the console.
Definition: stdio.c:79
#define va_end(LIST)
Definition: stdarg.h:10
#define va_start(LIST, ARG)
Definition: stdarg.h:9
__builtin_va_list va_list
GCC has <stdarg.h> functionality as built-ins, so all we need is to use it.
Definition: stdarg.h:7
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
Definition: string.c:73
Definition: tests.c:7
const char * name
Definition: tests.c:8
test_func * function
Definition: tests.c:9
void run_test(const char *name)
Runs the test named NAME.
Definition: tests.c:47
void pass(void)
Prints a message indicating the current test passed.
Definition: tests.c:98
void fail(const char *format,...)
Prints failure message FORMAT as if with printf(), prefixing the output by the name of the test and F...
Definition: tests.c:83
void msg(const char *format,...)
Prints FORMAT as if with printf(), prefixing the output by the name of the test and following it with...
Definition: tests.c:67
static const struct test tests[]
Definition: tests.c:12
static const char * test_name
Definition: tests.c:43
test_func test_priority_donate_chain
test_func test_priority_fifo
Definition: priority-fifo.c:32
test_func test_alarm_multiple
Definition: alarm-wait.c:22
test_func test_priority_donate_nest
test_func test_priority_donate_lower
test_func test_alarm_zero
Tests timer_sleep(0), which should return immediately.
Definition: alarm-zero.c:11
test_func test_alarm_negative
Tests timer_sleep(-100).
test_func test_priority_condvar
test_func test_mlfqs_fair_20
Definition: mlfqs-fair.c:37
test_func test_alarm_simultaneous
test_func test_mlfqs_nice_2
Definition: mlfqs-fair.c:43
test_func test_priority_change
test_func test_priority_preempt
test_func test_mlfqs_nice_10
Definition: mlfqs-fair.c:49
test_func test_priority_donate_one
test_func test_alarm_single
Definition: alarm-wait.c:16
test_func test_priority_donate_multiple2
test_func test_priority_sema
Definition: priority-sema.c:16
test_func test_priority_donate_sema
test_func test_mlfqs_fair_2
Definition: mlfqs-fair.c:31
test_func test_mlfqs_block
Definition: mlfqs-block.c:23
test_func test_mlfqs_load_avg
test_func test_mlfqs_load_60
test_func test_mlfqs_load_1
Verifies that a single busy thread raises the load average to 0.5 in 38 to 45 seconds.
Definition: mlfqs-load-1.c:18
test_func test_mlfqs_recent_1
Checks that recent_cpu is calculated properly for the case of a single ready process.
test_func test_priority_donate_multiple
void test_func(void)
Definition: tests.h:6
test_func test_alarm_priority