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 running_on_visible_desktop (void)
151 HMODULE huser32
= GetModuleHandle("user32.dll");
152 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
153 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
155 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
156 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
158 desktop
= GetDesktopWindow();
159 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
160 return IsWindowVisible(desktop
);
162 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
166 USEROBJECTFLAGS uoflags
;
168 wstation
= (HWINSTA
)pGetProcessWindowStation();
169 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
170 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
172 return IsWindowVisible(desktop
);
175 /* check for native dll when running under wine */
176 static BOOL
is_native_dll( HMODULE module
)
178 static const char fakedll_signature
[] = "Wine placeholder DLL";
179 const IMAGE_DOS_HEADER
*dos
;
181 if (!running_under_wine()) return FALSE
;
182 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
183 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
184 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
185 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
186 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
187 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
191 static void print_version (void)
194 static const char platform
[] = "i386";
195 #elif defined(__x86_64__)
196 static const char platform
[] = "x86_64";
197 #elif defined(__sparc__)
198 static const char platform
[] = "sparc";
199 #elif defined(__ALPHA__)
200 static const char platform
[] = "alpha";
201 #elif defined(__powerpc__)
202 static const char platform
[] = "powerpc";
207 const char *(CDECL
*wine_get_build_id
)(void);
208 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
209 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
210 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
212 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
213 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
215 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
216 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
217 report (R_FATAL
, "Can't get OS version.");
219 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
220 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
222 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
223 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
224 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
225 xprintf (" Submitter=%s\n", email
);
226 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
227 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
228 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
229 ver
.dwPlatformId
, ver
.szCSDVersion
);
231 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
232 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
233 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
234 if (wine_get_host_version
)
236 const char *sysname
, *release
;
237 wine_get_host_version( &sysname
, &release
);
238 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
240 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
242 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
246 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
247 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
248 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
249 ver
.wProductType
, ver
.wReserved
);
251 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
252 if (pGetProductInfo
&& !running_under_wine())
256 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
257 xprintf(" dwProductInfo=%u\n", prodtype
);
261 static inline int is_dot_dir(const char* x
)
263 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
266 static void remove_dir (const char *dir
)
271 size_t dirlen
= strlen (dir
);
273 /* Make sure the directory exists before going further */
274 memcpy (path
, dir
, dirlen
);
275 strcpy (path
+ dirlen
++, "\\*");
276 hFind
= FindFirstFile (path
, &wfd
);
277 if (hFind
== INVALID_HANDLE_VALUE
) return;
280 char *lp
= wfd
.cFileName
;
282 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
283 if (is_dot_dir (lp
)) continue;
284 strcpy (path
+ dirlen
, lp
);
285 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
287 else if (!DeleteFile (path
))
288 report (R_WARNING
, "Can't delete file %s: error %d",
289 path
, GetLastError ());
290 } while (FindNextFile (hFind
, &wfd
));
292 if (!RemoveDirectory (dir
))
293 report (R_WARNING
, "Can't remove directory %s: error %d",
294 dir
, GetLastError ());
297 static const char* get_test_source_file(const char* test
, const char* subtest
)
299 static const char* special_dirs
[][2] = {
302 static char buffer
[MAX_PATH
];
303 int i
, len
= strlen(test
);
305 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
307 len
= sprintf(buffer
, "programs/%s", test
) - 4;
310 else len
= sprintf(buffer
, "dlls/%s", test
);
312 for (i
= 0; special_dirs
[i
][0]; i
++) {
313 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
314 strcpy( buffer
, special_dirs
[i
][1] );
315 len
= strlen(buffer
);
320 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
324 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
330 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
331 !(*size
= SizeofResource (0, rsrc
)) ||
332 !(hdl
= LoadResource (0, rsrc
)) ||
333 !(addr
= LockResource (hdl
)))
338 /* Fills in the name and exename fields */
340 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
348 code
= extract_rcdata (res_name
, "TESTRES", &size
);
349 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
350 res_name
, GetLastError ());
351 test
->name
= heap_strdup( res_name
);
352 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
353 exepos
= strstr (test
->name
, testexe
);
354 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
356 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
357 report (R_STEP
, "Extracting: %s", test
->name
);
359 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
360 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
361 if (hfile
== INVALID_HANDLE_VALUE
)
362 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
364 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
365 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
370 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
372 DWORD wait
, diff
= 0, start
= GetTickCount();
375 while (diff
< timeout
)
377 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
378 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
379 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
380 diff
= GetTickCount() - start
;
385 static void append_path( const char *path
)
389 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
390 strcpy(newpath
, curpath
);
391 strcat(newpath
, ";");
392 strcat(newpath
, path
);
393 SetEnvironmentVariableA("PATH", newpath
);
398 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
401 Return the exit status, -2 if can't create process or the return
402 value of WaitForSingleObject.
405 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
408 PROCESS_INFORMATION pi
;
411 GetStartupInfo (&si
);
412 si
.dwFlags
= STARTF_USESTDHANDLES
;
413 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
414 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
415 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
417 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
418 NULL
, tempdir
, &si
, &pi
))
421 CloseHandle (pi
.hThread
);
422 status
= wait_process( pi
.hProcess
, ms
);
426 GetExitCodeProcess (pi
.hProcess
, &status
);
427 CloseHandle (pi
.hProcess
);
430 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
435 report (R_ERROR
, "Wait returned %d", status
);
438 if (!TerminateProcess (pi
.hProcess
, 257))
439 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
440 wait
= wait_process( pi
.hProcess
, 5000 );
446 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
449 report (R_ERROR
, "Can't kill process '%s'", cmd
);
452 report (R_ERROR
, "Waiting for termination: %d", wait
);
455 CloseHandle (pi
.hProcess
);
460 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
465 char buffer
[8192], *index
;
466 static const char header
[] = "Valid test names:";
467 int status
, allocated
;
468 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
469 SECURITY_ATTRIBUTES sa
;
471 test
->subtest_count
= 0;
473 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
474 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
475 report (R_FATAL
, "Can't name subtests file.");
477 /* make handle inheritable */
478 sa
.nLength
= sizeof(sa
);
479 sa
.lpSecurityDescriptor
= NULL
;
480 sa
.bInheritHandle
= TRUE
;
482 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
483 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
484 &sa
, CREATE_ALWAYS
, 0, NULL
);
486 if ((subfile
== INVALID_HANDLE_VALUE
) &&
487 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
488 /* FILE_SHARE_DELETE not supported on win9x */
489 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
490 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
491 &sa
, CREATE_ALWAYS
, 0, NULL
);
493 if (subfile
== INVALID_HANDLE_VALUE
) {
494 err
= GetLastError();
495 report (R_ERROR
, "Can't open subtests output of %s: %u",
496 test
->name
, GetLastError());
500 extract_test (test
, tempdir
, res_name
);
501 cmd
= strmake (NULL
, "%s --list", test
->exename
);
502 if (test
->maindllpath
) {
503 /* We need to add the path (to the main dll) to PATH */
504 append_path(test
->maindllpath
);
506 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
507 err
= GetLastError();
508 if (test
->maindllpath
) {
509 /* Restore PATH again */
510 SetEnvironmentVariableA("PATH", curpath
);
516 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
520 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
521 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
522 CloseHandle( subfile
);
523 if (sizeof buffer
== total
) {
524 report (R_ERROR
, "Subtest list of %s too big.",
525 test
->name
, sizeof buffer
);
526 err
= ERROR_OUTOFMEMORY
;
531 index
= strstr (buffer
, header
);
533 report (R_ERROR
, "Can't parse subtests output of %s",
535 err
= ERROR_INTERNAL_ERROR
;
538 index
+= sizeof header
;
541 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
542 index
= strtok (index
, whitespace
);
544 if (test
->subtest_count
== allocated
) {
546 test
->subtests
= heap_realloc (test
->subtests
,
547 allocated
* sizeof(char*));
549 if (!test_filtered_out( test
->name
, index
))
550 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
551 index
= strtok (NULL
, whitespace
);
553 test
->subtests
= heap_realloc (test
->subtests
,
554 test
->subtest_count
* sizeof(char*));
558 if (!DeleteFileA (subname
))
559 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
564 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
567 const char* file
= get_test_source_file(test
->name
, subtest
);
568 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
570 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
571 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
573 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
577 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
578 LPTSTR lpszName
, LONG_PTR lParam
)
580 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
584 static const struct clsid_mapping
590 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
591 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
595 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
597 const struct clsid_mapping
*mapping
;
599 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
601 if(!strcasecmp(name
, mapping
->name
))
603 *clsid
= mapping
->clsid
;
610 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
615 char dllname
[MAX_PATH
];
619 if(!get_main_clsid(name
, &clsid
)) return NULL
;
621 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
622 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
623 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
624 clsid
.Data4
[6], clsid
.Data4
[7]);
626 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
628 LONG size
= sizeof(dllname
);
629 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
631 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
633 strcpy( filename
, dllname
);
634 p
= strrchr(dllname
, '\\');
636 *path
= heap_strdup( dllname
);
645 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
647 char dllpath
[MAX_PATH
];
649 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
650 strcpy(filename
, dllpath
);
651 *strrchr(dllpath
, '\\') = '\0';
652 *path
= heap_strdup( dllpath
);
656 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
657 LPTSTR lpszName
, LONG_PTR lParam
)
659 const char *tempdir
= (const char *)lParam
;
660 char dllname
[MAX_PATH
];
661 char filename
[MAX_PATH
];
662 WCHAR dllnameW
[MAX_PATH
];
666 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
668 /* Check if the main dll is present on this system */
669 CharLowerA(lpszName
);
670 strcpy(dllname
, lpszName
);
671 *strstr(dllname
, testexe
) = 0;
673 wine_tests
[nr_of_files
].maindllpath
= NULL
;
674 strcpy(filename
, dllname
);
675 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
677 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
679 if (!dll
&& pLoadLibraryShim
)
681 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
682 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
684 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
686 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
693 xprintf (" %s=dll is missing\n", dllname
);
696 if (is_native_dll(dll
))
699 xprintf (" %s=load error Configured as native\n", dllname
);
705 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
707 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
708 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
713 xprintf (" %s=load error %u\n", dllname
, err
);
719 run_tests (char *logname
, char *outdir
)
722 char *strres
, *eol
, *nextline
;
724 SECURITY_ATTRIBUTES sa
;
725 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
728 /* Get the current PATH only once */
729 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
730 curpath
= heap_alloc(needed
);
731 GetEnvironmentVariableA("PATH", curpath
, needed
);
733 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
735 if (!GetTempPathA( MAX_PATH
, tmppath
))
736 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
739 static char tmpname
[MAX_PATH
];
740 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
741 report (R_FATAL
, "Can't name logfile.");
744 report (R_OUT
, logname
);
746 /* make handle inheritable */
747 sa
.nLength
= sizeof(sa
);
748 sa
.lpSecurityDescriptor
= NULL
;
749 sa
.bInheritHandle
= TRUE
;
751 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
752 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
753 &sa
, CREATE_ALWAYS
, 0, NULL
);
755 if ((logfile
== INVALID_HANDLE_VALUE
) &&
756 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
757 /* FILE_SHARE_DELETE not supported on win9x */
758 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
759 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
760 &sa
, CREATE_ALWAYS
, 0, NULL
);
762 if (logfile
== INVALID_HANDLE_VALUE
)
763 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
765 /* try stable path for ZoneAlarm */
767 strcpy( tempdir
, tmppath
);
768 strcat( tempdir
, "wct" );
770 if (!CreateDirectoryA( tempdir
, NULL
))
772 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
773 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
774 DeleteFileA( tempdir
);
775 if (!CreateDirectoryA( tempdir
, NULL
))
776 report (R_FATAL
, "Could not create directory: %s", tempdir
);
780 strcpy( tempdir
, outdir
);
782 report (R_DIR
, tempdir
);
784 xprintf ("Version 4\n");
785 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
786 xprintf ("Archive: -\n"); /* no longer used */
787 xprintf ("Tag: %s\n", tag
);
788 xprintf ("Build info:\n");
789 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
791 eol
= memchr (strres
, '\n', strsize
);
794 eol
= strres
+ strsize
;
796 strsize
-= eol
- strres
+ 1;
797 nextline
= strsize
?eol
+1:NULL
;
798 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
800 xprintf (" %.*s\n", eol
-strres
, strres
);
803 xprintf ("Operating system version:\n");
805 xprintf ("Dll info:\n" );
807 report (R_STATUS
, "Counting tests");
808 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
809 report (R_FATAL
, "Can't enumerate test files: %d",
811 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
813 /* Do this only once during extraction (and version checking) */
814 hmscoree
= LoadLibraryA("mscoree.dll");
815 pLoadLibraryShim
= NULL
;
817 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
819 report (R_STATUS
, "Extracting tests");
820 report (R_PROGRESS
, 0, nr_of_files
);
823 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
824 report (R_FATAL
, "Can't enumerate test files: %d",
827 FreeLibrary(hmscoree
);
829 xprintf ("Test output:\n" );
831 report (R_DELTA
, 0, "Extracting: Done");
834 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
836 report (R_STATUS
, "Running tests");
837 report (R_PROGRESS
, 1, nr_of_tests
);
838 for (i
= 0; i
< nr_of_files
; i
++) {
839 struct wine_test
*test
= wine_tests
+ i
;
842 if (test
->maindllpath
) {
843 /* We need to add the path (to the main dll) to PATH */
844 append_path(test
->maindllpath
);
847 for (j
= 0; j
< test
->subtest_count
; j
++) {
848 report (R_STEP
, "Running: %s:%s", test
->name
,
850 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
853 if (test
->maindllpath
) {
854 /* Restore PATH again */
855 SetEnvironmentVariableA("PATH", curpath
);
858 report (R_DELTA
, 0, "Running: Done");
860 report (R_STATUS
, "Cleaning up");
861 CloseHandle( logfile
);
864 remove_dir (tempdir
);
865 heap_free(wine_tests
);
871 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
873 if (ctrl_type
== CTRL_C_EVENT
) {
874 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
883 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
885 const char *target_dir
= (const char *)lParam
;
886 char filename
[MAX_PATH
];
888 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
890 strcpy(filename
, lpszName
);
891 CharLowerA(filename
);
893 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
898 static void extract_only (const char *target_dir
)
902 report (R_DIR
, target_dir
);
903 res
= CreateDirectoryA( target_dir
, NULL
);
904 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
905 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
908 report (R_STATUS
, "Counting tests");
909 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
910 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
912 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
914 report (R_STATUS
, "Extracting tests");
915 report (R_PROGRESS
, 0, nr_of_files
);
917 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
918 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
920 report (R_DELTA
, 0, "Extracting: Done");
927 "Usage: winetest [OPTION]... [TESTS]\n\n"
928 " --help print this message and exit\n"
929 " --version print the build version and exit\n"
930 " -c console mode, no GUI\n"
931 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
932 " -e preserve the environment\n"
933 " -h print this message and exit\n"
934 " -m MAIL an email address to enable developers to contact you\n"
935 " -p shutdown when the tests are done\n"
936 " -q quiet mode, no output at all\n"
937 " -o FILE put report into FILE, do not submit\n"
938 " -s FILE submit FILE, do not run tests\n"
939 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
940 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
943 int main( int argc
, char *argv
[] )
945 char *logname
= NULL
, *outdir
= NULL
;
946 const char *extract
= NULL
;
947 const char *cp
, *submit
= NULL
;
953 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
955 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
957 if (!strcmp(argv
[i
], "--help")) {
961 else if (!strcmp(argv
[i
], "--version")) {
962 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
965 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
966 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
968 report (R_ERROR
, "Too many test filters specified");
971 filters
[nb_filters
++] = argv
[i
];
973 else switch (argv
[i
][1]) {
986 if (!(email
= argv
[++i
]))
1000 if (!(submit
= argv
[++i
]))
1006 report (R_WARNING
, "ignoring tag for submission");
1010 if (!(logname
= argv
[++i
]))
1017 if (!(tag
= argv
[++i
]))
1022 if (strlen (tag
) > MAXTAGLEN
)
1023 report (R_FATAL
, "tag is too long (maximum %d characters)",
1025 cp
= findbadtagchar (tag
);
1027 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1033 report (R_TEXTMODE
);
1034 if (!(extract
= argv
[++i
]))
1037 extract_only (extract
);
1043 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1048 if (!submit
&& !extract
) {
1049 report (R_STATUS
, "Starting up");
1051 if (!running_on_visible_desktop ())
1052 report (R_FATAL
, "Tests must be run on a visible desktop");
1054 if (!check_mount_mgr())
1055 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly");
1057 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1061 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1062 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1063 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1064 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1067 if (!nb_filters
) /* don't submit results when filtering */
1071 report (R_FATAL
, "Please specify a tag (-t option) if "
1072 "running noninteractive!");
1073 if (guiAskTag () == IDABORT
) exit (1);
1079 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1080 " to contact you about your report if necessary.");
1081 if (guiAskEmail () == IDABORT
) exit (1);
1085 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1086 "To submit results, winetest needs to be built from a git checkout." );
1090 logname
= run_tests (NULL
, outdir
);
1091 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1092 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1093 if (!send_file (logname
) && !DeleteFileA(logname
))
1094 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1095 } else run_tests (logname
, outdir
);
1096 report (R_STATUS
, "Finished");
1101 TOKEN_PRIVILEGES npr
;
1103 /* enable the shutdown privilege for the current process */
1104 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1106 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1107 npr
.PrivilegeCount
= 1;
1108 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1109 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1110 CloseHandle(hToken
);
1112 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);