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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 int nr_of_files
, nr_of_tests
;
61 static struct rev_info
*rev_infos
= NULL
;
62 static const char whitespace
[] = " \t\r\n";
64 static int running_under_wine (void)
66 HMODULE module
= GetModuleHandleA("ntdll.dll");
68 if (!module
) return 0;
69 return (GetProcAddress(module
, "wine_server_call") != NULL
);
72 static int running_on_visible_desktop (void)
75 HMODULE huser32
= GetModuleHandle("user32.dll");
76 FARPROC pGetProcessWindowStation
= GetProcAddress(huser32
, "GetProcessWindowStation");
77 FARPROC pGetUserObjectInformationA
= GetProcAddress(huser32
, "GetUserObjectInformationA");
79 desktop
= GetDesktopWindow();
80 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
81 return IsWindowVisible(desktop
);
83 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
87 USEROBJECTFLAGS uoflags
;
89 wstation
= (HWINSTA
)pGetProcessWindowStation();
90 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
91 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
93 return IsWindowVisible(desktop
);
96 static void print_version (void)
102 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
103 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
105 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
106 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
107 report (R_FATAL
, "Can't get OS version.");
110 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
111 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
112 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
113 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
114 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
115 ver
.dwPlatformId
, ver
.szCSDVersion
);
117 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
119 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
123 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
124 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
125 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
126 ver
.wProductType
, ver
.wReserved
);
129 static inline int is_dot_dir(const char* x
)
131 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
134 static void remove_dir (const char *dir
)
139 size_t dirlen
= strlen (dir
);
141 /* Make sure the directory exists before going further */
142 memcpy (path
, dir
, dirlen
);
143 strcpy (path
+ dirlen
++, "\\*");
144 hFind
= FindFirstFile (path
, &wfd
);
145 if (hFind
== INVALID_HANDLE_VALUE
) return;
148 char *lp
= wfd
.cFileName
;
150 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
151 if (is_dot_dir (lp
)) continue;
152 strcpy (path
+ dirlen
, lp
);
153 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
155 else if (!DeleteFile (path
))
156 report (R_WARNING
, "Can't delete file %s: error %d",
157 path
, GetLastError ());
158 } while (FindNextFile (hFind
, &wfd
));
160 if (!RemoveDirectory (dir
))
161 report (R_WARNING
, "Can't remove directory %s: error %d",
162 dir
, GetLastError ());
165 static const char* get_test_source_file(const char* test
, const char* subtest
)
167 static const char* special_dirs
[][2] = {
170 static char buffer
[MAX_PATH
];
173 for (i
= 0; special_dirs
[i
][0]; i
++) {
174 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
175 test
= special_dirs
[i
][1];
180 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
184 static const char* get_file_rev(const char* file
)
186 const struct rev_info
* rev
;
188 for(rev
= rev_infos
; rev
->file
; rev
++) {
189 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
195 static void extract_rev_infos (void)
197 char revinfo
[256], *p
;
200 HMODULE module
= GetModuleHandle (NULL
);
202 for (i
= 0; TRUE
; i
++) {
205 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
207 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
209 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
210 if (len
== 0) break; /* end of revision info */
211 if (len
>= sizeof(revinfo
) - 1)
212 report (R_FATAL
, "Revision info too long.");
213 if(!(p
= strrchr(revinfo
, ':')))
214 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
216 rev_infos
[i
].file
= strdup(revinfo
);
217 rev_infos
[i
].rev
= strdup(p
+ 1);
221 static void* extract_rcdata (LPTSTR name
, int type
, DWORD
* size
)
227 if (!(rsrc
= FindResource (NULL
, name
, MAKEINTRESOURCE(type
))) ||
228 !(*size
= SizeofResource (0, rsrc
)) ||
229 !(hdl
= LoadResource (0, rsrc
)) ||
230 !(addr
= LockResource (hdl
)))
235 /* Fills in the name and exename fields */
237 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
244 code
= extract_rcdata (res_name
, TESTRES
, &size
);
245 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
246 res_name
, GetLastError ());
247 test
->name
= xstrdup( res_name
);
248 CharLowerA( test
->name
);
249 test
->exename
= strmake (NULL
, "%s/%s", dir
, test
->name
);
250 exepos
= strstr (test
->name
, "_test.exe");
251 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
253 test
->name
= xrealloc (test
->name
, exepos
- test
->name
+ 1);
254 report (R_STEP
, "Extracting: %s", test
->name
);
256 if (!(fout
= fopen (test
->exename
, "wb")) ||
257 (fwrite (code
, size
, 1, fout
) != 1) ||
258 fclose (fout
)) report (R_FATAL
, "Failed to write file %s.",
262 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
265 Return the exit status, -2 if can't create process or the return
266 value of WaitForSingleObject.
269 run_ex (char *cmd
, const char *out
, const char *tempdir
, DWORD ms
)
272 PROCESS_INFORMATION pi
;
273 int fd
, oldstdout
= -1;
276 GetStartupInfo (&si
);
280 fd
= open (out
, O_WRONLY
| O_CREAT
, 0666);
282 report (R_FATAL
, "Can't open '%s': %d", out
, errno
);
285 report (R_FATAL
, "Can't save stdout: %d", errno
);
286 if (-1 == dup2 (fd
, 1))
287 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
291 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, 0,
292 NULL
, tempdir
, &si
, &pi
)) {
295 CloseHandle (pi
.hThread
);
296 wait
= WaitForSingleObject (pi
.hProcess
, ms
);
297 if (wait
== WAIT_OBJECT_0
) {
298 GetExitCodeProcess (pi
.hProcess
, &status
);
302 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
,
306 report (R_ERROR
, "Process '%s' timed out.", cmd
);
309 report (R_ERROR
, "Wait returned %d", wait
);
312 if (!TerminateProcess (pi
.hProcess
, 257))
313 report (R_ERROR
, "TerminateProcess failed: %d",
315 wait
= WaitForSingleObject (pi
.hProcess
, 5000);
319 "Wait for termination of '%s' failed: %d",
320 cmd
, GetLastError ());
325 report (R_ERROR
, "Can't kill process '%s'", cmd
);
328 report (R_ERROR
, "Waiting for termination: %d",
332 CloseHandle (pi
.hProcess
);
337 if (-1 == dup2 (oldstdout
, 1))
338 report (R_FATAL
, "Can't recover stdout: %d", errno
);
345 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
350 char buffer
[8192], *index
;
351 static const char header
[] = "Valid test names:";
354 test
->subtest_count
= 0;
356 subname
= tempnam (0, "sub");
357 if (!subname
) report (R_FATAL
, "Can't name subtests file.");
359 extract_test (test
, tempdir
, res_name
);
360 cmd
= strmake (NULL
, "%s --list", test
->exename
);
361 run_ex (cmd
, subname
, tempdir
, 5000);
364 subfile
= fopen (subname
, "r");
366 report (R_ERROR
, "Can't open subtests output of %s: %d",
370 total
= fread (buffer
, 1, sizeof buffer
, subfile
);
372 if (sizeof buffer
== total
) {
373 report (R_ERROR
, "Subtest list of %s too big.",
374 test
->name
, sizeof buffer
);
379 index
= strstr (buffer
, header
);
381 report (R_ERROR
, "Can't parse subtests output of %s",
385 index
+= sizeof header
;
388 test
->subtests
= xmalloc (allocated
* sizeof(char*));
389 index
= strtok (index
, whitespace
);
391 if (test
->subtest_count
== allocated
) {
393 test
->subtests
= xrealloc (test
->subtests
,
394 allocated
* sizeof(char*));
396 test
->subtests
[test
->subtest_count
++] = strdup (index
);
397 index
= strtok (NULL
, whitespace
);
399 test
->subtests
= xrealloc (test
->subtests
,
400 test
->subtest_count
* sizeof(char*));
403 if (remove (subname
))
404 report (R_WARNING
, "Can't delete file '%s': %d",
410 run_test (struct wine_test
* test
, const char* subtest
, const char *tempdir
)
413 const char* file
= get_test_source_file(test
->name
, subtest
);
414 const char* rev
= get_file_rev(file
);
415 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
417 xprintf ("%s:%s start %s %s\n", test
->name
, subtest
, file
, rev
);
418 status
= run_ex (cmd
, NULL
, tempdir
, 120000);
420 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
424 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
425 LPTSTR lpszName
, LONG_PTR lParam
)
432 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
433 LPTSTR lpszName
, LONG_PTR lParam
)
435 const char *tempdir
= (const char *)lParam
;
436 get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
);
437 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
443 run_tests (char *logname
)
446 char *tempdir
, *shorttempdir
;
448 char *strres
, *eol
, *nextline
;
451 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
454 logname
= tempnam (0, "res");
455 if (!logname
) report (R_FATAL
, "Can't name logfile.");
457 report (R_OUT
, logname
);
459 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
463 report (R_FATAL
, "File %s already exists.", logname
);
464 else report (R_FATAL
, "Could not open logfile: %d", errno
);
466 if (-1 == dup2 (logfile
, 1))
467 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
470 tempdir
= tempnam (0, "wct");
472 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
473 shorttempdir
= strdup (tempdir
);
474 if (shorttempdir
) { /* try stable path for ZoneAlarm */
475 strstr (shorttempdir
, "wct")[3] = 0;
476 if (CreateDirectoryA (shorttempdir
, NULL
)) {
478 tempdir
= shorttempdir
;
479 } else free (shorttempdir
);
481 if (tempdir
!= shorttempdir
&& !CreateDirectoryA (tempdir
, NULL
))
482 report (R_FATAL
, "Could not create directory: %s", tempdir
);
483 report (R_DIR
, tempdir
);
485 xprintf ("Version 3\n");
486 strres
= extract_rcdata (MAKEINTRESOURCE(WINE_BUILD
), STRINGRES
, &strsize
);
487 xprintf ("Tests from build ");
488 if (strres
) xprintf ("%.*s", strsize
, strres
);
489 else xprintf ("-\n");
490 strres
= extract_rcdata (MAKEINTRESOURCE(TESTS_URL
), STRINGRES
, &strsize
);
491 xprintf ("Archive: ");
492 if (strres
) xprintf ("%.*s", strsize
, strres
);
493 else xprintf ("-\n");
494 xprintf ("Tag: %s\n", tag
);
495 xprintf ("Build info:\n");
496 strres
= extract_rcdata (MAKEINTRESOURCE(BUILD_INFO
), STRINGRES
, &strsize
);
498 eol
= memchr (strres
, '\n', strsize
);
501 eol
= strres
+ strsize
;
503 strsize
-= eol
- strres
+ 1;
504 nextline
= strsize
?eol
+1:NULL
;
505 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
507 xprintf (" %.*s\n", eol
-strres
, strres
);
510 xprintf ("Operating system version:\n");
512 xprintf ("Test output:\n" );
514 report (R_STATUS
, "Counting tests");
515 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
516 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
517 report (R_FATAL
, "Can't enumerate test files: %d",
519 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
521 report (R_STATUS
, "Extracting tests");
522 report (R_PROGRESS
, 0, nr_of_files
);
525 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
526 extract_test_proc
, (LPARAM
)tempdir
))
527 report (R_FATAL
, "Can't enumerate test files: %d",
530 report (R_DELTA
, 0, "Extracting: Done");
532 report (R_STATUS
, "Running tests");
533 report (R_PROGRESS
, 1, nr_of_tests
);
534 for (i
= 0; i
< nr_of_files
; i
++) {
535 struct wine_test
*test
= wine_tests
+ i
;
538 for (j
= 0; j
< test
->subtest_count
; j
++) {
539 report (R_STEP
, "Running: %s:%s", test
->name
,
541 run_test (test
, test
->subtests
[j
], tempdir
);
544 report (R_DELTA
, 0, "Running: Done");
546 report (R_STATUS
, "Cleaning up");
548 remove_dir (tempdir
);
559 "Usage: winetest [OPTION]...\n\n"
560 " -c console mode, no GUI\n"
561 " -e preserve the environment\n"
562 " -h print this message and exit\n"
563 " -q quiet mode, no output at all\n"
564 " -o FILE put report into FILE, do not submit\n"
565 " -s FILE submit FILE, do not run tests\n"
566 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
569 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
570 LPSTR cmdLine
, int cmdShow
)
572 char *logname
= NULL
;
573 const char *cp
, *submit
= NULL
;
577 /* initialize the revision information first */
580 cmdLine
= strtok (cmdLine
, whitespace
);
582 if (cmdLine
[0] != '-' || cmdLine
[2]) {
583 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
587 switch (cmdLine
[1]) {
603 submit
= strtok (NULL
, whitespace
);
605 report (R_WARNING
, "ignoring tag for submission");
609 logname
= strtok (NULL
, whitespace
);
612 tag
= strtok (NULL
, whitespace
);
613 if (strlen (tag
) > MAXTAGLEN
)
614 report (R_FATAL
, "tag is too long (maximum %d characters)",
616 cp
= findbadtagchar (tag
);
618 report (R_ERROR
, "invalid char in tag: %c", *cp
);
624 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
628 cmdLine
= strtok (NULL
, whitespace
);
631 static CHAR platform_windows
[] = "WINETEST_PLATFORM=windows",
632 debug_yes
[] = "WINETEST_DEBUG=1",
633 interactive_no
[] = "WINETEST_INTERACTIVE=0",
634 report_success_no
[] = "WINETEST_REPORT_SUCCESS=0";
636 report (R_STATUS
, "Starting up");
638 if (!running_on_visible_desktop ())
639 report (R_FATAL
, "Tests must be run on a visible desktop");
641 if (reset_env
&& (putenv (platform_windows
) ||
642 putenv (debug_yes
) ||
643 putenv (interactive_no
) ||
644 putenv (report_success_no
)))
645 report (R_FATAL
, "Could not reset environment: %d", errno
);
649 report (R_FATAL
, "Please specify a tag (-t option) if "
650 "running noninteractive!");
651 if (guiAskTag () == IDABORT
) exit (1);
656 logname
= run_tests (NULL
);
657 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
658 "test results?") == IDYES
)
659 if (!send_file (logname
) && remove (logname
))
660 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
662 } else run_tests (logname
);
663 report (R_STATUS
, "Finished");