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"
52 BOOL aborting
= FALSE
;
53 static struct wine_test
*wine_tests
;
54 static int nr_of_files
, nr_of_tests
;
55 static int nr_native_dlls
;
56 static const char whitespace
[] = " \t\r\n";
57 static const char testexe
[] = "_test.exe";
58 static char build_id
[64];
60 /* filters for running only specific tests */
61 static char *filters
[64];
62 static unsigned int nb_filters
= 0;
64 /* Needed to check for .NET dlls */
65 static HMODULE hmscoree
;
66 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
68 /* For SxS DLLs e.g. msvcr90 */
69 static HANDLE (WINAPI
*pCreateActCtxA
)(PACTCTXA
);
70 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
71 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
72 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
74 /* To store the current PATH setting (related to .NET only provided dlls) */
77 /* check if test is being filtered out */
78 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
80 char *p
, dllname
[MAX_PATH
];
83 strcpy( dllname
, module
);
84 CharLowerA( dllname
);
85 p
= strstr( dllname
, testexe
);
87 len
= strlen(dllname
);
89 if (!nb_filters
) return FALSE
;
90 for (i
= 0; i
< nb_filters
; i
++)
92 if (!strncmp( dllname
, filters
[i
], len
))
94 if (!filters
[i
][len
]) return FALSE
;
95 if (filters
[i
][len
] != ':') continue;
96 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
102 static char * get_file_version(char * file_name
)
104 static char version
[32];
108 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
110 char * data
= heap_alloc(size
);
112 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
113 static char backslash
[] = "\\";
114 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
116 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
117 sprintf(version
, "%d.%d.%d.%d",
118 pFixedVersionInfo
->dwFileVersionMS
>> 16,
119 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
120 pFixedVersionInfo
->dwFileVersionLS
>> 16,
121 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
123 sprintf(version
, "version not available");
125 sprintf(version
, "unknown");
128 sprintf(version
, "failed");
130 sprintf(version
, "version not available");
135 static int running_under_wine (void)
137 HMODULE module
= GetModuleHandleA("ntdll.dll");
139 if (!module
) return 0;
140 return (GetProcAddress(module
, "wine_server_call") != NULL
);
143 static int check_mount_mgr(void)
145 if (running_under_wine())
147 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
148 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
149 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
150 CloseHandle( handle
);
155 static int check_display_driver(void)
157 if (running_under_wine())
159 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
160 0, 0, GetModuleHandleA(0), 0 );
161 if (!hwnd
) return FALSE
;
162 DestroyWindow( hwnd
);
167 static int running_on_visible_desktop (void)
170 HMODULE huser32
= GetModuleHandle("user32.dll");
171 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
172 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
174 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
175 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
177 desktop
= GetDesktopWindow();
178 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
179 return IsWindowVisible(desktop
);
181 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
185 USEROBJECTFLAGS uoflags
;
187 wstation
= (HWINSTA
)pGetProcessWindowStation();
188 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
189 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
191 return IsWindowVisible(desktop
);
194 /* check for native dll when running under wine */
195 static BOOL
is_native_dll( HMODULE module
)
197 static const char fakedll_signature
[] = "Wine placeholder DLL";
198 const IMAGE_DOS_HEADER
*dos
;
200 if (!running_under_wine()) return FALSE
;
201 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
202 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
203 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
204 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
205 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
206 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
210 static void print_version (void)
213 static const char platform
[] = "i386";
214 #elif defined(__x86_64__)
215 static const char platform
[] = "x86_64";
216 #elif defined(__sparc__)
217 static const char platform
[] = "sparc";
218 #elif defined(__ALPHA__)
219 static const char platform
[] = "alpha";
220 #elif defined(__powerpc__)
221 static const char platform
[] = "powerpc";
228 const char *(CDECL
*wine_get_build_id
)(void);
229 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
230 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
231 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
233 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
234 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
236 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
237 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
238 report (R_FATAL
, "Can't get OS version.");
240 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
241 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
243 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
244 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
245 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
246 xprintf (" Submitter=%s\n", email
);
247 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
248 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
249 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
250 ver
.dwPlatformId
, ver
.szCSDVersion
);
252 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
253 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
254 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
255 if (wine_get_host_version
)
257 const char *sysname
, *release
;
258 wine_get_host_version( &sysname
, &release
);
259 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
261 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
263 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
267 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
268 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
269 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
270 ver
.wProductType
, ver
.wReserved
);
272 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
273 if (pGetProductInfo
&& !running_under_wine())
277 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
278 xprintf(" dwProductInfo=%u\n", prodtype
);
282 static inline int is_dot_dir(const char* x
)
284 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
287 static void remove_dir (const char *dir
)
292 size_t dirlen
= strlen (dir
);
294 /* Make sure the directory exists before going further */
295 memcpy (path
, dir
, dirlen
);
296 strcpy (path
+ dirlen
++, "\\*");
297 hFind
= FindFirstFile (path
, &wfd
);
298 if (hFind
== INVALID_HANDLE_VALUE
) return;
301 char *lp
= wfd
.cFileName
;
303 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
304 if (is_dot_dir (lp
)) continue;
305 strcpy (path
+ dirlen
, lp
);
306 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
308 else if (!DeleteFile (path
))
309 report (R_WARNING
, "Can't delete file %s: error %d",
310 path
, GetLastError ());
311 } while (FindNextFile (hFind
, &wfd
));
313 if (!RemoveDirectory (dir
))
314 report (R_WARNING
, "Can't remove directory %s: error %d",
315 dir
, GetLastError ());
318 static const char* get_test_source_file(const char* test
, const char* subtest
)
320 static const char* special_dirs
[][2] = {
323 static char buffer
[MAX_PATH
];
324 int i
, len
= strlen(test
);
326 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
328 len
= sprintf(buffer
, "programs/%s", test
) - 4;
331 else len
= sprintf(buffer
, "dlls/%s", test
);
333 for (i
= 0; special_dirs
[i
][0]; i
++) {
334 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
335 strcpy( buffer
, special_dirs
[i
][1] );
336 len
= strlen(buffer
);
341 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
345 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
351 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
352 !(*size
= SizeofResource (0, rsrc
)) ||
353 !(hdl
= LoadResource (0, rsrc
)) ||
354 !(addr
= LockResource (hdl
)))
359 /* Fills in the name and exename fields */
361 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
369 code
= extract_rcdata (res_name
, "TESTRES", &size
);
370 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
371 res_name
, GetLastError ());
372 test
->name
= heap_strdup( res_name
);
373 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
374 exepos
= strstr (test
->name
, testexe
);
375 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
377 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
378 report (R_STEP
, "Extracting: %s", test
->name
);
380 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
381 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
382 if (hfile
== INVALID_HANDLE_VALUE
)
383 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
385 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
386 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
391 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
393 DWORD wait
, diff
= 0, start
= GetTickCount();
396 while (diff
< timeout
)
398 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
399 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
400 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
401 diff
= GetTickCount() - start
;
406 static void append_path( const char *path
)
410 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
411 strcpy(newpath
, curpath
);
412 strcat(newpath
, ";");
413 strcat(newpath
, path
);
414 SetEnvironmentVariableA("PATH", newpath
);
419 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
422 Return the exit status, -2 if can't create process or the return
423 value of WaitForSingleObject.
426 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
429 PROCESS_INFORMATION pi
;
432 GetStartupInfo (&si
);
433 si
.dwFlags
= STARTF_USESTDHANDLES
;
434 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
435 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
436 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
438 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
439 NULL
, tempdir
, &si
, &pi
))
442 CloseHandle (pi
.hThread
);
443 status
= wait_process( pi
.hProcess
, ms
);
447 GetExitCodeProcess (pi
.hProcess
, &status
);
448 CloseHandle (pi
.hProcess
);
451 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
456 report (R_ERROR
, "Wait returned %d", status
);
459 if (!TerminateProcess (pi
.hProcess
, 257))
460 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
461 wait
= wait_process( pi
.hProcess
, 5000 );
467 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
470 report (R_ERROR
, "Can't kill process '%s'", cmd
);
473 report (R_ERROR
, "Waiting for termination: %d", wait
);
476 CloseHandle (pi
.hProcess
);
481 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
486 char buffer
[8192], *index
;
487 static const char header
[] = "Valid test names:";
488 int status
, allocated
;
489 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
490 SECURITY_ATTRIBUTES sa
;
492 test
->subtest_count
= 0;
494 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
495 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
496 report (R_FATAL
, "Can't name subtests file.");
498 /* make handle inheritable */
499 sa
.nLength
= sizeof(sa
);
500 sa
.lpSecurityDescriptor
= NULL
;
501 sa
.bInheritHandle
= TRUE
;
503 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
504 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
505 &sa
, CREATE_ALWAYS
, 0, NULL
);
507 if ((subfile
== INVALID_HANDLE_VALUE
) &&
508 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
509 /* FILE_SHARE_DELETE not supported on win9x */
510 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
511 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
512 &sa
, CREATE_ALWAYS
, 0, NULL
);
514 if (subfile
== INVALID_HANDLE_VALUE
) {
515 err
= GetLastError();
516 report (R_ERROR
, "Can't open subtests output of %s: %u",
517 test
->name
, GetLastError());
521 cmd
= strmake (NULL
, "%s --list", test
->exename
);
522 if (test
->maindllpath
) {
523 /* We need to add the path (to the main dll) to PATH */
524 append_path(test
->maindllpath
);
526 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
527 err
= GetLastError();
528 if (test
->maindllpath
) {
529 /* Restore PATH again */
530 SetEnvironmentVariableA("PATH", curpath
);
536 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
540 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
541 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
542 CloseHandle( subfile
);
543 if (sizeof buffer
== total
) {
544 report (R_ERROR
, "Subtest list of %s too big.",
545 test
->name
, sizeof buffer
);
546 err
= ERROR_OUTOFMEMORY
;
551 index
= strstr (buffer
, header
);
553 report (R_ERROR
, "Can't parse subtests output of %s",
555 err
= ERROR_INTERNAL_ERROR
;
558 index
+= sizeof header
;
561 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
562 index
= strtok (index
, whitespace
);
564 if (test
->subtest_count
== allocated
) {
566 test
->subtests
= heap_realloc (test
->subtests
,
567 allocated
* sizeof(char*));
569 if (!test_filtered_out( test
->name
, index
))
570 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
571 index
= strtok (NULL
, whitespace
);
573 test
->subtests
= heap_realloc (test
->subtests
,
574 test
->subtest_count
* sizeof(char*));
578 if (!DeleteFileA (subname
))
579 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
584 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
587 const char* file
= get_test_source_file(test
->name
, subtest
);
588 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
590 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
591 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
593 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
597 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
598 LPTSTR lpszName
, LONG_PTR lParam
)
600 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
604 static const struct clsid_mapping
610 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
611 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
615 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
617 const struct clsid_mapping
*mapping
;
619 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
621 if(!strcasecmp(name
, mapping
->name
))
623 *clsid
= mapping
->clsid
;
630 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
635 char dllname
[MAX_PATH
];
639 if(!get_main_clsid(name
, &clsid
)) return NULL
;
641 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
642 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
643 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
644 clsid
.Data4
[6], clsid
.Data4
[7]);
646 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
648 LONG size
= sizeof(dllname
);
649 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
651 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
653 strcpy( filename
, dllname
);
654 p
= strrchr(dllname
, '\\');
656 *path
= heap_strdup( dllname
);
665 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
667 char dllpath
[MAX_PATH
];
669 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
670 strcpy(filename
, dllpath
);
671 *strrchr(dllpath
, '\\') = '\0';
672 *path
= heap_strdup( dllpath
);
676 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
677 LPTSTR lpszName
, LONG_PTR lParam
)
679 const char *tempdir
= (const char *)lParam
;
680 char dllname
[MAX_PATH
];
681 char filename
[MAX_PATH
];
682 WCHAR dllnameW
[MAX_PATH
];
688 if (aborting
) return TRUE
;
689 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
691 CharLowerA(lpszName
);
692 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
694 /* Check if the main dll is present on this system */
695 strcpy(dllname
, lpszName
);
696 *strstr(dllname
, testexe
) = 0;
698 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
699 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
702 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
703 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
704 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
705 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
706 actctxinfo
.lpResourceName
= CREATEPROCESS_MANIFEST_RESOURCE_ID
;
707 actctx
= pCreateActCtxA(&actctxinfo
);
708 if (actctx
!= INVALID_HANDLE_VALUE
&&
709 ! pActivateActCtx(actctx
, &cookie
))
711 pReleaseActCtx(actctx
);
712 actctx
= INVALID_HANDLE_VALUE
;
714 } else actctx
= INVALID_HANDLE_VALUE
;
716 wine_tests
[nr_of_files
].maindllpath
= NULL
;
717 strcpy(filename
, dllname
);
718 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
720 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
722 if (!dll
&& pLoadLibraryShim
)
724 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
725 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
727 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
729 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
736 xprintf (" %s=dll is missing\n", dllname
);
737 if (actctx
!= INVALID_HANDLE_VALUE
)
739 pDeactivateActCtx(0, cookie
);
740 pReleaseActCtx(actctx
);
744 if (is_native_dll(dll
))
747 xprintf (" %s=load error Configured as native\n", dllname
);
749 if (actctx
!= INVALID_HANDLE_VALUE
)
751 pDeactivateActCtx(0, cookie
);
752 pReleaseActCtx(actctx
);
758 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
760 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
761 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
766 xprintf (" %s=load error %u\n", dllname
, err
);
769 if (actctx
!= INVALID_HANDLE_VALUE
)
771 pDeactivateActCtx(0, cookie
);
772 pReleaseActCtx(actctx
);
778 run_tests (char *logname
, char *outdir
)
781 char *strres
, *eol
, *nextline
;
783 SECURITY_ATTRIBUTES sa
;
784 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
788 /* Get the current PATH only once */
789 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
790 curpath
= heap_alloc(needed
);
791 GetEnvironmentVariableA("PATH", curpath
, needed
);
793 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
795 if (!GetTempPathA( MAX_PATH
, tmppath
))
796 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
799 static char tmpname
[MAX_PATH
];
800 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
801 report (R_FATAL
, "Can't name logfile.");
804 report (R_OUT
, logname
);
806 /* make handle inheritable */
807 sa
.nLength
= sizeof(sa
);
808 sa
.lpSecurityDescriptor
= NULL
;
809 sa
.bInheritHandle
= TRUE
;
811 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
812 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
813 &sa
, CREATE_ALWAYS
, 0, NULL
);
815 if ((logfile
== INVALID_HANDLE_VALUE
) &&
816 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
817 /* FILE_SHARE_DELETE not supported on win9x */
818 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
819 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
820 &sa
, CREATE_ALWAYS
, 0, NULL
);
822 if (logfile
== INVALID_HANDLE_VALUE
)
823 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
825 /* try stable path for ZoneAlarm */
827 strcpy( tempdir
, tmppath
);
828 strcat( tempdir
, "wct" );
830 if (!CreateDirectoryA( tempdir
, NULL
))
832 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
833 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
834 DeleteFileA( tempdir
);
835 if (!CreateDirectoryA( tempdir
, NULL
))
836 report (R_FATAL
, "Could not create directory: %s", tempdir
);
840 strcpy( tempdir
, outdir
);
842 report (R_DIR
, tempdir
);
844 xprintf ("Version 4\n");
845 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
846 xprintf ("Archive: -\n"); /* no longer used */
847 xprintf ("Tag: %s\n", tag
);
848 xprintf ("Build info:\n");
849 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
851 eol
= memchr (strres
, '\n', strsize
);
854 eol
= strres
+ strsize
;
856 strsize
-= eol
- strres
+ 1;
857 nextline
= strsize
?eol
+1:NULL
;
858 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
860 xprintf (" %.*s\n", eol
-strres
, strres
);
863 xprintf ("Operating system version:\n");
865 xprintf ("Dll info:\n" );
867 report (R_STATUS
, "Counting tests");
868 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
869 report (R_FATAL
, "Can't enumerate test files: %d",
871 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
873 /* Do this only once during extraction (and version checking) */
874 hmscoree
= LoadLibraryA("mscoree.dll");
875 pLoadLibraryShim
= NULL
;
877 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
878 kernel32
= GetModuleHandleA("kernel32.dll");
879 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
880 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
881 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
882 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
884 report (R_STATUS
, "Extracting tests");
885 report (R_PROGRESS
, 0, nr_of_files
);
888 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
889 report (R_FATAL
, "Can't enumerate test files: %d",
892 FreeLibrary(hmscoree
);
894 if (aborting
) return logname
;
896 xprintf ("Test output:\n" );
898 report (R_DELTA
, 0, "Extracting: Done");
901 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
903 report (R_STATUS
, "Running tests");
904 report (R_PROGRESS
, 1, nr_of_tests
);
905 for (i
= 0; i
< nr_of_files
; i
++) {
906 struct wine_test
*test
= wine_tests
+ i
;
911 if (test
->maindllpath
) {
912 /* We need to add the path (to the main dll) to PATH */
913 append_path(test
->maindllpath
);
916 for (j
= 0; j
< test
->subtest_count
; j
++) {
918 report (R_STEP
, "Running: %s:%s", test
->name
,
920 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
923 if (test
->maindllpath
) {
924 /* Restore PATH again */
925 SetEnvironmentVariableA("PATH", curpath
);
928 report (R_DELTA
, 0, "Running: Done");
930 report (R_STATUS
, "Cleaning up");
931 CloseHandle( logfile
);
934 remove_dir (tempdir
);
935 heap_free(wine_tests
);
941 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
943 if (ctrl_type
== CTRL_C_EVENT
) {
944 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
953 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
955 const char *target_dir
= (const char *)lParam
;
956 char filename
[MAX_PATH
];
958 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
960 strcpy(filename
, lpszName
);
961 CharLowerA(filename
);
963 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
968 static void extract_only (const char *target_dir
)
972 report (R_DIR
, target_dir
);
973 res
= CreateDirectoryA( target_dir
, NULL
);
974 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
975 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
978 report (R_STATUS
, "Counting tests");
979 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
980 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
982 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
984 report (R_STATUS
, "Extracting tests");
985 report (R_PROGRESS
, 0, nr_of_files
);
987 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
988 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
990 report (R_DELTA
, 0, "Extracting: Done");
997 "Usage: winetest [OPTION]... [TESTS]\n\n"
998 " --help print this message and exit\n"
999 " --version print the build version and exit\n"
1000 " -c console mode, no GUI\n"
1001 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1002 " -e preserve the environment\n"
1003 " -h print this message and exit\n"
1004 " -m MAIL an email address to enable developers to contact you\n"
1005 " -p shutdown when the tests are done\n"
1006 " -q quiet mode, no output at all\n"
1007 " -o FILE put report into FILE, do not submit\n"
1008 " -s FILE submit FILE, do not run tests\n"
1009 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1010 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1013 int main( int argc
, char *argv
[] )
1015 char *logname
= NULL
, *outdir
= NULL
;
1016 const char *extract
= NULL
;
1017 const char *cp
, *submit
= NULL
;
1020 int interactive
= 1;
1023 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1025 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1027 if (!strcmp(argv
[i
], "--help")) {
1031 else if (!strcmp(argv
[i
], "--version")) {
1032 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1035 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1036 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1038 report (R_ERROR
, "Too many test filters specified");
1041 filters
[nb_filters
++] = argv
[i
];
1043 else switch (argv
[i
][1]) {
1045 report (R_TEXTMODE
);
1056 if (!(email
= argv
[++i
]))
1070 if (!(submit
= argv
[++i
]))
1076 report (R_WARNING
, "ignoring tag for submission");
1080 if (!(logname
= argv
[++i
]))
1087 if (!(tag
= argv
[++i
]))
1092 if (strlen (tag
) > MAXTAGLEN
)
1093 report (R_FATAL
, "tag is too long (maximum %d characters)",
1095 cp
= findbadtagchar (tag
);
1097 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1103 report (R_TEXTMODE
);
1104 if (!(extract
= argv
[++i
]))
1107 extract_only (extract
);
1113 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1118 if (!submit
&& !extract
) {
1119 report (R_STATUS
, "Starting up");
1121 if (!running_on_visible_desktop ())
1122 report (R_FATAL
, "Tests must be run on a visible desktop");
1124 if (!check_mount_mgr())
1125 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1127 if (!check_display_driver())
1128 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1130 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1134 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1135 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1136 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1137 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1140 if (!nb_filters
) /* don't submit results when filtering */
1144 report (R_FATAL
, "Please specify a tag (-t option) if "
1145 "running noninteractive!");
1146 if (guiAskTag () == IDABORT
) exit (1);
1152 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1153 " to contact you about your report if necessary.");
1154 if (guiAskEmail () == IDABORT
) exit (1);
1158 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1159 "To submit results, winetest needs to be built from a git checkout." );
1163 logname
= run_tests (NULL
, outdir
);
1165 DeleteFileA(logname
);
1168 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1169 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1170 if (!send_file (logname
) && !DeleteFileA(logname
))
1171 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1172 } else run_tests (logname
, outdir
);
1173 report (R_STATUS
, "Finished");
1178 TOKEN_PRIVILEGES npr
;
1180 /* enable the shutdown privilege for the current process */
1181 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1183 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1184 npr
.PrivilegeCount
= 1;
1185 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1186 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1187 CloseHandle(hToken
);
1189 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);