2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2010 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <grub/misc.h>
21
#include <grub/test.h>
23
struct grub_test_failure
25
/* The next failure. */
26
struct grub_test_failure *next;
28
/* The test source file name. */
31
/* The test function name. */
34
/* The test call line number. */
37
/* The test failure message. */
40
typedef struct grub_test_failure *grub_test_failure_t;
42
grub_test_t grub_test_list;
43
static grub_test_failure_t failure_list;
46
add_failure (const char *file,
48
grub_uint32_t line, const char *fmt, va_list args)
50
grub_test_failure_t failure;
52
failure = (grub_test_failure_t) grub_malloc (sizeof (*failure));
56
failure->file = grub_strdup (file ? : "<unknown_file>");
57
failure->funp = grub_strdup (funp ? : "<unknown_function>");
59
failure->message = grub_xvasprintf (fmt, args);
61
grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure));
67
grub_test_failure_t item;
69
while ((item = grub_list_pop (GRUB_AS_LIST_P (&failure_list))) != 0)
72
grub_free (item->message);
75
grub_free (item->funp);
78
grub_free (item->file);
86
grub_test_nonzero (int cond,
88
const char *funp, grub_uint32_t line, const char *fmt, ...)
96
add_failure (file, funp, line, fmt, ap);
101
grub_test_register (const char *name, void (*test_main) (void))
105
test = (grub_test_t) grub_malloc (sizeof (*test));
109
test->name = grub_strdup (name);
110
test->main = test_main;
112
grub_list_push (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test));
116
grub_test_unregister (const char *name)
120
test = (grub_test_t) grub_named_list_find
121
(GRUB_AS_NAMED_LIST (grub_test_list), name);
125
grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test));
128
grub_free (test->name);
135
grub_test_run (grub_test_t test)
137
auto int print_failure (grub_test_failure_t item);
138
int print_failure (grub_test_failure_t item)
140
grub_test_failure_t failure = (grub_test_failure_t) item;
142
grub_printf (" %s:%s:%u: %s\n",
143
(failure->file ? : "<unknown_file>"),
144
(failure->funp ? : "<unknown_function>"),
145
failure->line, (failure->message ? : "<no message>"));
151
grub_printf ("%s:\n", test->name);
152
grub_list_iterate (GRUB_AS_LIST (failure_list),
153
(grub_list_hook_t) print_failure);
155
grub_printf ("%s: PASS\n", test->name);
157
grub_printf ("%s: FAIL\n", test->name);
160
return GRUB_ERR_NONE;