VirtualBox

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

Last change on this file since 10906 was 10906, checked in by vboxsync, 16 years ago

tstRunTestcases: Exclude tstGlobalConfig and tstFileAppendWin-1.

  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1/* $Id: tstRunTestcases.cpp 10906 2008-07-28 11:31:40Z 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.virtualbox.org. 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/tstFileAppendWin-1",
59 "testcase/tstGlobalConfig",
60 "testcase/tstLdr-2",
61 "testcase/tstLdr-3",
62 "testcase/tstLdr",
63 "testcase/tstLdrLoad",
64 "testcase/tstLdrObj",
65 "testcase/tstLdrObjR0",
66 "testcase/tstMove",
67 "testcase/tstRunTestcases",
68 "testcase/tstSDL",
69 "testcase/tstTime-3",
70 "testcase/tstSeamlessX11",
71 "./tstRunTestcases",
72 "./tstAnimate",
73 "./tstAPI",
74 "./tstHeadless",
75 "./tstMicro",
76 "./tstMicroGC",
77 "./tstVBoxDbg",
78 "./tstVMM-2",
79 "./tstTestServMgr",
80 "./tstXptDump",
81 "./tstnsIFileEnumerator",
82 "./tstSimpleTypeLib",
83 "./tstTestAtoms",
84 "./tstXptLink",
85 "./tstTestCallTemplates",
86#if 1 // later
87 "testcase/tstIntNetR0",
88 "./tstVMM",
89 "./tstVMReq",
90 "./tstVMREQ",
91#endif
92 /* final entry*/
93 ""
94};
95
96
97/**
98 * Checks if a testcase is include or should be skipped.
99 *
100 * @param pszTestcase The testcase (filename).
101 *
102 * @return true if the testcase is included.
103 * false if the testcase should be skipped.
104 */
105static bool IsTestcaseIncluded(const char *pszTestcase)
106{
107 char *pszDup = RTStrDup(pszTestcase);
108 if (pszDup)
109 {
110 RTPathStripExt(pszDup);
111 for (unsigned i = 0; i < ELEMENTS(g_apszExclude); i++)
112 {
113 if (!strcmp(g_apszExclude[i], pszDup))
114 {
115 RTStrFree(pszDup);
116 return false;
117 }
118 }
119 RTStrFree(pszDup);
120 return true;
121 }
122
123 RTPrintf("tstRunTestcases: Out of memory!\n");
124 return false;
125}
126
127
128/**
129 * Process the testcases found in the filter.
130 *
131 * @param pszFilter The filter (winnt) to pass to RTDirOpenFiltered for
132 * selecting the testcases.
133 * @param pszDir The directory we're processing.
134 */
135static void Process(const char *pszFilter, const char *pszDir)
136{
137 /*
138 * Open and enumerate the directory.
139 */
140 PRTDIR pDir;
141 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
142 if (RT_SUCCESS(rc))
143 {
144 for (;;)
145 {
146 RTDIRENTRY DirEntry;
147 rc = RTDirRead(pDir, &DirEntry, NULL);
148 if (RT_FAILURE(rc))
149 {
150 if (rc == VERR_NO_MORE_FILES)
151 rc = VINF_SUCCESS;
152 else
153 RTPrintf("tstRunTestcases: reading '%s' -> %Rrc\n", pszFilter, rc);
154 break;
155 }
156
157 /*
158 * Construct the testcase name.
159 */
160 char *pszTestcase;
161 RTStrAPrintf(&pszTestcase, "%s/%s", pszDir, DirEntry.szName);
162 if (!pszTestcase)
163 {
164 RTPrintf("tstRunTestcases: out of memory!\n");
165 rc = VERR_NO_MEMORY;
166 break;
167 }
168 if (IsTestcaseIncluded(pszTestcase))
169 {
170 /*
171 * Execute the testcase.
172 */
173 RTPrintf("*** %s: Executing...\n", pszTestcase); RTStrmFlush(g_pStdOut);
174 const char *papszArgs[2];
175 papszArgs[0] = pszTestcase;
176 papszArgs[1] = NULL;
177 RTPROCESS Process;
178 rc = RTProcCreate(pszTestcase, papszArgs, RTENV_DEFAULT, 0, &Process);
179 if (RT_SUCCESS(rc))
180 {
181 /*
182 * Wait for the process and collect it's return code.
183 * If it takes too long, we'll terminate it and continue.
184 */
185 RTTIMESPEC Start;
186 RTTimeNow(&Start);
187 RTPROCSTATUS ProcStatus;
188 for (;;)
189 {
190 rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
191 if (rc != VERR_PROCESS_RUNNING)
192 break;
193 RTTIMESPEC Now;
194 if (RTTimeSpecGetMilli(RTTimeSpecSub(RTTimeNow(&Now), &Start)) > 60*1000 /* 1 min */)
195 {
196 RTPrintf("*** %s: FAILED - timed out. killing it.\n", pszTestcase);
197 RTProcTerminate(Process);
198 RTThreadSleep(100);
199 RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
200 g_cFailures++;
201 break;
202 }
203 RTThreadSleep(100);
204 }
205
206 /*
207 * Examin the exit status.
208 */
209 if (RT_SUCCESS(rc))
210 {
211 if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
212 && ProcStatus.iStatus == 0)
213 {
214 RTPrintf("*** %s: PASSED\n", pszTestcase);
215 g_cPasses++;
216 }
217 else
218 {
219 RTPrintf("*** %s: FAILED\n", pszTestcase);
220 g_cFailures++;
221 }
222 }
223 else if (rc != VERR_PROCESS_RUNNING)
224 {
225 RTPrintf("tstRunTestcases: %s: RTProcWait failed -> %Rrc\n", pszTestcase, rc);
226 g_cFailures++;
227 }
228 }
229 else
230 {
231 RTPrintf("tstRunTestcases: %s: failed to start -> %Rrc\n", pszTestcase, rc);
232 g_cFailures++;
233 }
234
235 }
236 else
237 {
238 RTPrintf("tstRunTestcases: %s: SKIPPED\n", pszTestcase);
239 g_cSkipped++;
240 }
241 RTStrFree(pszTestcase);
242 } /* enumeration loop */
243
244 RTDirClose(pDir);
245 }
246 else
247 RTPrintf("tstRunTestcases: opening '%s' -> %Rrc\n", pszDir, rc);
248}
249
250
251
252int main(int argc, char **argv)
253{
254 RTR3Init(false, 0);
255
256 if (argc == 1)
257 {
258 Process("testcase/tst*", "testcase");
259 Process("tst*", ".");
260 }
261 else
262 {
263 char szDir[RTPATH_MAX];
264 for (int i = 1; i < argc; i++)
265 {
266 if (argv[i][0] == '-')
267 {
268 switch (argv[i][1])
269 {
270 /* case '':... */
271
272 default:
273 RTPrintf("syntax error: Option '%s' is not recognized\n", argv[i]);
274 return 1;
275 }
276 }
277 else
278 {
279 size_t cch = strlen(argv[i]);
280 if (cch >= sizeof(szDir))
281 {
282 RTPrintf("syntax error: '%s' is too long!\n", argv[i]);
283 return 1;
284 }
285 memcpy(szDir, argv[i], cch + 1);
286 char *pszFilename = RTPathFilename(szDir);
287 if (!pszFilename)
288 {
289 RTPrintf("syntax error: '%s' does not include a file name or file name mask!\n", argv[i]);
290 return 1;
291 }
292 RTPathStripFilename(szDir);
293 Process(argv[i], szDir);
294 }
295 }
296 }
297
298 RTPrintf("\n"
299 "********************\n"
300 "*** PASSED: %u\n"
301 "*** FAILED: %u\n"
302 "*** SKIPPED: %u\n"
303 "*** TOTAL: %u\n",
304 g_cPasses,
305 g_cFailures,
306 g_cSkipped,
307 g_cPasses + g_cFailures + g_cSkipped);
308 return !!g_cFailures;
309}
310
Note: See TracBrowser for help on using the repository browser.

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