2 * Wine Conformance Test EXE
4 * Copyright 2003 Jakob Eriksson (for Solid Form Sweden AB)
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Ferenc Wagner
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This program is dedicated to Anna Lindh,
23 * Swedish Minister of Foreign Affairs.
24 * Anna was murdered September 11, 2003.
29 #include "wine/port.h"
57 static struct wine_test *wine_tests;
58 static struct rev_info *rev_infos = NULL;
59 static const char whitespace[] = " \t\r\n";
61 static int running_under_wine ()
63 HMODULE module = GetModuleHandleA("ntdll.dll");
65 if (!module) return 0;
66 return (GetProcAddress(module, "wine_server_call") != NULL);
74 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
75 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
77 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
78 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
79 report (R_FATAL, "Can't get OS version.");
82 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
83 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
84 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
85 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
86 ver.dwPlatformId, ver.szCSDVersion);
90 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
91 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
92 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
93 ver.wProductType, ver.wReserved);
96 static inline int is_dot_dir(const char* x)
98 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
101 void remove_dir (const char *dir)
106 size_t dirlen = strlen (dir);
108 /* Make sure the directory exists before going further */
109 memcpy (path, dir, dirlen);
110 strcpy (path + dirlen++, "\\*");
111 hFind = FindFirstFile (path, &wfd);
112 if (hFind == INVALID_HANDLE_VALUE) return;
115 char *lp = wfd.cFileName;
117 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
118 if (is_dot_dir (lp)) continue;
119 strcpy (path + dirlen, lp);
120 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
122 else if (!DeleteFile (path))
123 report (R_WARNING, "Can't delete file %s: error %d",
124 path, GetLastError ());
125 } while (FindNextFile (hFind, &wfd));
127 if (!RemoveDirectory (dir))
128 report (R_WARNING, "Can't remove directory %s: error %d",
129 dir, GetLastError ());
132 const char* get_test_source_file(const char* test, const char* subtest)
134 static const char* special_dirs[][2] = {
135 { "gdi32", "gdi"}, { "kernel32", "kernel" },
136 { "msacm32", "msacm" },
137 { "user32", "user" }, { "winspool.drv", "winspool" },
138 { "ws2_32", "winsock" }, { 0, 0 }
140 static char buffer[MAX_PATH];
143 for (i = 0; special_dirs[i][0]; i++) {
144 if (strcmp(test, special_dirs[i][0]) == 0) {
145 test = special_dirs[i][1];
150 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
154 const char* get_file_rev(const char* file)
156 const struct rev_info* rev;
158 for(rev = rev_infos; rev->file; rev++) {
159 if (strcmp(rev->file, file) == 0) return rev->rev;
165 void extract_rev_infos ()
167 char revinfo[256], *p;
168 int size = 0, i, len;
169 HMODULE module = GetModuleHandle (NULL);
171 for (i = 0; TRUE; i++) {
174 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
176 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
178 len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
179 if (len == 0) break; /* end of revision info */
180 if (len >= sizeof(revinfo) - 1)
181 report (R_FATAL, "Revision info too long.");
182 if(!(p = strrchr(revinfo, ':')))
183 report (R_FATAL, "Revision info malformed (i=%d)", i);
185 rev_infos[i].file = strdup(revinfo);
186 rev_infos[i].rev = strdup(p + 1);
190 void* extract_rcdata (int id, int type, DWORD* size)
196 if (!(rsrc = FindResource (NULL, (LPTSTR)id, MAKEINTRESOURCE(type))) ||
197 !(*size = SizeofResource (0, rsrc)) ||
198 !(hdl = LoadResource (0, rsrc)) ||
199 !(addr = LockResource (hdl)))
204 /* Fills in the name and exename fields */
206 extract_test (struct wine_test *test, const char *dir, int id)
211 int strlen, bufflen = 128;
214 code = extract_rcdata (id, TESTRES, &size);
215 if (!code) report (R_FATAL, "Can't find test resource %d: %d",
216 id, GetLastError ());
217 test->name = xmalloc (bufflen);
218 while ((strlen = LoadStringA (NULL, id, test->name, bufflen))
221 test->name = xrealloc (test->name, bufflen);
223 if (!strlen) report (R_FATAL, "Can't read name of test %d.", id);
224 test->exename = strmake (NULL, "%s/%s", dir, test->name);
225 exepos = strstr (test->name, "_test.exe");
226 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
228 test->name = xrealloc (test->name, exepos - test->name + 1);
229 report (R_STEP, "Extracting: %s", test->name);
231 if (!(fout = fopen (test->exename, "wb")) ||
232 (fwrite (code, size, 1, fout) != 1) ||
233 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
237 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
240 Return the exit status, -2 if can't create process or the return
241 value of WaitForSingleObject.
244 run_ex (char *cmd, const char *out, DWORD ms)
247 PROCESS_INFORMATION pi;
248 int fd, oldstdout = -1;
251 GetStartupInfo (&si);
252 si.wShowWindow = SW_HIDE;
253 si.dwFlags = STARTF_USESHOWWINDOW;
256 fd = open (out, O_WRONLY | O_CREAT, 0666);
258 report (R_FATAL, "Can't open '%s': %d", out, errno);
261 report (R_FATAL, "Can't save stdout: %d", errno);
262 if (-1 == dup2 (fd, 1))
263 report (R_FATAL, "Can't redirect stdout: %d", errno);
267 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
268 NULL, NULL, &si, &pi)) {
271 CloseHandle (pi.hThread);
272 wait = WaitForSingleObject (pi.hProcess, ms);
273 if (wait == WAIT_OBJECT_0) {
274 GetExitCodeProcess (pi.hProcess, &status);
278 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
282 report (R_ERROR, "Process '%s' timed out.", cmd);
285 report (R_ERROR, "Wait returned %d", wait);
288 if (!TerminateProcess (pi.hProcess, 257))
289 report (R_ERROR, "TerminateProcess failed: %d",
291 wait = WaitForSingleObject (pi.hProcess, 5000);
295 "Wait for termination of '%s' failed: %d",
296 cmd, GetLastError ());
301 report (R_ERROR, "Can't kill process '%s'", cmd);
304 report (R_ERROR, "Waiting for termination: %d",
308 CloseHandle (pi.hProcess);
313 if (-1 == dup2 (oldstdout, 1))
314 report (R_FATAL, "Can't recover stdout: %d", errno);
321 get_subtests (const char *tempdir, struct wine_test *test, int id)
326 char buffer[8192], *index;
327 static const char header[] = "Valid test names:";
330 test->subtest_count = 0;
332 subname = tempnam (0, "sub");
333 if (!subname) report (R_FATAL, "Can't name subtests file.");
335 extract_test (test, tempdir, id);
336 run_ex (test->exename, subname, 5000);
338 subfile = fopen (subname, "r");
340 report (R_ERROR, "Can't open subtests output of %s: %d",
344 total = fread (buffer, 1, sizeof buffer, subfile);
346 if (sizeof buffer == total) {
347 report (R_ERROR, "Subtest list of %s too big.",
348 test->name, sizeof buffer);
353 index = strstr (buffer, header);
355 report (R_ERROR, "Can't parse subtests output of %s",
359 index += sizeof header;
362 test->subtests = xmalloc (allocated * sizeof(char*));
363 index = strtok (index, whitespace);
365 if (test->subtest_count == allocated) {
367 test->subtests = xrealloc (test->subtests,
368 allocated * sizeof(char*));
370 test->subtests[test->subtest_count++] = strdup (index);
371 index = strtok (NULL, whitespace);
373 test->subtests = xrealloc (test->subtests,
374 test->subtest_count * sizeof(char*));
377 if (remove (subname))
378 report (R_WARNING, "Can't delete file '%s': %d",
384 run_test (struct wine_test* test, const char* subtest)
387 const char* file = get_test_source_file(test->name, subtest);
388 const char* rev = get_file_rev(file);
389 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
391 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
392 status = run_ex (cmd, NULL, 120000);
394 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
398 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
399 LPTSTR lpszName, LONG_PTR lParam)
406 run_tests (char *logname, const char *tag)
408 int nr_of_files = 0, nr_of_tests = 0, i;
411 char *strres, *eol, *nextline;
414 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
417 logname = tempnam (0, "res");
418 if (!logname) report (R_FATAL, "Can't name logfile.");
420 report (R_OUT, logname);
422 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
426 report (R_FATAL, "File %s already exists.", logname);
427 else report (R_FATAL, "Could not open logfile: %d", errno);
429 if (-1 == dup2 (logfile, 1))
430 report (R_FATAL, "Can't redirect stdout: %d", errno);
433 tempdir = tempnam (0, "wct");
435 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
436 report (R_DIR, tempdir);
437 if (!CreateDirectory (tempdir, NULL))
438 report (R_FATAL, "Could not create directory: %s", tempdir);
440 xprintf ("Version 3\n");
441 strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize);
442 xprintf ("Tests from build ");
443 if (strres) xprintf ("%.*s", strsize, strres);
444 else xprintf ("-\n");
445 strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize);
446 xprintf ("Archive: ");
447 if (strres) xprintf ("%.*s", strsize, strres);
448 else xprintf ("-\n");
449 xprintf ("Tag: %s\n", tag?tag:"");
450 xprintf ("Build info:\n");
451 strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize);
453 eol = memchr (strres, '\n', strsize);
456 eol = strres + strsize;
458 strsize -= eol - strres + 1;
459 nextline = strsize?eol+1:NULL;
460 if (eol > strres && *(eol-1) == '\r') eol--;
462 xprintf (" %.*s\n", eol-strres, strres);
465 xprintf ("Operating system version:\n");
467 xprintf ("Test output:\n" );
469 report (R_STATUS, "Counting tests");
470 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
471 EnumTestFileProc, (LPARAM)&nr_of_files))
472 report (R_FATAL, "Can't enumerate test files: %d",
474 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
476 report (R_STATUS, "Extracting tests");
477 report (R_PROGRESS, 0, nr_of_files);
478 for (i = 0; i < nr_of_files; i++) {
479 get_subtests (tempdir, wine_tests+i, i);
480 nr_of_tests += wine_tests[i].subtest_count;
482 report (R_DELTA, 0, "Extracting: Done");
484 report (R_STATUS, "Running tests");
485 report (R_PROGRESS, 1, nr_of_tests);
486 for (i = 0; i < nr_of_files; i++) {
487 struct wine_test *test = wine_tests + i;
490 for (j = 0; j < test->subtest_count; j++) {
491 report (R_STEP, "Running: %s:%s", test->name,
493 run_test (test, test->subtests[j]);
496 report (R_DELTA, 0, "Running: Done");
498 report (R_STATUS, "Cleaning up");
500 remove_dir (tempdir);
511 Usage: winetest [OPTION]...\n\n\
512 -c console mode, no GUI\n\
513 -e preserve the environment\n\
514 -h print this message and exit\n\
515 -q quiet mode, no output at all\n\
516 -o FILE put report into FILE, do not submit\n\
517 -s FILE submit FILE, do not run tests\n\
518 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
521 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
522 LPSTR cmdLine, int cmdShow)
524 char *logname = NULL;
525 const char *cp, *submit = NULL, *tag = NULL;
528 /* initialize the revision information first */
531 cmdLine = strtok (cmdLine, whitespace);
533 if (cmdLine[0] != '-' || cmdLine[2]) {
534 report (R_ERROR, "Not a single letter option: %s", cmdLine);
538 switch (cmdLine[1]) {
552 submit = strtok (NULL, whitespace);
554 report (R_WARNING, "ignoring tag for submission");
558 logname = strtok (NULL, whitespace);
561 tag = strtok (NULL, whitespace);
562 cp = badtagchar (tag);
564 report (R_ERROR, "invalid char in tag: %c", *cp);
570 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
574 cmdLine = strtok (NULL, whitespace);
577 if (reset_env && (putenv ("WINETEST_PLATFORM=windows") ||
578 putenv ("WINETEST_DEBUG=1") ||
579 putenv ("WINETEST_INTERACTIVE=0") ||
580 putenv ("WINETEST_REPORT_SUCCESS=0")))
581 report (R_FATAL, "Could not reset environment: %d", errno);
583 report (R_STATUS, "Starting up");
584 logname = run_tests (logname, tag);
585 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
586 "test results?") == IDYES)
587 if (!send_file (logname) && remove (logname))
588 report (R_WARNING, "Can't remove logfile: %d.", errno);
590 report (R_STATUS, "Finished");