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