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"
51 static struct wine_test
*wine_tests
;
52 static int nr_of_files
, nr_of_tests
;
53 static int nr_native_dlls
;
54 static const char whitespace
[] = " \t\r\n";
55 static const char testexe
[] = "_test.exe";
56 static char build_id
[64];
58 /* filters for running only specific tests */
59 static char *filters
[64];
60 static unsigned int nb_filters
= 0;
62 /* Needed to check for .NET dlls */
63 static HMODULE hmscoree
;
64 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
66 /* To store the current PATH setting (related to .NET only provided dlls) */
69 /* check if test is being filtered out */
70 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
72 char *p
, dllname
[MAX_PATH
];
75 strcpy( dllname
, module
);
76 CharLowerA( dllname
);
77 p
= strstr( dllname
, testexe
);
79 len
= strlen(dllname
);
81 if (!nb_filters
) return FALSE
;
82 for (i
= 0; i
< nb_filters
; i
++)
84 if (!strncmp( dllname
, filters
[i
], len
))
86 if (!filters
[i
][len
]) return FALSE
;
87 if (filters
[i
][len
] != ':') continue;
88 if (!testname
|| !strcmp( testname
, &filters
[i
][len
+1] )) return FALSE
;
94 static char * get_file_version(char * file_name
)
96 static char version
[32];
100 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
102 char * data
= heap_alloc(size
);
104 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
105 static char backslash
[] = "\\";
106 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
108 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
109 sprintf(version
, "%d.%d.%d.%d",
110 pFixedVersionInfo
->dwFileVersionMS
>> 16,
111 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
112 pFixedVersionInfo
->dwFileVersionLS
>> 16,
113 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
115 sprintf(version
, "version not available");
117 sprintf(version
, "unknown");
120 sprintf(version
, "failed");
122 sprintf(version
, "version not available");
127 static int running_under_wine (void)
129 HMODULE module
= GetModuleHandleA("ntdll.dll");
131 if (!module
) return 0;
132 return (GetProcAddress(module
, "wine_server_call") != NULL
);
135 static int check_mount_mgr(void)
137 if (running_under_wine())
139 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
140 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
141 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
142 CloseHandle( handle
);
147 static int running_on_visible_desktop (void)
150 HMODULE huser32
= GetModuleHandle("user32.dll");
151 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
152 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
154 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
155 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
157 desktop
= GetDesktopWindow();
158 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
159 return IsWindowVisible(desktop
);
161 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
165 USEROBJECTFLAGS uoflags
;
167 wstation
= (HWINSTA
)pGetProcessWindowStation();
168 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
169 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
171 return IsWindowVisible(desktop
);
174 /* check for native dll when running under wine */
175 static BOOL
is_native_dll( HMODULE module
)
177 static const char fakedll_signature
[] = "Wine placeholder DLL";
178 const IMAGE_DOS_HEADER
*dos
;
180 if (!running_under_wine()) return FALSE
;
181 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
182 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
183 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
184 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
185 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
186 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
190 static void print_version (void)
193 static const char platform
[] = "i386";
194 #elif defined(__x86_64__)
195 static const char platform
[] = "x86_64";
196 #elif defined(__sparc__)
197 static const char platform
[] = "sparc";
198 #elif defined(__ALPHA__)
199 static const char platform
[] = "alpha";
200 #elif defined(__powerpc__)
201 static const char platform
[] = "powerpc";
206 const char *(CDECL
*wine_get_build_id
)(void);
207 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
208 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
209 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
211 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
212 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
214 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
215 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
216 report (R_FATAL
, "Can't get OS version.");
218 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
219 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
221 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
222 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
223 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
224 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
225 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
226 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
227 ver
.dwPlatformId
, ver
.szCSDVersion
);
229 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
230 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
231 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
232 if (wine_get_host_version
)
234 const char *sysname
, *release
;
235 wine_get_host_version( &sysname
, &release
);
236 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
238 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
240 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
244 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
245 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
246 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
247 ver
.wProductType
, ver
.wReserved
);
249 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
250 if (pGetProductInfo
&& !running_under_wine())
254 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
255 xprintf(" dwProductInfo=%u\n", prodtype
);
259 static inline int is_dot_dir(const char* x
)
261 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
264 static void remove_dir (const char *dir
)
269 size_t dirlen
= strlen (dir
);
271 /* Make sure the directory exists before going further */
272 memcpy (path
, dir
, dirlen
);
273 strcpy (path
+ dirlen
++, "\\*");
274 hFind
= FindFirstFile (path
, &wfd
);
275 if (hFind
== INVALID_HANDLE_VALUE
) return;
278 char *lp
= wfd
.cFileName
;
280 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
281 if (is_dot_dir (lp
)) continue;
282 strcpy (path
+ dirlen
, lp
);
283 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
285 else if (!DeleteFile (path
))
286 report (R_WARNING
, "Can't delete file %s: error %d",
287 path
, GetLastError ());
288 } while (FindNextFile (hFind
, &wfd
));
290 if (!RemoveDirectory (dir
))
291 report (R_WARNING
, "Can't remove directory %s: error %d",
292 dir
, GetLastError ());
295 static const char* get_test_source_file(const char* test
, const char* subtest
)
297 static const char* special_dirs
[][2] = {
300 static char buffer
[MAX_PATH
];
303 for (i
= 0; special_dirs
[i
][0]; i
++) {
304 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
305 test
= special_dirs
[i
][1];
310 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
314 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
320 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
321 !(*size
= SizeofResource (0, rsrc
)) ||
322 !(hdl
= LoadResource (0, rsrc
)) ||
323 !(addr
= LockResource (hdl
)))
328 /* Fills in the name and exename fields */
330 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
338 code
= extract_rcdata (res_name
, "TESTRES", &size
);
339 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
340 res_name
, GetLastError ());
341 test
->name
= heap_strdup( res_name
);
342 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
343 exepos
= strstr (test
->name
, testexe
);
344 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
346 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
347 report (R_STEP
, "Extracting: %s", test
->name
);
349 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
350 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
351 if (hfile
== INVALID_HANDLE_VALUE
)
352 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
354 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
355 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
360 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
362 DWORD wait
, diff
= 0, start
= GetTickCount();
365 while (diff
< timeout
)
367 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
368 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
369 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
370 diff
= GetTickCount() - start
;
375 static void append_path( const char *path
)
379 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
380 strcpy(newpath
, curpath
);
381 strcat(newpath
, ";");
382 strcat(newpath
, path
);
383 SetEnvironmentVariableA("PATH", newpath
);
388 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
391 Return the exit status, -2 if can't create process or the return
392 value of WaitForSingleObject.
395 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
398 PROCESS_INFORMATION pi
;
401 GetStartupInfo (&si
);
402 si
.dwFlags
= STARTF_USESTDHANDLES
;
403 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
404 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
405 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
407 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
408 NULL
, tempdir
, &si
, &pi
))
411 CloseHandle (pi
.hThread
);
412 status
= wait_process( pi
.hProcess
, ms
);
416 GetExitCodeProcess (pi
.hProcess
, &status
);
417 CloseHandle (pi
.hProcess
);
420 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
425 report (R_ERROR
, "Wait returned %d", status
);
428 if (!TerminateProcess (pi
.hProcess
, 257))
429 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
430 wait
= wait_process( pi
.hProcess
, 5000 );
436 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
439 report (R_ERROR
, "Can't kill process '%s'", cmd
);
442 report (R_ERROR
, "Waiting for termination: %d", wait
);
445 CloseHandle (pi
.hProcess
);
450 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
455 char buffer
[8192], *index
;
456 static const char header
[] = "Valid test names:";
457 int status
, allocated
;
458 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
459 SECURITY_ATTRIBUTES sa
;
461 test
->subtest_count
= 0;
463 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
464 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
465 report (R_FATAL
, "Can't name subtests file.");
467 /* make handle inheritable */
468 sa
.nLength
= sizeof(sa
);
469 sa
.lpSecurityDescriptor
= NULL
;
470 sa
.bInheritHandle
= TRUE
;
472 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
473 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
474 &sa
, CREATE_ALWAYS
, 0, NULL
);
476 if ((subfile
== INVALID_HANDLE_VALUE
) &&
477 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
478 /* FILE_SHARE_DELETE not supported on win9x */
479 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
480 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
481 &sa
, CREATE_ALWAYS
, 0, NULL
);
483 if (subfile
== INVALID_HANDLE_VALUE
) {
484 err
= GetLastError();
485 report (R_ERROR
, "Can't open subtests output of %s: %u",
486 test
->name
, GetLastError());
490 extract_test (test
, tempdir
, res_name
);
491 cmd
= strmake (NULL
, "%s --list", test
->exename
);
492 if (test
->maindllpath
) {
493 /* We need to add the path (to the main dll) to PATH */
494 append_path(test
->maindllpath
);
496 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
497 err
= GetLastError();
498 if (test
->maindllpath
) {
499 /* Restore PATH again */
500 SetEnvironmentVariableA("PATH", curpath
);
506 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
510 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
511 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
512 CloseHandle( subfile
);
513 if (sizeof buffer
== total
) {
514 report (R_ERROR
, "Subtest list of %s too big.",
515 test
->name
, sizeof buffer
);
516 err
= ERROR_OUTOFMEMORY
;
521 index
= strstr (buffer
, header
);
523 report (R_ERROR
, "Can't parse subtests output of %s",
525 err
= ERROR_INTERNAL_ERROR
;
528 index
+= sizeof header
;
531 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
532 index
= strtok (index
, whitespace
);
534 if (test
->subtest_count
== allocated
) {
536 test
->subtests
= heap_realloc (test
->subtests
,
537 allocated
* sizeof(char*));
539 if (!test_filtered_out( test
->name
, index
))
540 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
541 index
= strtok (NULL
, whitespace
);
543 test
->subtests
= heap_realloc (test
->subtests
,
544 test
->subtest_count
* sizeof(char*));
548 if (!DeleteFileA (subname
))
549 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
554 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
557 const char* file
= get_test_source_file(test
->name
, subtest
);
558 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
560 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
561 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
563 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
567 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
568 LPTSTR lpszName
, LONG_PTR lParam
)
570 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
574 static const struct clsid_mapping
580 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
581 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
585 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
587 const struct clsid_mapping
*mapping
;
589 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
591 if(!strcasecmp(name
, mapping
->name
))
593 *clsid
= mapping
->clsid
;
600 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
605 char dllname
[MAX_PATH
];
609 if(!get_main_clsid(name
, &clsid
)) return NULL
;
611 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
612 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
613 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
614 clsid
.Data4
[6], clsid
.Data4
[7]);
616 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
618 LONG size
= sizeof(dllname
);
619 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
621 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
623 strcpy( filename
, dllname
);
624 p
= strrchr(dllname
, '\\');
626 *path
= heap_strdup( dllname
);
635 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
637 char dllpath
[MAX_PATH
];
639 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
640 strcpy(filename
, dllpath
);
641 *strrchr(dllpath
, '\\') = '\0';
642 *path
= heap_strdup( dllpath
);
646 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
647 LPTSTR lpszName
, LONG_PTR lParam
)
649 const char *tempdir
= (const char *)lParam
;
650 char dllname
[MAX_PATH
];
651 char filename
[MAX_PATH
];
652 WCHAR dllnameW
[MAX_PATH
];
656 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
658 /* Check if the main dll is present on this system */
659 CharLowerA(lpszName
);
660 strcpy(dllname
, lpszName
);
661 *strstr(dllname
, testexe
) = 0;
663 wine_tests
[nr_of_files
].maindllpath
= NULL
;
664 strcpy(filename
, dllname
);
665 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
667 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
669 if (!dll
&& pLoadLibraryShim
)
671 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
672 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
674 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
676 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
683 xprintf (" %s=dll is missing\n", dllname
);
686 if (is_native_dll(dll
))
689 xprintf (" %s=load error Configured as native\n", dllname
);
695 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
697 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
698 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
703 xprintf (" %s=load error %u\n", dllname
, err
);
709 run_tests (char *logname
, char *outdir
)
712 char *strres
, *eol
, *nextline
;
714 SECURITY_ATTRIBUTES sa
;
715 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
718 /* Get the current PATH only once */
719 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
720 curpath
= heap_alloc(needed
);
721 GetEnvironmentVariableA("PATH", curpath
, needed
);
723 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
725 if (!GetTempPathA( MAX_PATH
, tmppath
))
726 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
729 static char tmpname
[MAX_PATH
];
730 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
731 report (R_FATAL
, "Can't name logfile.");
734 report (R_OUT
, logname
);
736 /* make handle inheritable */
737 sa
.nLength
= sizeof(sa
);
738 sa
.lpSecurityDescriptor
= NULL
;
739 sa
.bInheritHandle
= TRUE
;
741 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
742 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
743 &sa
, CREATE_ALWAYS
, 0, NULL
);
745 if ((logfile
== INVALID_HANDLE_VALUE
) &&
746 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
747 /* FILE_SHARE_DELETE not supported on win9x */
748 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
749 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
750 &sa
, CREATE_ALWAYS
, 0, NULL
);
752 if (logfile
== INVALID_HANDLE_VALUE
)
753 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
755 /* try stable path for ZoneAlarm */
757 strcpy( tempdir
, tmppath
);
758 strcat( tempdir
, "wct" );
760 if (!CreateDirectoryA( tempdir
, NULL
))
762 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
763 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
764 DeleteFileA( tempdir
);
765 if (!CreateDirectoryA( tempdir
, NULL
))
766 report (R_FATAL
, "Could not create directory: %s", tempdir
);
770 strcpy( tempdir
, outdir
);
772 report (R_DIR
, tempdir
);
774 xprintf ("Version 4\n");
775 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
776 xprintf ("Archive: -\n"); /* no longer used */
777 xprintf ("Tag: %s\n", tag
);
778 xprintf ("Build info:\n");
779 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
781 eol
= memchr (strres
, '\n', strsize
);
784 eol
= strres
+ strsize
;
786 strsize
-= eol
- strres
+ 1;
787 nextline
= strsize
?eol
+1:NULL
;
788 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
790 xprintf (" %.*s\n", eol
-strres
, strres
);
793 xprintf ("Operating system version:\n");
795 xprintf ("Dll info:\n" );
797 report (R_STATUS
, "Counting tests");
798 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
799 report (R_FATAL
, "Can't enumerate test files: %d",
801 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
803 /* Do this only once during extraction (and version checking) */
804 hmscoree
= LoadLibraryA("mscoree.dll");
805 pLoadLibraryShim
= NULL
;
807 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
809 report (R_STATUS
, "Extracting tests");
810 report (R_PROGRESS
, 0, nr_of_files
);
813 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
814 report (R_FATAL
, "Can't enumerate test files: %d",
817 FreeLibrary(hmscoree
);
819 xprintf ("Test output:\n" );
821 report (R_DELTA
, 0, "Extracting: Done");
824 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
826 report (R_STATUS
, "Running tests");
827 report (R_PROGRESS
, 1, nr_of_tests
);
828 for (i
= 0; i
< nr_of_files
; i
++) {
829 struct wine_test
*test
= wine_tests
+ i
;
832 if (test
->maindllpath
) {
833 /* We need to add the path (to the main dll) to PATH */
834 append_path(test
->maindllpath
);
837 for (j
= 0; j
< test
->subtest_count
; j
++) {
838 report (R_STEP
, "Running: %s:%s", test
->name
,
840 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
843 if (test
->maindllpath
) {
844 /* Restore PATH again */
845 SetEnvironmentVariableA("PATH", curpath
);
848 report (R_DELTA
, 0, "Running: Done");
850 report (R_STATUS
, "Cleaning up");
851 CloseHandle( logfile
);
854 remove_dir (tempdir
);
855 heap_free(wine_tests
);
861 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
863 if (ctrl_type
== CTRL_C_EVENT
) {
864 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
873 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
875 const char *target_dir
= (const char *)lParam
;
876 char filename
[MAX_PATH
];
878 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
880 strcpy(filename
, lpszName
);
881 CharLowerA(filename
);
883 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
888 static void extract_only (const char *target_dir
)
892 report (R_DIR
, target_dir
);
893 res
= CreateDirectoryA( target_dir
, NULL
);
894 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
895 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
898 report (R_STATUS
, "Counting tests");
899 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
900 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
902 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
904 report (R_STATUS
, "Extracting tests");
905 report (R_PROGRESS
, 0, nr_of_files
);
907 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
908 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
910 report (R_DELTA
, 0, "Extracting: Done");
917 "Usage: winetest [OPTION]... [TESTS]\n\n"
918 " --help print this message and exit\n"
919 " --version print the build version and exit\n"
920 " -c console mode, no GUI\n"
921 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
922 " -e preserve the environment\n"
923 " -h print this message and exit\n"
924 " -p shutdown when the tests are done\n"
925 " -q quiet mode, no output at all\n"
926 " -o FILE put report into FILE, do not submit\n"
927 " -s FILE submit FILE, do not run tests\n"
928 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
929 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
932 int main( int argc
, char *argv
[] )
934 char *logname
= NULL
, *outdir
= NULL
;
935 const char *extract
= NULL
;
936 const char *cp
, *submit
= NULL
;
942 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
944 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
946 if (!strcmp(argv
[i
], "--help")) {
950 else if (!strcmp(argv
[i
], "--version")) {
951 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
954 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
955 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
957 report (R_ERROR
, "Too many test filters specified");
960 filters
[nb_filters
++] = argv
[i
];
962 else switch (argv
[i
][1]) {
982 if (!(submit
= argv
[++i
]))
988 report (R_WARNING
, "ignoring tag for submission");
992 if (!(logname
= argv
[++i
]))
999 if (!(tag
= argv
[++i
]))
1004 if (strlen (tag
) > MAXTAGLEN
)
1005 report (R_FATAL
, "tag is too long (maximum %d characters)",
1007 cp
= findbadtagchar (tag
);
1009 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1015 report (R_TEXTMODE
);
1016 if (!(extract
= argv
[++i
]))
1019 extract_only (extract
);
1025 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1030 if (!submit
&& !extract
) {
1031 report (R_STATUS
, "Starting up");
1033 if (!running_on_visible_desktop ())
1034 report (R_FATAL
, "Tests must be run on a visible desktop");
1036 if (!check_mount_mgr())
1037 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly");
1039 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1043 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1044 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1045 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1046 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1049 if (!nb_filters
) /* don't submit results when filtering */
1053 report (R_FATAL
, "Please specify a tag (-t option) if "
1054 "running noninteractive!");
1055 if (guiAskTag () == IDABORT
) exit (1);
1060 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1061 "To submit results, winetest needs to be built from a git checkout." );
1065 logname
= run_tests (NULL
, outdir
);
1066 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1067 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1068 if (!send_file (logname
) && !DeleteFileA(logname
))
1069 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1070 } else run_tests (logname
, outdir
);
1071 report (R_STATUS
, "Finished");
1076 TOKEN_PRIVILEGES npr
;
1078 /* enable the shutdown privilege for the current process */
1079 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1081 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1082 npr
.PrivilegeCount
= 1;
1083 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1084 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1085 CloseHandle(hToken
);
1087 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);