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"
51 static struct wine_test
*wine_tests
;
52 static int nr_of_files
, nr_of_tests
;
53 static const char whitespace
[] = " \t\r\n";
54 static const char testexe
[] = "_test.exe";
55 static char build_id
[64];
57 /* filters for running only specific tests */
58 static char *filters
[64];
59 static unsigned int nb_filters
= 0;
61 /* Needed to check for .NET dlls */
62 static HMODULE hmscoree
;
63 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
65 /* To store the current PATH setting (related to .NET only provided dlls) */
68 /* check if test is being filtered out */
69 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
71 char *p
, dllname
[MAX_PATH
];
74 strcpy( dllname
, module
);
75 CharLowerA( dllname
);
76 p
= strstr( dllname
, testexe
);
78 len
= strlen(dllname
);
80 if (!nb_filters
) return FALSE
;
81 for (i
= 0; i
< nb_filters
; i
++)
83 if (!strncmp( dllname
, filters
[i
], len
))
85 if (!filters
[i
][len
]) return FALSE
;
86 if (filters
[i
][len
] != ':') continue;
87 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
93 static char * get_file_version(char * file_name
)
95 static char version
[32];
99 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
101 char * data
= heap_alloc(size
);
103 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
104 static char backslash
[] = "\\";
105 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
107 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
108 sprintf(version
, "%d.%d.%d.%d",
109 pFixedVersionInfo
->dwFileVersionMS
>> 16,
110 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
111 pFixedVersionInfo
->dwFileVersionLS
>> 16,
112 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
114 sprintf(version
, "version not available");
116 sprintf(version
, "unknown");
119 sprintf(version
, "failed");
121 sprintf(version
, "version not available");
126 static int running_under_wine (void)
128 HMODULE module
= GetModuleHandleA("ntdll.dll");
130 if (!module
) return 0;
131 return (GetProcAddress(module
, "wine_server_call") != NULL
);
134 static int running_on_visible_desktop (void)
137 HMODULE huser32
= GetModuleHandle("user32.dll");
138 FARPROC pGetProcessWindowStation
= GetProcAddress(huser32
, "GetProcessWindowStation");
139 FARPROC pGetUserObjectInformationA
= GetProcAddress(huser32
, "GetUserObjectInformationA");
141 desktop
= GetDesktopWindow();
142 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
143 return IsWindowVisible(desktop
);
145 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
149 USEROBJECTFLAGS uoflags
;
151 wstation
= (HWINSTA
)pGetProcessWindowStation();
152 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
153 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
155 return IsWindowVisible(desktop
);
158 /* check if Gecko is present, trying to trigger the install if not */
159 static BOOL
gecko_check(void)
165 CoInitialize( NULL
);
166 if (FAILED( CoCreateInstance( &CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
,
167 &IID_IHTMLDocument2
, (void **)&doc
))) return FALSE
;
168 if ((ret
= SUCCEEDED( IHTMLDocument2_get_body( doc
, &body
)))) IHTMLElement_Release( body
);
169 IHTMLDocument_Release( doc
);
173 static void print_version (void)
176 static const char platform
[] = "i386";
177 #elif defined(__x86_64__)
178 static const char platform
[] = "x86_64";
179 #elif defined(__sparc__)
180 static const char platform
[] = "sparc";
181 #elif defined(__ALPHA__)
182 static const char platform
[] = "alpha";
183 #elif defined(__powerpc__)
184 static const char platform
[] = "powerpc";
189 const char *(CDECL
*wine_get_build_id
)(void);
190 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
191 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
193 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
194 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
196 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
197 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
198 report (R_FATAL
, "Can't get OS version.");
200 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
201 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
203 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
204 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
205 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
206 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
207 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
208 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
209 ver
.dwPlatformId
, ver
.szCSDVersion
);
211 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
212 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
213 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
214 if (wine_get_host_version
)
216 const char *sysname
, *release
;
217 wine_get_host_version( &sysname
, &release
);
218 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
220 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
222 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
226 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
227 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
228 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
229 ver
.wProductType
, ver
.wReserved
);
232 static inline int is_dot_dir(const char* x
)
234 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
237 static void remove_dir (const char *dir
)
242 size_t dirlen
= strlen (dir
);
244 /* Make sure the directory exists before going further */
245 memcpy (path
, dir
, dirlen
);
246 strcpy (path
+ dirlen
++, "\\*");
247 hFind
= FindFirstFile (path
, &wfd
);
248 if (hFind
== INVALID_HANDLE_VALUE
) return;
251 char *lp
= wfd
.cFileName
;
253 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
254 if (is_dot_dir (lp
)) continue;
255 strcpy (path
+ dirlen
, lp
);
256 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
258 else if (!DeleteFile (path
))
259 report (R_WARNING
, "Can't delete file %s: error %d",
260 path
, GetLastError ());
261 } while (FindNextFile (hFind
, &wfd
));
263 if (!RemoveDirectory (dir
))
264 report (R_WARNING
, "Can't remove directory %s: error %d",
265 dir
, GetLastError ());
268 static const char* get_test_source_file(const char* test
, const char* subtest
)
270 static const char* special_dirs
[][2] = {
273 static char buffer
[MAX_PATH
];
276 for (i
= 0; special_dirs
[i
][0]; i
++) {
277 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
278 test
= special_dirs
[i
][1];
283 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
287 static void* extract_rcdata (LPTSTR name
, int type
, DWORD
* size
)
293 if (!(rsrc
= FindResource (NULL
, name
, MAKEINTRESOURCE(type
))) ||
294 !(*size
= SizeofResource (0, rsrc
)) ||
295 !(hdl
= LoadResource (0, rsrc
)) ||
296 !(addr
= LockResource (hdl
)))
301 /* Fills in the name and exename fields */
303 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
311 code
= extract_rcdata (res_name
, TESTRES
, &size
);
312 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
313 res_name
, GetLastError ());
314 test
->name
= heap_strdup( res_name
);
315 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
316 exepos
= strstr (test
->name
, testexe
);
317 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
319 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
320 report (R_STEP
, "Extracting: %s", test
->name
);
322 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
323 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
324 if (hfile
== INVALID_HANDLE_VALUE
)
325 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
327 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
328 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
333 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
335 DWORD wait
, diff
= 0, start
= GetTickCount();
338 while (diff
< timeout
)
340 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
341 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
342 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
343 diff
= GetTickCount() - start
;
348 static void append_path( const char *path
)
352 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
353 strcpy(newpath
, curpath
);
354 strcat(newpath
, ";");
355 strcat(newpath
, path
);
356 SetEnvironmentVariableA("PATH", newpath
);
361 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
364 Return the exit status, -2 if can't create process or the return
365 value of WaitForSingleObject.
368 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
371 PROCESS_INFORMATION pi
;
374 GetStartupInfo (&si
);
375 si
.dwFlags
= STARTF_USESTDHANDLES
;
376 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
377 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
378 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
380 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
381 NULL
, tempdir
, &si
, &pi
))
384 CloseHandle (pi
.hThread
);
385 status
= wait_process( pi
.hProcess
, ms
);
389 GetExitCodeProcess (pi
.hProcess
, &status
);
390 CloseHandle (pi
.hProcess
);
393 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
396 report (R_ERROR
, "Process '%s' timed out.", cmd
);
399 report (R_ERROR
, "Wait returned %d", status
);
402 if (!TerminateProcess (pi
.hProcess
, 257))
403 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
404 wait
= wait_process( pi
.hProcess
, 5000 );
410 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
413 report (R_ERROR
, "Can't kill process '%s'", cmd
);
416 report (R_ERROR
, "Waiting for termination: %d", wait
);
419 CloseHandle (pi
.hProcess
);
424 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
429 char buffer
[8192], *index
;
430 static const char header
[] = "Valid test names:";
431 int status
, allocated
;
432 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
433 SECURITY_ATTRIBUTES sa
;
435 test
->subtest_count
= 0;
437 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
438 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
439 report (R_FATAL
, "Can't name subtests file.");
441 /* make handle inheritable */
442 sa
.nLength
= sizeof(sa
);
443 sa
.lpSecurityDescriptor
= NULL
;
444 sa
.bInheritHandle
= TRUE
;
446 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
447 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
448 &sa
, CREATE_ALWAYS
, 0, NULL
);
450 if ((subfile
== INVALID_HANDLE_VALUE
) &&
451 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
452 /* FILE_SHARE_DELETE not supported on win9x */
453 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
454 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
455 &sa
, CREATE_ALWAYS
, 0, NULL
);
457 if (subfile
== INVALID_HANDLE_VALUE
) {
458 err
= GetLastError();
459 report (R_ERROR
, "Can't open subtests output of %s: %u",
460 test
->name
, GetLastError());
464 extract_test (test
, tempdir
, res_name
);
465 cmd
= strmake (NULL
, "%s --list", test
->exename
);
466 if (test
->maindllpath
) {
467 /* We need to add the path (to the main dll) to PATH */
468 append_path(test
->maindllpath
);
470 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
471 err
= GetLastError();
472 if (test
->maindllpath
) {
473 /* Restore PATH again */
474 SetEnvironmentVariableA("PATH", curpath
);
480 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
484 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
485 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
486 CloseHandle( subfile
);
487 if (sizeof buffer
== total
) {
488 report (R_ERROR
, "Subtest list of %s too big.",
489 test
->name
, sizeof buffer
);
490 err
= ERROR_OUTOFMEMORY
;
495 index
= strstr (buffer
, header
);
497 report (R_ERROR
, "Can't parse subtests output of %s",
499 err
= ERROR_INTERNAL_ERROR
;
502 index
+= sizeof header
;
505 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
506 index
= strtok (index
, whitespace
);
508 if (test
->subtest_count
== allocated
) {
510 test
->subtests
= heap_realloc (test
->subtests
,
511 allocated
* sizeof(char*));
513 if (!test_filtered_out( test
->name
, index
))
514 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
515 index
= strtok (NULL
, whitespace
);
517 test
->subtests
= heap_realloc (test
->subtests
,
518 test
->subtest_count
* sizeof(char*));
522 if (!DeleteFileA (subname
))
523 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
528 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
531 const char* file
= get_test_source_file(test
->name
, subtest
);
532 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
534 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
535 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
537 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
541 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
542 LPTSTR lpszName
, LONG_PTR lParam
)
544 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
549 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
550 LPTSTR lpszName
, LONG_PTR lParam
)
552 const char *tempdir
= (const char *)lParam
;
553 char dllname
[MAX_PATH
];
554 char filename
[MAX_PATH
];
555 WCHAR dllnameW
[MAX_PATH
];
559 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
561 /* Check if the main dll is present on this system */
562 CharLowerA(lpszName
);
563 strcpy(dllname
, lpszName
);
564 *strstr(dllname
, testexe
) = 0;
566 wine_tests
[nr_of_files
].maindllpath
= NULL
;
567 strcpy(filename
, dllname
);
568 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
569 if (!dll
&& pLoadLibraryShim
)
571 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
572 if (FAILED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ))
576 char dllpath
[MAX_PATH
];
578 /* We have a dll that cannot be found through LoadLibraryExA. This
579 * is the case for .NET provided dll's. We will add the directory
580 * where the dll resides to the PATH variable when dealing with
581 * the tests for this dll.
583 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
584 strcpy(filename
, dllpath
);
585 *strrchr(dllpath
, '\\') = '\0';
586 wine_tests
[nr_of_files
].maindllpath
= heap_strdup( dllpath
);
590 xprintf (" %s=dll is missing\n", dllname
);
593 if (!strcmp( dllname
, "mshtml" ) && running_under_wine() && !gecko_check())
596 xprintf (" %s=load error Gecko is not installed\n", dllname
);
601 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
603 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
604 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
609 xprintf (" %s=load error %u\n", dllname
, err
);
615 run_tests (char *logname
, char *outdir
)
618 char *strres
, *eol
, *nextline
;
620 SECURITY_ATTRIBUTES sa
;
621 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
624 /* Get the current PATH only once */
625 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
626 curpath
= heap_alloc(needed
);
627 GetEnvironmentVariableA("PATH", curpath
, needed
);
629 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
631 if (!GetTempPathA( MAX_PATH
, tmppath
))
632 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
635 static char tmpname
[MAX_PATH
];
636 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
637 report (R_FATAL
, "Can't name logfile.");
640 report (R_OUT
, logname
);
642 /* make handle inheritable */
643 sa
.nLength
= sizeof(sa
);
644 sa
.lpSecurityDescriptor
= NULL
;
645 sa
.bInheritHandle
= TRUE
;
647 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
648 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
649 &sa
, CREATE_ALWAYS
, 0, NULL
);
651 if ((logfile
== INVALID_HANDLE_VALUE
) &&
652 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
653 /* FILE_SHARE_DELETE not supported on win9x */
654 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
655 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
656 &sa
, CREATE_ALWAYS
, 0, NULL
);
658 if (logfile
== INVALID_HANDLE_VALUE
)
659 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
661 /* try stable path for ZoneAlarm */
663 strcpy( tempdir
, tmppath
);
664 strcat( tempdir
, "wct" );
666 if (!CreateDirectoryA( tempdir
, NULL
))
668 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
669 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
670 DeleteFileA( tempdir
);
671 if (!CreateDirectoryA( tempdir
, NULL
))
672 report (R_FATAL
, "Could not create directory: %s", tempdir
);
676 strcpy( tempdir
, outdir
);
678 report (R_DIR
, tempdir
);
680 xprintf ("Version 4\n");
681 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
682 xprintf ("Archive: -\n"); /* no longer used */
683 xprintf ("Tag: %s\n", tag
);
684 xprintf ("Build info:\n");
685 strres
= extract_rcdata (MAKEINTRESOURCE(BUILD_INFO
), STRINGRES
, &strsize
);
687 eol
= memchr (strres
, '\n', strsize
);
690 eol
= strres
+ strsize
;
692 strsize
-= eol
- strres
+ 1;
693 nextline
= strsize
?eol
+1:NULL
;
694 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
696 xprintf (" %.*s\n", eol
-strres
, strres
);
699 xprintf ("Operating system version:\n");
701 xprintf ("Dll info:\n" );
703 report (R_STATUS
, "Counting tests");
704 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
705 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
706 report (R_FATAL
, "Can't enumerate test files: %d",
708 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
710 /* Do this only once during extraction (and version checking) */
711 hmscoree
= LoadLibraryA("mscoree.dll");
712 pLoadLibraryShim
= NULL
;
714 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
716 report (R_STATUS
, "Extracting tests");
717 report (R_PROGRESS
, 0, nr_of_files
);
720 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
721 extract_test_proc
, (LPARAM
)tempdir
))
722 report (R_FATAL
, "Can't enumerate test files: %d",
725 FreeLibrary(hmscoree
);
727 xprintf ("Test output:\n" );
729 report (R_DELTA
, 0, "Extracting: Done");
731 report (R_STATUS
, "Running tests");
732 report (R_PROGRESS
, 1, nr_of_tests
);
733 for (i
= 0; i
< nr_of_files
; i
++) {
734 struct wine_test
*test
= wine_tests
+ i
;
737 if (test
->maindllpath
) {
738 /* We need to add the path (to the main dll) to PATH */
739 append_path(test
->maindllpath
);
742 for (j
= 0; j
< test
->subtest_count
; j
++) {
743 report (R_STEP
, "Running: %s:%s", test
->name
,
745 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
748 if (test
->maindllpath
) {
749 /* Restore PATH again */
750 SetEnvironmentVariableA("PATH", curpath
);
753 report (R_DELTA
, 0, "Running: Done");
755 report (R_STATUS
, "Cleaning up");
756 CloseHandle( logfile
);
759 remove_dir (tempdir
);
760 heap_free(wine_tests
);
766 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
768 if (ctrl_type
== CTRL_C_EVENT
) {
769 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
778 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
780 const char *target_dir
= (const char *)lParam
;
781 char filename
[MAX_PATH
];
783 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
785 strcpy(filename
, lpszName
);
786 CharLowerA(filename
);
788 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
793 static void extract_only (const char *target_dir
)
797 report (R_DIR
, target_dir
);
798 res
= CreateDirectoryA( target_dir
, NULL
);
799 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
800 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
803 report (R_STATUS
, "Counting tests");
804 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
), EnumTestFileProc
, (LPARAM
)&nr_of_files
))
805 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
807 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
809 report (R_STATUS
, "Extracting tests");
810 report (R_PROGRESS
, 0, nr_of_files
);
812 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
), extract_only_proc
, (LPARAM
)target_dir
))
813 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
815 report (R_DELTA
, 0, "Extracting: Done");
822 "Usage: winetest [OPTION]... [TESTS]\n\n"
823 " --help print this message and exit\n"
824 " --version print the build version and exit\n"
825 " -c console mode, no GUI\n"
826 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
827 " -e preserve the environment\n"
828 " -h print this message and exit\n"
829 " -p shutdown when the tests are done\n"
830 " -q quiet mode, no output at all\n"
831 " -o FILE put report into FILE, do not submit\n"
832 " -s FILE submit FILE, do not run tests\n"
833 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
834 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
837 int main( int argc
, char *argv
[] )
839 char *logname
= NULL
, *outdir
= NULL
;
840 const char *extract
= NULL
;
841 const char *cp
, *submit
= NULL
;
847 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
849 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
851 if (!strcmp(argv
[i
], "--help")) {
855 else if (!strcmp(argv
[i
], "--version")) {
856 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
859 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
860 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
862 report (R_ERROR
, "Too many test filters specified");
865 filters
[nb_filters
++] = argv
[i
];
867 else switch (argv
[i
][1]) {
887 if (!(submit
= argv
[++i
]))
893 report (R_WARNING
, "ignoring tag for submission");
897 if (!(logname
= argv
[++i
]))
904 if (!(tag
= argv
[++i
]))
909 if (strlen (tag
) > MAXTAGLEN
)
910 report (R_FATAL
, "tag is too long (maximum %d characters)",
912 cp
= findbadtagchar (tag
);
914 report (R_ERROR
, "invalid char in tag: %c", *cp
);
921 if (!(extract
= argv
[++i
]))
924 extract_only (extract
);
930 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
935 if (!submit
&& !extract
) {
936 report (R_STATUS
, "Starting up");
938 if (!running_on_visible_desktop ())
939 report (R_FATAL
, "Tests must be run on a visible desktop");
941 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
945 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
946 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
947 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
948 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
951 if (!nb_filters
) /* don't submit results when filtering */
955 report (R_FATAL
, "Please specify a tag (-t option) if "
956 "running noninteractive!");
957 if (guiAskTag () == IDABORT
) exit (1);
962 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
963 "To submit results, winetest needs to be built from a git checkout." );
967 logname
= run_tests (NULL
, outdir
);
968 if (build_id
[0] && !nb_filters
&&
969 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
970 if (!send_file (logname
) && !DeleteFileA(logname
))
971 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
972 } else run_tests (logname
, outdir
);
973 report (R_STATUS
, "Finished");
978 TOKEN_PRIVILEGES npr
;
980 /* enable the shutdown privilege for the current process */
981 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
983 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
984 npr
.PrivilegeCount
= 1;
985 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
986 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
989 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);