2 * Copyright (c) 2007 Michael Telahun Makonnen
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
37 #include "test_subr.h"
42 char g_funcname[FUNCNAMESIZE];
43 char g_testdesc[LINESIZE];
44 char g_errbuf[LINESIZE];
47 set_funcname(char *bufp, size_t bufsize)
49 strlcpy(g_funcname, bufp,
50 bufsize < FUNCNAMESIZE ? bufsize : FUNCNAMESIZE);
54 * desc is a NULL-terminated string.
57 checkptr(caddr_t expected, caddr_t got, const char *desc)
63 memset((void *)sbuf, 0, LINESIZE);
64 snprintf(g_testdesc, LINESIZE, desc);
68 if (got == expected) {
69 len = snprintf(sbuf, LINESIZE, "ok");
73 len = snprintf(sbuf, LINESIZE, "not ok");
74 snprintf(g_errbuf, LINESIZE, " : Expected %#x, but got %#x",
75 (unsigned int)expected, (unsigned int)got);
78 snprintf(sbuf + len, LINESIZE - len, " %d - %s (%s)",
79 g_total, g_funcname, g_testdesc);
85 memset((void *)g_errbuf, 0, LINESIZE);
86 memset((void *)g_testdesc, 0, LINESIZE);
90 checkstr(const char *expected, const char *got, size_t explen, const char *desc)
96 memset((void *)sbuf, 0, LINESIZE);
97 snprintf(g_testdesc, LINESIZE, desc);
101 if (strncmp(expected, got, explen) == 0) {
102 len = snprintf(sbuf, LINESIZE, "ok");
106 len = snprintf(sbuf, LINESIZE, "not ok");
107 snprintf(g_errbuf, LINESIZE,
108 " : Expected %s, but got %s", expected, got);
111 snprintf(sbuf + len, LINESIZE - len, " %d - %s (%s)",
112 g_total, g_funcname, g_testdesc);
118 memset((void *)g_errbuf, 0, LINESIZE);
119 memset((void *)g_testdesc, 0, LINESIZE);
123 checknum(int expected, int got, int cmp, const char *desc)
130 memset((void *)sbuf, 0, LINESIZE);
131 snprintf(g_testdesc, LINESIZE, desc);
138 pass = (got == expected) ? 1 : 0;
141 pass = (got > expected) ? 1 : 0;
144 pass = (got < expected) ? 1 : 0;
148 len = snprintf(sbuf, LINESIZE, "ok");
152 len = snprintf(sbuf, LINESIZE, "not ok");
153 snprintf(g_errbuf, LINESIZE,
154 " : Expected %d, but got %d", expected, got);
157 snprintf(sbuf + len, LINESIZE - len, " %d - %s (%s)",
158 g_total, g_funcname, g_testdesc);
164 memset((void *)g_errbuf, 0, LINESIZE);
165 memset((void *)g_testdesc, 0, LINESIZE);