VirtualBox

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

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

Fixed environment parameter for RTProcCreate and a problem with trying to execute tstVdi* images.

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1/* $Id: tstRunTestcases.cpp 5699 2007-11-12 09:44:11Z vboxsync $ */
2/** @file
3 * tstRunTescases - Driver program for running VBox testcase (tst* testcase/tst*).
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/runtime.h>
23#include <iprt/dir.h>
24#include <iprt/process.h>
25#include <iprt/path.h>
26#include <iprt/string.h>
27#include <iprt/stream.h>
28#include <iprt/thread.h>
29#include <iprt/err.h>
30#include <iprt/env.h>
31
32
33/*******************************************************************************
34* Global Variables *
35*******************************************************************************/
36/** The number of passed testcases. */
37static unsigned g_cPasses = 0;
38/** The number of failed testcases. */
39static unsigned g_cFailures = 0;
40/** The number of skipped testcases. */
41static unsigned g_cSkipped = 0;
42/** The exclude list. */
43static const char *g_apszExclude[] =
44{
45#if 1 // slow stuff
46 "testcase/tstFile",
47 "testcase/tstAvl",
48#endif
49 "testcase/tstFileLock",
50 "testcase/tstCritSect",
51 "testcase/tstCritSectW32",
52 "testcase/tstDeadlock",
53 "testcase/tstLdr-2",
54 "testcase/tstLdr-3",
55 "testcase/tstLdr",
56 "testcase/tstLdrLoad",
57 "testcase/tstLdrObj",
58 "testcase/tstLdrObjR0",
59 "testcase/tstMove",
60 "testcase/tstRunTestcases",
61 "testcase/tstSDL",
62 "testcase/tstTime-3",
63 "./tstRunTestcases",
64 "./tstAnimate",
65 "./tstAPI",
66 "./tstHeadless",
67 "./tstMicro",
68 "./tstMicroGC",
69 "./tstVBoxDbg",
70 "./tstVMM-2",
71 "./tstTestServMgr",
72 "./tstXptDump",
73 "./tstnsIFileEnumerator",
74 "./tstSimpleTypeLib",
75 "./tstTestAtoms",
76 "./tstXptLink",
77 "./tstTestCallTemplates",
78#if 1 // later
79 "testcase/tstIntNetR0",
80 "./tstVMM",
81 "./tstVMReq",
82 "./tstVMREQ",
83#endif
84 /* final entry*/
85 ""
86};
87
88
89/**
90 * Checks if a testcase is include or should be skipped.
91 *
92 * @param pszTestcase The testcase (filename).
93 *
94 * @return true if the testcase is included.
95 * false if the testcase should be skipped.
96 */
97static bool IsTestcaseIncluded(const char *pszTestcase)
98{
99 char *pszDup = RTStrDup(pszTestcase);
100 if (pszDup)
101 {
102 RTPathStripExt(pszDup);
103 for (unsigned i = 0; i < ELEMENTS(g_apszExclude); i++)
104 {
105 if (!strcmp(g_apszExclude[i], pszDup))
106 {
107 RTStrFree(pszDup);
108 return false;
109 }
110 }
111 RTStrFree(pszDup);
112 return true;
113 }
114
115 RTPrintf("tstRunTestcases: Out of memory!\n");
116 return false;
117}
118
119
120/**
121 * Process the testcases found in the filter.
122 *
123 * @param pszFilter The filter (winnt) to pass to RTDirOpenFiltered for
124 * selecting the testcases.
125 * @param pszDir The directory we're processing.
126 */
127static void Process(const char *pszFilter, const char *pszDir)
128{
129 RTENV env;
130 int rc = RTEnvClone(&env, RTENV_DEFAULT);
131 if (RT_FAILURE(rc)) {
132 RTPrintf("tstRunTestcases: Failed to clone environment -> %Rrc\n", rc);
133 return;
134 }
135 /*
136 * Open and enumerate the directory.
137 */
138 PRTDIR pDir;
139 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, env, 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 RTEnvDestroy(env);
247}
248
249
250
251int main(int argc, char **argv)
252{
253 RTR3Init(false, 0);
254
255 if (argc == 1)
256 {
257 Process("testcase/tst*", "testcase");
258 Process("tst*", ".");
259 }
260 else
261 {
262 char szDir[RTPATH_MAX];
263 for (int i = 1; i < argc; i++)
264 {
265 if (argv[i][0] == '-')
266 {
267 switch (argv[i][1])
268 {
269 /* case '':... */
270
271 default:
272 RTPrintf("syntax error: Option '%s' is not recognized\n", argv[i]);
273 return 1;
274 }
275 }
276 else
277 {
278 size_t cch = strlen(argv[i]);
279 if (cch >= sizeof(szDir))
280 {
281 RTPrintf("syntax error: '%s' is too long!\n", argv[i]);
282 return 1;
283 }
284 memcpy(szDir, argv[i], cch + 1);
285 char *pszFilename = RTPathFilename(szDir);
286 if (!pszFilename)
287 {
288 RTPrintf("syntax error: '%s' does not include a file name or file name mask!\n", argv[i]);
289 return 1;
290 }
291 RTPathStripFilename(szDir);
292 Process(argv[i], szDir);
293 }
294 }
295 }
296
297 RTPrintf("\n"
298 "********************\n"
299 "*** PASSED: %u\n"
300 "*** FAILED: %u\n"
301 "*** SKIPPED: %u\n"
302 "*** TOTAL: %u\n",
303 g_cPasses,
304 g_cFailures,
305 g_cSkipped,
306 g_cPasses + g_cFailures + g_cSkipped);
307 return !!g_cFailures;
308}
309
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