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 static struct wine_test
*wine_tests
;
53 static int nr_of_files
, nr_of_tests
;
54 static int nr_native_dlls
;
55 static const char whitespace
[] = " \t\r\n";
56 static const char testexe
[] = "_test.exe";
57 static char build_id
[64];
59 /* filters for running only specific tests */
60 static char *filters
[64];
61 static unsigned int nb_filters
= 0;
63 /* Needed to check for .NET dlls */
64 static HMODULE hmscoree
;
65 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
67 /* To store the current PATH setting (related to .NET only provided dlls) */
70 /* check if test is being filtered out */
71 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
73 char *p
, dllname
[MAX_PATH
];
76 strcpy( dllname
, module
);
77 CharLowerA( dllname
);
78 p
= strstr( dllname
, testexe
);
80 len
= strlen(dllname
);
82 if (!nb_filters
) return FALSE
;
83 for (i
= 0; i
< nb_filters
; i
++)
85 if (!strncmp( dllname
, filters
[i
], len
))
87 if (!filters
[i
][len
]) return FALSE
;
88 if (filters
[i
][len
] != ':') continue;
89 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
95 static char * get_file_version(char * file_name
)
97 static char version
[32];
101 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
103 char * data
= heap_alloc(size
);
105 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
106 static char backslash
[] = "\\";
107 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
109 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
110 sprintf(version
, "%d.%d.%d.%d",
111 pFixedVersionInfo
->dwFileVersionMS
>> 16,
112 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
113 pFixedVersionInfo
->dwFileVersionLS
>> 16,
114 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
116 sprintf(version
, "version not available");
118 sprintf(version
, "unknown");
121 sprintf(version
, "failed");
123 sprintf(version
, "version not available");
128 static int running_under_wine (void)
130 HMODULE module
= GetModuleHandleA("ntdll.dll");
132 if (!module
) return 0;
133 return (GetProcAddress(module
, "wine_server_call") != NULL
);
136 static int check_mount_mgr(void)
138 if (running_under_wine())
140 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
141 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
142 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
143 CloseHandle( handle
);
148 static int check_display_driver(void)
150 if (running_under_wine())
152 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
153 0, 0, GetModuleHandleA(0), 0 );
154 if (!hwnd
) return FALSE
;
155 DestroyWindow( hwnd
);
160 static int running_on_visible_desktop (void)
163 HMODULE huser32
= GetModuleHandle("user32.dll");
164 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
165 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
167 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
168 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
170 desktop
= GetDesktopWindow();
171 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
172 return IsWindowVisible(desktop
);
174 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
178 USEROBJECTFLAGS uoflags
;
180 wstation
= (HWINSTA
)pGetProcessWindowStation();
181 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
182 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
184 return IsWindowVisible(desktop
);
187 /* check for native dll when running under wine */
188 static BOOL
is_native_dll( HMODULE module
)
190 static const char fakedll_signature
[] = "Wine placeholder DLL";
191 const IMAGE_DOS_HEADER
*dos
;
193 if (!running_under_wine()) return FALSE
;
194 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
195 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
196 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
197 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
198 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
199 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
203 static void print_version (void)
206 static const char platform
[] = "i386";
207 #elif defined(__x86_64__)
208 static const char platform
[] = "x86_64";
209 #elif defined(__sparc__)
210 static const char platform
[] = "sparc";
211 #elif defined(__ALPHA__)
212 static const char platform
[] = "alpha";
213 #elif defined(__powerpc__)
214 static const char platform
[] = "powerpc";
219 const char *(CDECL
*wine_get_build_id
)(void);
220 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
221 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
222 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
224 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
225 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
227 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
228 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
229 report (R_FATAL
, "Can't get OS version.");
231 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
232 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
234 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
235 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
236 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
237 xprintf (" Submitter=%s\n", email
);
238 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
239 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
240 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
241 ver
.dwPlatformId
, ver
.szCSDVersion
);
243 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
244 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
245 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
246 if (wine_get_host_version
)
248 const char *sysname
, *release
;
249 wine_get_host_version( &sysname
, &release
);
250 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
252 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
254 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
258 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
259 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
260 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
261 ver
.wProductType
, ver
.wReserved
);
263 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
264 if (pGetProductInfo
&& !running_under_wine())
268 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
269 xprintf(" dwProductInfo=%u\n", prodtype
);
273 static inline int is_dot_dir(const char* x
)
275 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
278 static void remove_dir (const char *dir
)
283 size_t dirlen
= strlen (dir
);
285 /* Make sure the directory exists before going further */
286 memcpy (path
, dir
, dirlen
);
287 strcpy (path
+ dirlen
++, "\\*");
288 hFind
= FindFirstFile (path
, &wfd
);
289 if (hFind
== INVALID_HANDLE_VALUE
) return;
292 char *lp
= wfd
.cFileName
;
294 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
295 if (is_dot_dir (lp
)) continue;
296 strcpy (path
+ dirlen
, lp
);
297 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
299 else if (!DeleteFile (path
))
300 report (R_WARNING
, "Can't delete file %s: error %d",
301 path
, GetLastError ());
302 } while (FindNextFile (hFind
, &wfd
));
304 if (!RemoveDirectory (dir
))
305 report (R_WARNING
, "Can't remove directory %s: error %d",
306 dir
, GetLastError ());
309 static const char* get_test_source_file(const char* test
, const char* subtest
)
311 static const char* special_dirs
[][2] = {
314 static char buffer
[MAX_PATH
];
315 int i
, len
= strlen(test
);
317 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
319 len
= sprintf(buffer
, "programs/%s", test
) - 4;
322 else len
= sprintf(buffer
, "dlls/%s", test
);
324 for (i
= 0; special_dirs
[i
][0]; i
++) {
325 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
326 strcpy( buffer
, special_dirs
[i
][1] );
327 len
= strlen(buffer
);
332 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
336 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
342 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
343 !(*size
= SizeofResource (0, rsrc
)) ||
344 !(hdl
= LoadResource (0, rsrc
)) ||
345 !(addr
= LockResource (hdl
)))
350 /* Fills in the name and exename fields */
352 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
360 code
= extract_rcdata (res_name
, "TESTRES", &size
);
361 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
362 res_name
, GetLastError ());
363 test
->name
= heap_strdup( res_name
);
364 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
365 exepos
= strstr (test
->name
, testexe
);
366 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
368 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
369 report (R_STEP
, "Extracting: %s", test
->name
);
371 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
372 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
373 if (hfile
== INVALID_HANDLE_VALUE
)
374 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
376 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
377 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
382 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
384 DWORD wait
, diff
= 0, start
= GetTickCount();
387 while (diff
< timeout
)
389 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
390 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
391 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
392 diff
= GetTickCount() - start
;
397 static void append_path( const char *path
)
401 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
402 strcpy(newpath
, curpath
);
403 strcat(newpath
, ";");
404 strcat(newpath
, path
);
405 SetEnvironmentVariableA("PATH", newpath
);
410 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
413 Return the exit status, -2 if can't create process or the return
414 value of WaitForSingleObject.
417 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
420 PROCESS_INFORMATION pi
;
423 GetStartupInfo (&si
);
424 si
.dwFlags
= STARTF_USESTDHANDLES
;
425 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
426 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
427 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
429 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
430 NULL
, tempdir
, &si
, &pi
))
433 CloseHandle (pi
.hThread
);
434 status
= wait_process( pi
.hProcess
, ms
);
438 GetExitCodeProcess (pi
.hProcess
, &status
);
439 CloseHandle (pi
.hProcess
);
442 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
447 report (R_ERROR
, "Wait returned %d", status
);
450 if (!TerminateProcess (pi
.hProcess
, 257))
451 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
452 wait
= wait_process( pi
.hProcess
, 5000 );
458 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
461 report (R_ERROR
, "Can't kill process '%s'", cmd
);
464 report (R_ERROR
, "Waiting for termination: %d", wait
);
467 CloseHandle (pi
.hProcess
);
472 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
477 char buffer
[8192], *index
;
478 static const char header
[] = "Valid test names:";
479 int status
, allocated
;
480 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
481 SECURITY_ATTRIBUTES sa
;
483 test
->subtest_count
= 0;
485 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
486 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
487 report (R_FATAL
, "Can't name subtests file.");
489 /* make handle inheritable */
490 sa
.nLength
= sizeof(sa
);
491 sa
.lpSecurityDescriptor
= NULL
;
492 sa
.bInheritHandle
= TRUE
;
494 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
495 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
496 &sa
, CREATE_ALWAYS
, 0, NULL
);
498 if ((subfile
== INVALID_HANDLE_VALUE
) &&
499 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
500 /* FILE_SHARE_DELETE not supported on win9x */
501 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
502 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
503 &sa
, CREATE_ALWAYS
, 0, NULL
);
505 if (subfile
== INVALID_HANDLE_VALUE
) {
506 err
= GetLastError();
507 report (R_ERROR
, "Can't open subtests output of %s: %u",
508 test
->name
, GetLastError());
512 extract_test (test
, tempdir
, res_name
);
513 cmd
= strmake (NULL
, "%s --list", test
->exename
);
514 if (test
->maindllpath
) {
515 /* We need to add the path (to the main dll) to PATH */
516 append_path(test
->maindllpath
);
518 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
519 err
= GetLastError();
520 if (test
->maindllpath
) {
521 /* Restore PATH again */
522 SetEnvironmentVariableA("PATH", curpath
);
528 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
532 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
533 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
534 CloseHandle( subfile
);
535 if (sizeof buffer
== total
) {
536 report (R_ERROR
, "Subtest list of %s too big.",
537 test
->name
, sizeof buffer
);
538 err
= ERROR_OUTOFMEMORY
;
543 index
= strstr (buffer
, header
);
545 report (R_ERROR
, "Can't parse subtests output of %s",
547 err
= ERROR_INTERNAL_ERROR
;
550 index
+= sizeof header
;
553 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
554 index
= strtok (index
, whitespace
);
556 if (test
->subtest_count
== allocated
) {
558 test
->subtests
= heap_realloc (test
->subtests
,
559 allocated
* sizeof(char*));
561 if (!test_filtered_out( test
->name
, index
))
562 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
563 index
= strtok (NULL
, whitespace
);
565 test
->subtests
= heap_realloc (test
->subtests
,
566 test
->subtest_count
* sizeof(char*));
570 if (!DeleteFileA (subname
))
571 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
576 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
579 const char* file
= get_test_source_file(test
->name
, subtest
);
580 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
582 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
583 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
585 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
589 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
590 LPTSTR lpszName
, LONG_PTR lParam
)
592 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
596 static const struct clsid_mapping
602 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
603 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
607 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
609 const struct clsid_mapping
*mapping
;
611 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
613 if(!strcasecmp(name
, mapping
->name
))
615 *clsid
= mapping
->clsid
;
622 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
627 char dllname
[MAX_PATH
];
631 if(!get_main_clsid(name
, &clsid
)) return NULL
;
633 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
634 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
635 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
636 clsid
.Data4
[6], clsid
.Data4
[7]);
638 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
640 LONG size
= sizeof(dllname
);
641 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
643 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
645 strcpy( filename
, dllname
);
646 p
= strrchr(dllname
, '\\');
648 *path
= heap_strdup( dllname
);
657 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
659 char dllpath
[MAX_PATH
];
661 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
662 strcpy(filename
, dllpath
);
663 *strrchr(dllpath
, '\\') = '\0';
664 *path
= heap_strdup( dllpath
);
668 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
669 LPTSTR lpszName
, LONG_PTR lParam
)
671 const char *tempdir
= (const char *)lParam
;
672 char dllname
[MAX_PATH
];
673 char filename
[MAX_PATH
];
674 WCHAR dllnameW
[MAX_PATH
];
678 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
680 /* Check if the main dll is present on this system */
681 CharLowerA(lpszName
);
682 strcpy(dllname
, lpszName
);
683 *strstr(dllname
, testexe
) = 0;
685 wine_tests
[nr_of_files
].maindllpath
= NULL
;
686 strcpy(filename
, dllname
);
687 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
689 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
691 if (!dll
&& pLoadLibraryShim
)
693 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
694 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
696 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
698 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
705 xprintf (" %s=dll is missing\n", dllname
);
708 if (is_native_dll(dll
))
711 xprintf (" %s=load error Configured as native\n", dllname
);
717 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
719 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
720 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
725 xprintf (" %s=load error %u\n", dllname
, err
);
731 run_tests (char *logname
, char *outdir
)
734 char *strres
, *eol
, *nextline
;
736 SECURITY_ATTRIBUTES sa
;
737 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
740 /* Get the current PATH only once */
741 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
742 curpath
= heap_alloc(needed
);
743 GetEnvironmentVariableA("PATH", curpath
, needed
);
745 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
747 if (!GetTempPathA( MAX_PATH
, tmppath
))
748 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
751 static char tmpname
[MAX_PATH
];
752 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
753 report (R_FATAL
, "Can't name logfile.");
756 report (R_OUT
, logname
);
758 /* make handle inheritable */
759 sa
.nLength
= sizeof(sa
);
760 sa
.lpSecurityDescriptor
= NULL
;
761 sa
.bInheritHandle
= TRUE
;
763 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
764 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
765 &sa
, CREATE_ALWAYS
, 0, NULL
);
767 if ((logfile
== INVALID_HANDLE_VALUE
) &&
768 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
769 /* FILE_SHARE_DELETE not supported on win9x */
770 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
771 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
772 &sa
, CREATE_ALWAYS
, 0, NULL
);
774 if (logfile
== INVALID_HANDLE_VALUE
)
775 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
777 /* try stable path for ZoneAlarm */
779 strcpy( tempdir
, tmppath
);
780 strcat( tempdir
, "wct" );
782 if (!CreateDirectoryA( tempdir
, NULL
))
784 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
785 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
786 DeleteFileA( tempdir
);
787 if (!CreateDirectoryA( tempdir
, NULL
))
788 report (R_FATAL
, "Could not create directory: %s", tempdir
);
792 strcpy( tempdir
, outdir
);
794 report (R_DIR
, tempdir
);
796 xprintf ("Version 4\n");
797 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
798 xprintf ("Archive: -\n"); /* no longer used */
799 xprintf ("Tag: %s\n", tag
);
800 xprintf ("Build info:\n");
801 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
803 eol
= memchr (strres
, '\n', strsize
);
806 eol
= strres
+ strsize
;
808 strsize
-= eol
- strres
+ 1;
809 nextline
= strsize
?eol
+1:NULL
;
810 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
812 xprintf (" %.*s\n", eol
-strres
, strres
);
815 xprintf ("Operating system version:\n");
817 xprintf ("Dll info:\n" );
819 report (R_STATUS
, "Counting tests");
820 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
821 report (R_FATAL
, "Can't enumerate test files: %d",
823 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
825 /* Do this only once during extraction (and version checking) */
826 hmscoree
= LoadLibraryA("mscoree.dll");
827 pLoadLibraryShim
= NULL
;
829 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
831 report (R_STATUS
, "Extracting tests");
832 report (R_PROGRESS
, 0, nr_of_files
);
835 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
836 report (R_FATAL
, "Can't enumerate test files: %d",
839 FreeLibrary(hmscoree
);
841 xprintf ("Test output:\n" );
843 report (R_DELTA
, 0, "Extracting: Done");
846 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
848 report (R_STATUS
, "Running tests");
849 report (R_PROGRESS
, 1, nr_of_tests
);
850 for (i
= 0; i
< nr_of_files
; i
++) {
851 struct wine_test
*test
= wine_tests
+ i
;
854 if (test
->maindllpath
) {
855 /* We need to add the path (to the main dll) to PATH */
856 append_path(test
->maindllpath
);
859 for (j
= 0; j
< test
->subtest_count
; j
++) {
860 report (R_STEP
, "Running: %s:%s", test
->name
,
862 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
865 if (test
->maindllpath
) {
866 /* Restore PATH again */
867 SetEnvironmentVariableA("PATH", curpath
);
870 report (R_DELTA
, 0, "Running: Done");
872 report (R_STATUS
, "Cleaning up");
873 CloseHandle( logfile
);
876 remove_dir (tempdir
);
877 heap_free(wine_tests
);
883 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
885 if (ctrl_type
== CTRL_C_EVENT
) {
886 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
895 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
897 const char *target_dir
= (const char *)lParam
;
898 char filename
[MAX_PATH
];
900 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
902 strcpy(filename
, lpszName
);
903 CharLowerA(filename
);
905 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
910 static void extract_only (const char *target_dir
)
914 report (R_DIR
, target_dir
);
915 res
= CreateDirectoryA( target_dir
, NULL
);
916 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
917 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
920 report (R_STATUS
, "Counting tests");
921 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
922 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
924 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
926 report (R_STATUS
, "Extracting tests");
927 report (R_PROGRESS
, 0, nr_of_files
);
929 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
930 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
932 report (R_DELTA
, 0, "Extracting: Done");
939 "Usage: winetest [OPTION]... [TESTS]\n\n"
940 " --help print this message and exit\n"
941 " --version print the build version and exit\n"
942 " -c console mode, no GUI\n"
943 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
944 " -e preserve the environment\n"
945 " -h print this message and exit\n"
946 " -m MAIL an email address to enable developers to contact you\n"
947 " -p shutdown when the tests are done\n"
948 " -q quiet mode, no output at all\n"
949 " -o FILE put report into FILE, do not submit\n"
950 " -s FILE submit FILE, do not run tests\n"
951 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
952 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
955 int main( int argc
, char *argv
[] )
957 char *logname
= NULL
, *outdir
= NULL
;
958 const char *extract
= NULL
;
959 const char *cp
, *submit
= NULL
;
965 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
967 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
969 if (!strcmp(argv
[i
], "--help")) {
973 else if (!strcmp(argv
[i
], "--version")) {
974 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
977 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
978 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
980 report (R_ERROR
, "Too many test filters specified");
983 filters
[nb_filters
++] = argv
[i
];
985 else switch (argv
[i
][1]) {
998 if (!(email
= argv
[++i
]))
1012 if (!(submit
= argv
[++i
]))
1018 report (R_WARNING
, "ignoring tag for submission");
1022 if (!(logname
= argv
[++i
]))
1029 if (!(tag
= argv
[++i
]))
1034 if (strlen (tag
) > MAXTAGLEN
)
1035 report (R_FATAL
, "tag is too long (maximum %d characters)",
1037 cp
= findbadtagchar (tag
);
1039 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1045 report (R_TEXTMODE
);
1046 if (!(extract
= argv
[++i
]))
1049 extract_only (extract
);
1055 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1060 if (!submit
&& !extract
) {
1061 report (R_STATUS
, "Starting up");
1063 if (!running_on_visible_desktop ())
1064 report (R_FATAL
, "Tests must be run on a visible desktop");
1066 if (!check_mount_mgr())
1067 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1069 if (!check_display_driver())
1070 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1072 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1076 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1077 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1078 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1079 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1082 if (!nb_filters
) /* don't submit results when filtering */
1086 report (R_FATAL
, "Please specify a tag (-t option) if "
1087 "running noninteractive!");
1088 if (guiAskTag () == IDABORT
) exit (1);
1094 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1095 " to contact you about your report if necessary.");
1096 if (guiAskEmail () == IDABORT
) exit (1);
1100 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1101 "To submit results, winetest needs to be built from a git checkout." );
1105 logname
= run_tests (NULL
, outdir
);
1106 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1107 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1108 if (!send_file (logname
) && !DeleteFileA(logname
))
1109 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1110 } else run_tests (logname
, outdir
);
1111 report (R_STATUS
, "Finished");
1116 TOKEN_PRIVILEGES npr
;
1118 /* enable the shutdown privilege for the current process */
1119 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1121 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1122 npr
.PrivilegeCount
= 1;
1123 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1124 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1125 CloseHandle(hToken
);
1127 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);