VirtualBox

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

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

tstRunTestcases.

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