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 */
54 char *description
= NULL
;
57 BOOL aborting
= FALSE
;
58 static struct wine_test
*wine_tests
;
59 static int nr_of_files
, nr_of_tests
, nr_of_skips
;
60 static int nr_native_dlls
;
61 static const char whitespace
[] = " \t\r\n";
62 static const char testexe
[] = "_test.exe";
63 static char build_id
[64];
65 /* filters for running only specific tests */
66 static char *filters
[64];
67 static unsigned int nb_filters
= 0;
68 static BOOL exclude_tests
= FALSE
;
70 /* Needed to check for .NET dlls */
71 static HMODULE hmscoree
;
72 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
74 /* For SxS DLLs e.g. msvcr90 */
75 static HANDLE (WINAPI
*pCreateActCtxA
)(PACTCTXA
);
76 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
77 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
78 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
80 /* To store the current PATH setting (related to .NET only provided dlls) */
83 /* check if test is being filtered out */
84 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
86 char *p
, dllname
[MAX_PATH
];
89 strcpy( dllname
, module
);
90 CharLowerA( dllname
);
91 p
= strstr( dllname
, testexe
);
93 len
= strlen(dllname
);
95 if (!nb_filters
) return exclude_tests
;
96 for (i
= 0; i
< nb_filters
; i
++)
98 if (!strncmp( dllname
, filters
[i
], len
))
100 if (!filters
[i
][len
]) return exclude_tests
;
101 if (filters
[i
][len
] != ':') continue;
102 if (testname
&& !strcmp( testname
, &filters
[i
][len
+1] )) return exclude_tests
;
103 if (!testname
&& !exclude_tests
) return FALSE
;
106 return !exclude_tests
;
109 static char * get_file_version(char * file_name
)
111 static char version
[32];
115 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
117 char * data
= heap_alloc(size
);
119 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
120 static char backslash
[] = "\\";
121 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
123 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
124 sprintf(version
, "%d.%d.%d.%d",
125 pFixedVersionInfo
->dwFileVersionMS
>> 16,
126 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
127 pFixedVersionInfo
->dwFileVersionLS
>> 16,
128 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
130 sprintf(version
, "version not available");
132 sprintf(version
, "unknown");
135 sprintf(version
, "failed");
137 sprintf(version
, "version not available");
142 static int running_under_wine (void)
144 HMODULE module
= GetModuleHandleA("ntdll.dll");
146 if (!module
) return 0;
147 return (GetProcAddress(module
, "wine_server_call") != NULL
);
150 static int check_mount_mgr(void)
152 if (running_under_wine())
154 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
155 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
156 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
157 CloseHandle( handle
);
162 static int check_display_driver(void)
164 if (running_under_wine())
166 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
167 0, 0, GetModuleHandleA(0), 0 );
168 if (!hwnd
) return FALSE
;
169 DestroyWindow( hwnd
);
174 static int running_on_visible_desktop (void)
177 HMODULE huser32
= GetModuleHandle("user32.dll");
178 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
179 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
181 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
182 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
184 desktop
= GetDesktopWindow();
185 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
186 return IsWindowVisible(desktop
);
188 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
192 USEROBJECTFLAGS uoflags
;
194 wstation
= (HWINSTA
)pGetProcessWindowStation();
195 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
196 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
198 return IsWindowVisible(desktop
);
201 /* check for native dll when running under wine */
202 static BOOL
is_native_dll( HMODULE module
)
204 static const char fakedll_signature
[] = "Wine placeholder DLL";
205 const IMAGE_DOS_HEADER
*dos
;
207 if (!running_under_wine()) return FALSE
;
208 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
209 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
210 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
211 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
212 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
213 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
217 static void print_version (void)
220 static const char platform
[] = "i386";
221 #elif defined(__x86_64__)
222 static const char platform
[] = "x86_64";
223 #elif defined(__sparc__)
224 static const char platform
[] = "sparc";
225 #elif defined(__ALPHA__)
226 static const char platform
[] = "alpha";
227 #elif defined(__powerpc__)
228 static const char platform
[] = "powerpc";
229 #elif defined(__arm__)
230 static const char platform
[] = "arm";
237 const char *(CDECL
*wine_get_build_id
)(void);
238 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
239 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
240 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
242 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
243 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
245 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
246 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
247 report (R_FATAL
, "Can't get OS version.");
249 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
250 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
252 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
253 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
254 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
255 xprintf (" Submitter=%s\n", email
);
257 xprintf (" Description=%s\n", description
);
259 xprintf (" URL=%s\n", url
);
260 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
261 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
262 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
263 ver
.dwPlatformId
, ver
.szCSDVersion
);
265 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
266 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
267 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
268 if (wine_get_host_version
)
270 const char *sysname
, *release
;
271 wine_get_host_version( &sysname
, &release
);
272 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
274 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
276 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
280 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
281 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
282 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
283 ver
.wProductType
, ver
.wReserved
);
285 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
286 if (pGetProductInfo
&& !running_under_wine())
290 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
291 xprintf(" dwProductInfo=%u\n", prodtype
);
295 static inline int is_dot_dir(const char* x
)
297 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
300 static void remove_dir (const char *dir
)
305 size_t dirlen
= strlen (dir
);
307 /* Make sure the directory exists before going further */
308 memcpy (path
, dir
, dirlen
);
309 strcpy (path
+ dirlen
++, "\\*");
310 hFind
= FindFirstFile (path
, &wfd
);
311 if (hFind
== INVALID_HANDLE_VALUE
) return;
314 char *lp
= wfd
.cFileName
;
316 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
317 if (is_dot_dir (lp
)) continue;
318 strcpy (path
+ dirlen
, lp
);
319 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
321 else if (!DeleteFile (path
))
322 report (R_WARNING
, "Can't delete file %s: error %d",
323 path
, GetLastError ());
324 } while (FindNextFile (hFind
, &wfd
));
326 if (!RemoveDirectory (dir
))
327 report (R_WARNING
, "Can't remove directory %s: error %d",
328 dir
, GetLastError ());
331 static const char* get_test_source_file(const char* test
, const char* subtest
)
333 static const char* special_dirs
[][2] = {
336 static char buffer
[MAX_PATH
];
337 int i
, len
= strlen(test
);
339 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
341 len
= sprintf(buffer
, "programs/%s", test
) - 4;
344 else len
= sprintf(buffer
, "dlls/%s", test
);
346 for (i
= 0; special_dirs
[i
][0]; i
++) {
347 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
348 strcpy( buffer
, special_dirs
[i
][1] );
349 len
= strlen(buffer
);
354 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
358 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
364 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
365 !(*size
= SizeofResource (0, rsrc
)) ||
366 !(hdl
= LoadResource (0, rsrc
)) ||
367 !(addr
= LockResource (hdl
)))
372 /* Fills in the name and exename fields */
374 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
382 code
= extract_rcdata (res_name
, "TESTRES", &size
);
383 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
384 res_name
, GetLastError ());
385 test
->name
= heap_strdup( res_name
);
386 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
387 exepos
= strstr (test
->name
, testexe
);
388 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
390 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
391 report (R_STEP
, "Extracting: %s", test
->name
);
393 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
394 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
395 if (hfile
== INVALID_HANDLE_VALUE
)
396 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
398 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
399 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
404 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
406 DWORD wait
, diff
= 0, start
= GetTickCount();
409 while (diff
< timeout
)
411 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
412 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
413 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
414 diff
= GetTickCount() - start
;
419 static void append_path( const char *path
)
423 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
424 strcpy(newpath
, curpath
);
425 strcat(newpath
, ";");
426 strcat(newpath
, path
);
427 SetEnvironmentVariableA("PATH", newpath
);
432 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
435 Return the exit status, -2 if can't create process or the return
436 value of WaitForSingleObject.
439 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
442 PROCESS_INFORMATION pi
;
445 GetStartupInfo (&si
);
446 si
.dwFlags
= STARTF_USESTDHANDLES
;
447 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
448 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
449 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
451 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
452 NULL
, tempdir
, &si
, &pi
))
455 CloseHandle (pi
.hThread
);
456 status
= wait_process( pi
.hProcess
, ms
);
460 GetExitCodeProcess (pi
.hProcess
, &status
);
461 CloseHandle (pi
.hProcess
);
464 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
469 report (R_ERROR
, "Wait returned %d", status
);
472 if (!TerminateProcess (pi
.hProcess
, 257))
473 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
474 wait
= wait_process( pi
.hProcess
, 5000 );
480 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
483 report (R_ERROR
, "Can't kill process '%s'", cmd
);
486 report (R_ERROR
, "Waiting for termination: %d", wait
);
489 CloseHandle (pi
.hProcess
);
494 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
499 char buffer
[8192], *index
;
500 static const char header
[] = "Valid test names:";
501 int status
, allocated
;
502 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
503 SECURITY_ATTRIBUTES sa
;
505 test
->subtest_count
= 0;
507 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
508 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
509 report (R_FATAL
, "Can't name subtests file.");
511 /* make handle inheritable */
512 sa
.nLength
= sizeof(sa
);
513 sa
.lpSecurityDescriptor
= NULL
;
514 sa
.bInheritHandle
= TRUE
;
516 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
517 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
518 &sa
, CREATE_ALWAYS
, 0, NULL
);
520 if ((subfile
== INVALID_HANDLE_VALUE
) &&
521 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
522 /* FILE_SHARE_DELETE not supported on win9x */
523 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
524 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
525 &sa
, CREATE_ALWAYS
, 0, NULL
);
527 if (subfile
== INVALID_HANDLE_VALUE
) {
528 err
= GetLastError();
529 report (R_ERROR
, "Can't open subtests output of %s: %u",
530 test
->name
, GetLastError());
534 cmd
= strmake (NULL
, "%s --list", test
->exename
);
535 if (test
->maindllpath
) {
536 /* We need to add the path (to the main dll) to PATH */
537 append_path(test
->maindllpath
);
539 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
540 err
= GetLastError();
541 if (test
->maindllpath
) {
542 /* Restore PATH again */
543 SetEnvironmentVariableA("PATH", curpath
);
549 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
553 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
554 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
555 CloseHandle( subfile
);
556 if (sizeof buffer
== total
) {
557 report (R_ERROR
, "Subtest list of %s too big.",
558 test
->name
, sizeof buffer
);
559 err
= ERROR_OUTOFMEMORY
;
564 index
= strstr (buffer
, header
);
566 report (R_ERROR
, "Can't parse subtests output of %s",
568 err
= ERROR_INTERNAL_ERROR
;
571 index
+= sizeof header
;
574 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
575 index
= strtok (index
, whitespace
);
577 if (test
->subtest_count
== allocated
) {
579 test
->subtests
= heap_realloc (test
->subtests
,
580 allocated
* sizeof(char*));
582 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
583 index
= strtok (NULL
, whitespace
);
585 test
->subtests
= heap_realloc (test
->subtests
,
586 test
->subtest_count
* sizeof(char*));
590 if (!DeleteFileA (subname
))
591 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
596 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
598 const char* file
= get_test_source_file(test
->name
, subtest
);
600 if (test_filtered_out( test
->name
, subtest
))
602 report (R_STEP
, "Skipping: %s:%s", test
->name
, subtest
);
603 xprintf ("%s:%s skipped %s -\n", test
->name
, subtest
, file
);
609 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
610 report (R_STEP
, "Running: %s:%s", test
->name
, subtest
);
611 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
612 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
614 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
619 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
620 LPTSTR lpszName
, LONG_PTR lParam
)
622 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
626 static const struct clsid_mapping
632 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
633 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
637 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
639 const struct clsid_mapping
*mapping
;
641 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
643 if(!strcasecmp(name
, mapping
->name
))
645 *clsid
= mapping
->clsid
;
652 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
657 char dllname
[MAX_PATH
];
661 if(!get_main_clsid(name
, &clsid
)) return NULL
;
663 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
664 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
665 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
666 clsid
.Data4
[6], clsid
.Data4
[7]);
668 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
670 LONG size
= sizeof(dllname
);
671 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
673 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
675 strcpy( filename
, dllname
);
676 p
= strrchr(dllname
, '\\');
678 *path
= heap_strdup( dllname
);
687 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
689 char dllpath
[MAX_PATH
];
691 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
692 strcpy(filename
, dllpath
);
693 *strrchr(dllpath
, '\\') = '\0';
694 *path
= heap_strdup( dllpath
);
698 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
699 LPTSTR lpszName
, LONG_PTR lParam
)
701 const char *tempdir
= (const char *)lParam
;
702 char dllname
[MAX_PATH
];
703 char filename
[MAX_PATH
];
704 WCHAR dllnameW
[MAX_PATH
];
710 if (aborting
) return TRUE
;
712 /* Check if the main dll is present on this system */
713 CharLowerA(lpszName
);
714 strcpy(dllname
, lpszName
);
715 *strstr(dllname
, testexe
) = 0;
717 if (test_filtered_out( lpszName
, NULL
))
720 xprintf (" %s=skipped\n", dllname
);
723 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
725 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
726 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
729 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
730 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
731 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
732 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
733 actctxinfo
.lpResourceName
= CREATEPROCESS_MANIFEST_RESOURCE_ID
;
734 actctx
= pCreateActCtxA(&actctxinfo
);
735 if (actctx
!= INVALID_HANDLE_VALUE
&&
736 ! pActivateActCtx(actctx
, &cookie
))
738 pReleaseActCtx(actctx
);
739 actctx
= INVALID_HANDLE_VALUE
;
741 } else actctx
= INVALID_HANDLE_VALUE
;
743 wine_tests
[nr_of_files
].maindllpath
= NULL
;
744 strcpy(filename
, dllname
);
745 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
747 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
749 if (!dll
&& pLoadLibraryShim
)
751 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
752 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
754 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
756 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
763 xprintf (" %s=dll is missing\n", dllname
);
764 if (actctx
!= INVALID_HANDLE_VALUE
)
766 pDeactivateActCtx(0, cookie
);
767 pReleaseActCtx(actctx
);
771 if (is_native_dll(dll
))
774 xprintf (" %s=load error Configured as native\n", dllname
);
776 if (actctx
!= INVALID_HANDLE_VALUE
)
778 pDeactivateActCtx(0, cookie
);
779 pReleaseActCtx(actctx
);
785 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
787 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
788 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
793 xprintf (" %s=load error %u\n", dllname
, err
);
796 if (actctx
!= INVALID_HANDLE_VALUE
)
798 pDeactivateActCtx(0, cookie
);
799 pReleaseActCtx(actctx
);
805 run_tests (char *logname
, char *outdir
)
808 char *strres
, *eol
, *nextline
;
810 SECURITY_ATTRIBUTES sa
;
811 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
815 /* Get the current PATH only once */
816 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
817 curpath
= heap_alloc(needed
);
818 GetEnvironmentVariableA("PATH", curpath
, needed
);
820 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
822 if (!GetTempPathA( MAX_PATH
, tmppath
))
823 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
826 static char tmpname
[MAX_PATH
];
827 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
828 report (R_FATAL
, "Can't name logfile.");
831 report (R_OUT
, logname
);
833 /* make handle inheritable */
834 sa
.nLength
= sizeof(sa
);
835 sa
.lpSecurityDescriptor
= NULL
;
836 sa
.bInheritHandle
= TRUE
;
838 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
839 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
840 &sa
, CREATE_ALWAYS
, 0, NULL
);
842 if ((logfile
== INVALID_HANDLE_VALUE
) &&
843 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
844 /* FILE_SHARE_DELETE not supported on win9x */
845 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
846 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
847 &sa
, CREATE_ALWAYS
, 0, NULL
);
849 if (logfile
== INVALID_HANDLE_VALUE
)
850 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
852 /* try stable path for ZoneAlarm */
854 strcpy( tempdir
, tmppath
);
855 strcat( tempdir
, "wct" );
857 if (!CreateDirectoryA( tempdir
, NULL
))
859 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
860 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
861 DeleteFileA( tempdir
);
862 if (!CreateDirectoryA( tempdir
, NULL
))
863 report (R_FATAL
, "Could not create directory: %s", tempdir
);
867 strcpy( tempdir
, outdir
);
869 report (R_DIR
, tempdir
);
871 xprintf ("Version 4\n");
872 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
873 xprintf ("Archive: -\n"); /* no longer used */
874 xprintf ("Tag: %s\n", tag
);
875 xprintf ("Build info:\n");
876 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
878 eol
= memchr (strres
, '\n', strsize
);
881 eol
= strres
+ strsize
;
883 strsize
-= eol
- strres
+ 1;
884 nextline
= strsize
?eol
+1:NULL
;
885 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
887 xprintf (" %.*s\n", eol
-strres
, strres
);
890 xprintf ("Operating system version:\n");
892 xprintf ("Dll info:\n" );
894 report (R_STATUS
, "Counting tests");
895 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
896 report (R_FATAL
, "Can't enumerate test files: %d",
898 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
900 /* Do this only once during extraction (and version checking) */
901 hmscoree
= LoadLibraryA("mscoree.dll");
902 pLoadLibraryShim
= NULL
;
904 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
905 kernel32
= GetModuleHandleA("kernel32.dll");
906 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
907 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
908 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
909 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
911 report (R_STATUS
, "Extracting tests");
912 report (R_PROGRESS
, 0, nr_of_files
);
916 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
917 report (R_FATAL
, "Can't enumerate test files: %d",
920 FreeLibrary(hmscoree
);
922 if (aborting
) return logname
;
924 xprintf ("Test output:\n" );
926 report (R_DELTA
, 0, "Extracting: Done");
929 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
931 report (R_STATUS
, "Running tests");
932 report (R_PROGRESS
, 1, nr_of_tests
);
933 for (i
= 0; i
< nr_of_files
; i
++) {
934 struct wine_test
*test
= wine_tests
+ i
;
939 if (test
->maindllpath
) {
940 /* We need to add the path (to the main dll) to PATH */
941 append_path(test
->maindllpath
);
944 for (j
= 0; j
< test
->subtest_count
; j
++) {
946 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
949 if (test
->maindllpath
) {
950 /* Restore PATH again */
951 SetEnvironmentVariableA("PATH", curpath
);
954 report (R_DELTA
, 0, "Running: Done");
956 report (R_STATUS
, "Cleaning up");
957 CloseHandle( logfile
);
960 remove_dir (tempdir
);
961 heap_free(wine_tests
);
967 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
969 if (ctrl_type
== CTRL_C_EVENT
) {
970 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
979 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
981 const char *target_dir
= (const char *)lParam
;
982 char filename
[MAX_PATH
];
984 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
986 strcpy(filename
, lpszName
);
987 CharLowerA(filename
);
989 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
994 static void extract_only (const char *target_dir
)
998 report (R_DIR
, target_dir
);
999 res
= CreateDirectoryA( target_dir
, NULL
);
1000 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
1001 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
1004 report (R_STATUS
, "Counting tests");
1005 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1006 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1008 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
1010 report (R_STATUS
, "Extracting tests");
1011 report (R_PROGRESS
, 0, nr_of_files
);
1013 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
1014 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1016 report (R_DELTA
, 0, "Extracting: Done");
1023 "Usage: winetest [OPTION]... [TESTS]\n\n"
1024 " --help print this message and exit\n"
1025 " --version print the build version and exit\n"
1026 " -c console mode, no GUI\n"
1027 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1028 " -e preserve the environment\n"
1029 " -h print this message and exit\n"
1030 " -i INFO an optional description of the test platform\n"
1031 " -m MAIL an email address to enable developers to contact you\n"
1032 " -n exclude the specified tests\n"
1033 " -p shutdown when the tests are done\n"
1034 " -q quiet mode, no output at all\n"
1035 " -o FILE put report into FILE, do not submit\n"
1036 " -s FILE submit FILE, do not run tests\n"
1037 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1038 " -u URL include TestBot URL in the report\n"
1039 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1042 int main( int argc
, char *argv
[] )
1044 char *logname
= NULL
, *outdir
= NULL
;
1045 const char *extract
= NULL
;
1046 const char *cp
, *submit
= NULL
;
1049 int interactive
= 1;
1052 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1054 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1056 if (!strcmp(argv
[i
], "--help")) {
1060 else if (!strcmp(argv
[i
], "--version")) {
1061 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1064 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1065 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1067 report (R_ERROR
, "Too many test filters specified");
1070 filters
[nb_filters
++] = argv
[i
];
1072 else switch (argv
[i
][1]) {
1074 report (R_TEXTMODE
);
1085 if (!(description
= argv
[++i
]))
1092 if (!(email
= argv
[++i
]))
1099 exclude_tests
= TRUE
;
1109 if (!(submit
= argv
[++i
]))
1115 report (R_WARNING
, "ignoring tag for submission");
1119 if (!(logname
= argv
[++i
]))
1126 if (!(tag
= argv
[++i
]))
1131 if (strlen (tag
) > MAXTAGLEN
)
1132 report (R_FATAL
, "tag is too long (maximum %d characters)",
1134 cp
= findbadtagchar (tag
);
1136 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1142 if (!(url
= argv
[++i
]))
1149 report (R_TEXTMODE
);
1150 if (!(extract
= argv
[++i
]))
1153 extract_only (extract
);
1159 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1164 if (!submit
&& !extract
) {
1165 int is_win9x
= (GetVersion() & 0x80000000) != 0;
1167 report (R_STATUS
, "Starting up");
1170 report (R_WARNING
, "Running on win9x is not supported. You won't be able to submit results.");
1172 if (!running_on_visible_desktop ())
1173 report (R_FATAL
, "Tests must be run on a visible desktop");
1175 if (!check_mount_mgr())
1176 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1178 if (!check_display_driver())
1179 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1181 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1185 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1186 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1187 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1188 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1193 report (R_FATAL
, "Please specify a tag (-t option) if "
1194 "running noninteractive!");
1195 if (guiAskTag () == IDABORT
) exit (1);
1201 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1202 " to contact you about your report if necessary.");
1203 if (guiAskEmail () == IDABORT
) exit (1);
1207 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1208 "To submit results, winetest needs to be built from a git checkout." );
1211 logname
= run_tests (NULL
, outdir
);
1213 DeleteFileA(logname
);
1216 if (build_id
[0] && nr_of_skips
<= SKIP_LIMIT
&& !nr_native_dlls
&& !is_win9x
&&
1217 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1218 if (!send_file (logname
) && !DeleteFileA(logname
))
1219 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1220 } else run_tests (logname
, outdir
);
1221 report (R_STATUS
, "Finished");
1226 TOKEN_PRIVILEGES npr
;
1228 /* enable the shutdown privilege for the current process */
1229 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1231 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1232 npr
.PrivilegeCount
= 1;
1233 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1234 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1235 CloseHandle(hToken
);
1237 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);