Xen Test Framework
report.c
Go to the documentation of this file.
1#include <xtf/lib.h>
2#include <xtf/report.h>
3#include <xtf/hypercall.h>
4
11};
12
14static enum test_status status;
15
17static bool warnings;
18
19static const char *status_to_str[] =
20{
21#define STA(x) [STATUS_ ## x] = #x
22
23 STA(RUNNING),
24 STA(SUCCESS),
25 STA(SKIP),
26 STA(ERROR),
27 STA(FAILURE),
28
29#undef STA
30};
31
32static void set_status(enum test_status s)
33{
34 if ( s > status )
35 status = s;
36}
37
38void xtf_success(const char *fmt, ...)
39{
41
42 if ( fmt )
43 {
44 va_list args;
45
46 va_start(args, fmt);
47 vprintk(fmt, args);
48 va_end(args);
49 }
50}
51
52void xtf_warning(const char *fmt, ...)
53{
54 warnings = true;
55
56 if ( fmt )
57 {
58 va_list args;
59
60 va_start(args, fmt);
61 vprintk(fmt, args);
62 va_end(args);
63 }
64}
65
66void xtf_skip(const char *fmt, ...)
67{
69
70 if ( fmt )
71 {
72 va_list args;
73
74 va_start(args, fmt);
75 vprintk(fmt, args);
76 va_end(args);
77 }
78}
79
80void xtf_error(const char *fmt, ...)
81{
83
84 if ( fmt )
85 {
86 va_list args;
87
88 va_start(args, fmt);
89 vprintk(fmt, args);
90 va_end(args);
91 }
92}
93
94void xtf_failure(const char *fmt, ...)
95{
97
98 if ( fmt )
99 {
100 va_list args;
101
102 va_start(args, fmt);
103 vprintk(fmt, args);
104 va_end(args);
105 }
106}
107
109{
110 if ( status < STATUS_SUCCESS )
111 xtf_error("Test did not report a status\n");
112
113 printk("Test result: %s%s\n",
115 (warnings && (status == STATUS_SUCCESS)) ?
116 " with warnings" : "");
117}
118
120{
121 return status != STATUS_RUNNING;
122}
123
124void xtf_exit(void)
125{
128 panic("xtf_exit(): hypercall_shutdown(SHUTDOWN_poweroff) returned\n");
129}
130
131/*
132 * Local variables:
133 * mode: C
134 * c-file-style: "BSD"
135 * c-basic-offset: 4
136 * tab-width: 4
137 * indent-tabs-mode: nil
138 * End:
139 */
void vprintk(const char *fmt, va_list args)
Definition: console.c:119
void printk(const char *fmt,...)
Definition: console.c:134
static long hypercall_shutdown(unsigned int reason)
Definition: hypercall.h:201
void panic(const char *fmt,...)
Definition: lib.c:15
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
static enum test_status status
Current status of this test.
Definition: report.c:14
static void set_status(enum test_status s)
Definition: report.c:32
void xtf_report_status(void)
Print a status report.
Definition: report.c:108
static const char * status_to_str[]
Definition: report.c:19
test_status
Definition: report.c:5
@ STATUS_RUNNING
Test not yet completed.
Definition: report.c:6
@ STATUS_FAILURE
Issue with the tested matter.
Definition: report.c:10
@ STATUS_SKIP
Test cannot be completed.
Definition: report.c:8
@ STATUS_ERROR
Issue with the test itself.
Definition: report.c:9
@ STATUS_SUCCESS
Test was successful.
Definition: report.c:7
static bool warnings
Whether a warning has occurred.
Definition: report.c:17
void xtf_exit(void)
Exit the test early.
Definition: report.c:124
void xtf_skip(const char *fmt,...)
Report a test skip.
Definition: report.c:66
bool xtf_status_reported(void)
Query whether a status has already been reported.
Definition: report.c:119
#define STA(x)
void xtf_warning(const char *fmt,...)
Report a test warning.
Definition: report.c:52
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
API for reporting test status.
#define SHUTDOWN_poweroff
Definition: sched.h:26
#define va_end(v)
Definition: stdarg.h:11
#define va_start(v, l)
Definition: stdarg.h:10
__builtin_va_list va_list
Definition: stdarg.h:9