2 * Copyright (c) 2012 Jilles Tjoelker
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
42 static char *run_test(long classification, const char *label, int severity,
43 const char *text, const char *action, const char *tag);
56 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
57 "illegal option -- z", "refer to manual", "BSD:ls:001",
59 "BSD:ls: ERROR: illegal option -- z\n"
60 "TO FIX: refer to manual BSD:ls:001\n"
63 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
64 "illegal option -- z", "refer to manual", "BSD:ls:001",
65 "text:severity:action:tag",
66 "illegal option -- z: ERROR\n"
67 "TO FIX: refer to manual BSD:ls:001\n"
70 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
71 "illegal option -- z", "refer to manual", "BSD:ls:001",
73 "illegal option -- z\n"
76 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
77 "illegal option -- z", "refer to manual", "BSD:ls:001",
79 "ERROR: illegal option -- z\n"
82 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
83 "illegal option -- z", "refer to manual", "BSD:ls:001",
85 "BSD:ls: ERROR: illegal option -- z\n"
86 "TO FIX: refer to manual BSD:ls:001\n"
89 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
90 "illegal option -- z", "refer to manual", "BSD:ls:001",
91 "tag:severity:text:nothing:action",
92 "BSD:ls: ERROR: illegal option -- z\n"
93 "TO FIX: refer to manual BSD:ls:001\n"
96 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
97 "illegal option -- z", "refer to manual", "BSD:ls:001",
99 "BSD:ls: ERROR: illegal option -- z\n"
100 "TO FIX: refer to manual BSD:ls:001\n"
103 MM_UTIL | MM_PRINT, MM_NULLLBL, MM_ERROR,
104 "illegal option -- z", "refer to manual", "BSD:ls:001",
106 "ERROR: illegal option -- z\n"
107 "TO FIX: refer to manual BSD:ls:001\n"
110 MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
111 "illegal option -- z", MM_NULLACT, MM_NULLTAG,
113 "BSD:ls: ERROR: illegal option -- z\n"
116 MM_UTIL | MM_NULLMC, "BSD:ls", MM_ERROR,
117 "illegal option -- z", "refer to manual", "BSD:ls:001",
122 MM_APPL | MM_PRINT, "ABCDEFGHIJ:abcdefghijklmn", MM_INFO,
123 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
124 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
125 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
126 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
127 "refer to manual", "ABCDEFGHIJ:abcdefghijklmn:001",
129 "ABCDEFGHIJ:abcdefghijklmn: INFO: "
130 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
131 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
132 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
133 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
134 "TO FIX: refer to manual ABCDEFGHIJ:abcdefghijklmn:001\n"
137 MM_OPSYS | MM_PRINT, "TEST:test", MM_HALT,
138 "failed", "nothing can help me", "NOTHING",
140 "TEST:test: HALT: failed\n"
141 "TO FIX: nothing can help me NOTHING\n"
144 MM_OPSYS | MM_PRINT, "TEST:test", MM_WARNING,
145 "failed", "nothing can help me", "NOTHING",
147 "TEST:test: WARNING: failed\n"
148 "TO FIX: nothing can help me NOTHING\n"
151 MM_OPSYS | MM_PRINT, "TEST:test", MM_NOSEV,
152 "failed", "nothing can help me", "NOTHING",
154 "TEST:test: failed\n"
155 "TO FIX: nothing can help me NOTHING\n"
160 run_test(long classification, const char *label, int severity,
161 const char *text, const char *action, const char *tag)
177 if (pip[1] != STDERR_FILENO &&
178 dup2(pip[1], STDERR_FILENO) == -1)
180 if (fmtmsg(classification, label, severity, text, action, tag)
188 result = malloc(resultsize);
190 while ((n = read(pip[0], p, result + resultsize - p - 1)) != 0) {
198 if (result + resultsize == p - 1) {
200 result = realloc(result, resultsize);
205 if (memchr(result, '\0', p - result) != NULL) {
211 while ((wpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR)
222 ATF_TC_WITHOUT_HEAD(fmtmsg_test);
223 ATF_TC_BODY(fmtmsg_test, tc)
229 for (i = 0; i < nitems(testcases); i++) {
231 if (t->msgverb != NULL)
232 setenv("MSGVERB", t->msgverb, 1);
235 result = run_test(t->classification, t->label, t->severity,
236 t->text, t->action, t->tag);
237 ATF_CHECK_MSG(result != NULL, "testcase %d failed", i + 1);
239 ATF_CHECK_MSG(strcmp(result, t->result) == 0,
240 "results for testcase %d didn't match; "
241 "`%s` != `%s`", i + 1, result, t->result);
249 ATF_TP_ADD_TC(tp, fmtmsg_test);
251 return (atf_no_error());