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 int nr_native_dlls
;
54 static const char whitespace
[] = " \t\r\n";
55 static const char testexe
[] = "_test.exe";
56 static char build_id
[64];
58 /* filters for running only specific tests */
59 static char *filters
[64];
60 static unsigned int nb_filters
= 0;
62 /* Needed to check for .NET dlls */
63 static HMODULE hmscoree
;
64 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
66 /* To store the current PATH setting (related to .NET only provided dlls) */
69 /* check if test is being filtered out */
70 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
72 char *p
, dllname
[MAX_PATH
];
75 strcpy( dllname
, module
);
76 CharLowerA( dllname
);
77 p
= strstr( dllname
, testexe
);
79 len
= strlen(dllname
);
81 if (!nb_filters
) return FALSE
;
82 for (i
= 0; i
< nb_filters
; i
++)
84 if (!strncmp( dllname
, filters
[i
], len
))
86 if (!filters
[i
][len
]) return FALSE
;
87 if (filters
[i
][len
] != ':') continue;
88 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
94 static char * get_file_version(char * file_name
)
96 static char version
[32];
100 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
102 char * data
= heap_alloc(size
);
104 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
105 static char backslash
[] = "\\";
106 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
108 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
109 sprintf(version
, "%d.%d.%d.%d",
110 pFixedVersionInfo
->dwFileVersionMS
>> 16,
111 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
112 pFixedVersionInfo
->dwFileVersionLS
>> 16,
113 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
115 sprintf(version
, "version not available");
117 sprintf(version
, "unknown");
120 sprintf(version
, "failed");
122 sprintf(version
, "version not available");
127 static int running_under_wine (void)
129 HMODULE module
= GetModuleHandleA("ntdll.dll");
131 if (!module
) return 0;
132 return (GetProcAddress(module
, "wine_server_call") != NULL
);
135 static int running_on_visible_desktop (void)
138 HMODULE huser32
= GetModuleHandle("user32.dll");
139 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
140 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
142 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
143 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
145 desktop
= GetDesktopWindow();
146 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
147 return IsWindowVisible(desktop
);
149 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
153 USEROBJECTFLAGS uoflags
;
155 wstation
= (HWINSTA
)pGetProcessWindowStation();
156 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
157 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
159 return IsWindowVisible(desktop
);
162 /* check for native dll when running under wine */
163 static BOOL
is_native_dll( HMODULE module
)
165 static const char fakedll_signature
[] = "Wine placeholder DLL";
166 const IMAGE_DOS_HEADER
*dos
;
168 if (!running_under_wine()) return FALSE
;
169 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
170 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
171 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
172 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
173 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
174 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
178 /* check if Gecko is present, trying to trigger the install if not */
179 static BOOL
gecko_check(void)
185 CoInitialize( NULL
);
186 if (FAILED( CoCreateInstance( &CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
,
187 &IID_IHTMLDocument2
, (void **)&doc
))) return FALSE
;
188 if ((ret
= SUCCEEDED( IHTMLDocument2_get_body( doc
, &body
)))) IHTMLElement_Release( body
);
189 IHTMLDocument_Release( doc
);
193 static void print_version (void)
196 static const char platform
[] = "i386";
197 #elif defined(__x86_64__)
198 static const char platform
[] = "x86_64";
199 #elif defined(__sparc__)
200 static const char platform
[] = "sparc";
201 #elif defined(__ALPHA__)
202 static const char platform
[] = "alpha";
203 #elif defined(__powerpc__)
204 static const char platform
[] = "powerpc";
209 const char *(CDECL
*wine_get_build_id
)(void);
210 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
211 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
212 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
214 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
215 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
217 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
218 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
219 report (R_FATAL
, "Can't get OS version.");
221 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
222 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
224 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
225 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
226 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
227 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
228 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
229 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
230 ver
.dwPlatformId
, ver
.szCSDVersion
);
232 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
233 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
234 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
235 if (wine_get_host_version
)
237 const char *sysname
, *release
;
238 wine_get_host_version( &sysname
, &release
);
239 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
241 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
243 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
247 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
248 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
249 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
250 ver
.wProductType
, ver
.wReserved
);
252 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
253 if (pGetProductInfo
&& !running_under_wine())
257 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
258 xprintf(" dwProductInfo=%u\n", prodtype
);
262 static inline int is_dot_dir(const char* x
)
264 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
267 static void remove_dir (const char *dir
)
272 size_t dirlen
= strlen (dir
);
274 /* Make sure the directory exists before going further */
275 memcpy (path
, dir
, dirlen
);
276 strcpy (path
+ dirlen
++, "\\*");
277 hFind
= FindFirstFile (path
, &wfd
);
278 if (hFind
== INVALID_HANDLE_VALUE
) return;
281 char *lp
= wfd
.cFileName
;
283 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
284 if (is_dot_dir (lp
)) continue;
285 strcpy (path
+ dirlen
, lp
);
286 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
288 else if (!DeleteFile (path
))
289 report (R_WARNING
, "Can't delete file %s: error %d",
290 path
, GetLastError ());
291 } while (FindNextFile (hFind
, &wfd
));
293 if (!RemoveDirectory (dir
))
294 report (R_WARNING
, "Can't remove directory %s: error %d",
295 dir
, GetLastError ());
298 static const char* get_test_source_file(const char* test
, const char* subtest
)
300 static const char* special_dirs
[][2] = {
303 static char buffer
[MAX_PATH
];
306 for (i
= 0; special_dirs
[i
][0]; i
++) {
307 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
308 test
= special_dirs
[i
][1];
313 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
317 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
323 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
324 !(*size
= SizeofResource (0, rsrc
)) ||
325 !(hdl
= LoadResource (0, rsrc
)) ||
326 !(addr
= LockResource (hdl
)))
331 /* Fills in the name and exename fields */
333 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
341 code
= extract_rcdata (res_name
, "TESTRES", &size
);
342 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
343 res_name
, GetLastError ());
344 test
->name
= heap_strdup( res_name
);
345 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
346 exepos
= strstr (test
->name
, testexe
);
347 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
349 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
350 report (R_STEP
, "Extracting: %s", test
->name
);
352 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
353 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
354 if (hfile
== INVALID_HANDLE_VALUE
)
355 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
357 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
358 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
363 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
365 DWORD wait
, diff
= 0, start
= GetTickCount();
368 while (diff
< timeout
)
370 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
371 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
372 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
373 diff
= GetTickCount() - start
;
378 static void append_path( const char *path
)
382 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
383 strcpy(newpath
, curpath
);
384 strcat(newpath
, ";");
385 strcat(newpath
, path
);
386 SetEnvironmentVariableA("PATH", newpath
);
391 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
394 Return the exit status, -2 if can't create process or the return
395 value of WaitForSingleObject.
398 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
401 PROCESS_INFORMATION pi
;
404 GetStartupInfo (&si
);
405 si
.dwFlags
= STARTF_USESTDHANDLES
;
406 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
407 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
408 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
410 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
411 NULL
, tempdir
, &si
, &pi
))
414 CloseHandle (pi
.hThread
);
415 status
= wait_process( pi
.hProcess
, ms
);
419 GetExitCodeProcess (pi
.hProcess
, &status
);
420 CloseHandle (pi
.hProcess
);
423 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
428 report (R_ERROR
, "Wait returned %d", status
);
431 if (!TerminateProcess (pi
.hProcess
, 257))
432 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
433 wait
= wait_process( pi
.hProcess
, 5000 );
439 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
442 report (R_ERROR
, "Can't kill process '%s'", cmd
);
445 report (R_ERROR
, "Waiting for termination: %d", wait
);
448 CloseHandle (pi
.hProcess
);
453 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
458 char buffer
[8192], *index
;
459 static const char header
[] = "Valid test names:";
460 int status
, allocated
;
461 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
462 SECURITY_ATTRIBUTES sa
;
464 test
->subtest_count
= 0;
466 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
467 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
468 report (R_FATAL
, "Can't name subtests file.");
470 /* make handle inheritable */
471 sa
.nLength
= sizeof(sa
);
472 sa
.lpSecurityDescriptor
= NULL
;
473 sa
.bInheritHandle
= TRUE
;
475 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
476 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
477 &sa
, CREATE_ALWAYS
, 0, NULL
);
479 if ((subfile
== INVALID_HANDLE_VALUE
) &&
480 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
481 /* FILE_SHARE_DELETE not supported on win9x */
482 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
483 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
484 &sa
, CREATE_ALWAYS
, 0, NULL
);
486 if (subfile
== INVALID_HANDLE_VALUE
) {
487 err
= GetLastError();
488 report (R_ERROR
, "Can't open subtests output of %s: %u",
489 test
->name
, GetLastError());
493 extract_test (test
, tempdir
, res_name
);
494 cmd
= strmake (NULL
, "%s --list", test
->exename
);
495 if (test
->maindllpath
) {
496 /* We need to add the path (to the main dll) to PATH */
497 append_path(test
->maindllpath
);
499 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
500 err
= GetLastError();
501 if (test
->maindllpath
) {
502 /* Restore PATH again */
503 SetEnvironmentVariableA("PATH", curpath
);
509 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
513 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
514 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
515 CloseHandle( subfile
);
516 if (sizeof buffer
== total
) {
517 report (R_ERROR
, "Subtest list of %s too big.",
518 test
->name
, sizeof buffer
);
519 err
= ERROR_OUTOFMEMORY
;
524 index
= strstr (buffer
, header
);
526 report (R_ERROR
, "Can't parse subtests output of %s",
528 err
= ERROR_INTERNAL_ERROR
;
531 index
+= sizeof header
;
534 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
535 index
= strtok (index
, whitespace
);
537 if (test
->subtest_count
== allocated
) {
539 test
->subtests
= heap_realloc (test
->subtests
,
540 allocated
* sizeof(char*));
542 if (!test_filtered_out( test
->name
, index
))
543 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
544 index
= strtok (NULL
, whitespace
);
546 test
->subtests
= heap_realloc (test
->subtests
,
547 test
->subtest_count
* sizeof(char*));
551 if (!DeleteFileA (subname
))
552 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
557 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
560 const char* file
= get_test_source_file(test
->name
, subtest
);
561 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
563 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
564 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
566 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
570 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
571 LPTSTR lpszName
, LONG_PTR lParam
)
573 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
577 static const struct clsid_mapping
583 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
584 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
588 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
590 const struct clsid_mapping
*mapping
;
592 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
594 if(!strcasecmp(name
, mapping
->name
))
596 *clsid
= mapping
->clsid
;
603 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
608 char dllname
[MAX_PATH
];
612 if(!get_main_clsid(name
, &clsid
)) return NULL
;
614 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
615 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
616 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
617 clsid
.Data4
[6], clsid
.Data4
[7]);
619 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
621 LONG size
= sizeof(dllname
);
622 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
624 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
626 strcpy( filename
, dllname
);
627 p
= strrchr(dllname
, '\\');
629 *path
= heap_strdup( dllname
);
638 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
640 char dllpath
[MAX_PATH
];
642 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
643 strcpy(filename
, dllpath
);
644 *strrchr(dllpath
, '\\') = '\0';
645 *path
= heap_strdup( dllpath
);
649 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
650 LPTSTR lpszName
, LONG_PTR lParam
)
652 const char *tempdir
= (const char *)lParam
;
653 char dllname
[MAX_PATH
];
654 char filename
[MAX_PATH
];
655 WCHAR dllnameW
[MAX_PATH
];
659 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
661 /* Check if the main dll is present on this system */
662 CharLowerA(lpszName
);
663 strcpy(dllname
, lpszName
);
664 *strstr(dllname
, testexe
) = 0;
666 wine_tests
[nr_of_files
].maindllpath
= NULL
;
667 strcpy(filename
, dllname
);
668 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
670 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
672 if (!dll
&& pLoadLibraryShim
)
674 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
675 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
677 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
679 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
686 xprintf (" %s=dll is missing\n", dllname
);
689 if (is_native_dll(dll
))
692 xprintf (" %s=load error Configured as native\n", dllname
);
696 if (!strcmp( dllname
, "mshtml" ) && running_under_wine() && !gecko_check())
699 xprintf (" %s=load error Gecko is not installed\n", dllname
);
704 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
706 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
707 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
712 xprintf (" %s=load error %u\n", dllname
, err
);
718 run_tests (char *logname
, char *outdir
)
721 char *strres
, *eol
, *nextline
;
723 SECURITY_ATTRIBUTES sa
;
724 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
727 /* Get the current PATH only once */
728 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
729 curpath
= heap_alloc(needed
);
730 GetEnvironmentVariableA("PATH", curpath
, needed
);
732 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
734 if (!GetTempPathA( MAX_PATH
, tmppath
))
735 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
738 static char tmpname
[MAX_PATH
];
739 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
740 report (R_FATAL
, "Can't name logfile.");
743 report (R_OUT
, logname
);
745 /* make handle inheritable */
746 sa
.nLength
= sizeof(sa
);
747 sa
.lpSecurityDescriptor
= NULL
;
748 sa
.bInheritHandle
= TRUE
;
750 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
751 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
752 &sa
, CREATE_ALWAYS
, 0, NULL
);
754 if ((logfile
== INVALID_HANDLE_VALUE
) &&
755 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
756 /* FILE_SHARE_DELETE not supported on win9x */
757 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
758 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
759 &sa
, CREATE_ALWAYS
, 0, NULL
);
761 if (logfile
== INVALID_HANDLE_VALUE
)
762 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
764 /* try stable path for ZoneAlarm */
766 strcpy( tempdir
, tmppath
);
767 strcat( tempdir
, "wct" );
769 if (!CreateDirectoryA( tempdir
, NULL
))
771 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
772 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
773 DeleteFileA( tempdir
);
774 if (!CreateDirectoryA( tempdir
, NULL
))
775 report (R_FATAL
, "Could not create directory: %s", tempdir
);
779 strcpy( tempdir
, outdir
);
781 report (R_DIR
, tempdir
);
783 xprintf ("Version 4\n");
784 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
785 xprintf ("Archive: -\n"); /* no longer used */
786 xprintf ("Tag: %s\n", tag
);
787 xprintf ("Build info:\n");
788 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
790 eol
= memchr (strres
, '\n', strsize
);
793 eol
= strres
+ strsize
;
795 strsize
-= eol
- strres
+ 1;
796 nextline
= strsize
?eol
+1:NULL
;
797 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
799 xprintf (" %.*s\n", eol
-strres
, strres
);
802 xprintf ("Operating system version:\n");
804 xprintf ("Dll info:\n" );
806 report (R_STATUS
, "Counting tests");
807 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
808 report (R_FATAL
, "Can't enumerate test files: %d",
810 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
812 /* Do this only once during extraction (and version checking) */
813 hmscoree
= LoadLibraryA("mscoree.dll");
814 pLoadLibraryShim
= NULL
;
816 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
818 report (R_STATUS
, "Extracting tests");
819 report (R_PROGRESS
, 0, nr_of_files
);
822 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
823 report (R_FATAL
, "Can't enumerate test files: %d",
826 FreeLibrary(hmscoree
);
828 xprintf ("Test output:\n" );
830 report (R_DELTA
, 0, "Extracting: Done");
833 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
835 report (R_STATUS
, "Running tests");
836 report (R_PROGRESS
, 1, nr_of_tests
);
837 for (i
= 0; i
< nr_of_files
; i
++) {
838 struct wine_test
*test
= wine_tests
+ i
;
841 if (test
->maindllpath
) {
842 /* We need to add the path (to the main dll) to PATH */
843 append_path(test
->maindllpath
);
846 for (j
= 0; j
< test
->subtest_count
; j
++) {
847 report (R_STEP
, "Running: %s:%s", test
->name
,
849 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
852 if (test
->maindllpath
) {
853 /* Restore PATH again */
854 SetEnvironmentVariableA("PATH", curpath
);
857 report (R_DELTA
, 0, "Running: Done");
859 report (R_STATUS
, "Cleaning up");
860 CloseHandle( logfile
);
863 remove_dir (tempdir
);
864 heap_free(wine_tests
);
870 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
872 if (ctrl_type
== CTRL_C_EVENT
) {
873 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
882 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
884 const char *target_dir
= (const char *)lParam
;
885 char filename
[MAX_PATH
];
887 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
889 strcpy(filename
, lpszName
);
890 CharLowerA(filename
);
892 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
897 static void extract_only (const char *target_dir
)
901 report (R_DIR
, target_dir
);
902 res
= CreateDirectoryA( target_dir
, NULL
);
903 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
904 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
907 report (R_STATUS
, "Counting tests");
908 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
909 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
911 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
913 report (R_STATUS
, "Extracting tests");
914 report (R_PROGRESS
, 0, nr_of_files
);
916 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
917 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
919 report (R_DELTA
, 0, "Extracting: Done");
926 "Usage: winetest [OPTION]... [TESTS]\n\n"
927 " --help print this message and exit\n"
928 " --version print the build version and exit\n"
929 " -c console mode, no GUI\n"
930 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
931 " -e preserve the environment\n"
932 " -h print this message and exit\n"
933 " -p shutdown when the tests are done\n"
934 " -q quiet mode, no output at all\n"
935 " -o FILE put report into FILE, do not submit\n"
936 " -s FILE submit FILE, do not run tests\n"
937 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
938 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
941 int main( int argc
, char *argv
[] )
943 char *logname
= NULL
, *outdir
= NULL
;
944 const char *extract
= NULL
;
945 const char *cp
, *submit
= NULL
;
951 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
953 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
955 if (!strcmp(argv
[i
], "--help")) {
959 else if (!strcmp(argv
[i
], "--version")) {
960 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
963 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
964 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
966 report (R_ERROR
, "Too many test filters specified");
969 filters
[nb_filters
++] = argv
[i
];
971 else switch (argv
[i
][1]) {
991 if (!(submit
= argv
[++i
]))
997 report (R_WARNING
, "ignoring tag for submission");
1001 if (!(logname
= argv
[++i
]))
1008 if (!(tag
= argv
[++i
]))
1013 if (strlen (tag
) > MAXTAGLEN
)
1014 report (R_FATAL
, "tag is too long (maximum %d characters)",
1016 cp
= findbadtagchar (tag
);
1018 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1024 report (R_TEXTMODE
);
1025 if (!(extract
= argv
[++i
]))
1028 extract_only (extract
);
1034 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1039 if (!submit
&& !extract
) {
1040 report (R_STATUS
, "Starting up");
1042 if (!running_on_visible_desktop ())
1043 report (R_FATAL
, "Tests must be run on a visible desktop");
1045 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1049 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1050 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1051 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1052 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1055 if (!nb_filters
) /* don't submit results when filtering */
1059 report (R_FATAL
, "Please specify a tag (-t option) if "
1060 "running noninteractive!");
1061 if (guiAskTag () == IDABORT
) exit (1);
1066 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1067 "To submit results, winetest needs to be built from a git checkout." );
1071 logname
= run_tests (NULL
, outdir
);
1072 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1073 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1074 if (!send_file (logname
) && !DeleteFileA(logname
))
1075 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1076 } else run_tests (logname
, outdir
);
1077 report (R_STATUS
, "Finished");
1082 TOKEN_PRIVILEGES npr
;
1084 /* enable the shutdown privilege for the current process */
1085 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1087 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1088 npr
.PrivilegeCount
= 1;
1089 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1090 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1091 CloseHandle(hToken
);
1093 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);