xref: /kvm-unit-tests/lib/report.c (revision d3aacb4f57d05f74f2030dbe12e7dfd6aa1b273d)
1 /*
2  * Test result reporting
3  *
4  * Copyright (c) Siemens AG, 2014
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *  Andrew Jones <drjones@redhat.com>
9  *
10  * This work is licensed under the terms of the GNU LGPL, version 2.
11  */
12 
13 #include "libcflat.h"
14 
15 static unsigned int tests, failures, xfailures;
16 
17 void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
18 {
19 	char *pass = xfail ? "XPASS" : "PASS";
20 	char *fail = xfail ? "XFAIL" : "FAIL";
21 	char buf[2000];
22 
23 	tests++;
24 	printf("%s: ", cond ? pass : fail);
25 	vsnprintf(buf, sizeof(buf), msg_fmt, va);
26 	puts(buf);
27 	puts("\n");
28 	if (xfail && cond)
29 		failures++;
30 	else if (xfail)
31 		xfailures++;
32 	else if (!cond)
33 		failures++;
34 }
35 
36 void report(const char *msg_fmt, bool pass, ...)
37 {
38 	va_list va;
39 	va_start(va, pass);
40 	va_report_xfail(msg_fmt, false, pass, va);
41 	va_end(va);
42 }
43 
44 void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...)
45 {
46 	va_list va;
47 	va_start(va, pass);
48 	va_report_xfail(msg_fmt, xfail, pass, va);
49 	va_end(va);
50 }
51 
52 int report_summary(void)
53 {
54 	printf("\nSUMMARY: %d tests, %d unexpected failures", tests, failures);
55 	if (xfailures)
56 		printf(", %d expected failures\n", xfailures);
57 	else
58 		printf("\n");
59 	return failures > 0 ? 1 : 0;
60 }
61