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";
221 const char *(CDECL
*wine_get_build_id
)(void);
222 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
223 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
224 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
226 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
227 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
229 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
230 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
231 report (R_FATAL
, "Can't get OS version.");
233 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
234 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &wow64
)) wow64
= FALSE
;
236 xprintf (" Platform=%s%s\n", platform
, wow64
? " (WOW64)" : "");
237 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
238 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
239 xprintf (" Submitter=%s\n", email
);
240 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
241 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
242 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
243 ver
.dwPlatformId
, ver
.szCSDVersion
);
245 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
246 wine_get_host_version
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
247 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
248 if (wine_get_host_version
)
250 const char *sysname
, *release
;
251 wine_get_host_version( &sysname
, &release
);
252 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
254 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
256 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
260 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
261 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
262 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
263 ver
.wProductType
, ver
.wReserved
);
265 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
266 if (pGetProductInfo
&& !running_under_wine())
270 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
271 xprintf(" dwProductInfo=%u\n", prodtype
);
275 static inline int is_dot_dir(const char* x
)
277 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
280 static void remove_dir (const char *dir
)
285 size_t dirlen
= strlen (dir
);
287 /* Make sure the directory exists before going further */
288 memcpy (path
, dir
, dirlen
);
289 strcpy (path
+ dirlen
++, "\\*");
290 hFind
= FindFirstFile (path
, &wfd
);
291 if (hFind
== INVALID_HANDLE_VALUE
) return;
294 char *lp
= wfd
.cFileName
;
296 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
297 if (is_dot_dir (lp
)) continue;
298 strcpy (path
+ dirlen
, lp
);
299 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
301 else if (!DeleteFile (path
))
302 report (R_WARNING
, "Can't delete file %s: error %d",
303 path
, GetLastError ());
304 } while (FindNextFile (hFind
, &wfd
));
306 if (!RemoveDirectory (dir
))
307 report (R_WARNING
, "Can't remove directory %s: error %d",
308 dir
, GetLastError ());
311 static const char* get_test_source_file(const char* test
, const char* subtest
)
313 static const char* special_dirs
[][2] = {
316 static char buffer
[MAX_PATH
];
317 int i
, len
= strlen(test
);
319 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
321 len
= sprintf(buffer
, "programs/%s", test
) - 4;
324 else len
= sprintf(buffer
, "dlls/%s", test
);
326 for (i
= 0; special_dirs
[i
][0]; i
++) {
327 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
328 strcpy( buffer
, special_dirs
[i
][1] );
329 len
= strlen(buffer
);
334 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
338 static void* extract_rcdata (LPCTSTR name
, LPCTSTR type
, DWORD
* size
)
344 if (!(rsrc
= FindResource (NULL
, name
, type
)) ||
345 !(*size
= SizeofResource (0, rsrc
)) ||
346 !(hdl
= LoadResource (0, rsrc
)) ||
347 !(addr
= LockResource (hdl
)))
352 /* Fills in the name and exename fields */
354 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
362 code
= extract_rcdata (res_name
, "TESTRES", &size
);
363 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
364 res_name
, GetLastError ());
365 test
->name
= heap_strdup( res_name
);
366 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
367 exepos
= strstr (test
->name
, testexe
);
368 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
370 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
371 report (R_STEP
, "Extracting: %s", test
->name
);
373 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
374 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
375 if (hfile
== INVALID_HANDLE_VALUE
)
376 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
378 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
379 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
384 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
386 DWORD wait
, diff
= 0, start
= GetTickCount();
389 while (diff
< timeout
)
391 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
392 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
393 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
394 diff
= GetTickCount() - start
;
399 static void append_path( const char *path
)
403 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
404 strcpy(newpath
, curpath
);
405 strcat(newpath
, ";");
406 strcat(newpath
, path
);
407 SetEnvironmentVariableA("PATH", newpath
);
412 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
415 Return the exit status, -2 if can't create process or the return
416 value of WaitForSingleObject.
419 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
422 PROCESS_INFORMATION pi
;
425 GetStartupInfo (&si
);
426 si
.dwFlags
= STARTF_USESTDHANDLES
;
427 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
428 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
429 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
431 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
432 NULL
, tempdir
, &si
, &pi
))
435 CloseHandle (pi
.hThread
);
436 status
= wait_process( pi
.hProcess
, ms
);
440 GetExitCodeProcess (pi
.hProcess
, &status
);
441 CloseHandle (pi
.hProcess
);
444 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
449 report (R_ERROR
, "Wait returned %d", status
);
452 if (!TerminateProcess (pi
.hProcess
, 257))
453 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
454 wait
= wait_process( pi
.hProcess
, 5000 );
460 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
463 report (R_ERROR
, "Can't kill process '%s'", cmd
);
466 report (R_ERROR
, "Waiting for termination: %d", wait
);
469 CloseHandle (pi
.hProcess
);
474 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
479 char buffer
[8192], *index
;
480 static const char header
[] = "Valid test names:";
481 int status
, allocated
;
482 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
483 SECURITY_ATTRIBUTES sa
;
485 test
->subtest_count
= 0;
487 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
488 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
489 report (R_FATAL
, "Can't name subtests file.");
491 /* make handle inheritable */
492 sa
.nLength
= sizeof(sa
);
493 sa
.lpSecurityDescriptor
= NULL
;
494 sa
.bInheritHandle
= TRUE
;
496 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
497 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
498 &sa
, CREATE_ALWAYS
, 0, NULL
);
500 if ((subfile
== INVALID_HANDLE_VALUE
) &&
501 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
502 /* FILE_SHARE_DELETE not supported on win9x */
503 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
504 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
505 &sa
, CREATE_ALWAYS
, 0, NULL
);
507 if (subfile
== INVALID_HANDLE_VALUE
) {
508 err
= GetLastError();
509 report (R_ERROR
, "Can't open subtests output of %s: %u",
510 test
->name
, GetLastError());
514 extract_test (test
, tempdir
, res_name
);
515 cmd
= strmake (NULL
, "%s --list", test
->exename
);
516 if (test
->maindllpath
) {
517 /* We need to add the path (to the main dll) to PATH */
518 append_path(test
->maindllpath
);
520 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
521 err
= GetLastError();
522 if (test
->maindllpath
) {
523 /* Restore PATH again */
524 SetEnvironmentVariableA("PATH", curpath
);
530 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
534 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
535 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
536 CloseHandle( subfile
);
537 if (sizeof buffer
== total
) {
538 report (R_ERROR
, "Subtest list of %s too big.",
539 test
->name
, sizeof buffer
);
540 err
= ERROR_OUTOFMEMORY
;
545 index
= strstr (buffer
, header
);
547 report (R_ERROR
, "Can't parse subtests output of %s",
549 err
= ERROR_INTERNAL_ERROR
;
552 index
+= sizeof header
;
555 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
556 index
= strtok (index
, whitespace
);
558 if (test
->subtest_count
== allocated
) {
560 test
->subtests
= heap_realloc (test
->subtests
,
561 allocated
* sizeof(char*));
563 if (!test_filtered_out( test
->name
, index
))
564 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
565 index
= strtok (NULL
, whitespace
);
567 test
->subtests
= heap_realloc (test
->subtests
,
568 test
->subtest_count
* sizeof(char*));
572 if (!DeleteFileA (subname
))
573 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
578 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
581 const char* file
= get_test_source_file(test
->name
, subtest
);
582 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
584 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
585 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
587 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
591 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
592 LPTSTR lpszName
, LONG_PTR lParam
)
594 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
598 static const struct clsid_mapping
604 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
605 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
609 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
611 const struct clsid_mapping
*mapping
;
613 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
615 if(!strcasecmp(name
, mapping
->name
))
617 *clsid
= mapping
->clsid
;
624 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
629 char dllname
[MAX_PATH
];
633 if(!get_main_clsid(name
, &clsid
)) return NULL
;
635 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
636 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
637 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
638 clsid
.Data4
[6], clsid
.Data4
[7]);
640 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
642 LONG size
= sizeof(dllname
);
643 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
645 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
647 strcpy( filename
, dllname
);
648 p
= strrchr(dllname
, '\\');
650 *path
= heap_strdup( dllname
);
659 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
661 char dllpath
[MAX_PATH
];
663 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
664 strcpy(filename
, dllpath
);
665 *strrchr(dllpath
, '\\') = '\0';
666 *path
= heap_strdup( dllpath
);
670 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
671 LPTSTR lpszName
, LONG_PTR lParam
)
673 const char *tempdir
= (const char *)lParam
;
674 char dllname
[MAX_PATH
];
675 char filename
[MAX_PATH
];
676 WCHAR dllnameW
[MAX_PATH
];
680 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
682 /* Check if the main dll is present on this system */
683 CharLowerA(lpszName
);
684 strcpy(dllname
, lpszName
);
685 *strstr(dllname
, testexe
) = 0;
687 wine_tests
[nr_of_files
].maindllpath
= NULL
;
688 strcpy(filename
, dllname
);
689 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
691 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
693 if (!dll
&& pLoadLibraryShim
)
695 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
696 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
698 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
700 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
707 xprintf (" %s=dll is missing\n", dllname
);
710 if (is_native_dll(dll
))
713 xprintf (" %s=load error Configured as native\n", dllname
);
719 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
721 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
722 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
727 xprintf (" %s=load error %u\n", dllname
, err
);
733 run_tests (char *logname
, char *outdir
)
736 char *strres
, *eol
, *nextline
;
738 SECURITY_ATTRIBUTES sa
;
739 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
742 /* Get the current PATH only once */
743 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
744 curpath
= heap_alloc(needed
);
745 GetEnvironmentVariableA("PATH", curpath
, needed
);
747 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
749 if (!GetTempPathA( MAX_PATH
, tmppath
))
750 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
753 static char tmpname
[MAX_PATH
];
754 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
755 report (R_FATAL
, "Can't name logfile.");
758 report (R_OUT
, logname
);
760 /* make handle inheritable */
761 sa
.nLength
= sizeof(sa
);
762 sa
.lpSecurityDescriptor
= NULL
;
763 sa
.bInheritHandle
= TRUE
;
765 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
766 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
767 &sa
, CREATE_ALWAYS
, 0, NULL
);
769 if ((logfile
== INVALID_HANDLE_VALUE
) &&
770 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
771 /* FILE_SHARE_DELETE not supported on win9x */
772 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
773 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
774 &sa
, CREATE_ALWAYS
, 0, NULL
);
776 if (logfile
== INVALID_HANDLE_VALUE
)
777 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
779 /* try stable path for ZoneAlarm */
781 strcpy( tempdir
, tmppath
);
782 strcat( tempdir
, "wct" );
784 if (!CreateDirectoryA( tempdir
, NULL
))
786 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
787 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
788 DeleteFileA( tempdir
);
789 if (!CreateDirectoryA( tempdir
, NULL
))
790 report (R_FATAL
, "Could not create directory: %s", tempdir
);
794 strcpy( tempdir
, outdir
);
796 report (R_DIR
, tempdir
);
798 xprintf ("Version 4\n");
799 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
800 xprintf ("Archive: -\n"); /* no longer used */
801 xprintf ("Tag: %s\n", tag
);
802 xprintf ("Build info:\n");
803 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
805 eol
= memchr (strres
, '\n', strsize
);
808 eol
= strres
+ strsize
;
810 strsize
-= eol
- strres
+ 1;
811 nextline
= strsize
?eol
+1:NULL
;
812 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
814 xprintf (" %.*s\n", eol
-strres
, strres
);
817 xprintf ("Operating system version:\n");
819 xprintf ("Dll info:\n" );
821 report (R_STATUS
, "Counting tests");
822 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
823 report (R_FATAL
, "Can't enumerate test files: %d",
825 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
827 /* Do this only once during extraction (and version checking) */
828 hmscoree
= LoadLibraryA("mscoree.dll");
829 pLoadLibraryShim
= NULL
;
831 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
833 report (R_STATUS
, "Extracting tests");
834 report (R_PROGRESS
, 0, nr_of_files
);
837 if (!EnumResourceNames (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
838 report (R_FATAL
, "Can't enumerate test files: %d",
841 FreeLibrary(hmscoree
);
843 xprintf ("Test output:\n" );
845 report (R_DELTA
, 0, "Extracting: Done");
848 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
850 report (R_STATUS
, "Running tests");
851 report (R_PROGRESS
, 1, nr_of_tests
);
852 for (i
= 0; i
< nr_of_files
; i
++) {
853 struct wine_test
*test
= wine_tests
+ i
;
856 if (test
->maindllpath
) {
857 /* We need to add the path (to the main dll) to PATH */
858 append_path(test
->maindllpath
);
861 for (j
= 0; j
< test
->subtest_count
; j
++) {
862 report (R_STEP
, "Running: %s:%s", test
->name
,
864 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
867 if (test
->maindllpath
) {
868 /* Restore PATH again */
869 SetEnvironmentVariableA("PATH", curpath
);
872 report (R_DELTA
, 0, "Running: Done");
874 report (R_STATUS
, "Cleaning up");
875 CloseHandle( logfile
);
878 remove_dir (tempdir
);
879 heap_free(wine_tests
);
885 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
887 if (ctrl_type
== CTRL_C_EVENT
) {
888 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
897 extract_only_proc (HMODULE hModule
, LPCTSTR lpszType
, LPTSTR lpszName
, LONG_PTR lParam
)
899 const char *target_dir
= (const char *)lParam
;
900 char filename
[MAX_PATH
];
902 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
904 strcpy(filename
, lpszName
);
905 CharLowerA(filename
);
907 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
912 static void extract_only (const char *target_dir
)
916 report (R_DIR
, target_dir
);
917 res
= CreateDirectoryA( target_dir
, NULL
);
918 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
919 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
922 report (R_STATUS
, "Counting tests");
923 if (!EnumResourceNames (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
924 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
926 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
928 report (R_STATUS
, "Extracting tests");
929 report (R_PROGRESS
, 0, nr_of_files
);
931 if (!EnumResourceNames (NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
932 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
934 report (R_DELTA
, 0, "Extracting: Done");
941 "Usage: winetest [OPTION]... [TESTS]\n\n"
942 " --help print this message and exit\n"
943 " --version print the build version and exit\n"
944 " -c console mode, no GUI\n"
945 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
946 " -e preserve the environment\n"
947 " -h print this message and exit\n"
948 " -m MAIL an email address to enable developers to contact you\n"
949 " -p shutdown when the tests are done\n"
950 " -q quiet mode, no output at all\n"
951 " -o FILE put report into FILE, do not submit\n"
952 " -s FILE submit FILE, do not run tests\n"
953 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
954 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
957 int main( int argc
, char *argv
[] )
959 char *logname
= NULL
, *outdir
= NULL
;
960 const char *extract
= NULL
;
961 const char *cp
, *submit
= NULL
;
967 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
969 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
971 if (!strcmp(argv
[i
], "--help")) {
975 else if (!strcmp(argv
[i
], "--version")) {
976 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
979 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
980 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
982 report (R_ERROR
, "Too many test filters specified");
985 filters
[nb_filters
++] = argv
[i
];
987 else switch (argv
[i
][1]) {
1000 if (!(email
= argv
[++i
]))
1014 if (!(submit
= argv
[++i
]))
1020 report (R_WARNING
, "ignoring tag for submission");
1024 if (!(logname
= argv
[++i
]))
1031 if (!(tag
= argv
[++i
]))
1036 if (strlen (tag
) > MAXTAGLEN
)
1037 report (R_FATAL
, "tag is too long (maximum %d characters)",
1039 cp
= findbadtagchar (tag
);
1041 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1047 report (R_TEXTMODE
);
1048 if (!(extract
= argv
[++i
]))
1051 extract_only (extract
);
1057 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1062 if (!submit
&& !extract
) {
1063 report (R_STATUS
, "Starting up");
1065 if (!running_on_visible_desktop ())
1066 report (R_FATAL
, "Tests must be run on a visible desktop");
1068 if (!check_mount_mgr())
1069 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1071 if (!check_display_driver())
1072 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1074 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1078 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1079 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1080 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1081 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1084 if (!nb_filters
) /* don't submit results when filtering */
1088 report (R_FATAL
, "Please specify a tag (-t option) if "
1089 "running noninteractive!");
1090 if (guiAskTag () == IDABORT
) exit (1);
1096 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1097 " to contact you about your report if necessary.");
1098 if (guiAskEmail () == IDABORT
) exit (1);
1102 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1103 "To submit results, winetest needs to be built from a git checkout." );
1107 logname
= run_tests (NULL
, outdir
);
1108 if (build_id
[0] && !nb_filters
&& !nr_native_dlls
&&
1109 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1110 if (!send_file (logname
) && !DeleteFileA(logname
))
1111 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1112 } else run_tests (logname
, outdir
);
1113 report (R_STATUS
, "Finished");
1118 TOKEN_PRIVILEGES npr
;
1120 /* enable the shutdown privilege for the current process */
1121 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1123 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
1124 npr
.PrivilegeCount
= 1;
1125 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1126 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1127 CloseHandle(hToken
);
1129 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);