2 * Wine Conformance Test EXE
4 * Copyright 2003, 2004 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"
59 static struct wine_test *wine_tests;
60 static struct rev_info *rev_infos = NULL;
61 static const char whitespace[] = " \t\r\n";
63 static int running_under_wine ()
65 HMODULE module = GetModuleHandleA("ntdll.dll");
67 if (!module) return 0;
68 return (GetProcAddress(module, "wine_server_call") != NULL);
71 static int running_on_visible_desktop ()
74 HMODULE huser32 = GetModuleHandle("user32.dll");
75 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
76 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
78 desktop = GetDesktopWindow();
79 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
80 return IsWindowVisible(desktop);
82 if (pGetProcessWindowStation && pGetUserObjectInformationA)
86 USEROBJECTFLAGS uoflags;
88 wstation = (HWINSTA)pGetProcessWindowStation();
89 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
90 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
92 return IsWindowVisible(desktop);
100 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
101 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
103 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
104 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
105 report (R_FATAL, "Can't get OS version.");
108 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
109 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
110 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
111 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
112 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
113 ver.dwPlatformId, ver.szCSDVersion);
117 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
118 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
119 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
120 ver.wProductType, ver.wReserved);
123 static inline int is_dot_dir(const char* x)
125 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
128 void remove_dir (const char *dir)
133 size_t dirlen = strlen (dir);
135 /* Make sure the directory exists before going further */
136 memcpy (path, dir, dirlen);
137 strcpy (path + dirlen++, "\\*");
138 hFind = FindFirstFile (path, &wfd);
139 if (hFind == INVALID_HANDLE_VALUE) return;
142 char *lp = wfd.cFileName;
144 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
145 if (is_dot_dir (lp)) continue;
146 strcpy (path + dirlen, lp);
147 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
149 else if (!DeleteFile (path))
150 report (R_WARNING, "Can't delete file %s: error %d",
151 path, GetLastError ());
152 } while (FindNextFile (hFind, &wfd));
154 if (!RemoveDirectory (dir))
155 report (R_WARNING, "Can't remove directory %s: error %d",
156 dir, GetLastError ());
159 const char* get_test_source_file(const char* test, const char* subtest)
161 static const char* special_dirs[][2] = {
162 { "gdi32", "gdi"}, { "kernel32", "kernel" },
163 { "msacm32", "msacm" },
164 { "user32", "user" }, { "winspool.drv", "winspool" },
165 { "ws2_32", "winsock" }, { 0, 0 }
167 static char buffer[MAX_PATH];
170 for (i = 0; special_dirs[i][0]; i++) {
171 if (strcmp(test, special_dirs[i][0]) == 0) {
172 test = special_dirs[i][1];
177 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
181 const char* get_file_rev(const char* file)
183 const struct rev_info* rev;
185 for(rev = rev_infos; rev->file; rev++) {
186 if (strcmp(rev->file, file) == 0) return rev->rev;
192 void extract_rev_infos ()
194 char revinfo[256], *p;
197 HMODULE module = GetModuleHandle (NULL);
199 for (i = 0; TRUE; i++) {
202 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
204 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
206 len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
207 if (len == 0) break; /* end of revision info */
208 if (len >= sizeof(revinfo) - 1)
209 report (R_FATAL, "Revision info too long.");
210 if(!(p = strrchr(revinfo, ':')))
211 report (R_FATAL, "Revision info malformed (i=%d)", i);
213 rev_infos[i].file = strdup(revinfo);
214 rev_infos[i].rev = strdup(p + 1);
218 void* extract_rcdata (int id, int type, DWORD* size)
224 if (!(rsrc = FindResource (NULL, (LPTSTR)id, MAKEINTRESOURCE(type))) ||
225 !(*size = SizeofResource (0, rsrc)) ||
226 !(hdl = LoadResource (0, rsrc)) ||
227 !(addr = LockResource (hdl)))
232 /* Fills in the name and exename fields */
234 extract_test (struct wine_test *test, const char *dir, int id)
239 int strlen, bufflen = 128;
242 code = extract_rcdata (id, TESTRES, &size);
243 if (!code) report (R_FATAL, "Can't find test resource %d: %d",
244 id, GetLastError ());
245 test->name = xmalloc (bufflen);
246 while ((strlen = LoadStringA (NULL, id, test->name, bufflen))
249 test->name = xrealloc (test->name, bufflen);
251 if (!strlen) report (R_FATAL, "Can't read name of test %d.", id);
252 test->exename = strmake (NULL, "%s/%s", dir, test->name);
253 exepos = strstr (test->name, "_test.exe");
254 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
256 test->name = xrealloc (test->name, exepos - test->name + 1);
257 report (R_STEP, "Extracting: %s", test->name);
259 if (!(fout = fopen (test->exename, "wb")) ||
260 (fwrite (code, size, 1, fout) != 1) ||
261 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
265 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
268 Return the exit status, -2 if can't create process or the return
269 value of WaitForSingleObject.
272 run_ex (char *cmd, const char *out, DWORD ms)
275 PROCESS_INFORMATION pi;
276 int fd, oldstdout = -1;
279 GetStartupInfo (&si);
280 si.wShowWindow = SW_HIDE;
281 si.dwFlags = STARTF_USESHOWWINDOW;
284 fd = open (out, O_WRONLY | O_CREAT, 0666);
286 report (R_FATAL, "Can't open '%s': %d", out, errno);
289 report (R_FATAL, "Can't save stdout: %d", errno);
290 if (-1 == dup2 (fd, 1))
291 report (R_FATAL, "Can't redirect stdout: %d", errno);
295 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
296 NULL, NULL, &si, &pi)) {
299 CloseHandle (pi.hThread);
300 wait = WaitForSingleObject (pi.hProcess, ms);
301 if (wait == WAIT_OBJECT_0) {
302 GetExitCodeProcess (pi.hProcess, &status);
306 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
310 report (R_ERROR, "Process '%s' timed out.", cmd);
313 report (R_ERROR, "Wait returned %d", wait);
316 if (!TerminateProcess (pi.hProcess, 257))
317 report (R_ERROR, "TerminateProcess failed: %d",
319 wait = WaitForSingleObject (pi.hProcess, 5000);
323 "Wait for termination of '%s' failed: %d",
324 cmd, GetLastError ());
329 report (R_ERROR, "Can't kill process '%s'", cmd);
332 report (R_ERROR, "Waiting for termination: %d",
336 CloseHandle (pi.hProcess);
341 if (-1 == dup2 (oldstdout, 1))
342 report (R_FATAL, "Can't recover stdout: %d", errno);
349 get_subtests (const char *tempdir, struct wine_test *test, int id)
354 char buffer[8192], *index;
355 static const char header[] = "Valid test names:";
358 test->subtest_count = 0;
360 subname = tempnam (0, "sub");
361 if (!subname) report (R_FATAL, "Can't name subtests file.");
363 extract_test (test, tempdir, id);
364 run_ex (test->exename, subname, 5000);
366 subfile = fopen (subname, "r");
368 report (R_ERROR, "Can't open subtests output of %s: %d",
372 total = fread (buffer, 1, sizeof buffer, subfile);
374 if (sizeof buffer == total) {
375 report (R_ERROR, "Subtest list of %s too big.",
376 test->name, sizeof buffer);
381 index = strstr (buffer, header);
383 report (R_ERROR, "Can't parse subtests output of %s",
387 index += sizeof header;
390 test->subtests = xmalloc (allocated * sizeof(char*));
391 index = strtok (index, whitespace);
393 if (test->subtest_count == allocated) {
395 test->subtests = xrealloc (test->subtests,
396 allocated * sizeof(char*));
398 test->subtests[test->subtest_count++] = strdup (index);
399 index = strtok (NULL, whitespace);
401 test->subtests = xrealloc (test->subtests,
402 test->subtest_count * sizeof(char*));
405 if (remove (subname))
406 report (R_WARNING, "Can't delete file '%s': %d",
412 run_test (struct wine_test* test, const char* subtest)
415 const char* file = get_test_source_file(test->name, subtest);
416 const char* rev = get_file_rev(file);
417 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
419 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
420 status = run_ex (cmd, NULL, 120000);
422 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
426 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
427 LPTSTR lpszName, LONG_PTR lParam)
434 run_tests (char *logname)
436 int nr_of_files = 0, nr_of_tests = 0, i;
437 char *tempdir, *shorttempdir;
439 char *strres, *eol, *nextline;
442 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
445 logname = tempnam (0, "res");
446 if (!logname) report (R_FATAL, "Can't name logfile.");
448 report (R_OUT, logname);
450 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
454 report (R_FATAL, "File %s already exists.", logname);
455 else report (R_FATAL, "Could not open logfile: %d", errno);
457 if (-1 == dup2 (logfile, 1))
458 report (R_FATAL, "Can't redirect stdout: %d", errno);
461 tempdir = tempnam (0, "wct");
463 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
464 shorttempdir = strdup (tempdir);
465 if (shorttempdir) { /* try stable path for ZoneAlarm */
466 strstr (shorttempdir, "wct")[3] = 0;
467 if (CreateDirectoryA (shorttempdir, NULL)) {
469 tempdir = shorttempdir;
470 } else free (shorttempdir);
472 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
473 report (R_FATAL, "Could not create directory: %s", tempdir);
474 report (R_DIR, tempdir);
476 xprintf ("Version 3\n");
477 strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize);
478 xprintf ("Tests from build ");
479 if (strres) xprintf ("%.*s", strsize, strres);
480 else xprintf ("-\n");
481 strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize);
482 xprintf ("Archive: ");
483 if (strres) xprintf ("%.*s", strsize, strres);
484 else xprintf ("-\n");
485 xprintf ("Tag: %s\n", tag);
486 xprintf ("Build info:\n");
487 strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize);
489 eol = memchr (strres, '\n', strsize);
492 eol = strres + strsize;
494 strsize -= eol - strres + 1;
495 nextline = strsize?eol+1:NULL;
496 if (eol > strres && *(eol-1) == '\r') eol--;
498 xprintf (" %.*s\n", eol-strres, strres);
501 xprintf ("Operating system version:\n");
503 xprintf ("Test output:\n" );
505 report (R_STATUS, "Counting tests");
506 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
507 EnumTestFileProc, (LPARAM)&nr_of_files))
508 report (R_FATAL, "Can't enumerate test files: %d",
510 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
512 report (R_STATUS, "Extracting tests");
513 report (R_PROGRESS, 0, nr_of_files);
514 for (i = 0; i < nr_of_files; i++) {
515 get_subtests (tempdir, wine_tests+i, i);
516 nr_of_tests += wine_tests[i].subtest_count;
518 report (R_DELTA, 0, "Extracting: Done");
520 report (R_STATUS, "Running tests");
521 report (R_PROGRESS, 1, nr_of_tests);
522 for (i = 0; i < nr_of_files; i++) {
523 struct wine_test *test = wine_tests + i;
526 for (j = 0; j < test->subtest_count; j++) {
527 report (R_STEP, "Running: %s:%s", test->name,
529 run_test (test, test->subtests[j]);
532 report (R_DELTA, 0, "Running: Done");
534 report (R_STATUS, "Cleaning up");
536 remove_dir (tempdir);
547 Usage: winetest [OPTION]...\n\n\
548 -c console mode, no GUI\n\
549 -e preserve the environment\n\
550 -h print this message and exit\n\
551 -q quiet mode, no output at all\n\
552 -o FILE put report into FILE, do not submit\n\
553 -s FILE submit FILE, do not run tests\n\
554 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
557 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
558 LPSTR cmdLine, int cmdShow)
560 char *logname = NULL;
561 const char *cp, *submit = NULL;
565 /* initialize the revision information first */
568 cmdLine = strtok (cmdLine, whitespace);
570 if (cmdLine[0] != '-' || cmdLine[2]) {
571 report (R_ERROR, "Not a single letter option: %s", cmdLine);
575 switch (cmdLine[1]) {
591 submit = strtok (NULL, whitespace);
593 report (R_WARNING, "ignoring tag for submission");
597 logname = strtok (NULL, whitespace);
600 tag = strtok (NULL, whitespace);
601 if (strlen (tag) > MAXTAGLEN)
602 report (R_FATAL, "tag is too long (maximum %d characters)",
604 cp = badtagchar (tag);
606 report (R_ERROR, "invalid char in tag: %c", *cp);
612 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
616 cmdLine = strtok (NULL, whitespace);
619 report (R_STATUS, "Starting up");
621 if (!running_on_visible_desktop ())
622 report (R_FATAL, "Tests must be run on a visible desktop");
624 if (reset_env && (putenv ("WINETEST_PLATFORM=windows") ||
625 putenv ("WINETEST_DEBUG=1") ||
626 putenv ("WINETEST_INTERACTIVE=0") ||
627 putenv ("WINETEST_REPORT_SUCCESS=0")))
628 report (R_FATAL, "Could not reset environment: %d", errno);
632 report (R_FATAL, "Please specify a tag (-t option) if "
633 "running noninteractive!");
634 if (guiAskTag () == IDABORT) exit (1);
639 logname = run_tests (NULL);
640 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
641 "test results?") == IDYES)
642 if (!send_file (logname) && remove (logname))
643 report (R_WARNING, "Can't remove logfile: %d.", errno);
645 } else run_tests (logname);
646 report (R_STATUS, "Finished");