1180059Sjhb/*-
2180059Sjhb * Copyright (c) 2008 Yahoo!, Inc.
3180059Sjhb * All rights reserved.
4180059Sjhb * Written by: John Baldwin <jhb@FreeBSD.org>
5180059Sjhb *
6180059Sjhb * Redistribution and use in source and binary forms, with or without
7180059Sjhb * modification, are permitted provided that the following conditions
8180059Sjhb * are met:
9180059Sjhb * 1. Redistributions of source code must retain the above copyright
10180059Sjhb *    notice, this list of conditions and the following disclaimer.
11180059Sjhb * 2. Redistributions in binary form must reproduce the above copyright
12180059Sjhb *    notice, this list of conditions and the following disclaimer in the
13180059Sjhb *    documentation and/or other materials provided with the distribution.
14180059Sjhb * 3. Neither the name of the author nor the names of any co-contributors
15180059Sjhb *    may be used to endorse or promote products derived from this software
16180059Sjhb *    without specific prior written permission.
17180059Sjhb *
18180059Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19180059Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20180059Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21180059Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22180059Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23180059Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24180059Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25180059Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26180059Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27180059Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28180059Sjhb * SUCH DAMAGE.
29180059Sjhb */
30180059Sjhb
31180059Sjhb#include <sys/cdefs.h>
32180059Sjhb__FBSDID("$FreeBSD$");
33180059Sjhb
34180059Sjhb#include <stdarg.h>
35180059Sjhb#include <stdio.h>
36180059Sjhb
37180059Sjhb#include "test.h"
38180059Sjhb
39180059Sjhbstatic int test_index;
40180059Sjhbstatic struct regression_test *test;
41180059Sjhbstatic int test_acknowleged;
42180059Sjhb
43180059SjhbSET_DECLARE(regression_tests_set, struct regression_test);
44180059Sjhb
45180059Sjhb/*
46180059Sjhb * Outputs a test summary of the following:
47180059Sjhb *
48180059Sjhb * <status> <test #> [name] [# <fmt> [fmt args]]
49180059Sjhb */
50180059Sjhbstatic void
51180059Sjhbvprint_status(const char *status, const char *fmt, va_list ap)
52180059Sjhb{
53180059Sjhb
54180059Sjhb	printf("%s %d", status, test_index);
55180059Sjhb	if (test->rt_name)
56180059Sjhb		printf(" - %s", test->rt_name);
57180059Sjhb	if (fmt) {
58180059Sjhb		printf(" # ");
59180059Sjhb		vprintf(fmt, ap);
60180059Sjhb	}
61180059Sjhb	printf("\n");
62180059Sjhb	test_acknowleged = 1;
63180059Sjhb}
64180059Sjhb
65180059Sjhbstatic void
66180059Sjhbprint_status(const char *status, const char *fmt, ...)
67180059Sjhb{
68180059Sjhb	va_list ap;
69180059Sjhb
70180059Sjhb	va_start(ap, fmt);
71180059Sjhb	vprint_status(status, fmt, ap);
72180059Sjhb	va_end(ap);
73180059Sjhb}
74180059Sjhb
75180059Sjhbvoid
76180059Sjhbpass(void)
77180059Sjhb{
78180059Sjhb
79180059Sjhb	print_status("ok", NULL);
80180059Sjhb}
81180059Sjhb
82180059Sjhbvoid
83180059Sjhbfail(void)
84180059Sjhb{
85180059Sjhb
86180059Sjhb	print_status("not ok", NULL);
87180059Sjhb}
88180059Sjhb
89180059Sjhbvoid
90180059Sjhbfail_err(const char *fmt, ...)
91180059Sjhb{
92180059Sjhb	va_list ap;
93180059Sjhb
94180059Sjhb	va_start(ap, fmt);
95180059Sjhb	vprint_status("not ok", fmt, ap);
96180059Sjhb	va_end(ap);
97180059Sjhb}
98180059Sjhb
99180059Sjhbvoid
100180059Sjhbskip(const char *reason)
101180059Sjhb{
102180059Sjhb
103180059Sjhb	print_status("ok", "skip %s", reason);
104180059Sjhb}
105180059Sjhb
106180059Sjhbvoid
107180059Sjhbtodo(const char *reason)
108180059Sjhb{
109180059Sjhb
110180059Sjhb	print_status("not ok", "TODO %s", reason);
111180059Sjhb}
112180059Sjhb
113180059Sjhbvoid
114180059Sjhbrun_tests(void)
115180059Sjhb{
116180059Sjhb	struct regression_test **testp;
117180059Sjhb
118180059Sjhb	printf("1..%td\n", SET_COUNT(regression_tests_set));
119180059Sjhb	test_index = 1;
120180059Sjhb	SET_FOREACH(testp, regression_tests_set) {
121180059Sjhb		test_acknowleged = 0;
122180059Sjhb		test = *testp;
123180059Sjhb		test->rt_function();
124180059Sjhb		if (!test_acknowleged)
125180059Sjhb			print_status("not ok", "unknown status");
126180059Sjhb		test_index++;
127180059Sjhb	}
128180059Sjhb}
129