CS318 - Pintos
Pintos source browser for JHU CS318 course
tests.c
Go to the documentation of this file.
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 
putchar
int putchar(int c)
Writes C to the vga display and serial port.
Definition: console.c:163
test_mlfqs_load_1
test_func test_mlfqs_load_1
name
char * name[]
Definition: insult.c:47
test_mlfqs_fair_2
test_func test_mlfqs_fair_2
va_end
#define va_end(LIST)
Definition: stdarg.h:10
msg
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
va_start
#define va_start(LIST, ARG)
Definition: stdarg.h:9
test_priority_donate_chain
test_func test_priority_donate_chain
test_priority_donate_sema
test_func test_priority_donate_sema
test
Definition: tests.c:6
test_priority_change
test_func test_priority_change
string.h
strcmp
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
Definition: string.c:73
test_alarm_single
test_func test_alarm_single
test_priority_donate_lower
test_func test_priority_donate_lower
test_alarm_negative
test_func test_alarm_negative
tests
static const struct test tests[]
Definition: tests.c:12
test_mlfqs_nice_10
test_func test_mlfqs_nice_10
PANIC
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
Definition: debug.h:14
test_alarm_zero
test_func test_alarm_zero
test_mlfqs_load_avg
test_func test_mlfqs_load_avg
test_priority_donate_nest
test_func test_priority_donate_nest
test_func
void test_func(void)
Definition: tests.h:6
printf
int printf(const char *format,...)
Writes formatted output to the console.
Definition: stdio.c:79
test_priority_condvar
test_func test_priority_condvar
test_priority_donate_multiple2
test_func test_priority_donate_multiple2
test_alarm_simultaneous
test_func test_alarm_simultaneous
test_mlfqs_block
test_func test_mlfqs_block
vprintf
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
fail
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
test_name
static const char * test_name
Definition: tests.c:43
va_list
__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
pass
void pass(void)
Prints a message indicating the current test passed.
Definition: tests.c:98
test_mlfqs_load_60
test_func test_mlfqs_load_60
test_priority_fifo
test_func test_priority_fifo
test_mlfqs_fair_20
test_func test_mlfqs_fair_20
test_mlfqs_recent_1
test_func test_mlfqs_recent_1
test_priority_preempt
test_func test_priority_preempt
test_alarm_priority
test_func test_alarm_priority
test::function
test_func * function
Definition: tests.c:9
test_priority_donate_multiple
test_func test_priority_donate_multiple
tests.h
test::name
const char * name
Definition: tests.c:8
test_priority_sema
test_func test_priority_sema
test_priority_donate_one
test_func test_priority_donate_one
test_alarm_multiple
test_func test_alarm_multiple
run_test
void run_test(const char *name)
Runs the test named NAME.
Definition: tests.c:47
debug.h
test_mlfqs_nice_2
test_func test_mlfqs_nice_2