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"
40 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
43 /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
44 #define FAILURES_LIMIT 50
56 char *description
= NULL
;
59 BOOL aborting
= FALSE
;
60 static struct wine_test
*wine_tests
;
61 static int nr_of_files
, nr_of_tests
, nr_of_skips
;
62 static int nr_native_dlls
;
63 static const char whitespace
[] = " \t\r\n";
64 static const char testexe
[] = "_test.exe";
65 static char build_id
[64];
69 /* filters for running only specific tests */
70 static char *filters
[64];
71 static unsigned int nb_filters
= 0;
72 static BOOL exclude_tests
= FALSE
;
74 /* Needed to check for .NET dlls */
75 static HMODULE hmscoree
;
76 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
78 /* For SxS DLLs e.g. msvcr90 */
79 static HANDLE (WINAPI
*pCreateActCtxA
)(PACTCTXA
);
80 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
81 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
82 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
84 /* To store the current PATH setting (related to .NET only provided dlls) */
87 /* check if test is being filtered out */
88 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
90 char *p
, dllname
[MAX_PATH
];
93 strcpy( dllname
, module
);
94 CharLowerA( dllname
);
95 p
= strstr( dllname
, testexe
);
97 len
= strlen(dllname
);
99 if (!nb_filters
) return exclude_tests
;
100 for (i
= 0; i
< nb_filters
; i
++)
102 if (!strncmp( dllname
, filters
[i
], len
))
104 if (!filters
[i
][len
]) return exclude_tests
;
105 if (filters
[i
][len
] != ':') continue;
106 if (testname
&& !strcmp( testname
, &filters
[i
][len
+1] )) return exclude_tests
;
107 if (!testname
&& !exclude_tests
) return FALSE
;
110 return !exclude_tests
;
113 static char * get_file_version(char * file_name
)
115 static char version
[32];
119 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
121 char * data
= heap_alloc(size
);
123 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
124 static const char backslash
[] = "\\";
125 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
127 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
128 sprintf(version
, "%d.%d.%d.%d",
129 pFixedVersionInfo
->dwFileVersionMS
>> 16,
130 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
131 pFixedVersionInfo
->dwFileVersionLS
>> 16,
132 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
134 sprintf(version
, "version not available");
136 sprintf(version
, "unknown");
139 sprintf(version
, "failed");
141 sprintf(version
, "version not available");
146 static BOOL
running_under_wine (void)
148 HMODULE module
= GetModuleHandleA("ntdll.dll");
150 if (!module
) return FALSE
;
151 return (GetProcAddress(module
, "wine_server_call") != NULL
);
154 static BOOL
check_mount_mgr(void)
156 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
157 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
158 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
159 CloseHandle( handle
);
163 static BOOL
check_wow64_registry(void)
165 char buffer
[MAX_PATH
];
166 DWORD type
, size
= MAX_PATH
;
170 if (!is_wow64
) return TRUE
;
171 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey
))
173 ret
= !RegQueryValueExA( hkey
, "ProgramFilesDir (x86)", NULL
, &type
, (BYTE
*)buffer
, &size
);
178 static BOOL
check_display_driver(void)
180 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
181 0, 0, GetModuleHandleA(0), 0 );
182 if (!hwnd
) return FALSE
;
183 DestroyWindow( hwnd
);
187 static BOOL
running_on_visible_desktop (void)
190 HMODULE huser32
= GetModuleHandleA("user32.dll");
191 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
192 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
194 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
195 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
197 desktop
= GetDesktopWindow();
198 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
199 return IsWindowVisible(desktop
);
201 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
205 USEROBJECTFLAGS uoflags
;
207 wstation
= (HWINSTA
)pGetProcessWindowStation();
208 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
209 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
211 return IsWindowVisible(desktop
);
214 static int running_as_admin (void)
216 PSID administrators
= NULL
;
217 SID_IDENTIFIER_AUTHORITY nt_authority
= { SECURITY_NT_AUTHORITY
};
220 PTOKEN_GROUPS groups
;
223 /* Create a well-known SID for the Administrators group. */
224 if (! AllocateAndInitializeSid(&nt_authority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
225 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0,
229 /* Get the process token */
230 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
232 FreeSid(administrators
);
236 /* Get the group info from the token */
238 GetTokenInformation(token
, TokenGroups
, NULL
, 0, &groups_size
);
239 groups
= heap_alloc(groups_size
);
243 FreeSid(administrators
);
246 if (! GetTokenInformation(token
, TokenGroups
, groups
, groups_size
, &groups_size
))
250 FreeSid(administrators
);
255 /* Now check if the token groups include the Administrators group */
256 for (group_index
= 0; group_index
< groups
->GroupCount
; group_index
++)
258 if (EqualSid(groups
->Groups
[group_index
].Sid
, administrators
))
261 FreeSid(administrators
);
266 /* If we end up here we didn't find the Administrators group */
268 FreeSid(administrators
);
272 static int running_elevated (void)
275 TOKEN_ELEVATION elevation_info
;
278 /* Get the process token */
279 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
282 /* Get the elevation info from the token */
283 if (! GetTokenInformation(token
, TokenElevation
, &elevation_info
,
284 sizeof(TOKEN_ELEVATION
), &size
))
291 return elevation_info
.TokenIsElevated
;
294 /* check for native dll when running under wine */
295 static BOOL
is_native_dll( HMODULE module
)
297 static const char fakedll_signature
[] = "Wine placeholder DLL";
298 const IMAGE_DOS_HEADER
*dos
;
300 if (!running_under_wine()) return FALSE
;
301 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
302 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
303 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
304 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
305 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
306 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
310 static void print_version (void)
313 static const char platform
[] = "i386";
314 #elif defined(__x86_64__)
315 static const char platform
[] = "x86_64";
316 #elif defined(__powerpc__)
317 static const char platform
[] = "powerpc";
318 #elif defined(__arm__)
319 static const char platform
[] = "arm";
320 #elif defined(__aarch64__)
321 static const char platform
[] = "arm64";
325 OSVERSIONINFOEXA ver
;
327 int is_win2k3_r2
, is_admin
, is_elevated
;
328 const char *(CDECL
*wine_get_build_id
)(void);
329 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
330 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
332 ver
.dwOSVersionInfoSize
= sizeof(ver
);
333 if (!(ext
= GetVersionExA ((OSVERSIONINFOA
*) &ver
)))
335 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
336 if (!GetVersionExA ((OSVERSIONINFOA
*) &ver
))
337 report (R_FATAL
, "Can't get OS version.");
339 xprintf (" Platform=%s%s\n", platform
, is_wow64
? " (WOW64)" : "");
340 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
341 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
342 is_admin
= running_as_admin ();
345 xprintf (" Account=%s", is_admin
? "admin" : "non-admin");
346 is_elevated
= running_elevated ();
347 if (0 <= is_elevated
)
348 xprintf(", %s", is_elevated
? "elevated" : "not elevated");
351 xprintf (" Submitter=%s\n", email
);
353 xprintf (" Description=%s\n", description
);
355 xprintf (" URL=%s\n", url
);
356 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
357 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
358 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
359 ver
.dwPlatformId
, ver
.szCSDVersion
);
361 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
362 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
363 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
364 if (wine_get_host_version
)
366 const char *sysname
, *release
;
367 wine_get_host_version( &sysname
, &release
);
368 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
370 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
372 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
376 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
377 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
378 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
379 ver
.wProductType
, ver
.wReserved
);
381 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
382 if (pGetProductInfo
&& !running_under_wine())
386 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
387 xprintf(" dwProductInfo=%u\n", prodtype
);
391 static void print_language(void)
394 LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void);
395 LANGID (WINAPI
*pGetThreadUILanguage
)(void);
397 xprintf (" SystemDefaultLCID=%x\n", GetSystemDefaultLCID());
398 xprintf (" UserDefaultLCID=%x\n", GetUserDefaultLCID());
399 xprintf (" ThreadLocale=%x\n", GetThreadLocale());
401 hkernel32
= GetModuleHandleA("kernel32.dll");
402 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
403 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
404 if (pGetUserDefaultUILanguage
)
405 xprintf (" UserDefaultUILanguage=%x\n", pGetUserDefaultUILanguage());
406 if (pGetThreadUILanguage
)
407 xprintf (" ThreadUILanguage=%x\n", pGetThreadUILanguage());
410 static inline BOOL
is_dot_dir(const char* x
)
412 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
415 static void remove_dir (const char *dir
)
418 WIN32_FIND_DATAA wfd
;
420 size_t dirlen
= strlen (dir
);
422 /* Make sure the directory exists before going further */
423 memcpy (path
, dir
, dirlen
);
424 strcpy (path
+ dirlen
++, "\\*");
425 hFind
= FindFirstFileA (path
, &wfd
);
426 if (hFind
== INVALID_HANDLE_VALUE
) return;
429 char *lp
= wfd
.cFileName
;
431 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
432 if (is_dot_dir (lp
)) continue;
433 strcpy (path
+ dirlen
, lp
);
434 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
436 else if (!DeleteFileA(path
))
437 report (R_WARNING
, "Can't delete file %s: error %d",
438 path
, GetLastError ());
439 } while (FindNextFileA(hFind
, &wfd
));
441 if (!RemoveDirectoryA(dir
))
442 report (R_WARNING
, "Can't remove directory %s: error %d",
443 dir
, GetLastError ());
446 static const char* get_test_source_file(const char* test
, const char* subtest
)
448 static const char* special_dirs
[][2] = {
451 static char buffer
[MAX_PATH
];
452 int i
, len
= strlen(test
);
454 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
456 len
= sprintf(buffer
, "programs/%s", test
) - 4;
459 else len
= sprintf(buffer
, "dlls/%s", test
);
461 for (i
= 0; special_dirs
[i
][0]; i
++) {
462 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
463 strcpy( buffer
, special_dirs
[i
][1] );
464 len
= strlen(buffer
);
469 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
473 static void* extract_rcdata (LPCSTR name
, LPCSTR type
, DWORD
* size
)
479 if (!(rsrc
= FindResourceA(NULL
, name
, type
)) ||
480 !(*size
= SizeofResource (0, rsrc
)) ||
481 !(hdl
= LoadResource (0, rsrc
)) ||
482 !(addr
= LockResource (hdl
)))
487 /* Fills in the name and exename fields */
489 extract_test (struct wine_test
*test
, const char *dir
, LPSTR res_name
)
497 code
= extract_rcdata (res_name
, "TESTRES", &size
);
498 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
499 res_name
, GetLastError ());
500 test
->name
= heap_strdup( res_name
);
501 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
502 exepos
= strstr (test
->name
, testexe
);
503 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
505 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
506 report (R_STEP
, "Extracting: %s", test
->name
);
508 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
509 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
510 if (hfile
== INVALID_HANDLE_VALUE
)
511 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
513 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
514 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
519 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
521 DWORD wait
, diff
= 0, start
= GetTickCount();
524 while (diff
< timeout
)
526 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
527 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
528 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
529 diff
= GetTickCount() - start
;
534 static void append_path( const char *path
)
538 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
539 strcpy(newpath
, curpath
);
540 strcat(newpath
, ";");
541 strcat(newpath
, path
);
542 SetEnvironmentVariableA("PATH", newpath
);
547 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
550 Return the exit status, -2 if can't create process or the return
551 value of WaitForSingleObject.
554 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
557 PROCESS_INFORMATION pi
;
560 GetStartupInfoA (&si
);
561 si
.dwFlags
= STARTF_USESTDHANDLES
;
562 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
563 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
564 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
566 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
567 NULL
, tempdir
, &si
, &pi
))
570 CloseHandle (pi
.hThread
);
571 status
= wait_process( pi
.hProcess
, ms
);
575 GetExitCodeProcess (pi
.hProcess
, &status
);
576 CloseHandle (pi
.hProcess
);
579 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
584 report (R_ERROR
, "Wait returned %d", status
);
587 if (!TerminateProcess (pi
.hProcess
, 257))
588 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
589 wait
= wait_process( pi
.hProcess
, 5000 );
595 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
598 report (R_ERROR
, "Can't kill process '%s'", cmd
);
601 report (R_ERROR
, "Waiting for termination: %d", wait
);
604 CloseHandle (pi
.hProcess
);
609 get_subtests (const char *tempdir
, struct wine_test
*test
, LPSTR res_name
)
614 char buffer
[8192], *index
;
615 static const char header
[] = "Valid test names:";
616 int status
, allocated
;
617 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
618 SECURITY_ATTRIBUTES sa
;
620 test
->subtest_count
= 0;
622 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
623 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
624 report (R_FATAL
, "Can't name subtests file.");
626 /* make handle inheritable */
627 sa
.nLength
= sizeof(sa
);
628 sa
.lpSecurityDescriptor
= NULL
;
629 sa
.bInheritHandle
= TRUE
;
631 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
632 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
633 &sa
, CREATE_ALWAYS
, 0, NULL
);
635 if ((subfile
== INVALID_HANDLE_VALUE
) &&
636 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
637 /* FILE_SHARE_DELETE not supported on win9x */
638 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
639 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
640 &sa
, CREATE_ALWAYS
, 0, NULL
);
642 if (subfile
== INVALID_HANDLE_VALUE
) {
643 err
= GetLastError();
644 report (R_ERROR
, "Can't open subtests output of %s: %u",
645 test
->name
, GetLastError());
649 cmd
= strmake (NULL
, "%s --list", test
->exename
);
650 if (test
->maindllpath
) {
651 /* We need to add the path (to the main dll) to PATH */
652 append_path(test
->maindllpath
);
654 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
655 err
= GetLastError();
656 if (test
->maindllpath
) {
657 /* Restore PATH again */
658 SetEnvironmentVariableA("PATH", curpath
);
664 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
665 CloseHandle( subfile
);
669 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
670 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
671 CloseHandle( subfile
);
672 if (sizeof buffer
== total
) {
673 report (R_ERROR
, "Subtest list of %s too big.",
674 test
->name
, sizeof buffer
);
675 err
= ERROR_OUTOFMEMORY
;
680 index
= strstr (buffer
, header
);
682 report (R_ERROR
, "Can't parse subtests output of %s",
684 err
= ERROR_INTERNAL_ERROR
;
687 index
+= sizeof header
;
690 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
691 index
= strtok (index
, whitespace
);
693 if (test
->subtest_count
== allocated
) {
695 test
->subtests
= heap_realloc (test
->subtests
,
696 allocated
* sizeof(char*));
698 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
699 index
= strtok (NULL
, whitespace
);
701 test
->subtests
= heap_realloc (test
->subtests
,
702 test
->subtest_count
* sizeof(char*));
706 if (!DeleteFileA (subname
))
707 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
712 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
714 const char* file
= get_test_source_file(test
->name
, subtest
);
716 if (test_filtered_out( test
->name
, subtest
))
718 report (R_STEP
, "Skipping: %s:%s", test
->name
, subtest
);
719 xprintf ("%s:%s skipped %s -\n", test
->name
, subtest
, file
);
725 DWORD start
= GetTickCount();
726 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
727 report (R_STEP
, "Running: %s:%s", test
->name
, subtest
);
728 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
729 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
731 xprintf ("%s:%s done (%d) in %ds\n", test
->name
, subtest
, status
, (GetTickCount()-start
)/1000);
732 if (status
) failures
++;
734 if (failures
) report (R_STATUS
, "Running tests - %u failures", failures
);
738 EnumTestFileProc (HMODULE hModule
, LPCSTR lpszType
,
739 LPSTR lpszName
, LONG_PTR lParam
)
741 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
745 static const struct clsid_mapping
751 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
752 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
756 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
758 const struct clsid_mapping
*mapping
;
760 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
762 if(!strcasecmp(name
, mapping
->name
))
764 *clsid
= mapping
->clsid
;
771 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
776 char dllname
[MAX_PATH
];
780 if(!get_main_clsid(name
, &clsid
)) return NULL
;
782 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
783 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
784 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
785 clsid
.Data4
[6], clsid
.Data4
[7]);
787 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
789 LONG size
= sizeof(dllname
);
790 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
792 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
794 strcpy( filename
, dllname
);
795 p
= strrchr(dllname
, '\\');
797 *path
= heap_strdup( dllname
);
806 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
808 char dllpath
[MAX_PATH
];
810 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
811 strcpy(filename
, dllpath
);
812 *strrchr(dllpath
, '\\') = '\0';
813 *path
= heap_strdup( dllpath
);
817 extract_test_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
819 const char *tempdir
= (const char *)lParam
;
820 char dllname
[MAX_PATH
];
821 char filename
[MAX_PATH
];
822 WCHAR dllnameW
[MAX_PATH
];
828 if (aborting
) return TRUE
;
830 /* Check if the main dll is present on this system */
831 CharLowerA(lpszName
);
832 strcpy(dllname
, lpszName
);
833 *strstr(dllname
, testexe
) = 0;
835 if (test_filtered_out( lpszName
, NULL
))
838 xprintf (" %s=skipped\n", dllname
);
841 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
843 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
844 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
847 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
848 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
849 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
850 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
851 actctxinfo
.lpResourceName
= (LPSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
852 actctx
= pCreateActCtxA(&actctxinfo
);
853 if (actctx
!= INVALID_HANDLE_VALUE
&&
854 ! pActivateActCtx(actctx
, &cookie
))
856 pReleaseActCtx(actctx
);
857 actctx
= INVALID_HANDLE_VALUE
;
859 } else actctx
= INVALID_HANDLE_VALUE
;
861 wine_tests
[nr_of_files
].maindllpath
= NULL
;
862 strcpy(filename
, dllname
);
863 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
865 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
867 if (!dll
&& pLoadLibraryShim
)
869 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
870 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
872 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
874 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
881 xprintf (" %s=dll is missing\n", dllname
);
882 if (actctx
!= INVALID_HANDLE_VALUE
)
884 pDeactivateActCtx(0, cookie
);
885 pReleaseActCtx(actctx
);
889 if (is_native_dll(dll
))
892 xprintf (" %s=load error Configured as native\n", dllname
);
894 if (actctx
!= INVALID_HANDLE_VALUE
)
896 pDeactivateActCtx(0, cookie
);
897 pReleaseActCtx(actctx
);
903 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
905 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
906 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
911 xprintf (" %s=load error %u\n", dllname
, err
);
914 if (actctx
!= INVALID_HANDLE_VALUE
)
916 pDeactivateActCtx(0, cookie
);
917 pReleaseActCtx(actctx
);
923 run_tests (char *logname
, char *outdir
)
926 char *strres
, *eol
, *nextline
;
928 SECURITY_ATTRIBUTES sa
;
929 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
933 /* Get the current PATH only once */
934 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
935 curpath
= heap_alloc(needed
);
936 GetEnvironmentVariableA("PATH", curpath
, needed
);
938 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
940 if (!GetTempPathA( MAX_PATH
, tmppath
))
941 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
944 static char tmpname
[MAX_PATH
];
945 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
946 report (R_FATAL
, "Can't name logfile.");
949 report (R_OUT
, logname
);
951 /* make handle inheritable */
952 sa
.nLength
= sizeof(sa
);
953 sa
.lpSecurityDescriptor
= NULL
;
954 sa
.bInheritHandle
= TRUE
;
956 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
957 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
958 &sa
, CREATE_ALWAYS
, 0, NULL
);
960 if ((logfile
== INVALID_HANDLE_VALUE
) &&
961 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
962 /* FILE_SHARE_DELETE not supported on win9x */
963 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
964 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
965 &sa
, CREATE_ALWAYS
, 0, NULL
);
967 if (logfile
== INVALID_HANDLE_VALUE
)
968 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
970 /* try stable path for ZoneAlarm */
972 strcpy( tempdir
, tmppath
);
973 strcat( tempdir
, "wct" );
975 if (!CreateDirectoryA( tempdir
, NULL
))
977 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
978 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
979 DeleteFileA( tempdir
);
980 if (!CreateDirectoryA( tempdir
, NULL
))
981 report (R_FATAL
, "Could not create directory: %s", tempdir
);
985 strcpy( tempdir
, outdir
);
987 report (R_DIR
, tempdir
);
989 xprintf ("Version 4\n");
990 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
991 xprintf ("Archive: -\n"); /* no longer used */
992 xprintf ("Tag: %s\n", tag
);
993 xprintf ("Build info:\n");
994 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
996 eol
= memchr (strres
, '\n', strsize
);
999 eol
= strres
+ strsize
;
1001 strsize
-= eol
- strres
+ 1;
1002 nextline
= strsize
?eol
+1:NULL
;
1003 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
1005 xprintf (" %.*s\n", eol
-strres
, strres
);
1008 xprintf ("Operating system version:\n");
1011 xprintf ("Dll info:\n" );
1013 report (R_STATUS
, "Counting tests");
1014 if (!EnumResourceNamesA (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1015 report (R_FATAL
, "Can't enumerate test files: %d",
1017 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
1019 /* Do this only once during extraction (and version checking) */
1020 hmscoree
= LoadLibraryA("mscoree.dll");
1021 pLoadLibraryShim
= NULL
;
1023 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
1024 kernel32
= GetModuleHandleA("kernel32.dll");
1025 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
1026 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
1027 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
1028 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
1030 report (R_STATUS
, "Extracting tests");
1031 report (R_PROGRESS
, 0, nr_of_files
);
1035 if (!EnumResourceNamesA (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
1036 report (R_FATAL
, "Can't enumerate test files: %d",
1039 FreeLibrary(hmscoree
);
1041 if (aborting
) return logname
;
1043 xprintf ("Test output:\n" );
1045 report (R_DELTA
, 0, "Extracting: Done");
1048 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
1050 report (R_STATUS
, "Running tests");
1051 report (R_PROGRESS
, 1, nr_of_tests
);
1052 for (i
= 0; i
< nr_of_files
; i
++) {
1053 struct wine_test
*test
= wine_tests
+ i
;
1056 if (aborting
) break;
1058 if (test
->maindllpath
) {
1059 /* We need to add the path (to the main dll) to PATH */
1060 append_path(test
->maindllpath
);
1063 for (j
= 0; j
< test
->subtest_count
; j
++) {
1064 if (aborting
) break;
1065 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
1068 if (test
->maindllpath
) {
1069 /* Restore PATH again */
1070 SetEnvironmentVariableA("PATH", curpath
);
1073 report (R_DELTA
, 0, "Running: Done");
1075 report (R_STATUS
, "Cleaning up - %u failures", failures
);
1076 CloseHandle( logfile
);
1079 remove_dir (tempdir
);
1080 heap_free(wine_tests
);
1086 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
1088 if (ctrl_type
== CTRL_C_EVENT
) {
1089 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1097 static BOOL CALLBACK
1098 extract_only_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
1100 const char *target_dir
= (const char *)lParam
;
1101 char filename
[MAX_PATH
];
1103 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
1105 strcpy(filename
, lpszName
);
1106 CharLowerA(filename
);
1108 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
1113 static void extract_only (const char *target_dir
)
1117 report (R_DIR
, target_dir
);
1118 res
= CreateDirectoryA( target_dir
, NULL
);
1119 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
1120 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
1123 report (R_STATUS
, "Counting tests");
1124 if (!EnumResourceNamesA(NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1125 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1127 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
1129 report (R_STATUS
, "Extracting tests");
1130 report (R_PROGRESS
, 0, nr_of_files
);
1132 if (!EnumResourceNamesA(NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
1133 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1135 report (R_DELTA
, 0, "Extracting: Done");
1142 "Usage: winetest [OPTION]... [TESTS]\n\n"
1143 " --help print this message and exit\n"
1144 " --version print the build version and exit\n"
1145 " -c console mode, no GUI\n"
1146 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1147 " -e preserve the environment\n"
1148 " -h print this message and exit\n"
1149 " -i INFO an optional description of the test platform\n"
1150 " -m MAIL an email address to enable developers to contact you\n"
1151 " -n exclude the specified tests\n"
1152 " -p shutdown when the tests are done\n"
1153 " -q quiet mode, no output at all\n"
1154 " -o FILE put report into FILE, do not submit\n"
1155 " -s FILE submit FILE, do not run tests\n"
1156 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1157 " -u URL include TestBot URL in the report\n"
1158 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1161 int main( int argc
, char *argv
[] )
1163 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
1164 char *logname
= NULL
, *outdir
= NULL
;
1165 const char *extract
= NULL
;
1166 const char *cp
, *submit
= NULL
;
1169 int interactive
= 1;
1172 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1174 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1175 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1177 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1179 if (!strcmp(argv
[i
], "--help")) {
1183 else if (!strcmp(argv
[i
], "--version")) {
1184 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1187 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1188 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1190 report (R_ERROR
, "Too many test filters specified");
1193 filters
[nb_filters
++] = argv
[i
];
1195 else switch (argv
[i
][1]) {
1197 report (R_TEXTMODE
);
1208 if (!(description
= argv
[++i
]))
1215 if (!(email
= argv
[++i
]))
1222 exclude_tests
= TRUE
;
1232 if (!(submit
= argv
[++i
]))
1238 report (R_WARNING
, "ignoring tag for submission");
1242 if (!(logname
= argv
[++i
]))
1249 if (!(tag
= argv
[++i
]))
1254 if (strlen (tag
) > MAXTAGLEN
)
1255 report (R_FATAL
, "tag is too long (maximum %d characters)",
1257 cp
= findbadtagchar (tag
);
1259 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1265 if (!(url
= argv
[++i
]))
1272 report (R_TEXTMODE
);
1273 if (!(extract
= argv
[++i
]))
1276 extract_only (extract
);
1282 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1287 if (!submit
&& !extract
) {
1288 int is_win9x
= (GetVersion() & 0x80000000) != 0;
1290 report (R_STATUS
, "Starting up");
1293 report (R_WARNING
, "Running on win9x is not supported. You won't be able to submit results.");
1295 if (!running_on_visible_desktop ())
1296 report (R_FATAL
, "Tests must be run on a visible desktop");
1298 if (running_under_wine())
1300 if (!check_mount_mgr())
1301 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1303 if (!check_wow64_registry())
1304 report (R_FATAL
, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1306 if (!check_display_driver())
1307 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1310 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1314 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1315 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1316 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1317 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1322 report (R_FATAL
, "Please specify a tag (-t option) if "
1323 "running noninteractive!");
1324 if (guiAskTag () == IDABORT
) exit (1);
1330 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1331 " to contact you about your report if necessary.");
1332 if (guiAskEmail () == IDABORT
) exit (1);
1336 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1337 "To submit results, winetest needs to be built from a git checkout." );
1340 logname
= run_tests (NULL
, outdir
);
1342 DeleteFileA(logname
);
1345 if (failures
> FAILURES_LIMIT
)
1347 "%d tests failed, there's probably something broken with your setup.\n"
1348 "You need to address this before submitting results.", failures
);
1350 if (build_id
[0] && nr_of_skips
<= SKIP_LIMIT
&& failures
<= FAILURES_LIMIT
&&
1351 !nr_native_dlls
&& !is_win9x
&&
1352 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1353 if (!send_file (logname
) && !DeleteFileA(logname
))
1354 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1355 } else run_tests (logname
, outdir
);
1356 report (R_STATUS
, "Finished - %u failures", failures
);
1361 TOKEN_PRIVILEGES npr
;
1363 /* enable the shutdown privilege for the current process */
1364 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1366 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
1367 npr
.PrivilegeCount
= 1;
1368 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1369 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1370 CloseHandle(hToken
);
1372 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);