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";
63 static const char testexe
[] = "_test.exe";
65 static int running_under_wine (void)
67 HMODULE module
= GetModuleHandleA("ntdll.dll");
69 if (!module
) return 0;
70 return (GetProcAddress(module
, "wine_server_call") != NULL
);
73 static int running_on_visible_desktop (void)
76 HMODULE huser32
= GetModuleHandle("user32.dll");
77 FARPROC pGetProcessWindowStation
= GetProcAddress(huser32
, "GetProcessWindowStation");
78 FARPROC pGetUserObjectInformationA
= GetProcAddress(huser32
, "GetUserObjectInformationA");
80 desktop
= GetDesktopWindow();
81 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
82 return IsWindowVisible(desktop
);
84 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
88 USEROBJECTFLAGS uoflags
;
90 wstation
= (HWINSTA
)pGetProcessWindowStation();
91 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
92 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
94 return IsWindowVisible(desktop
);
97 static void print_version (void)
103 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
104 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
106 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
107 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
108 report (R_FATAL
, "Can't get OS version.");
111 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
112 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
113 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
114 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
115 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
116 ver
.dwPlatformId
, ver
.szCSDVersion
);
118 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
120 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
124 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
125 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
126 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
127 ver
.wProductType
, ver
.wReserved
);
130 static inline int is_dot_dir(const char* x
)
132 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
135 static void remove_dir (const char *dir
)
140 size_t dirlen
= strlen (dir
);
142 /* Make sure the directory exists before going further */
143 memcpy (path
, dir
, dirlen
);
144 strcpy (path
+ dirlen
++, "\\*");
145 hFind
= FindFirstFile (path
, &wfd
);
146 if (hFind
== INVALID_HANDLE_VALUE
) return;
149 char *lp
= wfd
.cFileName
;
151 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
152 if (is_dot_dir (lp
)) continue;
153 strcpy (path
+ dirlen
, lp
);
154 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
156 else if (!DeleteFile (path
))
157 report (R_WARNING
, "Can't delete file %s: error %d",
158 path
, GetLastError ());
159 } while (FindNextFile (hFind
, &wfd
));
161 if (!RemoveDirectory (dir
))
162 report (R_WARNING
, "Can't remove directory %s: error %d",
163 dir
, GetLastError ());
166 static const char* get_test_source_file(const char* test
, const char* subtest
)
168 static const char* special_dirs
[][2] = {
171 static char buffer
[MAX_PATH
];
174 for (i
= 0; special_dirs
[i
][0]; i
++) {
175 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
176 test
= special_dirs
[i
][1];
181 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
185 static const char* get_file_rev(const char* file
)
187 const struct rev_info
* rev
;
189 for(rev
= rev_infos
; rev
->file
; rev
++) {
190 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
196 static void extract_rev_infos (void)
198 char revinfo
[256], *p
;
201 HMODULE module
= GetModuleHandle (NULL
);
203 for (i
= 0; TRUE
; i
++) {
206 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
208 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
210 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
211 if (len
== 0) break; /* end of revision info */
212 if (len
>= sizeof(revinfo
) - 1)
213 report (R_FATAL
, "Revision info too long.");
214 if(!(p
= strrchr(revinfo
, ':')))
215 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
217 rev_infos
[i
].file
= strdup(revinfo
);
218 rev_infos
[i
].rev
= strdup(p
+ 1);
222 static void* extract_rcdata (LPTSTR name
, int type
, DWORD
* size
)
228 if (!(rsrc
= FindResource (NULL
, name
, MAKEINTRESOURCE(type
))) ||
229 !(*size
= SizeofResource (0, rsrc
)) ||
230 !(hdl
= LoadResource (0, rsrc
)) ||
231 !(addr
= LockResource (hdl
)))
236 /* Fills in the name and exename fields */
238 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
245 code
= extract_rcdata (res_name
, TESTRES
, &size
);
246 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
247 res_name
, GetLastError ());
248 test
->name
= xstrdup( res_name
);
249 test
->exename
= strmake (NULL
, "%s/%s", dir
, test
->name
);
250 exepos
= strstr (test
->name
, testexe
);
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 char dllname
[MAX_PATH
];
439 /* Check if the main dll is present on this system */
440 CharLowerA(lpszName
);
441 strcpy(dllname
, lpszName
);
442 *strstr(dllname
, testexe
) = 0;
444 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
446 xprintf ("%s:%s_dll_missing start 0 0\n", dllname
, dllname
);
447 xprintf ("%s_dll_missing: -1 tests executed (-1 marked as todo, -1 failures), -1 skipped.\n", dllname
);
448 xprintf ("%s:%s_dll_missing done (0)\n", dllname
, dllname
);
453 get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
);
454 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
460 run_tests (char *logname
)
463 char *tempdir
, *shorttempdir
;
465 char *strres
, *eol
, *nextline
;
468 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
471 logname
= tempnam (0, "res");
472 if (!logname
) report (R_FATAL
, "Can't name logfile.");
474 report (R_OUT
, logname
);
476 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
480 report (R_FATAL
, "File %s already exists.", logname
);
481 else report (R_FATAL
, "Could not open logfile: %d", errno
);
483 if (-1 == dup2 (logfile
, 1))
484 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
487 tempdir
= tempnam (0, "wct");
489 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
490 shorttempdir
= strdup (tempdir
);
491 if (shorttempdir
) { /* try stable path for ZoneAlarm */
492 strstr (shorttempdir
, "wct")[3] = 0;
493 if (CreateDirectoryA (shorttempdir
, NULL
)) {
495 tempdir
= shorttempdir
;
496 } else free (shorttempdir
);
498 if (tempdir
!= shorttempdir
&& !CreateDirectoryA (tempdir
, NULL
))
499 report (R_FATAL
, "Could not create directory: %s", tempdir
);
500 report (R_DIR
, tempdir
);
502 xprintf ("Version 4\n");
503 strres
= extract_rcdata (MAKEINTRESOURCE(WINE_BUILD
), STRINGRES
, &strsize
);
504 xprintf ("Tests from build ");
505 if (strres
) xprintf ("%.*s", strsize
, strres
);
506 else xprintf ("-\n");
507 strres
= extract_rcdata (MAKEINTRESOURCE(TESTS_URL
), STRINGRES
, &strsize
);
508 xprintf ("Archive: ");
509 if (strres
) xprintf ("%.*s", strsize
, strres
);
510 else xprintf ("-\n");
511 xprintf ("Tag: %s\n", tag
);
512 xprintf ("Build info:\n");
513 strres
= extract_rcdata (MAKEINTRESOURCE(BUILD_INFO
), STRINGRES
, &strsize
);
515 eol
= memchr (strres
, '\n', strsize
);
518 eol
= strres
+ strsize
;
520 strsize
-= eol
- strres
+ 1;
521 nextline
= strsize
?eol
+1:NULL
;
522 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
524 xprintf (" %.*s\n", eol
-strres
, strres
);
527 xprintf ("Operating system version:\n");
529 xprintf ("Test output:\n" );
531 report (R_STATUS
, "Counting tests");
532 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
533 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
534 report (R_FATAL
, "Can't enumerate test files: %d",
536 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
538 report (R_STATUS
, "Extracting tests");
539 report (R_PROGRESS
, 0, nr_of_files
);
542 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
543 extract_test_proc
, (LPARAM
)tempdir
))
544 report (R_FATAL
, "Can't enumerate test files: %d",
547 report (R_DELTA
, 0, "Extracting: Done");
549 report (R_STATUS
, "Running tests");
550 report (R_PROGRESS
, 1, nr_of_tests
);
551 for (i
= 0; i
< nr_of_files
; i
++) {
552 struct wine_test
*test
= wine_tests
+ i
;
555 for (j
= 0; j
< test
->subtest_count
; j
++) {
556 report (R_STEP
, "Running: %s:%s", test
->name
,
558 run_test (test
, test
->subtests
[j
], tempdir
);
561 report (R_DELTA
, 0, "Running: Done");
563 report (R_STATUS
, "Cleaning up");
565 remove_dir (tempdir
);
576 "Usage: winetest [OPTION]...\n\n"
577 " -c console mode, no GUI\n"
578 " -e preserve the environment\n"
579 " -h print this message and exit\n"
580 " -q quiet mode, no output at all\n"
581 " -o FILE put report into FILE, do not submit\n"
582 " -s FILE submit FILE, do not run tests\n"
583 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
586 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
587 LPSTR cmdLine
, int cmdShow
)
589 char *logname
= NULL
;
590 const char *cp
, *submit
= NULL
;
594 /* initialize the revision information first */
597 cmdLine
= strtok (cmdLine
, whitespace
);
599 if (cmdLine
[0] != '-' || cmdLine
[2]) {
600 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
604 switch (cmdLine
[1]) {
620 submit
= strtok (NULL
, whitespace
);
622 report (R_WARNING
, "ignoring tag for submission");
626 logname
= strtok (NULL
, whitespace
);
629 tag
= strtok (NULL
, whitespace
);
630 if (strlen (tag
) > MAXTAGLEN
)
631 report (R_FATAL
, "tag is too long (maximum %d characters)",
633 cp
= findbadtagchar (tag
);
635 report (R_ERROR
, "invalid char in tag: %c", *cp
);
641 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
645 cmdLine
= strtok (NULL
, whitespace
);
648 static CHAR platform_windows
[] = "WINETEST_PLATFORM=windows",
649 platform_wine
[] = "WINETEST_PLATFORM=wine",
650 debug_yes
[] = "WINETEST_DEBUG=1",
651 interactive_no
[] = "WINETEST_INTERACTIVE=0",
652 report_success_no
[] = "WINETEST_REPORT_SUCCESS=0";
655 report (R_STATUS
, "Starting up");
657 if (!running_on_visible_desktop ())
658 report (R_FATAL
, "Tests must be run on a visible desktop");
660 platform
= running_under_wine () ? platform_wine
: platform_windows
;
662 if (reset_env
&& (putenv (platform
) ||
663 putenv (debug_yes
) ||
664 putenv (interactive_no
) ||
665 putenv (report_success_no
)))
666 report (R_FATAL
, "Could not reset environment: %d", errno
);
670 report (R_FATAL
, "Please specify a tag (-t option) if "
671 "running noninteractive!");
672 if (guiAskTag () == IDABORT
) exit (1);
677 logname
= run_tests (NULL
);
678 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
679 "test results?") == IDYES
)
680 if (!send_file (logname
) && remove (logname
))
681 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
683 } else run_tests (logname
);
684 report (R_STATUS
, "Finished");