10SN/A/*- 22362SN/A * Copyright (c) 2008 Yahoo!, Inc. 30SN/A * All rights reserved. 40SN/A * Written by: John Baldwin <jhb@FreeBSD.org> 50SN/A * 60SN/A * Redistribution and use in source and binary forms, with or without 72362SN/A * modification, are permitted provided that the following conditions 80SN/A * are met: 92362SN/A * 1. Redistributions of source code must retain the above copyright 100SN/A * notice, this list of conditions and the following disclaimer. 110SN/A * 2. Redistributions in binary form must reproduce the above copyright 120SN/A * notice, this list of conditions and the following disclaimer in the 130SN/A * documentation and/or other materials provided with the distribution. 140SN/A * 3. Neither the name of the author nor the names of any co-contributors 150SN/A * may be used to endorse or promote products derived from this software 160SN/A * without specific prior written permission. 170SN/A * 180SN/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 190SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 200SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212362SN/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 222362SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232362SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 240SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 250SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 260SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 270SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 280SN/A * SUCH DAMAGE. 290SN/A */ 300SN/A 310SN/A#include <sys/cdefs.h> 320SN/A__FBSDID("$FreeBSD$"); 330SN/A 340SN/A#include <stdarg.h> 350SN/A#include <stdio.h> 360SN/A 370SN/A#include "test.h" 380SN/A 390SN/Astatic int test_index; 400SN/Astatic struct regression_test *test; 410SN/Astatic int test_acknowleged; 420SN/A 430SN/ASET_DECLARE(regression_tests_set, struct regression_test); 440SN/A 450SN/A/* 460SN/A * Outputs a test summary of the following: 470SN/A * 480SN/A * <status> <test #> [name] [# <fmt> [fmt args]] 490SN/A */ 500SN/Astatic void 510SN/Avprint_status(const char *status, const char *fmt, va_list ap) 520SN/A{ 530SN/A 540SN/A printf("%s %d", status, test_index); 550SN/A if (test->rt_name) 560SN/A printf(" - %s", test->rt_name); 570SN/A if (fmt) { 580SN/A printf(" # "); 590SN/A vprintf(fmt, ap); 600SN/A } 610SN/A printf("\n"); 620SN/A test_acknowleged = 1; 630SN/A} 640SN/A 650SN/Astatic void 660SN/Aprint_status(const char *status, const char *fmt, ...) 670SN/A{ 680SN/A va_list ap; 690SN/A 700SN/A va_start(ap, fmt); 710SN/A vprint_status(status, fmt, ap); 720SN/A va_end(ap); 730SN/A} 740SN/A 750SN/Avoid 760SN/Apass(void) 770SN/A{ 780SN/A 790SN/A print_status("ok", NULL); 800SN/A} 810SN/A 820SN/Avoid 830SN/Afail(void) 840SN/A{ 850SN/A 860SN/A print_status("not ok", NULL); 870SN/A} 880SN/A 890SN/Avoid 900SN/Afail_err(const char *fmt, ...) 910SN/A{ 920SN/A va_list ap; 930SN/A 940SN/A va_start(ap, fmt); 950SN/A vprint_status("not ok", fmt, ap); 960SN/A va_end(ap); 970SN/A} 980SN/A 990SN/Avoid 1000SN/Askip(const char *reason) 1010SN/A{ 1020SN/A 1030SN/A print_status("ok", "skip %s", reason); 1040SN/A} 1050SN/A 1060SN/Avoid 1070SN/Atodo(const char *reason) 1080SN/A{ 1090SN/A 1100SN/A print_status("not ok", "TODO %s", reason); 1110SN/A} 1120SN/A 1130SN/Avoid 1140SN/Arun_tests(void) 1150SN/A{ 1160SN/A struct regression_test **testp; 1170SN/A 1180SN/A printf("1..%td\n", SET_COUNT(regression_tests_set)); 1190SN/A test_index = 1; 1200SN/A SET_FOREACH(testp, regression_tests_set) { 1210SN/A test_acknowleged = 0; 1220SN/A test = *testp; 1230SN/A test->rt_function(); 1240SN/A if (!test_acknowleged) 1250SN/A print_status("not ok", "unknown status"); 1260SN/A test_index++; 1270SN/A } 1280SN/A} 1290SN/A