C99 testsuite readiness: Compile more tests with -std=gnu89
[official-gcc.git] / gcc / jit / jit-dejagnu.h
blobbdf5785753701c7df9f8ca307c7ea6d225df883f
1 /* DejaGnu unit testing header.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
4 This file is part of DejaGnu.
6 DejaGnu is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 DejaGnu is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DejaGnu; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* Imported from 1.6.2 with modifications
21 * to avoid and unused symbol in C compilations
22 * avoid wait () clashing with system-provided routines
23 * provide a deterministic last line of output after the totals. */
25 #ifndef __DEJAGNU_H__
26 #define __DEJAGNU_H__
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <string.h>
32 /* If you have problems with DejaGnu dropping failed, untested, or
33 * unresolved messages generated by a unit testcase, then: */
35 /* #define _DEJAGNU_WAIT_ */
37 #ifdef _DEJAGNU_WAIT_
38 #include <sys/time.h>
39 #include <sys/types.h>
40 #include <unistd.h>
41 #endif
43 static int passed;
44 static int failed;
45 static int untest;
46 static int unresolve;
47 static int xfailed;
48 #ifdef __cplusplus
49 static int xpassed;
50 #endif
52 static char buffer[512];
54 #ifdef _DEJAGNU_WAIT_
55 void
56 dg_wait (void)
58 fd_set rfds;
59 struct timeval tv;
61 FD_ZERO (&rfds);
62 tv.tv_sec = 0;
63 tv.tv_usec = 1;
65 select (0, &rfds, NULL, NULL, &tv);
67 #endif
69 inline void
70 pass (const char* fmt, ...)
72 va_list ap;
74 passed++;
75 va_start (ap, fmt);
76 vsnprintf (buffer, sizeof (buffer), fmt, ap);
77 va_end (ap);
78 printf ("\tPASSED: %s\n", buffer);
79 #ifdef _DEJAGNU_WAIT_
80 dg_wait ();
81 #endif
84 inline void
85 xpass (const char* fmt, ...)
87 va_list ap;
89 passed++;
90 va_start (ap, fmt);
91 vsnprintf (buffer, sizeof (buffer), fmt, ap);
92 va_end (ap);
93 printf ("\tXPASSED: %s\n", buffer);
94 #ifdef _DEJAGNU_WAIT_
95 dg_wait ();
96 #endif
99 inline void
100 fail (const char* fmt, ...)
102 va_list ap;
104 failed++;
105 va_start (ap, fmt);
106 vsnprintf (buffer, sizeof (buffer), fmt, ap);
107 va_end (ap);
108 printf ("\tFAILED: %s\n", buffer);
109 #ifdef _DEJAGNU_WAIT_
110 dg_wait ();
111 #endif
114 inline void
115 xfail (const char* fmt, ...)
117 va_list ap;
119 failed++;
120 va_start (ap, fmt);
121 vsnprintf (buffer, sizeof (buffer), fmt, ap);
122 va_end (ap);
123 printf ("\tXFAILED: %s\n", buffer);
124 #ifdef _DEJAGNU_WAIT_
125 dg_wait ();
126 #endif
129 inline void
130 untested (const char* fmt, ...)
132 va_list ap;
134 untest++;
135 va_start (ap, fmt);
136 vsnprintf (buffer, sizeof (buffer), fmt, ap);
137 va_end (ap);
138 printf ("\tUNTESTED: %s\n", buffer);
139 #ifdef _DEJAGNU_WAIT_
140 dg_wait ();
141 #endif
144 inline void
145 unresolved (const char* fmt, ...)
147 va_list ap;
149 unresolve++;
150 va_start (ap, fmt);
151 vsnprintf (buffer, sizeof (buffer), fmt, ap);
152 va_end (ap);
153 printf ("\tUNRESOLVED: %s\n", buffer);
154 #ifdef _DEJAGNU_WAIT_
155 dg_wait ();
156 #endif
159 inline void
160 note (const char* fmt, ...)
162 va_list ap;
164 va_start (ap, fmt);
165 vsnprintf (buffer, sizeof (buffer), fmt, ap);
166 va_end (ap);
167 printf ("\tNOTE: %s\n", buffer);
168 #ifdef _DEJAGNU_WAIT_
169 dg_wait ();
170 #endif
173 inline void
174 totals (void)
176 printf ("\nTotals:\n");
177 printf ("\t#passed:\t\t%d\n", passed);
178 printf ("\t#real failed:\t\t%d\n", failed);
179 if (xfailed)
180 printf ("\t#expected failures:\t\t%d\n", xfailed);
181 if (untest)
182 printf ("\t#untested:\t\t%d\n", untest);
183 if (unresolve)
184 printf ("\t#unresolved:\t\t%d\n", unresolve);
185 printf ("\njit-dg-harness-complete\n");
188 #ifdef __cplusplus
190 #include <iostream>
191 #include <iomanip>
192 #include <fstream>
193 #include <string>
195 const char *outstate_list[] = {
196 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
199 const char ** outstate = outstate_list;
201 enum teststate { FAILED, PASSED, UNTESTED, UNRESOLVED, XFAILED, XPASSED} laststate;
203 class TestState {
204 private:
205 teststate laststate;
206 std::string lastmsg;
207 public:
208 TestState (void)
210 passed = 0;
211 failed = 0;
212 untest = 0;
213 xpassed = 0;
214 xfailed = 0;
215 unresolve = 0;
218 ~TestState (void) { totals(); }
220 void testrun (bool b, std::string s)
222 if (b)
223 pass (s);
224 else
225 fail (s);
228 void pass (std::string s)
230 passed++;
231 laststate = PASSED;
232 lastmsg = s;
233 std::cout << "\t" << outstate[PASSED] << s << std::endl;
236 void pass (const char *c)
238 std::string s = c;
239 pass (s);
242 void xpass (std::string s)
244 xpassed++;
245 laststate = PASSED;
246 lastmsg = s;
247 std::cout << "\t" << outstate[XPASSED] << s << std::endl;
250 void xpass (const char *c)
252 std::string s = c;
253 xpass (s);
256 void fail (std::string s)
258 failed++;
259 laststate = FAILED;
260 lastmsg = s;
261 std::cout << "\t" << outstate[FAILED] << s << std::endl;
264 void fail (const char *c)
266 std::string s = c;
267 fail (s);
270 void xfail (std::string s)
272 xfailed++;
273 laststate = XFAILED;
274 lastmsg = s;
275 std::cout << "\t" << outstate[XFAILED] << s << std::endl;
278 void xfail (const char *c)
280 std::string s = c;
281 xfail (s);
284 void untested (std::string s)
286 untest++;
287 laststate = UNTESTED;
288 lastmsg = s;
289 std::cout << "\t" << outstate[UNTESTED] << s << std::endl;
292 void untested (const char *c)
294 std::string s = c;
295 untested (s);
298 void unresolved (std::string s)
300 unresolve++;
301 laststate = UNRESOLVED;
302 lastmsg = s;
303 std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl;
306 void unresolved (const char *c)
308 std::string s = c;
309 unresolved (s);
312 void totals (void)
314 std::cout << "\t#passed:\t\t" << passed << std::endl;
315 std::cout << "\t#real failed:\t\t" << failed << std::endl;
316 if (xfailed)
317 std::cout << "\t#expected failures:\t\t" << xfailed << std::endl;
318 if (xpassed)
319 std::cout << "\t#unexpected passes:\t\t" << xpassed << std::endl;
320 if (untest)
321 std::cout << "\t#untested:\t\t" << untest << std::endl;
322 if (unresolve)
323 std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
324 std::cout << "\njit-dg-harness-complete" << std::endl;
327 // This is so this class can be printed in an ostream.
328 friend std::ostream & operator << (std::ostream &os, TestState& t)
330 return os << "\t" << outstate[t.laststate] << t.lastmsg ;
333 int GetState (void) { return laststate; }
334 std::string GetMsg (void) { return lastmsg; }
337 #endif /* __cplusplus */
338 #endif /* _DEJAGNU_H_ */