VirtualBox

source: vbox/trunk/src/testcase/tstRunTestcases.cpp@ 10904

Last change on this file since 10904 was 10904, checked in by vboxsync, 17 years ago

tstRunTestcases: Exclude testcase/tstDisasm-2

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1/* $Id: tstRunTestcases.cpp 10904 2008-07-28 11:12:32Z vboxsync $ */
2/** @file
3 * tstRunTescases - Driver program for running VBox testcase (tst* testcase/tst*).
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/runtime.h>
27#include <iprt/dir.h>
28#include <iprt/process.h>
29#include <iprt/path.h>
30#include <iprt/string.h>
31#include <iprt/stream.h>
32#include <iprt/thread.h>
33#include <iprt/err.h>
34#include <iprt/env.h>
35
36
37/*******************************************************************************
38* Global Variables *
39*******************************************************************************/
40/** The number of passed testcases. */
41static unsigned g_cPasses = 0;
42/** The number of failed testcases. */
43static unsigned g_cFailures = 0;
44/** The number of skipped testcases. */
45static unsigned g_cSkipped = 0;
46/** The exclude list. */
47static const char *g_apszExclude[] =
48{
49#if 1 // slow stuff
50 "testcase/tstFile",
51 "testcase/tstAvl",
52#endif
53 "testcase/tstFileLock",
54 "testcase/tstCritSect",
55 "testcase/tstCritSectW32",
56 "testcase/tstDeadlock",
57 "testcase/tstDisasm-2",
58 "testcase/tstLdr-2",
59 "testcase/tstLdr-3",
60 "testcase/tstLdr",
61 "testcase/tstLdrLoad",
62 "testcase/tstLdrObj",
63 "testcase/tstLdrObjR0",
64 "testcase/tstMove",
65 "testcase/tstRunTestcases",
66 "testcase/tstSDL",
67 "testcase/tstTime-3",
68 "testcase/tstSeamlessX11",
69 "./tstRunTestcases",
70 "./tstAnimate",
71 "./tstAPI",
72 "./tstHeadless",
73 "./tstMicro",
74 "./tstMicroGC",
75 "./tstVBoxDbg",
76 "./tstVMM-2",
77 "./tstTestServMgr",
78 "./tstXptDump",
79 "./tstnsIFileEnumerator",
80 "./tstSimpleTypeLib",
81 "./tstTestAtoms",
82 "./tstXptLink",
83 "./tstTestCallTemplates",
84#if 1 // later
85 "testcase/tstIntNetR0",
86 "./tstVMM",
87 "./tstVMReq",
88 "./tstVMREQ",
89#endif
90 /* final entry*/
91 ""
92};
93
94
95/**
96 * Checks if a testcase is include or should be skipped.
97 *
98 * @param pszTestcase The testcase (filename).
99 *
100 * @return true if the testcase is included.
101 * false if the testcase should be skipped.
102 */
103static bool IsTestcaseIncluded(const char *pszTestcase)
104{
105 char *pszDup = RTStrDup(pszTestcase);
106 if (pszDup)
107 {
108 RTPathStripExt(pszDup);
109 for (unsigned i = 0; i < ELEMENTS(g_apszExclude); i++)
110 {
111 if (!strcmp(g_apszExclude[i], pszDup))
112 {
113 RTStrFree(pszDup);
114 return false;
115 }
116 }
117 RTStrFree(pszDup);
118 return true;
119 }
120
121 RTPrintf("tstRunTestcases: Out of memory!\n");
122 return false;
123}
124
125
126/**
127 * Process the testcases found in the filter.
128 *
129 * @param pszFilter The filter (winnt) to pass to RTDirOpenFiltered for
130 * selecting the testcases.
131 * @param pszDir The directory we're processing.
132 */
133static void Process(const char *pszFilter, const char *pszDir)
134{
135 /*
136 * Open and enumerate the directory.
137 */
138 PRTDIR pDir;
139 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
140 if (RT_SUCCESS(rc))
141 {
142 for (;;)
143 {
144 RTDIRENTRY DirEntry;
145 rc = RTDirRead(pDir, &DirEntry, NULL);
146 if (RT_FAILURE(rc))
147 {
148 if (rc == VERR_NO_MORE_FILES)
149 rc = VINF_SUCCESS;
150 else
151 RTPrintf("tstRunTestcases: reading '%s' -> %Rrc\n", pszFilter, rc);
152 break;
153 }
154
155 /*
156 * Construct the testcase name.
157 */
158 char *pszTestcase;
159 RTStrAPrintf(&pszTestcase, "%s/%s", pszDir, DirEntry.szName);
160 if (!pszTestcase)
161 {
162 RTPrintf("tstRunTestcases: out of memory!\n");
163 rc = VERR_NO_MEMORY;
164 break;
165 }
166 if (IsTestcaseIncluded(pszTestcase))
167 {
168 /*
169 * Execute the testcase.
170 */
171 RTPrintf("*** %s: Executing...\n", pszTestcase); RTStrmFlush(g_pStdOut);
172 const char *papszArgs[2];
173 papszArgs[0] = pszTestcase;
174 papszArgs[1] = NULL;
175 RTPROCESS Process;
176 rc = RTProcCreate(pszTestcase, papszArgs, RTENV_DEFAULT, 0, &Process);
177 if (RT_SUCCESS(rc))
178 {
179 /*
180 * Wait for the process and collect it's return code.
181 * If it takes too long, we'll terminate it and continue.
182 */
183 RTTIMESPEC Start;
184 RTTimeNow(&Start);
185 RTPROCSTATUS ProcStatus;
186 for (;;)
187 {
188 rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
189 if (rc != VERR_PROCESS_RUNNING)
190 break;
191 RTTIMESPEC Now;
192 if (RTTimeSpecGetMilli(RTTimeSpecSub(RTTimeNow(&Now), &Start)) > 60*1000 /* 1 min */)
193 {
194 RTPrintf("*** %s: FAILED - timed out. killing it.\n", pszTestcase);
195 RTProcTerminate(Process);
196 RTThreadSleep(100);
197 RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
198 g_cFailures++;
199 break;
200 }
201 RTThreadSleep(100);
202 }
203
204 /*
205 * Examin the exit status.
206 */
207 if (RT_SUCCESS(rc))
208 {
209 if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
210 && ProcStatus.iStatus == 0)
211 {
212 RTPrintf("*** %s: PASSED\n", pszTestcase);
213 g_cPasses++;
214 }
215 else
216 {
217 RTPrintf("*** %s: FAILED\n", pszTestcase);
218 g_cFailures++;
219 }
220 }
221 else if (rc != VERR_PROCESS_RUNNING)
222 {
223 RTPrintf("tstRunTestcases: %s: RTProcWait failed -> %Rrc\n", pszTestcase, rc);
224 g_cFailures++;
225 }
226 }
227 else
228 {
229 RTPrintf("tstRunTestcases: %s: failed to start -> %Rrc\n", pszTestcase, rc);
230 g_cFailures++;
231 }
232
233 }
234 else
235 {
236 RTPrintf("tstRunTestcases: %s: SKIPPED\n", pszTestcase);
237 g_cSkipped++;
238 }
239 RTStrFree(pszTestcase);
240 } /* enumeration loop */
241
242 RTDirClose(pDir);
243 }
244 else
245 RTPrintf("tstRunTestcases: opening '%s' -> %Rrc\n", pszDir, rc);
246}
247
248
249
250int main(int argc, char **argv)
251{
252 RTR3Init(false, 0);
253
254 if (argc == 1)
255 {
256 Process("testcase/tst*", "testcase");
257 Process("tst*", ".");
258 }
259 else
260 {
261 char szDir[RTPATH_MAX];
262 for (int i = 1; i < argc; i++)
263 {
264 if (argv[i][0] == '-')
265 {
266 switch (argv[i][1])
267 {
268 /* case '':... */
269
270 default:
271 RTPrintf("syntax error: Option '%s' is not recognized\n", argv[i]);
272 return 1;
273 }
274 }
275 else
276 {
277 size_t cch = strlen(argv[i]);
278 if (cch >= sizeof(szDir))
279 {
280 RTPrintf("syntax error: '%s' is too long!\n", argv[i]);
281 return 1;
282 }
283 memcpy(szDir, argv[i], cch + 1);
284 char *pszFilename = RTPathFilename(szDir);
285 if (!pszFilename)
286 {
287 RTPrintf("syntax error: '%s' does not include a file name or file name mask!\n", argv[i]);
288 return 1;
289 }
290 RTPathStripFilename(szDir);
291 Process(argv[i], szDir);
292 }
293 }
294 }
295
296 RTPrintf("\n"
297 "********************\n"
298 "*** PASSED: %u\n"
299 "*** FAILED: %u\n"
300 "*** SKIPPED: %u\n"
301 "*** TOTAL: %u\n",
302 g_cPasses,
303 g_cFailures,
304 g_cSkipped,
305 g_cPasses + g_cFailures + g_cSkipped);
306 return !!g_cFailures;
307}
308
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette