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 /* To store the current PATH setting (related to .NET only provided dlls) */
71 /* check if test is being filtered out */
72 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
74 char *p
, dllname
[MAX_PATH
];
77 strcpy( dllname
, module
);
78 CharLowerA( dllname
);
79 p
= strstr( dllname
, testexe
);
81 len
= strlen(dllname
);
83 if (!nb_filters
) return FALSE
;
84 for (i
= 0; i
< nb_filters
; i
++)
86 if (!strncmp( dllname
, filters
[i
], len
))
88 if (!filters
[i
][len
]) return FALSE
;
89 if (filters
[i
][len
] != ':') continue;
90 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
96 static char * get_file_version(char * file_name
)
98 static char version
[32];
102 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
104 char * data
= heap_alloc(size
);
106 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
107 static char backslash
[] = "\\";
108 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
110 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
111 sprintf(version
, "%d.%d.%d.%d",
112 pFixedVersionInfo
->dwFileVersionMS
>> 16,
113 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
114 pFixedVersionInfo
->dwFileVersionLS
>> 16,
115 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
117 sprintf(version
, "version not available");
119 sprintf(version
, "unknown");
122 sprintf(version
, "failed");
124 sprintf(version
, "version not available");
129 static int running_under_wine (void)
131 HMODULE module
= GetModuleHandleA("ntdll.dll");
133 if (!module
) return 0;
134 return (GetProcAddress(module
, "wine_server_call") != NULL
);
137 static int check_mount_mgr(void)
139 if (running_under_wine())
141 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
142 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
143 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
144 CloseHandle( handle
);
149 static int check_display_driver(void)
151 if (running_under_wine())
153 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
154 0, 0, GetModuleHandleA(0), 0 );
155 if (!hwnd
) return FALSE
;
156 DestroyWindow( hwnd
);
161 static int running_on_visible_desktop (void)
164 HMODULE huser32
= GetModuleHandle("user32.dll");
165 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
166 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
168 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
169 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
171 desktop
= GetDesktopWindow();
172 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
173 return IsWindowVisible(desktop
);
175 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
179 USEROBJECTFLAGS uoflags
;
181 wstation
= (HWINSTA
)pGetProcessWindowStation();
182 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
183 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
185 return IsWindowVisible(desktop
);
188 /* check for native dll when running under wine */
189 static BOOL
is_native_dll( HMODULE module
)
191 static const char fakedll_signature
[] = "Wine placeholder DLL";
192 const IMAGE_DOS_HEADER
*dos
;
194 if (!running_under_wine()) return FALSE
;
195 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
196 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
197 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
198 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
199 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
200 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
204 static void print_version (void)
207 static const char platform
[] = "i386";
208 #elif defined(__x86_64__)
209 static const char platform
[] = "x86_64";
210 #elif defined(__sparc__)
211 static const char platform
[] = "sparc";
212 #elif defined(__ALPHA__)
213 static const char platform
[] = "alpha";
214 #elif defined(__powerpc__)
215 static const char platform
[] = "powerpc";
222 const char *(CDECL
*wine_get_build_id
)(void);
223 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
224 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
225 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
227 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
228 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
230 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
231 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
232 report (R_FATAL
, "Can't get OS version.");
234 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
235 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
237 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
238 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
239 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
240 xprintf (" Submitter=%s\n", email
);
241 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
242 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
243 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
244 ver
.dwPlatformId
, ver
.szCSDVersion
);
246 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
247 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
248 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
249 if (wine_get_host_version
)
251 const char *sysname
, *release
;
252 wine_get_host_version( &sysname
, &release
);
253 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
255 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
257 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
261 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
262 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
263 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
264 ver
.wProductType
, ver
.wReserved
);
266 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
267 if (pGetProductInfo
&& !running_under_wine())
271 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
272 xprintf(" dwProductInfo=%u\n", prodtype
);
276 static inline int is_dot_dir(const char* x
)
278 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
281 static void remove_dir (const char *dir
)
286 size_t dirlen
= strlen (dir
);
288 /* Make sure the directory exists before going further */
289 memcpy (path
, dir
, dirlen
);
290 strcpy (path
+ dirlen
++, "\\*");
291 hFind
= FindFirstFile (path
, &wfd
);
292 if (hFind
== INVALID_HANDLE_VALUE
) return;
295 char *lp
= wfd
.cFileName
;
297 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
298 if (is_dot_dir (lp
)) continue;
299 strcpy (path
+ dirlen
, lp
);
300 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
302 else if (!DeleteFile (path
))
303 report (R_WARNING
, "Can't delete file %s: error %d",
304 path
, GetLastError ());
305 } while (FindNextFile (hFind
, &wfd
));
307 if (!RemoveDirectory (dir
))
308 report (R_WARNING
, "Can't remove directory %s: error %d",
309 dir
, GetLastError ());
312 static const char* get_test_source_file(const char* test
, const char* subtest
)
314 static const char* special_dirs
[][2] = {
317 static char buffer
[MAX_PATH
];
318 int i
, len
= strlen(test
);
320 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
322 len
= sprintf(buffer
, "programs/%s", test
) - 4;
325 else len
= sprintf(buffer
, "dlls/%s", test
);
327 for (i
= 0; special_dirs
[i
][0]; i
++) {
328 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
329 strcpy( buffer
, special_dirs
[i
][1] );
330 len
= strlen(buffer
);
335 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
339 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
345 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
346 !(*size
= SizeofResource (0, rsrc
)) ||
347 !(hdl
= LoadResource (0, rsrc
)) ||
348 !(addr
= LockResource (hdl
)))
353 /* Fills in the name and exename fields */
355 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
363 code
= extract_rcdata (res_name
, "TESTRES", &size
);
364 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
365 res_name
, GetLastError ());
366 test
->name
= heap_strdup( res_name
);
367 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
368 exepos
= strstr (test
->name
, testexe
);
369 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
371 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
372 report (R_STEP
, "Extracting: %s", test
->name
);
374 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
375 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
376 if (hfile
== INVALID_HANDLE_VALUE
)
377 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
379 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
380 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
385 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
387 DWORD wait
, diff
= 0, start
= GetTickCount();
390 while (diff
< timeout
)
392 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
393 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
394 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
395 diff
= GetTickCount() - start
;
400 static void append_path( const char *path
)
404 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
405 strcpy(newpath
, curpath
);
406 strcat(newpath
, ";");
407 strcat(newpath
, path
);
408 SetEnvironmentVariableA("PATH", newpath
);
413 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
416 Return the exit status, -2 if can't create process or the return
417 value of WaitForSingleObject.
420 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
423 PROCESS_INFORMATION pi
;
426 GetStartupInfo (&si
);
427 si
.dwFlags
= STARTF_USESTDHANDLES
;
428 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
429 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
430 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
432 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
433 NULL
, tempdir
, &si
, &pi
))
436 CloseHandle (pi
.hThread
);
437 status
= wait_process( pi
.hProcess
, ms
);
441 GetExitCodeProcess (pi
.hProcess
, &status
);
442 CloseHandle (pi
.hProcess
);
445 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
450 report (R_ERROR
, "Wait returned %d", status
);
453 if (!TerminateProcess (pi
.hProcess
, 257))
454 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
455 wait
= wait_process( pi
.hProcess
, 5000 );
461 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
464 report (R_ERROR
, "Can't kill process '%s'", cmd
);
467 report (R_ERROR
, "Waiting for termination: %d", wait
);
470 CloseHandle (pi
.hProcess
);
475 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
480 char buffer
[8192], *index
;
481 static const char header
[] = "Valid test names:";
482 int status
, allocated
;
483 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
484 SECURITY_ATTRIBUTES sa
;
486 test
->subtest_count
= 0;
488 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
489 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
490 report (R_FATAL
, "Can't name subtests file.");
492 /* make handle inheritable */
493 sa
.nLength
= sizeof(sa
);
494 sa
.lpSecurityDescriptor
= NULL
;
495 sa
.bInheritHandle
= TRUE
;
497 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
498 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
499 &sa
, CREATE_ALWAYS
, 0, NULL
);
501 if ((subfile
== INVALID_HANDLE_VALUE
) &&
502 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
503 /* FILE_SHARE_DELETE not supported on win9x */
504 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
505 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
506 &sa
, CREATE_ALWAYS
, 0, NULL
);
508 if (subfile
== INVALID_HANDLE_VALUE
) {
509 err
= GetLastError();
510 report (R_ERROR
, "Can't open subtests output of %s: %u",
511 test
->name
, GetLastError());
515 extract_test (test
, tempdir
, res_name
);
516 cmd
= strmake (NULL
, "%s --list", test
->exename
);
517 if (test
->maindllpath
) {
518 /* We need to add the path (to the main dll) to PATH */
519 append_path(test
->maindllpath
);
521 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
522 err
= GetLastError();
523 if (test
->maindllpath
) {
524 /* Restore PATH again */
525 SetEnvironmentVariableA("PATH", curpath
);
531 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
535 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
536 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
537 CloseHandle( subfile
);
538 if (sizeof buffer
== total
) {
539 report (R_ERROR
, "Subtest list of %s too big.",
540 test
->name
, sizeof buffer
);
541 err
= ERROR_OUTOFMEMORY
;
546 index
= strstr (buffer
, header
);
548 report (R_ERROR
, "Can't parse subtests output of %s",
550 err
= ERROR_INTERNAL_ERROR
;
553 index
+= sizeof header
;
556 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
557 index
= strtok (index
, whitespace
);
559 if (test
->subtest_count
== allocated
) {
561 test
->subtests
= heap_realloc (test
->subtests
,
562 allocated
* sizeof(char*));
564 if (!test_filtered_out( test
->name
, index
))
565 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
566 index
= strtok (NULL
, whitespace
);
568 test
->subtests
= heap_realloc (test
->subtests
,
569 test
->subtest_count
* sizeof(char*));
573 if (!DeleteFileA (subname
))
574 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
579 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
582 const char* file
= get_test_source_file(test
->name
, subtest
);
583 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
585 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
586 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
588 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
592 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
593 LPTSTR lpszName
, LONG_PTR lParam
)
595 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
599 static const struct clsid_mapping
605 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
606 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
610 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
612 const struct clsid_mapping
*mapping
;
614 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
616 if(!strcasecmp(name
, mapping
->name
))
618 *clsid
= mapping
->clsid
;
625 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
630 char dllname
[MAX_PATH
];
634 if(!get_main_clsid(name
, &clsid
)) return NULL
;
636 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
637 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
638 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
639 clsid
.Data4
[6], clsid
.Data4
[7]);
641 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
643 LONG size
= sizeof(dllname
);
644 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
646 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
648 strcpy( filename
, dllname
);
649 p
= strrchr(dllname
, '\\');
651 *path
= heap_strdup( dllname
);
660 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
662 char dllpath
[MAX_PATH
];
664 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
665 strcpy(filename
, dllpath
);
666 *strrchr(dllpath
, '\\') = '\0';
667 *path
= heap_strdup( dllpath
);
671 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
672 LPTSTR lpszName
, LONG_PTR lParam
)
674 const char *tempdir
= (const char *)lParam
;
675 char dllname
[MAX_PATH
];
676 char filename
[MAX_PATH
];
677 WCHAR dllnameW
[MAX_PATH
];
681 if (aborting
) return TRUE
;
682 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
684 /* Check if the main dll is present on this system */
685 CharLowerA(lpszName
);
686 strcpy(dllname
, lpszName
);
687 *strstr(dllname
, testexe
) = 0;
689 wine_tests
[nr_of_files
].maindllpath
= NULL
;
690 strcpy(filename
, dllname
);
691 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
693 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
695 if (!dll
&& pLoadLibraryShim
)
697 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
698 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
700 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
702 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
709 xprintf (" %s=dll is missing\n", dllname
);
712 if (is_native_dll(dll
))
715 xprintf (" %s=load error Configured as native\n", dllname
);
721 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
723 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
724 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
729 xprintf (" %s=load error %u\n", dllname
, err
);
735 run_tests (char *logname
, char *outdir
)
738 char *strres
, *eol
, *nextline
;
740 SECURITY_ATTRIBUTES sa
;
741 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
744 /* Get the current PATH only once */
745 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
746 curpath
= heap_alloc(needed
);
747 GetEnvironmentVariableA("PATH", curpath
, needed
);
749 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
751 if (!GetTempPathA( MAX_PATH
, tmppath
))
752 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
755 static char tmpname
[MAX_PATH
];
756 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
757 report (R_FATAL
, "Can't name logfile.");
760 report (R_OUT
, logname
);
762 /* make handle inheritable */
763 sa
.nLength
= sizeof(sa
);
764 sa
.lpSecurityDescriptor
= NULL
;
765 sa
.bInheritHandle
= TRUE
;
767 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
768 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
769 &sa
, CREATE_ALWAYS
, 0, NULL
);
771 if ((logfile
== INVALID_HANDLE_VALUE
) &&
772 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
773 /* FILE_SHARE_DELETE not supported on win9x */
774 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
775 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
776 &sa
, CREATE_ALWAYS
, 0, NULL
);
778 if (logfile
== INVALID_HANDLE_VALUE
)
779 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
781 /* try stable path for ZoneAlarm */
783 strcpy( tempdir
, tmppath
);
784 strcat( tempdir
, "wct" );
786 if (!CreateDirectoryA( tempdir
, NULL
))
788 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
789 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
790 DeleteFileA( tempdir
);
791 if (!CreateDirectoryA( tempdir
, NULL
))
792 report (R_FATAL
, "Could not create directory: %s", tempdir
);
796 strcpy( tempdir
, outdir
);
798 report (R_DIR
, tempdir
);
800 xprintf ("Version 4\n");
801 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
802 xprintf ("Archive: -\n"); /* no longer used */
803 xprintf ("Tag: %s\n", tag
);
804 xprintf ("Build info:\n");
805 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
807 eol
= memchr (strres
, '\n', strsize
);
810 eol
= strres
+ strsize
;
812 strsize
-= eol
- strres
+ 1;
813 nextline
= strsize
?eol
+1:NULL
;
814 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
816 xprintf (" %.*s\n", eol
-strres
, strres
);
819 xprintf ("Operating system version:\n");
821 xprintf ("Dll info:\n" );
823 report (R_STATUS
, "Counting tests");
824 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
825 report (R_FATAL
, "Can't enumerate test files: %d",
827 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
829 /* Do this only once during extraction (and version checking) */
830 hmscoree
= LoadLibraryA("mscoree.dll");
831 pLoadLibraryShim
= NULL
;
833 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
835 report (R_STATUS
, "Extracting tests");
836 report (R_PROGRESS
, 0, nr_of_files
);
839 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
840 report (R_FATAL
, "Can't enumerate test files: %d",
843 FreeLibrary(hmscoree
);
845 if (aborting
) return logname
;
847 xprintf ("Test output:\n" );
849 report (R_DELTA
, 0, "Extracting: Done");
852 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
854 report (R_STATUS
, "Running tests");
855 report (R_PROGRESS
, 1, nr_of_tests
);
856 for (i
= 0; i
< nr_of_files
; i
++) {
857 struct wine_test
*test
= wine_tests
+ i
;
862 if (test
->maindllpath
) {
863 /* We need to add the path (to the main dll) to PATH */
864 append_path(test
->maindllpath
);
867 for (j
= 0; j
< test
->subtest_count
; j
++) {
869 report (R_STEP
, "Running: %s:%s", test
->name
,
871 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
874 if (test
->maindllpath
) {
875 /* Restore PATH again */
876 SetEnvironmentVariableA("PATH", curpath
);
879 report (R_DELTA
, 0, "Running: Done");
881 report (R_STATUS
, "Cleaning up");
882 CloseHandle( logfile
);
885 remove_dir (tempdir
);
886 heap_free(wine_tests
);
892 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
894 if (ctrl_type
== CTRL_C_EVENT
) {
895 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
904 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
906 const char *target_dir
= (const char *)lParam
;
907 char filename
[MAX_PATH
];
909 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
911 strcpy(filename
, lpszName
);
912 CharLowerA(filename
);
914 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
919 static void extract_only (const char *target_dir
)
923 report (R_DIR
, target_dir
);
924 res
= CreateDirectoryA( target_dir
, NULL
);
925 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
926 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
929 report (R_STATUS
, "Counting tests");
930 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
931 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
933 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
935 report (R_STATUS
, "Extracting tests");
936 report (R_PROGRESS
, 0, nr_of_files
);
938 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
939 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
941 report (R_DELTA
, 0, "Extracting: Done");
948 "Usage: winetest [OPTION]... [TESTS]\n\n"
949 " --help print this message and exit\n"
950 " --version print the build version and exit\n"
951 " -c console mode, no GUI\n"
952 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
953 " -e preserve the environment\n"
954 " -h print this message and exit\n"
955 " -m MAIL an email address to enable developers to contact you\n"
956 " -p shutdown when the tests are done\n"
957 " -q quiet mode, no output at all\n"
958 " -o FILE put report into FILE, do not submit\n"
959 " -s FILE submit FILE, do not run tests\n"
960 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
961 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
964 int main( int argc
, char *argv
[] )
966 char *logname
= NULL
, *outdir
= NULL
;
967 const char *extract
= NULL
;
968 const char *cp
, *submit
= NULL
;
974 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
976 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
978 if (!strcmp(argv
[i
], "--help")) {
982 else if (!strcmp(argv
[i
], "--version")) {
983 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
986 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
987 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
989 report (R_ERROR
, "Too many test filters specified");
992 filters
[nb_filters
++] = argv
[i
];
994 else switch (argv
[i
][1]) {
1007 if (!(email
= argv
[++i
]))
1021 if (!(submit
= argv
[++i
]))
1027 report (R_WARNING
, "ignoring tag for submission");
1031 if (!(logname
= argv
[++i
]))
1038 if (!(tag
= argv
[++i
]))
1043 if (strlen (tag
) > MAXTAGLEN
)
1044 report (R_FATAL
, "tag is too long (maximum %d characters)",
1046 cp
= findbadtagchar (tag
);
1048 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1054 report (R_TEXTMODE
);
1055 if (!(extract
= argv
[++i
]))
1058 extract_only (extract
);
1064 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1069 if (!submit
&& !extract
) {
1070 report (R_STATUS
, "Starting up");
1072 if (!running_on_visible_desktop ())
1073 report (R_FATAL
, "Tests must be run on a visible desktop");
1075 if (!check_mount_mgr())
1076 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1078 if (!check_display_driver())
1079 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1081 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1085 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1086 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1087 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1088 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1091 if (!nb_filters
) /* don't submit results when filtering */
1095 report (R_FATAL
, "Please specify a tag (-t option) if "
1096 "running noninteractive!");
1097 if (guiAskTag () == IDABORT
) exit (1);
1103 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1104 " to contact you about your report if necessary.");
1105 if (guiAskEmail () == IDABORT
) exit (1);
1109 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1110 "To submit results, winetest needs to be built from a git checkout." );
1114 logname
= run_tests (NULL
, outdir
);
1116 DeleteFileA(logname
);
1119 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1120 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1121 if (!send_file (logname
) && !DeleteFileA(logname
))
1122 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1123 } else run_tests (logname
, outdir
);
1124 report (R_STATUS
, "Finished");
1129 TOKEN_PRIVILEGES npr
;
1131 /* enable the shutdown privilege for the current process */
1132 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1134 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1135 npr
.PrivilegeCount
= 1;
1136 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1137 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1138 CloseHandle(hToken
);
1140 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);