VirtualBox

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

Last change on this file since 732 was 732, checked in by vboxsync, 18 years ago

some exclude updates.

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1/* $Id: tstRunTestcases.cpp 732 2007-02-07 00:31:37Z vboxsync $ */
2/** @file
3 * tstRunTescases - Driver program for running VBox testcase (tst* testcase/tst*).
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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
35
36/*******************************************************************************
37* Global Variables *
38*******************************************************************************/
39/** The number of passed testcases. */
40static unsigned g_cPasses = 0;
41/** The number of failed testcases. */
42static unsigned g_cFailures = 0;
43/** The number of skipped testcases. */
44static unsigned g_cSkipped = 0;
45/** The exclude list. */
46static const char *g_apszExclude[] =
47{
48#if 1 // slow stuff
49 "testcase/tstFile",
50 "testcase/tstAvl",
51#endif
52 "testcase/tstFileLock",
53 "testcase/tstCritSect",
54 "testcase/tstCritSectW32",
55 "testcase/tstDeadlock",
56 "testcase/tstLdr-2",
57 "testcase/tstLdr-3",
58 "testcase/tstLdr",
59 "testcase/tstLdrLoad",
60 "testcase/tstLdrObj",
61 "testcase/tstMove",
62 "testcase/tstRunTestcases",
63 "testcase/tstSDL",
64 "testcase/tstTime-3",
65 "./tstRunTestcases",
66 "./tstAnimate",
67 "./tstAPI",
68 "./tstHeadless",
69 "./tstMicro",
70 "./tstMicroGC",
71 "./tstVBoxDbg",
72 "./tstVMM-2",
73 "./tstTestServMgr",
74 "./tstXptDump",
75 "./tstnsIFileEnumerator",
76 "./tstSimpleTypeLib",
77 "./tstTestAtoms",
78 "./tstXptLink",
79 "./tstTestCallTemplates",
80#if 1 // later
81 "testcase/tstIntNetR0",
82 "./tstVMM",
83 "./tstVMReq",
84 "./tstVMREQ",
85#endif
86 /* final entry*/
87 ""
88};
89
90
91/**
92 * Checks if a testcase is include or should be skipped.
93 *
94 * @param pszTestcase The testcase (filename).
95 *
96 * @return true if the testcase is included.
97 * false if the testcase should be skipped.
98 */
99static bool IsTestcaseIncluded(const char *pszTestcase)
100{
101 char *pszDup = RTStrDup(pszTestcase);
102 if (pszDup)
103 {
104 RTPathStripExt(pszDup);
105 for (unsigned i = 0; i < ELEMENTS(g_apszExclude); i++)
106 {
107 if (!strcmp(g_apszExclude[i], pszDup))
108 {
109 RTStrFree(pszDup);
110 return false;
111 }
112 }
113 RTStrFree(pszDup);
114 return true;
115 }
116
117 RTPrintf("tstRunTestcases: Out of memory!\n");
118 return false;
119}
120
121
122/**
123 * Process the testcases found in the filter.
124 *
125 * @param pszFilter The filter (winnt) to pass to RTDirOpenFiltered for
126 * selecting the testcases.
127 * @param pszDir The directory we're processing.
128 */
129static void Process(const char *pszFilter, const char *pszDir)
130{
131 /*
132 * Open and enumerate the directory.
133 */
134 PRTDIR pDir;
135 int rc = RTDirOpenFiltered(&pDir, pszFilter, RTDIRFILTER_WINNT);
136 if (RT_SUCCESS(rc))
137 {
138 for (;;)
139 {
140 RTDIRENTRY DirEntry;
141 rc = RTDirRead(pDir, &DirEntry, NULL);
142 if (RT_FAILURE(rc))
143 {
144 if (rc == VERR_NO_MORE_FILES)
145 rc = VINF_SUCCESS;
146 else
147 RTPrintf("tstRunTestcases: reading '%s' -> %Rrc\n", pszFilter, rc);
148 break;
149 }
150
151 /*
152 * Construct the testcase name.
153 */
154 char *pszTestcase;
155 RTStrAPrintf(&pszTestcase, "%s/%s", pszDir, DirEntry.szName);
156 if (!pszTestcase)
157 {
158 RTPrintf("tstRunTestcases: out of memory!\n");
159 rc = VERR_NO_MEMORY;
160 break;
161 }
162 if (IsTestcaseIncluded(pszTestcase))
163 {
164 /*
165 * Execute the testcase.
166 */
167 RTPrintf("*** %s: Executing...\n", pszTestcase); RTStrmFlush(g_pStdOut);
168 const char *papszArgs[2];
169 papszArgs[0] = pszTestcase;
170 papszArgs[1] = NULL;
171 RTPROCESS Process;
172 rc = RTProcCreate(pszTestcase, papszArgs, NULL, 0, &Process);
173 if (RT_SUCCESS(rc))
174 {
175 /*
176 * Wait for the process and collect it's return code.
177 * If it takes too long, we'll terminate it and continue.
178 */
179 RTTIMESPEC Start;
180 RTTimeNow(&Start);
181 RTPROCSTATUS ProcStatus;
182 for (;;)
183 {
184 rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
185 if (rc != VERR_PROCESS_RUNNING)
186 break;
187 RTTIMESPEC Now;
188 if (RTTimeSpecGetMilli(RTTimeSpecSub(RTTimeNow(&Now), &Start)) > 60*1000 /* 1 min */)
189 {
190 RTPrintf("*** %s: FAILED - timed out. killing it.\n", pszTestcase);
191 RTProcTerminate(Process);
192 RTThreadSleep(100);
193 RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
194 g_cFailures++;
195 break;
196 }
197 RTThreadSleep(100);
198 }
199
200 /*
201 * Examin the exit status.
202 */
203 if (RT_SUCCESS(rc))
204 {
205 if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
206 && ProcStatus.iStatus == 0)
207 {
208 RTPrintf("*** %s: PASSED\n", pszTestcase);
209 g_cPasses++;
210 }
211 else
212 {
213 RTPrintf("*** %s: FAILED\n", pszTestcase);
214 g_cFailures++;
215 }
216 }
217 else if (rc != VERR_PROCESS_RUNNING)
218 {
219 RTPrintf("tstRunTestcases: %s: RTProcWait failed -> %Rrc\n", pszTestcase, rc);
220 g_cFailures++;
221 }
222 }
223 else
224 {
225 RTPrintf("tstRunTestcases: %s: failed to start -> %Rrc\n", pszTestcase, rc);
226 g_cFailures++;
227 }
228
229 }
230 else
231 {
232 RTPrintf("tstRunTestcases: %s: SKIPPED\n", pszTestcase);
233 g_cSkipped++;
234 }
235 RTStrFree(pszTestcase);
236 } /* enumeration loop */
237
238 RTDirClose(pDir);
239 }
240 else
241 RTPrintf("tstRunTestcases: opening '%s' -> %Rrc\n", pszDir, rc);
242}
243
244
245
246int main(int argc, char **argv)
247{
248 RTR3Init(false, 0);
249 Process("testcase/tst*", "testcase");
250 Process("tst*", ".");
251
252 RTPrintf("\n"
253 "********************\n"
254 "*** PASSED: %u\n"
255 "*** FAILED: %u\n"
256 "*** SKIPPED: %u\n"
257 "*** TOTAL: %u\n",
258 g_cPasses,
259 g_cFailures,
260 g_cSkipped,
261 g_cPasses + g_cFailures + g_cSkipped);
262 return !!g_cFailures;
263}
264
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