VirtualBox

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

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

Additions/VBoxControl: support guestproperty wait

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