VirtualBox

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

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

tstRunTestcases: increase timeout to 120 seconds; added a few more exceptions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1/* $Id: tstRunTestcases.cpp 20669 2009-06-17 13:57:45Z 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/initterm.h>
27#include <iprt/dir.h>
28#include <iprt/param.h>
29#include <iprt/path.h>
30#include <iprt/process.h>
31#include <iprt/string.h>
32#include <iprt/stream.h>
33#include <iprt/thread.h>
34#include <iprt/err.h>
35#include <iprt/env.h>
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41/** The number of passed testcases. */
42static unsigned g_cPasses = 0;
43/** The number of failed testcases. */
44static unsigned g_cFailures = 0;
45/** The number of skipped testcases. */
46static unsigned g_cSkipped = 0;
47/** The exclude list. */
48static const char *g_apszExclude[] =
49{
50#if 1 // slow stuff
51 "testcase/tstFile",
52 "testcase/tstAvl",
53 "testcase/tstSemMutex",
54 "testcase/tstVD",
55#endif
56 "testcase/tstFileLock",
57 "testcase/tstCritSect",
58 "testcase/tstCritSectW32",
59 "testcase/tstDeadlock",
60 "testcase/tstDisasm-2",
61 "testcase/tstFileAppendWin-1",
62 "testcase/tstDir", /* useless, requires parameters */
63 "testcase/tstDir-2", /* useless, requires parameters */
64 "testcase/tstGlobalConfig",
65 "testcase/tstHostHardwareLinux", /* must be killed with CTRL-C */
66 "testcase/tstLdr-2",
67 "testcase/tstLdr-3",
68 "testcase/tstLdr",
69 "testcase/tstLdrLoad",
70 "testcase/tstLdrObj",
71 "testcase/tstLdrObjR0",
72 "testcase/tstMove",
73 "testcase/tstR0ThreadPreemption.r0", /* r0 driver, not directly executable */
74 "testcase/tstRunTestcases",
75 "testcase/tstRTS3", /* requires parameters <access key>, <secret key> */
76 "testcase/tstSDL",
77 "testcase/tstTime-3",
78 "testcase/tstSeamlessX11",
79 "testcase/tstVBoxControl",
80 "testcase/tstVDCopy", /* requires parameters <hdd1>, <hdd2> */
81 "./tstRunTestcases",
82 "./tstAnimate",
83 "./tstAPI",
84 "./tstHeadless",
85 "./tstHeadless2",
86 "./tstMicro",
87 "./tstMicroGC",
88 "./tstVBoxDbg",
89 "./tstVMM-2",
90 "./tstTestServMgr",
91 "./tstPDMAsyncCompletion", /* requires parameters <source>, <dest> */
92 "./tstXptDump",
93 "./tstnsIFileEnumerator",
94 "./tstSimpleTypeLib",
95 "./tstTestAtoms",
96 "./tstXptLink",
97 "./tstXPCOMCGlue", /* user interaction required */
98 "./tstTestCallTemplates",
99#if 1 // later
100 "testcase/tstIntNetR0",
101 "./tstVMM",
102 "./tstVMReq",
103 "./tstVMREQ",
104#endif
105 /* final entry*/
106 ""
107};
108
109
110/**
111 * Checks if a testcase is include or should be skipped.
112 *
113 * @param pszTestcase The testcase (filename).
114 *
115 * @return true if the testcase is included.
116 * false if the testcase should be skipped.
117 */
118static bool IsTestcaseIncluded(const char *pszTestcase)
119{
120 char *pszDup = RTStrDup(pszTestcase);
121 if (pszDup)
122 {
123 RTPathStripExt(pszDup);
124 for (unsigned i = 0; i < RT_ELEMENTS(g_apszExclude); i++)
125 {
126 if (!strcmp(g_apszExclude[i], pszDup))
127 {
128 RTStrFree(pszDup);
129 return false;
130 }
131 }
132 RTStrFree(pszDup);
133 return true;
134 }
135
136 RTPrintf("tstRunTestcases: Out of memory!\n");
137 return false;
138}
139
140
141/**
142 * Process the testcases found in the filter.
143 *
144 * @param pszFilter The filter (winnt) to pass to RTDirOpenFiltered for
145 * selecting the testcases.
146 * @param pszDir The directory we're processing.
147 */
148static void Process(const char *pszFilter, const char *pszDir)
149{
150 /*
151 * Open and enumerate the directory.
152 */
153 PRTDIR pDir;
154 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
155 if (RT_SUCCESS(rc))
156 {
157 for (;;)
158 {
159 RTDIRENTRY DirEntry;
160 rc = RTDirRead(pDir, &DirEntry, NULL);
161 if (RT_FAILURE(rc))
162 {
163 if (rc == VERR_NO_MORE_FILES)
164 rc = VINF_SUCCESS;
165 else
166 RTPrintf("tstRunTestcases: reading '%s' -> %Rrc\n", pszFilter, rc);
167 break;
168 }
169
170 /*
171 * Construct the testcase name.
172 */
173 char *pszTestcase;
174 RTStrAPrintf(&pszTestcase, "%s/%s", pszDir, DirEntry.szName);
175 if (!pszTestcase)
176 {
177 RTPrintf("tstRunTestcases: out of memory!\n");
178 rc = VERR_NO_MEMORY;
179 break;
180 }
181 if (IsTestcaseIncluded(pszTestcase))
182 {
183 /*
184 * Execute the testcase.
185 */
186 RTPrintf("*** %s: Executing...\n", pszTestcase); RTStrmFlush(g_pStdOut);
187 const char *papszArgs[2];
188 papszArgs[0] = pszTestcase;
189 papszArgs[1] = NULL;
190 RTPROCESS Process;
191 rc = RTProcCreate(pszTestcase, papszArgs, RTENV_DEFAULT, 0, &Process);
192 if (RT_SUCCESS(rc))
193 {
194 /*
195 * Wait for the process and collect it's return code.
196 * If it takes too long, we'll terminate it and continue.
197 */
198 RTTIMESPEC Start;
199 RTTimeNow(&Start);
200 RTPROCSTATUS ProcStatus;
201 for (;;)
202 {
203 rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
204 if (rc != VERR_PROCESS_RUNNING)
205 break;
206 RTTIMESPEC Now;
207 if (RTTimeSpecGetMilli(RTTimeSpecSub(RTTimeNow(&Now), &Start)) > 120*1000 /* 1 min */)
208 {
209 RTPrintf("*** %s: FAILED - timed out. killing it.\n", pszTestcase);
210 RTProcTerminate(Process);
211 RTThreadSleep(100);
212 RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
213 g_cFailures++;
214 break;
215 }
216 RTThreadSleep(100);
217 }
218
219 /*
220 * Examin the exit status.
221 */
222 if (RT_SUCCESS(rc))
223 {
224 if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
225 && ProcStatus.iStatus == 0)
226 {
227 RTPrintf("*** %s: PASSED\n", pszTestcase);
228 g_cPasses++;
229 }
230 else
231 {
232 RTPrintf("*** %s: FAILED\n", pszTestcase);
233 g_cFailures++;
234 }
235 }
236 else if (rc != VERR_PROCESS_RUNNING)
237 {
238 RTPrintf("tstRunTestcases: %s: RTProcWait failed -> %Rrc\n", pszTestcase, rc);
239 g_cFailures++;
240 }
241 }
242 else
243 {
244 RTPrintf("tstRunTestcases: %s: failed to start -> %Rrc\n", pszTestcase, rc);
245 g_cFailures++;
246 }
247
248 }
249 else
250 {
251 RTPrintf("tstRunTestcases: %s: SKIPPED\n", pszTestcase);
252 g_cSkipped++;
253 }
254 RTStrFree(pszTestcase);
255 } /* enumeration loop */
256
257 RTDirClose(pDir);
258 }
259 else
260 RTPrintf("tstRunTestcases: opening '%s' -> %Rrc\n", pszDir, rc);
261}
262
263
264
265int main(int argc, char **argv)
266{
267 RTR3Init();
268
269 if (argc == 1)
270 {
271 char szPath[RTPATH_MAX];
272 int rc = RTPathExecDir(szPath, sizeof(szPath) - sizeof("/.."));
273 if (RT_FAILURE(rc))
274 {
275 RTPrintf("fatal error: RTPathExecDir -> %Rrc\n", rc);
276 return 1;
277 }
278 rc = RTPathSetCurrent(strcat(szPath, "/.."));
279 if (RT_FAILURE(rc))
280 {
281 RTPrintf("fatal error: RTPathSetCurrent -> %Rrc\n", rc);
282 return 1;
283 }
284
285 Process("testcase/tst*", "testcase");
286 Process("tst*", ".");
287 }
288 else
289 {
290 char szDir[RTPATH_MAX];
291 for (int i = 1; i < argc; i++)
292 {
293 if (argv[i][0] == '-')
294 {
295 switch (argv[i][1])
296 {
297 /* case '':... */
298
299 default:
300 RTPrintf("syntax error: Option '%s' is not recognized\n", argv[i]);
301 return 1;
302 }
303 }
304 else
305 {
306 size_t cch = strlen(argv[i]);
307 if (cch >= sizeof(szDir))
308 {
309 RTPrintf("syntax error: '%s' is too long!\n", argv[i]);
310 return 1;
311 }
312 memcpy(szDir, argv[i], cch + 1);
313 char *pszFilename = RTPathFilename(szDir);
314 if (!pszFilename)
315 {
316 RTPrintf("syntax error: '%s' does not include a file name or file name mask!\n", argv[i]);
317 return 1;
318 }
319 RTPathStripFilename(szDir);
320 Process(argv[i], szDir);
321 }
322 }
323 }
324
325 RTPrintf("\n"
326 "********************\n"
327 "*** PASSED: %u\n"
328 "*** FAILED: %u\n"
329 "*** SKIPPED: %u\n"
330 "*** TOTAL: %u\n",
331 g_cPasses,
332 g_cFailures,
333 g_cSkipped,
334 g_cPasses + g_cFailures + g_cSkipped);
335 return !!g_cFailures;
336}
337
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