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 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 int running_under_wine (void)
148 HMODULE module
= GetModuleHandleA("ntdll.dll");
150 if (!module
) return 0;
151 return (GetProcAddress(module
, "wine_server_call") != NULL
);
154 static int 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 int 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 int 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 int 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(__sparc__)
317 static const char platform
[] = "sparc";
318 #elif defined(__powerpc__)
319 static const char platform
[] = "powerpc";
320 #elif defined(__arm__)
321 static const char platform
[] = "arm";
322 #elif defined(__aarch64__)
323 static const char platform
[] = "arm64";
327 OSVERSIONINFOEXA ver
;
329 int is_win2k3_r2
, is_admin
, is_elevated
;
330 const char *(CDECL
*wine_get_build_id
)(void);
331 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
332 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
334 ver
.dwOSVersionInfoSize
= sizeof(ver
);
335 if (!(ext
= GetVersionExA ((OSVERSIONINFOA
*) &ver
)))
337 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
338 if (!GetVersionExA ((OSVERSIONINFOA
*) &ver
))
339 report (R_FATAL
, "Can't get OS version.");
341 xprintf (" Platform=%s%s\n", platform
, is_wow64
? " (WOW64)" : "");
342 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
343 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
344 is_admin
= running_as_admin ();
347 xprintf (" Account=%s", is_admin
? "admin" : "non-admin");
348 is_elevated
= running_elevated ();
349 if (0 <= is_elevated
)
350 xprintf(", %s", is_elevated
? "elevated" : "not elevated");
353 xprintf (" Submitter=%s\n", email
);
355 xprintf (" Description=%s\n", description
);
357 xprintf (" URL=%s\n", url
);
358 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
359 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
360 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
361 ver
.dwPlatformId
, ver
.szCSDVersion
);
363 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
364 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
365 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
366 if (wine_get_host_version
)
368 const char *sysname
, *release
;
369 wine_get_host_version( &sysname
, &release
);
370 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
372 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
374 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
378 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
379 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
380 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
381 ver
.wProductType
, ver
.wReserved
);
383 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
384 if (pGetProductInfo
&& !running_under_wine())
388 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
389 xprintf(" dwProductInfo=%u\n", prodtype
);
393 static void print_language(void)
396 LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void);
397 LANGID (WINAPI
*pGetThreadUILanguage
)(void);
399 xprintf (" SystemDefaultLCID=%x\n", GetSystemDefaultLCID());
400 xprintf (" UserDefaultLCID=%x\n", GetUserDefaultLCID());
401 xprintf (" ThreadLocale=%x\n", GetThreadLocale());
403 hkernel32
= GetModuleHandleA("kernel32.dll");
404 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
405 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
406 if (pGetUserDefaultUILanguage
)
407 xprintf (" UserDefaultUILanguage=%x\n", pGetUserDefaultUILanguage());
408 if (pGetThreadUILanguage
)
409 xprintf (" ThreadUILanguage=%x\n", pGetThreadUILanguage());
412 static inline int is_dot_dir(const char* x
)
414 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
417 static void remove_dir (const char *dir
)
420 WIN32_FIND_DATAA wfd
;
422 size_t dirlen
= strlen (dir
);
424 /* Make sure the directory exists before going further */
425 memcpy (path
, dir
, dirlen
);
426 strcpy (path
+ dirlen
++, "\\*");
427 hFind
= FindFirstFileA (path
, &wfd
);
428 if (hFind
== INVALID_HANDLE_VALUE
) return;
431 char *lp
= wfd
.cFileName
;
433 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
434 if (is_dot_dir (lp
)) continue;
435 strcpy (path
+ dirlen
, lp
);
436 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
438 else if (!DeleteFileA(path
))
439 report (R_WARNING
, "Can't delete file %s: error %d",
440 path
, GetLastError ());
441 } while (FindNextFileA(hFind
, &wfd
));
443 if (!RemoveDirectoryA(dir
))
444 report (R_WARNING
, "Can't remove directory %s: error %d",
445 dir
, GetLastError ());
448 static const char* get_test_source_file(const char* test
, const char* subtest
)
450 static const char* special_dirs
[][2] = {
453 static char buffer
[MAX_PATH
];
454 int i
, len
= strlen(test
);
456 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
458 len
= sprintf(buffer
, "programs/%s", test
) - 4;
461 else len
= sprintf(buffer
, "dlls/%s", test
);
463 for (i
= 0; special_dirs
[i
][0]; i
++) {
464 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
465 strcpy( buffer
, special_dirs
[i
][1] );
466 len
= strlen(buffer
);
471 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
475 static void* extract_rcdata (LPCSTR name
, LPCSTR type
, DWORD
* size
)
481 if (!(rsrc
= FindResourceA(NULL
, name
, type
)) ||
482 !(*size
= SizeofResource (0, rsrc
)) ||
483 !(hdl
= LoadResource (0, rsrc
)) ||
484 !(addr
= LockResource (hdl
)))
489 /* Fills in the name and exename fields */
491 extract_test (struct wine_test
*test
, const char *dir
, LPSTR res_name
)
499 code
= extract_rcdata (res_name
, "TESTRES", &size
);
500 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
501 res_name
, GetLastError ());
502 test
->name
= heap_strdup( res_name
);
503 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
504 exepos
= strstr (test
->name
, testexe
);
505 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
507 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
508 report (R_STEP
, "Extracting: %s", test
->name
);
510 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
511 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
512 if (hfile
== INVALID_HANDLE_VALUE
)
513 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
515 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
516 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
521 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
523 DWORD wait
, diff
= 0, start
= GetTickCount();
526 while (diff
< timeout
)
528 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
529 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
530 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
531 diff
= GetTickCount() - start
;
536 static void append_path( const char *path
)
540 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
541 strcpy(newpath
, curpath
);
542 strcat(newpath
, ";");
543 strcat(newpath
, path
);
544 SetEnvironmentVariableA("PATH", newpath
);
549 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
552 Return the exit status, -2 if can't create process or the return
553 value of WaitForSingleObject.
556 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
559 PROCESS_INFORMATION pi
;
562 GetStartupInfoA (&si
);
563 si
.dwFlags
= STARTF_USESTDHANDLES
;
564 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
565 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
566 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
568 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
569 NULL
, tempdir
, &si
, &pi
))
572 CloseHandle (pi
.hThread
);
573 status
= wait_process( pi
.hProcess
, ms
);
577 GetExitCodeProcess (pi
.hProcess
, &status
);
578 CloseHandle (pi
.hProcess
);
581 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
586 report (R_ERROR
, "Wait returned %d", status
);
589 if (!TerminateProcess (pi
.hProcess
, 257))
590 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
591 wait
= wait_process( pi
.hProcess
, 5000 );
597 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
600 report (R_ERROR
, "Can't kill process '%s'", cmd
);
603 report (R_ERROR
, "Waiting for termination: %d", wait
);
606 CloseHandle (pi
.hProcess
);
611 get_subtests (const char *tempdir
, struct wine_test
*test
, LPSTR res_name
)
616 char buffer
[8192], *index
;
617 static const char header
[] = "Valid test names:";
618 int status
, allocated
;
619 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
620 SECURITY_ATTRIBUTES sa
;
622 test
->subtest_count
= 0;
624 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
625 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
626 report (R_FATAL
, "Can't name subtests file.");
628 /* make handle inheritable */
629 sa
.nLength
= sizeof(sa
);
630 sa
.lpSecurityDescriptor
= NULL
;
631 sa
.bInheritHandle
= TRUE
;
633 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
634 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
635 &sa
, CREATE_ALWAYS
, 0, NULL
);
637 if ((subfile
== INVALID_HANDLE_VALUE
) &&
638 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
639 /* FILE_SHARE_DELETE not supported on win9x */
640 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
641 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
642 &sa
, CREATE_ALWAYS
, 0, NULL
);
644 if (subfile
== INVALID_HANDLE_VALUE
) {
645 err
= GetLastError();
646 report (R_ERROR
, "Can't open subtests output of %s: %u",
647 test
->name
, GetLastError());
651 cmd
= strmake (NULL
, "%s --list", test
->exename
);
652 if (test
->maindllpath
) {
653 /* We need to add the path (to the main dll) to PATH */
654 append_path(test
->maindllpath
);
656 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
657 err
= GetLastError();
658 if (test
->maindllpath
) {
659 /* Restore PATH again */
660 SetEnvironmentVariableA("PATH", curpath
);
666 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
667 CloseHandle( subfile
);
671 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
672 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
673 CloseHandle( subfile
);
674 if (sizeof buffer
== total
) {
675 report (R_ERROR
, "Subtest list of %s too big.",
676 test
->name
, sizeof buffer
);
677 err
= ERROR_OUTOFMEMORY
;
682 index
= strstr (buffer
, header
);
684 report (R_ERROR
, "Can't parse subtests output of %s",
686 err
= ERROR_INTERNAL_ERROR
;
689 index
+= sizeof header
;
692 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
693 index
= strtok (index
, whitespace
);
695 if (test
->subtest_count
== allocated
) {
697 test
->subtests
= heap_realloc (test
->subtests
,
698 allocated
* sizeof(char*));
700 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
701 index
= strtok (NULL
, whitespace
);
703 test
->subtests
= heap_realloc (test
->subtests
,
704 test
->subtest_count
* sizeof(char*));
708 if (!DeleteFileA (subname
))
709 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
714 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
716 const char* file
= get_test_source_file(test
->name
, subtest
);
718 if (test_filtered_out( test
->name
, subtest
))
720 report (R_STEP
, "Skipping: %s:%s", test
->name
, subtest
);
721 xprintf ("%s:%s skipped %s -\n", test
->name
, subtest
, file
);
727 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
728 report (R_STEP
, "Running: %s:%s", test
->name
, subtest
);
729 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
730 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
732 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
733 if (status
) failures
++;
735 if (failures
) report (R_STATUS
, "Running tests - %u failures", failures
);
739 EnumTestFileProc (HMODULE hModule
, LPCSTR lpszType
,
740 LPSTR lpszName
, LONG_PTR lParam
)
742 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
746 static const struct clsid_mapping
752 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
753 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
757 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
759 const struct clsid_mapping
*mapping
;
761 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
763 if(!strcasecmp(name
, mapping
->name
))
765 *clsid
= mapping
->clsid
;
772 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
777 char dllname
[MAX_PATH
];
781 if(!get_main_clsid(name
, &clsid
)) return NULL
;
783 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
784 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
785 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
786 clsid
.Data4
[6], clsid
.Data4
[7]);
788 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
790 LONG size
= sizeof(dllname
);
791 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
793 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
795 strcpy( filename
, dllname
);
796 p
= strrchr(dllname
, '\\');
798 *path
= heap_strdup( dllname
);
807 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
809 char dllpath
[MAX_PATH
];
811 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
812 strcpy(filename
, dllpath
);
813 *strrchr(dllpath
, '\\') = '\0';
814 *path
= heap_strdup( dllpath
);
818 extract_test_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
820 const char *tempdir
= (const char *)lParam
;
821 char dllname
[MAX_PATH
];
822 char filename
[MAX_PATH
];
823 WCHAR dllnameW
[MAX_PATH
];
829 if (aborting
) return TRUE
;
831 /* Check if the main dll is present on this system */
832 CharLowerA(lpszName
);
833 strcpy(dllname
, lpszName
);
834 *strstr(dllname
, testexe
) = 0;
836 if (test_filtered_out( lpszName
, NULL
))
839 xprintf (" %s=skipped\n", dllname
);
842 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
844 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
845 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
848 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
849 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
850 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
851 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
852 actctxinfo
.lpResourceName
= (LPSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
853 actctx
= pCreateActCtxA(&actctxinfo
);
854 if (actctx
!= INVALID_HANDLE_VALUE
&&
855 ! pActivateActCtx(actctx
, &cookie
))
857 pReleaseActCtx(actctx
);
858 actctx
= INVALID_HANDLE_VALUE
;
860 } else actctx
= INVALID_HANDLE_VALUE
;
862 wine_tests
[nr_of_files
].maindllpath
= NULL
;
863 strcpy(filename
, dllname
);
864 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
866 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
868 if (!dll
&& pLoadLibraryShim
)
870 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
871 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
873 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
875 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
882 xprintf (" %s=dll is missing\n", dllname
);
883 if (actctx
!= INVALID_HANDLE_VALUE
)
885 pDeactivateActCtx(0, cookie
);
886 pReleaseActCtx(actctx
);
890 if (is_native_dll(dll
))
893 xprintf (" %s=load error Configured as native\n", dllname
);
895 if (actctx
!= INVALID_HANDLE_VALUE
)
897 pDeactivateActCtx(0, cookie
);
898 pReleaseActCtx(actctx
);
904 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
906 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
907 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
912 xprintf (" %s=load error %u\n", dllname
, err
);
915 if (actctx
!= INVALID_HANDLE_VALUE
)
917 pDeactivateActCtx(0, cookie
);
918 pReleaseActCtx(actctx
);
924 run_tests (char *logname
, char *outdir
)
927 char *strres
, *eol
, *nextline
;
929 SECURITY_ATTRIBUTES sa
;
930 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
934 /* Get the current PATH only once */
935 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
936 curpath
= heap_alloc(needed
);
937 GetEnvironmentVariableA("PATH", curpath
, needed
);
939 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
941 if (!GetTempPathA( MAX_PATH
, tmppath
))
942 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
945 static char tmpname
[MAX_PATH
];
946 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
947 report (R_FATAL
, "Can't name logfile.");
950 report (R_OUT
, logname
);
952 /* make handle inheritable */
953 sa
.nLength
= sizeof(sa
);
954 sa
.lpSecurityDescriptor
= NULL
;
955 sa
.bInheritHandle
= TRUE
;
957 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
958 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
959 &sa
, CREATE_ALWAYS
, 0, NULL
);
961 if ((logfile
== INVALID_HANDLE_VALUE
) &&
962 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
963 /* FILE_SHARE_DELETE not supported on win9x */
964 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
965 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
966 &sa
, CREATE_ALWAYS
, 0, NULL
);
968 if (logfile
== INVALID_HANDLE_VALUE
)
969 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
971 /* try stable path for ZoneAlarm */
973 strcpy( tempdir
, tmppath
);
974 strcat( tempdir
, "wct" );
976 if (!CreateDirectoryA( tempdir
, NULL
))
978 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
979 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
980 DeleteFileA( tempdir
);
981 if (!CreateDirectoryA( tempdir
, NULL
))
982 report (R_FATAL
, "Could not create directory: %s", tempdir
);
986 strcpy( tempdir
, outdir
);
988 report (R_DIR
, tempdir
);
990 xprintf ("Version 4\n");
991 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
992 xprintf ("Archive: -\n"); /* no longer used */
993 xprintf ("Tag: %s\n", tag
);
994 xprintf ("Build info:\n");
995 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
997 eol
= memchr (strres
, '\n', strsize
);
1000 eol
= strres
+ strsize
;
1002 strsize
-= eol
- strres
+ 1;
1003 nextline
= strsize
?eol
+1:NULL
;
1004 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
1006 xprintf (" %.*s\n", eol
-strres
, strres
);
1009 xprintf ("Operating system version:\n");
1012 xprintf ("Dll info:\n" );
1014 report (R_STATUS
, "Counting tests");
1015 if (!EnumResourceNamesA (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1016 report (R_FATAL
, "Can't enumerate test files: %d",
1018 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
1020 /* Do this only once during extraction (and version checking) */
1021 hmscoree
= LoadLibraryA("mscoree.dll");
1022 pLoadLibraryShim
= NULL
;
1024 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
1025 kernel32
= GetModuleHandleA("kernel32.dll");
1026 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
1027 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
1028 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
1029 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
1031 report (R_STATUS
, "Extracting tests");
1032 report (R_PROGRESS
, 0, nr_of_files
);
1036 if (!EnumResourceNamesA (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
1037 report (R_FATAL
, "Can't enumerate test files: %d",
1040 FreeLibrary(hmscoree
);
1042 if (aborting
) return logname
;
1044 xprintf ("Test output:\n" );
1046 report (R_DELTA
, 0, "Extracting: Done");
1049 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
1051 report (R_STATUS
, "Running tests");
1052 report (R_PROGRESS
, 1, nr_of_tests
);
1053 for (i
= 0; i
< nr_of_files
; i
++) {
1054 struct wine_test
*test
= wine_tests
+ i
;
1057 if (aborting
) break;
1059 if (test
->maindllpath
) {
1060 /* We need to add the path (to the main dll) to PATH */
1061 append_path(test
->maindllpath
);
1064 for (j
= 0; j
< test
->subtest_count
; j
++) {
1065 if (aborting
) break;
1066 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
1069 if (test
->maindllpath
) {
1070 /* Restore PATH again */
1071 SetEnvironmentVariableA("PATH", curpath
);
1074 report (R_DELTA
, 0, "Running: Done");
1076 report (R_STATUS
, "Cleaning up");
1077 CloseHandle( logfile
);
1080 remove_dir (tempdir
);
1081 heap_free(wine_tests
);
1087 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
1089 if (ctrl_type
== CTRL_C_EVENT
) {
1090 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1098 static BOOL CALLBACK
1099 extract_only_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
1101 const char *target_dir
= (const char *)lParam
;
1102 char filename
[MAX_PATH
];
1104 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
1106 strcpy(filename
, lpszName
);
1107 CharLowerA(filename
);
1109 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
1114 static void extract_only (const char *target_dir
)
1118 report (R_DIR
, target_dir
);
1119 res
= CreateDirectoryA( target_dir
, NULL
);
1120 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
1121 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
1124 report (R_STATUS
, "Counting tests");
1125 if (!EnumResourceNamesA(NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1126 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1128 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
1130 report (R_STATUS
, "Extracting tests");
1131 report (R_PROGRESS
, 0, nr_of_files
);
1133 if (!EnumResourceNamesA(NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
1134 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1136 report (R_DELTA
, 0, "Extracting: Done");
1143 "Usage: winetest [OPTION]... [TESTS]\n\n"
1144 " --help print this message and exit\n"
1145 " --version print the build version and exit\n"
1146 " -c console mode, no GUI\n"
1147 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1148 " -e preserve the environment\n"
1149 " -h print this message and exit\n"
1150 " -i INFO an optional description of the test platform\n"
1151 " -m MAIL an email address to enable developers to contact you\n"
1152 " -n exclude the specified tests\n"
1153 " -p shutdown when the tests are done\n"
1154 " -q quiet mode, no output at all\n"
1155 " -o FILE put report into FILE, do not submit\n"
1156 " -s FILE submit FILE, do not run tests\n"
1157 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1158 " -u URL include TestBot URL in the report\n"
1159 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1162 int main( int argc
, char *argv
[] )
1164 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
1165 char *logname
= NULL
, *outdir
= NULL
;
1166 const char *extract
= NULL
;
1167 const char *cp
, *submit
= NULL
;
1170 int interactive
= 1;
1173 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1175 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1176 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1178 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1180 if (!strcmp(argv
[i
], "--help")) {
1184 else if (!strcmp(argv
[i
], "--version")) {
1185 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1188 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1189 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1191 report (R_ERROR
, "Too many test filters specified");
1194 filters
[nb_filters
++] = argv
[i
];
1196 else switch (argv
[i
][1]) {
1198 report (R_TEXTMODE
);
1209 if (!(description
= argv
[++i
]))
1216 if (!(email
= argv
[++i
]))
1223 exclude_tests
= TRUE
;
1233 if (!(submit
= argv
[++i
]))
1239 report (R_WARNING
, "ignoring tag for submission");
1243 if (!(logname
= argv
[++i
]))
1250 if (!(tag
= argv
[++i
]))
1255 if (strlen (tag
) > MAXTAGLEN
)
1256 report (R_FATAL
, "tag is too long (maximum %d characters)",
1258 cp
= findbadtagchar (tag
);
1260 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1266 if (!(url
= argv
[++i
]))
1273 report (R_TEXTMODE
);
1274 if (!(extract
= argv
[++i
]))
1277 extract_only (extract
);
1283 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1288 if (!submit
&& !extract
) {
1289 int is_win9x
= (GetVersion() & 0x80000000) != 0;
1291 report (R_STATUS
, "Starting up");
1294 report (R_WARNING
, "Running on win9x is not supported. You won't be able to submit results.");
1296 if (!running_on_visible_desktop ())
1297 report (R_FATAL
, "Tests must be run on a visible desktop");
1299 if (running_under_wine())
1301 if (!check_mount_mgr())
1302 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1304 if (!check_wow64_registry())
1305 report (R_FATAL
, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1307 if (!check_display_driver())
1308 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1311 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1315 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1316 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1317 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1318 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1323 report (R_FATAL
, "Please specify a tag (-t option) if "
1324 "running noninteractive!");
1325 if (guiAskTag () == IDABORT
) exit (1);
1331 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1332 " to contact you about your report if necessary.");
1333 if (guiAskEmail () == IDABORT
) exit (1);
1337 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1338 "To submit results, winetest needs to be built from a git checkout." );
1341 logname
= run_tests (NULL
, outdir
);
1343 DeleteFileA(logname
);
1346 if (failures
> FAILURES_LIMIT
)
1348 "%d tests failed, there's probably something broken with your setup.\n"
1349 "You need to address this before submitting results.", failures
);
1351 if (build_id
[0] && nr_of_skips
<= SKIP_LIMIT
&& failures
<= FAILURES_LIMIT
&&
1352 !nr_native_dlls
&& !is_win9x
&&
1353 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1354 if (!send_file (logname
) && !DeleteFileA(logname
))
1355 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1356 } else run_tests (logname
, outdir
);
1357 report (R_STATUS
, "Finished");
1362 TOKEN_PRIVILEGES npr
;
1364 /* enable the shutdown privilege for the current process */
1365 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1367 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
1368 npr
.PrivilegeCount
= 1;
1369 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1370 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1371 CloseHandle(hToken
);
1373 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);