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
57 char *description
= NULL
;
60 BOOL aborting
= FALSE
;
61 static struct wine_test
*wine_tests
;
62 static int nr_of_files
, nr_of_tests
, nr_of_skips
;
63 static int nr_native_dlls
;
64 static const char whitespace
[] = " \t\r\n";
65 static const char testexe
[] = "_test.exe";
66 static char build_id
[64];
70 /* filters for running only specific tests */
71 static char *filters
[64];
72 static unsigned int nb_filters
= 0;
73 static BOOL exclude_tests
= FALSE
;
75 /* Needed to check for .NET dlls */
76 static HMODULE hmscoree
;
77 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
79 /* For SxS DLLs e.g. msvcr90 */
80 static HANDLE (WINAPI
*pCreateActCtxA
)(PACTCTXA
);
81 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
82 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
83 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
85 /* To store the current PATH setting (related to .NET only provided dlls) */
88 /* check if test is being filtered out */
89 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
91 char *p
, dllname
[MAX_PATH
];
94 strcpy( dllname
, module
);
95 CharLowerA( dllname
);
96 p
= strstr( dllname
, testexe
);
98 len
= strlen(dllname
);
100 if (!nb_filters
) return exclude_tests
;
101 for (i
= 0; i
< nb_filters
; i
++)
103 if (!strncmp( dllname
, filters
[i
], len
))
105 if (!filters
[i
][len
]) return exclude_tests
;
106 if (filters
[i
][len
] != ':') continue;
107 if (testname
&& !strcmp( testname
, &filters
[i
][len
+1] )) return exclude_tests
;
108 if (!testname
&& !exclude_tests
) return FALSE
;
111 return !exclude_tests
;
114 static char * get_file_version(char * file_name
)
116 static char version
[32];
120 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
122 char * data
= heap_alloc(size
);
124 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
125 static char backslash
[] = "\\";
126 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
128 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
129 sprintf(version
, "%d.%d.%d.%d",
130 pFixedVersionInfo
->dwFileVersionMS
>> 16,
131 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
132 pFixedVersionInfo
->dwFileVersionLS
>> 16,
133 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
135 sprintf(version
, "version not available");
137 sprintf(version
, "unknown");
140 sprintf(version
, "failed");
142 sprintf(version
, "version not available");
147 static int running_under_wine (void)
149 HMODULE module
= GetModuleHandleA("ntdll.dll");
151 if (!module
) return 0;
152 return (GetProcAddress(module
, "wine_server_call") != NULL
);
155 static int check_mount_mgr(void)
157 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
158 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
159 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
160 CloseHandle( handle
);
164 static int check_wow64_registry(void)
166 char buffer
[MAX_PATH
];
167 DWORD type
, size
= MAX_PATH
;
171 if (!is_wow64
) return TRUE
;
172 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey
))
174 ret
= !RegQueryValueExA( hkey
, "ProgramFilesDir (x86)", NULL
, &type
, (BYTE
*)buffer
, &size
);
179 static int check_display_driver(void)
181 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
182 0, 0, GetModuleHandleA(0), 0 );
183 if (!hwnd
) return FALSE
;
184 DestroyWindow( hwnd
);
188 static int running_on_visible_desktop (void)
191 HMODULE huser32
= GetModuleHandle("user32.dll");
192 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
193 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
195 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
196 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
198 desktop
= GetDesktopWindow();
199 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
200 return IsWindowVisible(desktop
);
202 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
206 USEROBJECTFLAGS uoflags
;
208 wstation
= (HWINSTA
)pGetProcessWindowStation();
209 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
210 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
212 return IsWindowVisible(desktop
);
215 static int running_as_admin (void)
217 PSID administrators
= NULL
;
218 SID_IDENTIFIER_AUTHORITY nt_authority
= { SECURITY_NT_AUTHORITY
};
221 PTOKEN_GROUPS groups
;
224 /* Create a well-known SID for the Administrators group. */
225 if (! AllocateAndInitializeSid(&nt_authority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
226 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0,
230 /* Get the process token */
231 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
233 FreeSid(administrators
);
237 /* Get the group info from the token */
239 GetTokenInformation(token
, TokenGroups
, NULL
, 0, &groups_size
);
240 groups
= heap_alloc(groups_size
);
244 FreeSid(administrators
);
247 if (! GetTokenInformation(token
, TokenGroups
, groups
, groups_size
, &groups_size
))
251 FreeSid(administrators
);
256 /* Now check if the token groups include the Administrators group */
257 for (group_index
= 0; group_index
< groups
->GroupCount
; group_index
++)
259 if (EqualSid(groups
->Groups
[group_index
].Sid
, administrators
))
262 FreeSid(administrators
);
267 /* If we end up here we didn't find the Administrators group */
269 FreeSid(administrators
);
273 static int running_elevated (void)
276 TOKEN_ELEVATION elevation_info
;
279 /* Get the process token */
280 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
283 /* Get the elevation info from the token */
284 if (! GetTokenInformation(token
, TokenElevation
, &elevation_info
,
285 sizeof(TOKEN_ELEVATION
), &size
))
292 return elevation_info
.TokenIsElevated
;
295 /* check for native dll when running under wine */
296 static BOOL
is_native_dll( HMODULE module
)
298 static const char fakedll_signature
[] = "Wine placeholder DLL";
299 const IMAGE_DOS_HEADER
*dos
;
301 if (!running_under_wine()) return FALSE
;
302 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
303 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
304 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
305 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
306 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
307 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
311 static void print_version (void)
314 static const char platform
[] = "i386";
315 #elif defined(__x86_64__)
316 static const char platform
[] = "x86_64";
317 #elif defined(__sparc__)
318 static const char platform
[] = "sparc";
319 #elif defined(__powerpc__)
320 static const char platform
[] = "powerpc";
321 #elif defined(__arm__)
322 static const char platform
[] = "arm";
328 int is_win2k3_r2
, is_admin
, is_elevated
;
329 const char *(CDECL
*wine_get_build_id
)(void);
330 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
331 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
333 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
334 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
336 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
337 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
338 report (R_FATAL
, "Can't get OS version.");
340 xprintf (" Platform=%s%s\n", platform
, is_wow64
? " (WOW64)" : "");
341 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
342 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
343 is_admin
= running_as_admin ();
346 xprintf (" Account=%s", is_admin
? "admin" : "non-admin");
347 is_elevated
= running_elevated ();
348 if (0 <= is_elevated
)
349 xprintf(", %s", is_elevated
? "elevated" : "not elevated");
352 xprintf (" Submitter=%s\n", email
);
354 xprintf (" Description=%s\n", description
);
356 xprintf (" URL=%s\n", url
);
357 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
358 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
359 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
360 ver
.dwPlatformId
, ver
.szCSDVersion
);
362 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
363 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
364 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
365 if (wine_get_host_version
)
367 const char *sysname
, *release
;
368 wine_get_host_version( &sysname
, &release
);
369 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
371 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
373 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
377 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
378 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
379 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
380 ver
.wProductType
, ver
.wReserved
);
382 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
383 if (pGetProductInfo
&& !running_under_wine())
387 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
388 xprintf(" dwProductInfo=%u\n", prodtype
);
392 static void print_language(void)
395 LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void);
396 LANGID (WINAPI
*pGetThreadUILanguage
)(void);
398 xprintf (" SystemDefaultLCID=%x\n", GetSystemDefaultLCID());
399 xprintf (" UserDefaultLCID=%x\n", GetUserDefaultLCID());
400 xprintf (" ThreadLocale=%x\n", GetThreadLocale());
402 hkernel32
= GetModuleHandleA("kernel32.dll");
403 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
404 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
405 if (pGetUserDefaultUILanguage
)
406 xprintf (" UserDefaultUILanguage=%x\n", pGetUserDefaultUILanguage());
407 if (pGetThreadUILanguage
)
408 xprintf (" ThreadUILanguage=%x\n", pGetThreadUILanguage());
411 static inline int is_dot_dir(const char* x
)
413 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
416 static void remove_dir (const char *dir
)
421 size_t dirlen
= strlen (dir
);
423 /* Make sure the directory exists before going further */
424 memcpy (path
, dir
, dirlen
);
425 strcpy (path
+ dirlen
++, "\\*");
426 hFind
= FindFirstFile (path
, &wfd
);
427 if (hFind
== INVALID_HANDLE_VALUE
) return;
430 char *lp
= wfd
.cFileName
;
432 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
433 if (is_dot_dir (lp
)) continue;
434 strcpy (path
+ dirlen
, lp
);
435 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
437 else if (!DeleteFile (path
))
438 report (R_WARNING
, "Can't delete file %s: error %d",
439 path
, GetLastError ());
440 } while (FindNextFile (hFind
, &wfd
));
442 if (!RemoveDirectory (dir
))
443 report (R_WARNING
, "Can't remove directory %s: error %d",
444 dir
, GetLastError ());
447 static const char* get_test_source_file(const char* test
, const char* subtest
)
449 static const char* special_dirs
[][2] = {
452 static char buffer
[MAX_PATH
];
453 int i
, len
= strlen(test
);
455 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
457 len
= sprintf(buffer
, "programs/%s", test
) - 4;
460 else len
= sprintf(buffer
, "dlls/%s", test
);
462 for (i
= 0; special_dirs
[i
][0]; i
++) {
463 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
464 strcpy( buffer
, special_dirs
[i
][1] );
465 len
= strlen(buffer
);
470 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
474 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
480 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
481 !(*size
= SizeofResource (0, rsrc
)) ||
482 !(hdl
= LoadResource (0, rsrc
)) ||
483 !(addr
= LockResource (hdl
)))
488 /* Fills in the name and exename fields */
490 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
498 code
= extract_rcdata (res_name
, "TESTRES", &size
);
499 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
500 res_name
, GetLastError ());
501 test
->name
= heap_strdup( res_name
);
502 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
503 exepos
= strstr (test
->name
, testexe
);
504 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
506 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
507 report (R_STEP
, "Extracting: %s", test
->name
);
509 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
510 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
511 if (hfile
== INVALID_HANDLE_VALUE
)
512 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
514 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
515 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
520 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
522 DWORD wait
, diff
= 0, start
= GetTickCount();
525 while (diff
< timeout
)
527 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
528 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
529 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
530 diff
= GetTickCount() - start
;
535 static void append_path( const char *path
)
539 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
540 strcpy(newpath
, curpath
);
541 strcat(newpath
, ";");
542 strcat(newpath
, path
);
543 SetEnvironmentVariableA("PATH", newpath
);
548 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
551 Return the exit status, -2 if can't create process or the return
552 value of WaitForSingleObject.
555 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
558 PROCESS_INFORMATION pi
;
561 GetStartupInfo (&si
);
562 si
.dwFlags
= STARTF_USESTDHANDLES
;
563 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
564 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
565 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
567 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
568 NULL
, tempdir
, &si
, &pi
))
571 CloseHandle (pi
.hThread
);
572 status
= wait_process( pi
.hProcess
, ms
);
576 GetExitCodeProcess (pi
.hProcess
, &status
);
577 CloseHandle (pi
.hProcess
);
580 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
585 report (R_ERROR
, "Wait returned %d", status
);
588 if (!TerminateProcess (pi
.hProcess
, 257))
589 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
590 wait
= wait_process( pi
.hProcess
, 5000 );
596 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
599 report (R_ERROR
, "Can't kill process '%s'", cmd
);
602 report (R_ERROR
, "Waiting for termination: %d", wait
);
605 CloseHandle (pi
.hProcess
);
610 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
615 char buffer
[8192], *index
;
616 static const char header
[] = "Valid test names:";
617 int status
, allocated
;
618 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
619 SECURITY_ATTRIBUTES sa
;
621 test
->subtest_count
= 0;
623 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
624 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
625 report (R_FATAL
, "Can't name subtests file.");
627 /* make handle inheritable */
628 sa
.nLength
= sizeof(sa
);
629 sa
.lpSecurityDescriptor
= NULL
;
630 sa
.bInheritHandle
= TRUE
;
632 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
633 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
634 &sa
, CREATE_ALWAYS
, 0, NULL
);
636 if ((subfile
== INVALID_HANDLE_VALUE
) &&
637 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
638 /* FILE_SHARE_DELETE not supported on win9x */
639 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
640 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
641 &sa
, CREATE_ALWAYS
, 0, NULL
);
643 if (subfile
== INVALID_HANDLE_VALUE
) {
644 err
= GetLastError();
645 report (R_ERROR
, "Can't open subtests output of %s: %u",
646 test
->name
, GetLastError());
650 cmd
= strmake (NULL
, "%s --list", test
->exename
);
651 if (test
->maindllpath
) {
652 /* We need to add the path (to the main dll) to PATH */
653 append_path(test
->maindllpath
);
655 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
656 err
= GetLastError();
657 if (test
->maindllpath
) {
658 /* Restore PATH again */
659 SetEnvironmentVariableA("PATH", curpath
);
665 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
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 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
726 report (R_STEP
, "Running: %s:%s", test
->name
, subtest
);
727 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
728 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
730 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
731 if (status
) failures
++;
736 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
737 LPTSTR lpszName
, LONG_PTR lParam
)
739 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
743 static const struct clsid_mapping
749 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
750 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
754 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
756 const struct clsid_mapping
*mapping
;
758 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
760 if(!strcasecmp(name
, mapping
->name
))
762 *clsid
= mapping
->clsid
;
769 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
774 char dllname
[MAX_PATH
];
778 if(!get_main_clsid(name
, &clsid
)) return NULL
;
780 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
781 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
782 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
783 clsid
.Data4
[6], clsid
.Data4
[7]);
785 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
787 LONG size
= sizeof(dllname
);
788 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
790 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
792 strcpy( filename
, dllname
);
793 p
= strrchr(dllname
, '\\');
795 *path
= heap_strdup( dllname
);
804 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
806 char dllpath
[MAX_PATH
];
808 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
809 strcpy(filename
, dllpath
);
810 *strrchr(dllpath
, '\\') = '\0';
811 *path
= heap_strdup( dllpath
);
815 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
816 LPTSTR lpszName
, LONG_PTR lParam
)
818 const char *tempdir
= (const char *)lParam
;
819 char dllname
[MAX_PATH
];
820 char filename
[MAX_PATH
];
821 WCHAR dllnameW
[MAX_PATH
];
827 if (aborting
) return TRUE
;
829 /* Check if the main dll is present on this system */
830 CharLowerA(lpszName
);
831 strcpy(dllname
, lpszName
);
832 *strstr(dllname
, testexe
) = 0;
834 if (test_filtered_out( lpszName
, NULL
))
837 xprintf (" %s=skipped\n", dllname
);
840 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
842 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
843 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
846 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
847 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
848 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
849 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
850 actctxinfo
.lpResourceName
= CREATEPROCESS_MANIFEST_RESOURCE_ID
;
851 actctx
= pCreateActCtxA(&actctxinfo
);
852 if (actctx
!= INVALID_HANDLE_VALUE
&&
853 ! pActivateActCtx(actctx
, &cookie
))
855 pReleaseActCtx(actctx
);
856 actctx
= INVALID_HANDLE_VALUE
;
858 } else actctx
= INVALID_HANDLE_VALUE
;
860 wine_tests
[nr_of_files
].maindllpath
= NULL
;
861 strcpy(filename
, dllname
);
862 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
864 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
866 if (!dll
&& pLoadLibraryShim
)
868 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
869 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
871 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
873 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
880 xprintf (" %s=dll is missing\n", dllname
);
881 if (actctx
!= INVALID_HANDLE_VALUE
)
883 pDeactivateActCtx(0, cookie
);
884 pReleaseActCtx(actctx
);
888 if (is_native_dll(dll
))
891 xprintf (" %s=load error Configured as native\n", dllname
);
893 if (actctx
!= INVALID_HANDLE_VALUE
)
895 pDeactivateActCtx(0, cookie
);
896 pReleaseActCtx(actctx
);
902 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
904 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
905 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
910 xprintf (" %s=load error %u\n", dllname
, err
);
913 if (actctx
!= INVALID_HANDLE_VALUE
)
915 pDeactivateActCtx(0, cookie
);
916 pReleaseActCtx(actctx
);
922 run_tests (char *logname
, char *outdir
)
925 char *strres
, *eol
, *nextline
;
927 SECURITY_ATTRIBUTES sa
;
928 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
932 /* Get the current PATH only once */
933 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
934 curpath
= heap_alloc(needed
);
935 GetEnvironmentVariableA("PATH", curpath
, needed
);
937 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
939 if (!GetTempPathA( MAX_PATH
, tmppath
))
940 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
943 static char tmpname
[MAX_PATH
];
944 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
945 report (R_FATAL
, "Can't name logfile.");
948 report (R_OUT
, logname
);
950 /* make handle inheritable */
951 sa
.nLength
= sizeof(sa
);
952 sa
.lpSecurityDescriptor
= NULL
;
953 sa
.bInheritHandle
= TRUE
;
955 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
956 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
957 &sa
, CREATE_ALWAYS
, 0, NULL
);
959 if ((logfile
== INVALID_HANDLE_VALUE
) &&
960 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
961 /* FILE_SHARE_DELETE not supported on win9x */
962 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
963 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
964 &sa
, CREATE_ALWAYS
, 0, NULL
);
966 if (logfile
== INVALID_HANDLE_VALUE
)
967 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
969 /* try stable path for ZoneAlarm */
971 strcpy( tempdir
, tmppath
);
972 strcat( tempdir
, "wct" );
974 if (!CreateDirectoryA( tempdir
, NULL
))
976 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
977 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
978 DeleteFileA( tempdir
);
979 if (!CreateDirectoryA( tempdir
, NULL
))
980 report (R_FATAL
, "Could not create directory: %s", tempdir
);
984 strcpy( tempdir
, outdir
);
986 report (R_DIR
, tempdir
);
988 xprintf ("Version 4\n");
989 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
990 xprintf ("Archive: -\n"); /* no longer used */
991 xprintf ("Tag: %s\n", tag
);
992 xprintf ("Build info:\n");
993 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
995 eol
= memchr (strres
, '\n', strsize
);
998 eol
= strres
+ strsize
;
1000 strsize
-= eol
- strres
+ 1;
1001 nextline
= strsize
?eol
+1:NULL
;
1002 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
1004 xprintf (" %.*s\n", eol
-strres
, strres
);
1007 xprintf ("Operating system version:\n");
1010 xprintf ("Dll info:\n" );
1012 report (R_STATUS
, "Counting tests");
1013 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1014 report (R_FATAL
, "Can't enumerate test files: %d",
1016 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
1018 /* Do this only once during extraction (and version checking) */
1019 hmscoree
= LoadLibraryA("mscoree.dll");
1020 pLoadLibraryShim
= NULL
;
1022 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
1023 kernel32
= GetModuleHandleA("kernel32.dll");
1024 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
1025 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
1026 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
1027 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
1029 report (R_STATUS
, "Extracting tests");
1030 report (R_PROGRESS
, 0, nr_of_files
);
1034 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
1035 report (R_FATAL
, "Can't enumerate test files: %d",
1038 FreeLibrary(hmscoree
);
1040 if (aborting
) return logname
;
1042 xprintf ("Test output:\n" );
1044 report (R_DELTA
, 0, "Extracting: Done");
1047 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
1049 report (R_STATUS
, "Running tests");
1050 report (R_PROGRESS
, 1, nr_of_tests
);
1051 for (i
= 0; i
< nr_of_files
; i
++) {
1052 struct wine_test
*test
= wine_tests
+ i
;
1055 if (aborting
) break;
1057 if (test
->maindllpath
) {
1058 /* We need to add the path (to the main dll) to PATH */
1059 append_path(test
->maindllpath
);
1062 for (j
= 0; j
< test
->subtest_count
; j
++) {
1063 if (aborting
) break;
1064 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
1067 if (test
->maindllpath
) {
1068 /* Restore PATH again */
1069 SetEnvironmentVariableA("PATH", curpath
);
1072 report (R_DELTA
, 0, "Running: Done");
1074 report (R_STATUS
, "Cleaning up");
1075 CloseHandle( logfile
);
1078 remove_dir (tempdir
);
1079 heap_free(wine_tests
);
1085 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
1087 if (ctrl_type
== CTRL_C_EVENT
) {
1088 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1096 static BOOL CALLBACK
1097 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
1099 const char *target_dir
= (const char *)lParam
;
1100 char filename
[MAX_PATH
];
1102 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
1104 strcpy(filename
, lpszName
);
1105 CharLowerA(filename
);
1107 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
1112 static void extract_only (const char *target_dir
)
1116 report (R_DIR
, target_dir
);
1117 res
= CreateDirectoryA( target_dir
, NULL
);
1118 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
1119 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
1122 report (R_STATUS
, "Counting tests");
1123 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1124 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1126 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
1128 report (R_STATUS
, "Extracting tests");
1129 report (R_PROGRESS
, 0, nr_of_files
);
1131 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
1132 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1134 report (R_DELTA
, 0, "Extracting: Done");
1141 "Usage: winetest [OPTION]... [TESTS]\n\n"
1142 " --help print this message and exit\n"
1143 " --version print the build version and exit\n"
1144 " -c console mode, no GUI\n"
1145 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1146 " -e preserve the environment\n"
1147 " -h print this message and exit\n"
1148 " -i INFO an optional description of the test platform\n"
1149 " -m MAIL an email address to enable developers to contact you\n"
1150 " -n exclude the specified tests\n"
1151 " -p shutdown when the tests are done\n"
1152 " -q quiet mode, no output at all\n"
1153 " -o FILE put report into FILE, do not submit\n"
1154 " -s FILE submit FILE, do not run tests\n"
1155 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1156 " -u URL include TestBot URL in the report\n"
1157 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1160 int main( int argc
, char *argv
[] )
1162 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
1163 char *logname
= NULL
, *outdir
= NULL
;
1164 const char *extract
= NULL
;
1165 const char *cp
, *submit
= NULL
;
1168 int interactive
= 1;
1171 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1173 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1174 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1176 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1178 if (!strcmp(argv
[i
], "--help")) {
1182 else if (!strcmp(argv
[i
], "--version")) {
1183 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1186 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1187 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1189 report (R_ERROR
, "Too many test filters specified");
1192 filters
[nb_filters
++] = argv
[i
];
1194 else switch (argv
[i
][1]) {
1196 report (R_TEXTMODE
);
1207 if (!(description
= argv
[++i
]))
1214 if (!(email
= argv
[++i
]))
1221 exclude_tests
= TRUE
;
1231 if (!(submit
= argv
[++i
]))
1237 report (R_WARNING
, "ignoring tag for submission");
1241 if (!(logname
= argv
[++i
]))
1248 if (!(tag
= argv
[++i
]))
1253 if (strlen (tag
) > MAXTAGLEN
)
1254 report (R_FATAL
, "tag is too long (maximum %d characters)",
1256 cp
= findbadtagchar (tag
);
1258 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1264 if (!(url
= argv
[++i
]))
1271 report (R_TEXTMODE
);
1272 if (!(extract
= argv
[++i
]))
1275 extract_only (extract
);
1281 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1286 if (!submit
&& !extract
) {
1287 int is_win9x
= (GetVersion() & 0x80000000) != 0;
1289 report (R_STATUS
, "Starting up");
1292 report (R_WARNING
, "Running on win9x is not supported. You won't be able to submit results.");
1294 if (!running_on_visible_desktop ())
1295 report (R_FATAL
, "Tests must be run on a visible desktop");
1297 if (running_under_wine())
1299 if (!check_mount_mgr())
1300 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1302 if (!check_wow64_registry())
1303 report (R_FATAL
, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1305 if (!check_display_driver())
1306 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1309 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1313 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1314 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1315 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1316 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1321 report (R_FATAL
, "Please specify a tag (-t option) if "
1322 "running noninteractive!");
1323 if (guiAskTag () == IDABORT
) exit (1);
1329 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1330 " to contact you about your report if necessary.");
1331 if (guiAskEmail () == IDABORT
) exit (1);
1335 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1336 "To submit results, winetest needs to be built from a git checkout." );
1339 logname
= run_tests (NULL
, outdir
);
1341 DeleteFileA(logname
);
1344 if (failures
> FAILURES_LIMIT
)
1346 "%d tests failed, there's probably something broken with your setup.\n"
1347 "You need to address this before submitting results.", failures
);
1349 if (build_id
[0] && nr_of_skips
<= SKIP_LIMIT
&& failures
<= FAILURES_LIMIT
&&
1350 !nr_native_dlls
&& !is_win9x
&&
1351 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1352 if (!send_file (logname
) && !DeleteFileA(logname
))
1353 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1354 } else run_tests (logname
, outdir
);
1355 report (R_STATUS
, "Finished");
1360 TOKEN_PRIVILEGES npr
;
1362 /* enable the shutdown privilege for the current process */
1363 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1365 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1366 npr
.PrivilegeCount
= 1;
1367 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1368 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1369 CloseHandle(hToken
);
1371 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);