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 (void)
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 (void)
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
);
95 static void print_version (void)
101 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
102 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
104 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
105 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
106 report (R_FATAL
, "Can't get OS version.");
109 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
110 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
111 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
112 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
113 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
114 ver
.dwPlatformId
, ver
.szCSDVersion
);
116 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
118 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
122 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
123 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
124 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
125 ver
.wProductType
, ver
.wReserved
);
128 static inline int is_dot_dir(const char* x
)
130 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
133 static void remove_dir (const char *dir
)
138 size_t dirlen
= strlen (dir
);
140 /* Make sure the directory exists before going further */
141 memcpy (path
, dir
, dirlen
);
142 strcpy (path
+ dirlen
++, "\\*");
143 hFind
= FindFirstFile (path
, &wfd
);
144 if (hFind
== INVALID_HANDLE_VALUE
) return;
147 char *lp
= wfd
.cFileName
;
149 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
150 if (is_dot_dir (lp
)) continue;
151 strcpy (path
+ dirlen
, lp
);
152 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
154 else if (!DeleteFile (path
))
155 report (R_WARNING
, "Can't delete file %s: error %d",
156 path
, GetLastError ());
157 } while (FindNextFile (hFind
, &wfd
));
159 if (!RemoveDirectory (dir
))
160 report (R_WARNING
, "Can't remove directory %s: error %d",
161 dir
, GetLastError ());
164 static const char* get_test_source_file(const char* test
, const char* subtest
)
166 static const char* special_dirs
[][2] = {
167 { "gdi32", "gdi"}, { "kernel32", "kernel" },
168 { "msacm32", "msacm" },
169 { "user32", "user" }, { "winspool.drv", "winspool" },
170 { "ws2_32", "winsock" }, { 0, 0 }
172 static char buffer
[MAX_PATH
];
175 for (i
= 0; special_dirs
[i
][0]; i
++) {
176 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
177 test
= special_dirs
[i
][1];
182 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
186 static const char* get_file_rev(const char* file
)
188 const struct rev_info
* rev
;
190 for(rev
= rev_infos
; rev
->file
; rev
++) {
191 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
197 static void extract_rev_infos (void)
199 char revinfo
[256], *p
;
202 HMODULE module
= GetModuleHandle (NULL
);
204 for (i
= 0; TRUE
; i
++) {
207 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
209 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
211 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
212 if (len
== 0) break; /* end of revision info */
213 if (len
>= sizeof(revinfo
) - 1)
214 report (R_FATAL
, "Revision info too long.");
215 if(!(p
= strrchr(revinfo
, ':')))
216 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
218 rev_infos
[i
].file
= strdup(revinfo
);
219 rev_infos
[i
].rev
= strdup(p
+ 1);
223 static void* extract_rcdata (int id
, int type
, DWORD
* size
)
229 if (!(rsrc
= FindResource (NULL
, (LPTSTR
)id
, MAKEINTRESOURCE(type
))) ||
230 !(*size
= SizeofResource (0, rsrc
)) ||
231 !(hdl
= LoadResource (0, rsrc
)) ||
232 !(addr
= LockResource (hdl
)))
237 /* Fills in the name and exename fields */
239 extract_test (struct wine_test
*test
, const char *dir
, int id
)
244 int strlen
, bufflen
= 128;
247 code
= extract_rcdata (id
, TESTRES
, &size
);
248 if (!code
) report (R_FATAL
, "Can't find test resource %d: %d",
249 id
, GetLastError ());
250 test
->name
= xmalloc (bufflen
);
251 while ((strlen
= LoadStringA (NULL
, id
, test
->name
, bufflen
))
254 test
->name
= xrealloc (test
->name
, bufflen
);
256 if (!strlen
) report (R_FATAL
, "Can't read name of test %d.", id
);
257 test
->exename
= strmake (NULL
, "%s/%s", dir
, test
->name
);
258 exepos
= strstr (test
->name
, "_test.exe");
259 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
261 test
->name
= xrealloc (test
->name
, exepos
- test
->name
+ 1);
262 report (R_STEP
, "Extracting: %s", test
->name
);
264 if (!(fout
= fopen (test
->exename
, "wb")) ||
265 (fwrite (code
, size
, 1, fout
) != 1) ||
266 fclose (fout
)) report (R_FATAL
, "Failed to write file %s.",
270 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
273 Return the exit status, -2 if can't create process or the return
274 value of WaitForSingleObject.
277 run_ex (char *cmd
, const char *out
, DWORD ms
)
280 PROCESS_INFORMATION pi
;
281 int fd
, oldstdout
= -1;
284 GetStartupInfo (&si
);
285 si
.wShowWindow
= SW_HIDE
;
286 si
.dwFlags
= STARTF_USESHOWWINDOW
;
289 fd
= open (out
, O_WRONLY
| O_CREAT
, 0666);
291 report (R_FATAL
, "Can't open '%s': %d", out
, errno
);
294 report (R_FATAL
, "Can't save stdout: %d", errno
);
295 if (-1 == dup2 (fd
, 1))
296 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
300 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, 0,
301 NULL
, NULL
, &si
, &pi
)) {
304 CloseHandle (pi
.hThread
);
305 wait
= WaitForSingleObject (pi
.hProcess
, ms
);
306 if (wait
== WAIT_OBJECT_0
) {
307 GetExitCodeProcess (pi
.hProcess
, &status
);
311 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
,
315 report (R_ERROR
, "Process '%s' timed out.", cmd
);
318 report (R_ERROR
, "Wait returned %d", wait
);
321 if (!TerminateProcess (pi
.hProcess
, 257))
322 report (R_ERROR
, "TerminateProcess failed: %d",
324 wait
= WaitForSingleObject (pi
.hProcess
, 5000);
328 "Wait for termination of '%s' failed: %d",
329 cmd
, GetLastError ());
334 report (R_ERROR
, "Can't kill process '%s'", cmd
);
337 report (R_ERROR
, "Waiting for termination: %d",
341 CloseHandle (pi
.hProcess
);
346 if (-1 == dup2 (oldstdout
, 1))
347 report (R_FATAL
, "Can't recover stdout: %d", errno
);
354 get_subtests (const char *tempdir
, struct wine_test
*test
, int id
)
359 char buffer
[8192], *index
;
360 static const char header
[] = "Valid test names:";
363 test
->subtest_count
= 0;
365 subname
= tempnam (0, "sub");
366 if (!subname
) report (R_FATAL
, "Can't name subtests file.");
368 extract_test (test
, tempdir
, id
);
369 cmd
= strmake (NULL
, "%s --list", test
->exename
);
370 run_ex (cmd
, subname
, 5000);
373 subfile
= fopen (subname
, "r");
375 report (R_ERROR
, "Can't open subtests output of %s: %d",
379 total
= fread (buffer
, 1, sizeof buffer
, subfile
);
381 if (sizeof buffer
== total
) {
382 report (R_ERROR
, "Subtest list of %s too big.",
383 test
->name
, sizeof buffer
);
388 index
= strstr (buffer
, header
);
390 report (R_ERROR
, "Can't parse subtests output of %s",
394 index
+= sizeof header
;
397 test
->subtests
= xmalloc (allocated
* sizeof(char*));
398 index
= strtok (index
, whitespace
);
400 if (test
->subtest_count
== allocated
) {
402 test
->subtests
= xrealloc (test
->subtests
,
403 allocated
* sizeof(char*));
405 test
->subtests
[test
->subtest_count
++] = strdup (index
);
406 index
= strtok (NULL
, whitespace
);
408 test
->subtests
= xrealloc (test
->subtests
,
409 test
->subtest_count
* sizeof(char*));
412 if (remove (subname
))
413 report (R_WARNING
, "Can't delete file '%s': %d",
419 run_test (struct wine_test
* test
, const char* subtest
)
422 const char* file
= get_test_source_file(test
->name
, subtest
);
423 const char* rev
= get_file_rev(file
);
424 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
426 xprintf ("%s:%s start %s %s\n", test
->name
, subtest
, file
, rev
);
427 status
= run_ex (cmd
, NULL
, 120000);
429 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
433 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
434 LPTSTR lpszName
, LONG_PTR lParam
)
441 run_tests (char *logname
)
443 int nr_of_files
= 0, nr_of_tests
= 0, i
;
444 char *tempdir
, *shorttempdir
;
446 char *strres
, *eol
, *nextline
;
449 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
452 logname
= tempnam (0, "res");
453 if (!logname
) report (R_FATAL
, "Can't name logfile.");
455 report (R_OUT
, logname
);
457 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
461 report (R_FATAL
, "File %s already exists.", logname
);
462 else report (R_FATAL
, "Could not open logfile: %d", errno
);
464 if (-1 == dup2 (logfile
, 1))
465 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
468 tempdir
= tempnam (0, "wct");
470 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
471 shorttempdir
= strdup (tempdir
);
472 if (shorttempdir
) { /* try stable path for ZoneAlarm */
473 strstr (shorttempdir
, "wct")[3] = 0;
474 if (CreateDirectoryA (shorttempdir
, NULL
)) {
476 tempdir
= shorttempdir
;
477 } else free (shorttempdir
);
479 if (tempdir
!= shorttempdir
&& !CreateDirectoryA (tempdir
, NULL
))
480 report (R_FATAL
, "Could not create directory: %s", tempdir
);
481 report (R_DIR
, tempdir
);
483 xprintf ("Version 3\n");
484 strres
= extract_rcdata (WINE_BUILD
, STRINGRES
, &strsize
);
485 xprintf ("Tests from build ");
486 if (strres
) xprintf ("%.*s", strsize
, strres
);
487 else xprintf ("-\n");
488 strres
= extract_rcdata (TESTS_URL
, STRINGRES
, &strsize
);
489 xprintf ("Archive: ");
490 if (strres
) xprintf ("%.*s", strsize
, strres
);
491 else xprintf ("-\n");
492 xprintf ("Tag: %s\n", tag
);
493 xprintf ("Build info:\n");
494 strres
= extract_rcdata (BUILD_INFO
, STRINGRES
, &strsize
);
496 eol
= memchr (strres
, '\n', strsize
);
499 eol
= strres
+ strsize
;
501 strsize
-= eol
- strres
+ 1;
502 nextline
= strsize
?eol
+1:NULL
;
503 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
505 xprintf (" %.*s\n", eol
-strres
, strres
);
508 xprintf ("Operating system version:\n");
510 xprintf ("Test output:\n" );
512 report (R_STATUS
, "Counting tests");
513 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
514 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
515 report (R_FATAL
, "Can't enumerate test files: %d",
517 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
519 report (R_STATUS
, "Extracting tests");
520 report (R_PROGRESS
, 0, nr_of_files
);
521 for (i
= 0; i
< nr_of_files
; i
++) {
522 get_subtests (tempdir
, wine_tests
+i
, i
);
523 nr_of_tests
+= wine_tests
[i
].subtest_count
;
525 report (R_DELTA
, 0, "Extracting: Done");
527 report (R_STATUS
, "Running tests");
528 report (R_PROGRESS
, 1, nr_of_tests
);
529 for (i
= 0; i
< nr_of_files
; i
++) {
530 struct wine_test
*test
= wine_tests
+ i
;
533 for (j
= 0; j
< test
->subtest_count
; j
++) {
534 report (R_STEP
, "Running: %s:%s", test
->name
,
536 run_test (test
, test
->subtests
[j
]);
539 report (R_DELTA
, 0, "Running: Done");
541 report (R_STATUS
, "Cleaning up");
543 remove_dir (tempdir
);
554 Usage: winetest [OPTION]...\n\n\
555 -c console mode, no GUI\n\
556 -e preserve the environment\n\
557 -h print this message and exit\n\
558 -q quiet mode, no output at all\n\
559 -o FILE put report into FILE, do not submit\n\
560 -s FILE submit FILE, do not run tests\n\
561 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
564 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
565 LPSTR cmdLine
, int cmdShow
)
567 char *logname
= NULL
;
568 const char *cp
, *submit
= NULL
;
572 /* initialize the revision information first */
575 cmdLine
= strtok (cmdLine
, whitespace
);
577 if (cmdLine
[0] != '-' || cmdLine
[2]) {
578 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
582 switch (cmdLine
[1]) {
598 submit
= strtok (NULL
, whitespace
);
600 report (R_WARNING
, "ignoring tag for submission");
604 logname
= strtok (NULL
, whitespace
);
607 tag
= strtok (NULL
, whitespace
);
608 if (strlen (tag
) > MAXTAGLEN
)
609 report (R_FATAL
, "tag is too long (maximum %d characters)",
611 cp
= findbadtagchar (tag
);
613 report (R_ERROR
, "invalid char in tag: %c", *cp
);
619 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
623 cmdLine
= strtok (NULL
, whitespace
);
626 report (R_STATUS
, "Starting up");
628 if (!running_on_visible_desktop ())
629 report (R_FATAL
, "Tests must be run on a visible desktop");
631 if (reset_env
&& (putenv ("WINETEST_PLATFORM=windows") ||
632 putenv ("WINETEST_DEBUG=1") ||
633 putenv ("WINETEST_INTERACTIVE=0") ||
634 putenv ("WINETEST_REPORT_SUCCESS=0")))
635 report (R_FATAL
, "Could not reset environment: %d", errno
);
639 report (R_FATAL
, "Please specify a tag (-t option) if "
640 "running noninteractive!");
641 if (guiAskTag () == IDABORT
) exit (1);
646 logname
= run_tests (NULL
);
647 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
648 "test results?") == IDYES
)
649 if (!send_file (logname
) && remove (logname
))
650 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
652 } else run_tests (logname
);
653 report (R_STATUS
, "Finished");