mf/tests: Test output type for WMA decoder DMO.
[wine.git] / programs / winetest / main.c
bloba939034e8b9747bc654921342770f10fdd6a1083
1 /*
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.
28 #define COBJMACROS
29 #include <stdio.h>
30 #include <assert.h>
31 #include <windows.h>
32 #include <commctrl.h>
33 #include <winternl.h>
34 #include <mshtml.h>
36 #include "winetest.h"
37 #include "resource.h"
39 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
40 #define SKIP_LIMIT 10
42 /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
43 #define FAILURES_LIMIT 50
45 /* Maximum output size for individual test */
46 #define MAX_OUTPUT_SIZE (32 * 1024)
48 struct wine_test
50 char *name;
51 int subtest_count;
52 char **subtests;
53 char *exename;
54 char *maindllpath;
57 char *tag = NULL;
58 char *description = NULL;
59 char *url = NULL;
60 char *email = NULL;
61 BOOL aborting = FALSE;
62 static struct wine_test *wine_tests;
63 static int nr_of_files, nr_of_tests, nr_of_skips;
64 static int nr_native_dlls;
65 static const char whitespace[] = " \t\r\n";
66 static const char testexe[] = "_test.exe";
67 static char build_id[64];
68 static BOOL is_wow64;
69 static int failures;
70 static int quiet_mode;
72 /* filters for running only specific tests */
73 static char **filters;
74 static unsigned int nb_filters;
75 static unsigned int alloc_filters;
76 static BOOL exclude_tests = FALSE;
78 /* Needed to check for .NET dlls */
79 static HMODULE hmscoree;
80 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
82 /* For SxS DLLs e.g. msvcr90 */
83 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
84 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
85 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
86 static void (WINAPI *pReleaseActCtx)(HANDLE);
88 /* To store the current PATH setting (related to .NET only provided dlls) */
89 static char *curpath;
91 /* check if test is being filtered out */
92 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
94 char *p, dllname[MAX_PATH];
95 unsigned int i, len;
97 strcpy( dllname, module );
98 CharLowerA( dllname );
99 p = strstr( dllname, testexe );
100 if (p) *p = 0;
101 len = strlen(dllname);
103 if (!nb_filters) return exclude_tests;
104 for (i = 0; i < nb_filters; i++)
106 if (!strncmp( dllname, filters[i], len ))
108 if (!filters[i][len]) return exclude_tests;
109 if (filters[i][len] != ':') continue;
110 if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
111 if (!testname && !exclude_tests) return FALSE;
114 return !exclude_tests;
117 static void add_filter( const char *name )
119 if (name[0] == '@')
121 char *p, *str, buffer[256];
122 FILE *f = fopen( name + 1, "rt" );
123 if (!f) return;
125 while (fgets( buffer, sizeof(buffer), f ))
127 p = buffer;
128 while (*p == ' ' || *p == '\t') p++;
129 if (*p == '#') continue;
130 str = p;
131 while (*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n') p++;
132 *p = 0;
133 add_filter( str );
135 fclose( f );
136 return;
139 if (nb_filters >= alloc_filters)
141 alloc_filters = max( alloc_filters * 2, 64 );
142 filters = xrealloc( filters, alloc_filters * sizeof(*filters) );
144 filters[nb_filters++] = xstrdup(name);
147 static HANDLE create_output_file( const char *name )
149 SECURITY_ATTRIBUTES sa;
150 HANDLE file;
152 /* make handle inheritable */
153 sa.nLength = sizeof(sa);
154 sa.lpSecurityDescriptor = NULL;
155 sa.bInheritHandle = TRUE;
157 file = CreateFileA( name, GENERIC_READ|GENERIC_WRITE,
158 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
159 &sa, CREATE_ALWAYS, 0, NULL );
161 if (file == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_PARAMETER)
163 /* FILE_SHARE_DELETE not supported on win9x */
164 file = CreateFileA( name, GENERIC_READ|GENERIC_WRITE,
165 FILE_SHARE_READ | FILE_SHARE_WRITE,
166 &sa, CREATE_ALWAYS, 0, NULL );
168 return file;
171 static HANDLE create_temp_file( char name[MAX_PATH] )
173 char tmpdir[MAX_PATH];
175 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
176 !GetTempFileNameA( tmpdir, "out", 0, name ))
177 report (R_FATAL, "Can't name temp file.");
179 return create_output_file( name );
182 static void close_temp_file( const char *name, HANDLE file )
184 CloseHandle( file );
185 DeleteFileA( name );
188 static char *flush_temp_file( const char *name, HANDLE file, DWORD *retsize )
190 DWORD size = SetFilePointer( file, 0, NULL, FILE_CURRENT );
191 char *buffer = xalloc( size + 1 );
193 SetFilePointer( file, 0, NULL, FILE_BEGIN );
194 if (!ReadFile( file, buffer, size, retsize, NULL )) *retsize = 0;
195 close_temp_file( name, file );
196 buffer[*retsize] = 0;
197 return buffer;
200 static char * get_file_version(char * file_name)
202 static char version[32];
203 DWORD size;
204 DWORD handle;
206 size = GetFileVersionInfoSizeA(file_name, &handle);
207 if (size) {
208 char * data = xalloc(size);
209 if (GetFileVersionInfoA(file_name, handle, size, data)) {
210 static const char backslash[] = "\\";
211 VS_FIXEDFILEINFO *pFixedVersionInfo;
212 UINT len;
213 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
214 sprintf(version, "%ld.%ld.%ld.%ld",
215 pFixedVersionInfo->dwFileVersionMS >> 16,
216 pFixedVersionInfo->dwFileVersionMS & 0xffff,
217 pFixedVersionInfo->dwFileVersionLS >> 16,
218 pFixedVersionInfo->dwFileVersionLS & 0xffff);
219 } else
220 sprintf(version, "version not found");
221 } else
222 sprintf(version, "version error %lu", GetLastError());
223 free(data);
224 } else if (GetLastError() == ERROR_FILE_NOT_FOUND)
225 sprintf(version, "dll is missing");
226 else
227 sprintf(version, "version not present %lu", GetLastError());
229 return version;
232 static BOOL running_under_wine (void)
234 HMODULE module = GetModuleHandleA("ntdll.dll");
236 if (!module) return FALSE;
237 return (GetProcAddress(module, "wine_server_call") != NULL);
240 static BOOL check_mount_mgr(void)
242 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
243 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
244 if (handle == INVALID_HANDLE_VALUE) return FALSE;
245 CloseHandle( handle );
246 return TRUE;
249 static BOOL check_wow64_registry(void)
251 char buffer[MAX_PATH];
252 DWORD type, size = MAX_PATH;
253 HKEY hkey;
254 BOOL ret;
256 if (!is_wow64) return TRUE;
257 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey ))
258 return FALSE;
259 ret = !RegQueryValueExA( hkey, "ProgramFilesDir (x86)", NULL, &type, (BYTE *)buffer, &size );
260 RegCloseKey( hkey );
261 return ret;
264 static BOOL check_display_driver(void)
266 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
267 0, 0, GetModuleHandleA(0), 0 );
268 if (!hwnd) return FALSE;
269 DestroyWindow( hwnd );
270 return TRUE;
273 static BOOL running_on_visible_desktop (void)
275 HWND desktop;
276 HMODULE huser32 = GetModuleHandleA("user32.dll");
277 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
278 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
280 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
281 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
283 desktop = GetDesktopWindow();
284 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
285 return IsWindowVisible(desktop);
287 if (pGetProcessWindowStation && pGetUserObjectInformationA)
289 DWORD len;
290 HWINSTA wstation;
291 USEROBJECTFLAGS uoflags;
293 wstation = pGetProcessWindowStation();
294 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
295 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
297 return IsWindowVisible(desktop);
300 static int running_as_admin (void)
302 PSID administrators = NULL;
303 SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
304 HANDLE token;
305 DWORD groups_size;
306 PTOKEN_GROUPS groups;
307 DWORD group_index;
309 /* Create a well-known SID for the Administrators group. */
310 if (! AllocateAndInitializeSid(&nt_authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
311 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
312 &administrators))
313 return -1;
315 /* Get the process token */
316 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
318 FreeSid(administrators);
319 return -1;
322 /* Get the group info from the token */
323 groups_size = 0;
324 GetTokenInformation(token, TokenGroups, NULL, 0, &groups_size);
325 groups = xalloc(groups_size);
326 if (! GetTokenInformation(token, TokenGroups, groups, groups_size, &groups_size))
328 free(groups);
329 CloseHandle(token);
330 FreeSid(administrators);
331 return -1;
333 CloseHandle(token);
335 /* Now check if the token groups include the Administrators group */
336 for (group_index = 0; group_index < groups->GroupCount; group_index++)
338 if (EqualSid(groups->Groups[group_index].Sid, administrators))
340 free(groups);
341 FreeSid(administrators);
342 return 1;
346 /* If we end up here we didn't find the Administrators group */
347 free(groups);
348 FreeSid(administrators);
349 return 0;
352 static int running_elevated (void)
354 HANDLE token;
355 TOKEN_ELEVATION elevation_info;
356 DWORD size;
358 /* Get the process token */
359 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
360 return -1;
362 /* Get the elevation info from the token */
363 if (! GetTokenInformation(token, TokenElevation, &elevation_info,
364 sizeof(TOKEN_ELEVATION), &size))
366 CloseHandle(token);
367 return -1;
369 CloseHandle(token);
371 return elevation_info.TokenIsElevated;
374 /* check for native dll when running under wine */
375 static BOOL is_native_dll( HMODULE module )
377 static const char builtin_signature[] = "Wine builtin DLL";
378 static const char fakedll_signature[] = "Wine placeholder DLL";
379 const IMAGE_DOS_HEADER *dos;
381 if (!running_under_wine()) return FALSE;
382 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
383 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
384 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
385 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
386 if (dos->e_lfanew >= sizeof(*dos) + 32)
388 if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) )) return FALSE;
389 if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
391 return TRUE;
395 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
396 * to install that component. To bypass this check we need to look at the version resource.
398 static BOOL is_stub_dll(const char *filename)
400 UINT size;
401 DWORD ver;
402 BOOL isstub = FALSE;
403 char *p, *data;
405 size = GetFileVersionInfoSizeA(filename, &ver);
406 if (!size) return FALSE;
408 data = xalloc(size);
409 if (GetFileVersionInfoA(filename, ver, size, data))
411 char buf[256];
413 sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
414 if (VerQueryValueA(data, buf, (void**)&p, &size))
415 isstub = !lstrcmpiA("wcodstub.dll", p);
417 free(data);
419 return isstub;
422 static int disable_crash_dialog(void)
424 HKEY key;
425 DWORD type, data, size;
426 int ret = 0;
428 if (RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &key )) return 0;
429 size = sizeof(data);
430 if (RegQueryValueExA( key, "ShowCrashDialog", NULL, &type, (BYTE *)&data, &size )) ret = 1;
431 else if (type != REG_DWORD || data) ret = 2;
432 data = 0;
433 RegSetValueExA( key, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&data, sizeof(data) );
434 RegCloseKey( key );
435 return ret;
438 static void restore_crash_dialog( int prev )
440 HKEY key;
441 DWORD data = 1;
443 if (!prev) return;
444 if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &key )) return;
445 if (prev == 1) RegDeleteKeyValueA( key, NULL, "ShowCrashDialog" );
446 else RegSetValueExA( key, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&data, sizeof(data) );
447 RegCloseKey( key );
450 static void print_version (void)
452 #ifdef __i386__
453 static const char platform[] = "i386";
454 #elif defined(__x86_64__)
455 static const char platform[] = "x86_64";
456 #elif defined(__arm__)
457 static const char platform[] = "arm";
458 #elif defined(__aarch64__)
459 static const char platform[] = "arm64";
460 #else
461 # error CPU unknown
462 #endif
463 OSVERSIONINFOEXA ver;
464 RTL_OSVERSIONINFOEXW rtlver;
465 BOOL ext;
466 int is_win2k3_r2, is_admin, is_elevated;
467 const char *(CDECL *wine_get_build_id)(void);
468 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
469 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
470 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
471 NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
473 ver.dwOSVersionInfoSize = sizeof(ver);
474 if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
476 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
477 if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
478 report (R_FATAL, "Can't get OS version.");
481 /* try to get non-faked values */
482 if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
484 rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
486 pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
487 pRtlGetVersion(&rtlver);
489 ver.dwMajorVersion = rtlver.dwMajorVersion;
490 ver.dwMinorVersion = rtlver.dwMinorVersion;
491 ver.dwBuildNumber = rtlver.dwBuildNumber;
492 ver.dwPlatformId = rtlver.dwPlatformId;
493 ver.wServicePackMajor = rtlver.wServicePackMajor;
494 ver.wServicePackMinor = rtlver.wServicePackMinor;
495 ver.wSuiteMask = rtlver.wSuiteMask;
496 ver.wProductType = rtlver.wProductType;
498 WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
501 xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
502 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
503 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
504 is_admin = running_as_admin ();
505 if (0 <= is_admin)
507 xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
508 is_elevated = running_elevated ();
509 if (0 <= is_elevated)
510 xprintf(", %s", is_elevated ? "elevated" : "not elevated");
511 xprintf ("\n");
513 if (email)
514 xprintf (" Submitter=%s\n", email );
515 if (description)
516 xprintf (" Description=%s\n", description );
517 if (url)
518 xprintf (" URL=%s\n", url );
519 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
520 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
521 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
522 ver.dwPlatformId, ver.szCSDVersion);
524 wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
525 wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
526 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
527 if (wine_get_host_version)
529 const char *sysname, *release;
530 wine_get_host_version( &sysname, &release );
531 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
533 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
534 if(is_win2k3_r2)
535 xprintf(" R2 build number=%d\n", is_win2k3_r2);
537 if (!ext) return;
539 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
540 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
541 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
542 ver.wProductType, ver.wReserved);
544 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
545 if (pGetProductInfo && !running_under_wine())
547 DWORD prodtype = 0;
549 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
550 xprintf(" dwProductInfo=%u\n", prodtype);
554 static void print_language(void)
556 HMODULE hkernel32;
557 BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
558 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
559 LANGID (WINAPI *pGetThreadUILanguage)(void);
561 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
562 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
563 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
565 hkernel32 = GetModuleHandleA("kernel32.dll");
566 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
567 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
568 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
570 if (pGetSystemPreferredUILanguages && !running_under_wine())
572 WCHAR langW[32];
573 ULONG num, size = ARRAY_SIZE(langW);
574 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
576 char lang[32], *p = lang;
577 WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
578 for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
579 xprintf (" SystemPreferredUILanguages=%s\n", lang);
582 if (pGetUserDefaultUILanguage)
583 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
584 if (pGetThreadUILanguage)
585 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
586 xprintf (" KeyboardLayout=%p\n", GetKeyboardLayout(0));
587 xprintf (" Country=%d\n", GetUserGeoID(GEOCLASS_NATION));
588 xprintf (" ACP=%d\n", GetACP());
591 static inline BOOL is_dot_dir(const char* x)
593 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
596 static void remove_dir (const char *dir)
598 HANDLE hFind;
599 WIN32_FIND_DATAA wfd;
600 char path[MAX_PATH];
601 size_t dirlen = strlen (dir);
603 /* Make sure the directory exists before going further */
604 memcpy (path, dir, dirlen);
605 strcpy (path + dirlen++, "\\*");
606 hFind = FindFirstFileA (path, &wfd);
607 if (hFind == INVALID_HANDLE_VALUE) return;
609 do {
610 char *lp = wfd.cFileName;
612 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
613 if (is_dot_dir (lp)) continue;
614 strcpy (path + dirlen, lp);
615 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
616 remove_dir(path);
617 else if (!DeleteFileA(path))
618 report (R_WARNING, "Can't delete file %s: error %d",
619 path, GetLastError ());
620 } while (FindNextFileA(hFind, &wfd));
621 FindClose (hFind);
622 if (!RemoveDirectoryA(dir))
623 report (R_WARNING, "Can't remove directory %s: error %d",
624 dir, GetLastError ());
627 static const char* get_test_source_file(const char* test, const char* subtest)
629 static char buffer[MAX_PATH];
630 int len = strlen(test);
632 if (len > 4 && !strcmp( test + len - 4, ".exe" ) &&
633 strcmp( test, "ntoskrnl.exe" )) /* the one exception! */
635 len = sprintf(buffer, "programs/%s", test) - 4;
636 buffer[len] = 0;
638 else len = sprintf(buffer, "dlls/%s", test);
640 sprintf(buffer + len, "/tests/%s.c", subtest);
641 return buffer;
644 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
646 HRSRC rsrc;
647 HGLOBAL hdl;
648 LPVOID addr;
650 if (!(rsrc = FindResourceA(NULL, name, type)) ||
651 !(*size = SizeofResource (0, rsrc)) ||
652 !(hdl = LoadResource (0, rsrc)) ||
653 !(addr = LockResource (hdl)))
654 return NULL;
655 return addr;
658 /* Fills in the name and exename fields */
659 static void
660 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
662 BYTE* code;
663 DWORD size;
664 char *exepos;
665 HANDLE hfile;
666 DWORD written;
668 code = extract_rcdata (res_name, "TESTRES", &size);
669 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
670 res_name, GetLastError ());
671 test->name = xstrdup( res_name );
672 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
673 exepos = strstr (test->name, testexe);
674 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
675 *exepos = 0;
676 test->name = xrealloc(test->name, exepos - test->name + 1);
677 report (R_STEP, "Extracting: %s", test->name);
679 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
680 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
681 if (hfile == INVALID_HANDLE_VALUE)
682 report (R_FATAL, "Failed to open file %s.", test->exename);
684 if (!WriteFile(hfile, code, size, &written, NULL))
685 report (R_FATAL, "Failed to write file %s.", test->exename);
687 CloseHandle(hfile);
690 static DWORD wait_process( HANDLE process, DWORD timeout )
692 DWORD wait, diff = 0, start = GetTickCount();
693 MSG msg;
695 while (diff < timeout)
697 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
698 if (wait != WAIT_OBJECT_0 + 1) return wait;
699 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
700 diff = GetTickCount() - start;
702 return WAIT_TIMEOUT;
705 static void append_path( const char *path)
707 char *newpath = strmake( NULL, "%s;%s", curpath, path );
708 SetEnvironmentVariableA("PATH", newpath);
709 free(newpath);
712 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
713 stdout to there.
715 Return the exit status, -2 if can't create process or the return
716 value of WaitForSingleObject.
718 static int
719 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritical, DWORD* pid)
721 STARTUPINFOA si;
722 PROCESS_INFORMATION pi;
723 DWORD wait, status, flags;
724 UINT old_errmode;
726 GetStartupInfoA (&si);
727 si.dwFlags = STARTF_USESTDHANDLES;
728 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
729 si.hStdOutput = out_file;
730 si.hStdError = out_file;
731 if (nocritical)
733 old_errmode = SetErrorMode(0);
734 SetErrorMode(old_errmode | SEM_FAILCRITICALERRORS);
735 flags = 0;
737 else
738 flags = CREATE_DEFAULT_ERROR_MODE;
740 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, flags,
741 NULL, tempdir, &si, &pi))
743 if (nocritical) SetErrorMode(old_errmode);
744 if (pid) *pid = 0;
745 return -2;
748 if (nocritical) SetErrorMode(old_errmode);
749 CloseHandle (pi.hThread);
750 if (pid) *pid = pi.dwProcessId;
751 status = wait_process( pi.hProcess, ms );
752 switch (status)
754 case WAIT_OBJECT_0:
755 GetExitCodeProcess (pi.hProcess, &status);
756 CloseHandle (pi.hProcess);
757 return status;
758 case WAIT_FAILED:
759 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
760 break;
761 case WAIT_TIMEOUT:
762 break;
763 default:
764 report (R_ERROR, "Wait returned %d", status);
765 break;
767 if (!TerminateProcess (pi.hProcess, 257))
768 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
769 wait = wait_process( pi.hProcess, 5000 );
770 switch (wait)
772 case WAIT_OBJECT_0:
773 break;
774 case WAIT_FAILED:
775 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
776 break;
777 case WAIT_TIMEOUT:
778 report (R_ERROR, "Can't kill process '%s'", cmd);
779 break;
780 default:
781 report (R_ERROR, "Waiting for termination: %d", wait);
782 break;
784 CloseHandle (pi.hProcess);
785 return status;
788 static DWORD
789 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
791 char *cmd;
792 HANDLE subfile;
793 DWORD err, total;
794 char *buffer, *index;
795 static const char header[] = "Valid test names:";
796 int status, allocated;
797 char subname[MAX_PATH];
799 test->subtest_count = 0;
801 subfile = create_temp_file( subname );
802 if (subfile == INVALID_HANDLE_VALUE) return GetLastError();
804 cmd = strmake (NULL, "%s --list", test->exename);
805 if (test->maindllpath) {
806 /* We need to add the path (to the main dll) to PATH */
807 append_path(test->maindllpath);
809 status = run_ex (cmd, subfile, tempdir, 5000, TRUE, NULL);
810 err = GetLastError();
811 if (test->maindllpath) {
812 /* Restore PATH again */
813 SetEnvironmentVariableA("PATH", curpath);
815 free(cmd);
817 if (status)
819 close_temp_file( subname, subfile );
820 return status == -2 ? err : status;
823 buffer = flush_temp_file( subname, subfile, &total );
824 index = strstr (buffer, header);
825 if (!index) {
826 report (R_ERROR, "Can't parse subtests output of %s",
827 test->name);
828 return ERROR_INTERNAL_ERROR;
830 index += sizeof header;
832 allocated = 10;
833 test->subtests = xalloc(allocated * sizeof(char*));
834 index = strtok (index, whitespace);
835 while (index) {
836 if (test->subtest_count == allocated) {
837 allocated *= 2;
838 test->subtests = xrealloc(test->subtests, allocated * sizeof(char*));
840 test->subtests[test->subtest_count++] = xstrdup(index);
841 index = strtok (NULL, whitespace);
843 test->subtests = xrealloc(test->subtests, test->subtest_count * sizeof(char*));
844 free( buffer );
845 return 0;
848 static void
849 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
851 /* Build the source filename so analysis tools can link to it */
852 const char* file = get_test_source_file(test->name, subtest);
854 if (test_filtered_out( test->name, subtest ))
856 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
857 xprintf ("%s:%s skipped %s\n", test->name, subtest, file);
858 nr_of_skips++;
860 else
862 int status;
863 DWORD pid, size, start = GetTickCount();
864 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
865 report (R_STEP, "Running: %s:%s", test->name, subtest);
866 xprintf ("%s:%s start %s\n", test->name, subtest, file);
867 /* Flush to disk so we know which test caused Windows to crash if it does */
868 FlushFileBuffers(out_file);
869 if (quiet_mode > 1)
871 char *data, tmpname[MAX_PATH];
872 HANDLE tmpfile = create_temp_file( tmpname );
873 status = run_ex (cmd, tmpfile, tempdir, 120000, FALSE, &pid);
874 data = flush_temp_file( tmpname, tmpfile, &size );
875 if (status || size > MAX_OUTPUT_SIZE) WriteFile( out_file, data, size, &size, NULL );
876 free( data );
878 else
880 DWORD start_size = GetFileSize( out_file, NULL );
881 status = run_ex (cmd, out_file, tempdir, 120000, FALSE, &pid);
882 size = GetFileSize( out_file, NULL ) - start_size;
884 if (status == -2) status = -GetLastError();
885 free(cmd);
886 xprintf ("%s:%s:%04x done (%d) in %ds %uB\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000, size);
887 if (size > MAX_OUTPUT_SIZE)
889 xprintf ("%s:%s:%04x The test prints too much data (%u bytes)\n", test->name, subtest, pid, size);
890 failures++;
892 else if (status) failures++;
894 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
897 static BOOL CALLBACK
898 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
899 LPSTR lpszName, LONG_PTR lParam)
901 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
902 return TRUE;
905 static const struct clsid_mapping
907 const char *name;
908 CLSID clsid;
909 } clsid_list[] =
911 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
912 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
916 static BOOL get_main_clsid(const char *name, CLSID *clsid)
918 const struct clsid_mapping *mapping;
920 for(mapping = clsid_list; mapping->name; mapping++)
922 if(!strcasecmp(name, mapping->name))
924 *clsid = mapping->clsid;
925 return TRUE;
928 return FALSE;
931 static HMODULE load_com_dll(const char *name, char **path, char *filename)
933 HMODULE dll = NULL;
934 HKEY hkey;
935 char keyname[100];
936 char dllname[MAX_PATH];
937 char *p;
938 CLSID clsid;
940 if(!get_main_clsid(name, &clsid)) return NULL;
942 sprintf(keyname, "CLSID\\{%08lx-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
943 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
944 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
945 clsid.Data4[6], clsid.Data4[7]);
947 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
949 LONG size = sizeof(dllname);
950 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
952 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
954 strcpy( filename, dllname );
955 p = strrchr(dllname, '\\');
956 if (p) *p = 0;
957 *path = xstrdup( dllname );
960 RegCloseKey(hkey);
963 return dll;
966 static void get_dll_path(HMODULE dll, char **path, char *filename)
968 char dllpath[MAX_PATH];
970 GetModuleFileNameA(dll, dllpath, MAX_PATH);
971 strcpy(filename, dllpath);
972 *strrchr(dllpath, '\\') = '\0';
973 *path = xstrdup( dllpath );
976 static BOOL CALLBACK
977 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
979 const char *tempdir = (const char *)lParam;
980 char dllname[MAX_PATH];
981 char filename[MAX_PATH];
982 WCHAR dllnameW[MAX_PATH];
983 HMODULE dll;
984 DWORD err;
985 HANDLE actctx;
986 ULONG_PTR cookie;
987 BOOL run;
989 if (aborting) return TRUE;
991 /* Check if the main dll is present on this system */
992 CharLowerA(lpszName);
993 strcpy(dllname, lpszName);
994 *strstr(dllname, testexe) = 0;
996 if (test_filtered_out( lpszName, NULL ))
998 nr_of_skips++;
999 if (exclude_tests) xprintf (" %s=skipped\n", dllname);
1000 return TRUE;
1002 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
1004 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
1005 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
1007 ACTCTXA actctxinfo;
1008 memset(&actctxinfo, 0, sizeof(ACTCTXA));
1009 actctxinfo.cbSize = sizeof(ACTCTXA);
1010 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
1011 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
1012 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
1013 actctx = pCreateActCtxA(&actctxinfo);
1014 if (actctx != INVALID_HANDLE_VALUE &&
1015 ! pActivateActCtx(actctx, &cookie))
1017 pReleaseActCtx(actctx);
1018 actctx = INVALID_HANDLE_VALUE;
1020 } else actctx = INVALID_HANDLE_VALUE;
1022 wine_tests[nr_of_files].maindllpath = NULL;
1023 strcpy(filename, dllname);
1024 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
1026 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
1028 if (!dll && pLoadLibraryShim)
1030 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
1031 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
1033 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
1034 FreeLibrary(dll);
1035 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
1037 else dll = 0;
1040 run = TRUE;
1041 if (dll)
1043 if (is_stub_dll(dllname))
1045 xprintf (" %s=dll is a stub\n", dllname);
1046 run = FALSE;
1048 else if (is_native_dll(dll))
1050 xprintf (" %s=dll is native\n", dllname);
1051 nr_native_dlls++;
1052 run = FALSE;
1054 FreeLibrary(dll);
1057 if (run)
1059 err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
1060 switch (err)
1062 case 0:
1063 xprintf (" %s=%s\n", dllname, get_file_version(filename));
1064 nr_of_tests += wine_tests[nr_of_files].subtest_count;
1065 nr_of_files++;
1066 break;
1067 case STATUS_DLL_NOT_FOUND:
1068 xprintf (" %s=dll is missing\n", dllname);
1069 /* or it is a side-by-side dll but the test has no manifest */
1070 break;
1071 case STATUS_ORDINAL_NOT_FOUND:
1072 xprintf (" %s=dll is missing an ordinal (%s)\n", dllname, get_file_version(filename));
1073 break;
1074 case STATUS_ENTRYPOINT_NOT_FOUND:
1075 xprintf (" %s=dll is missing an entrypoint (%s)\n", dllname, get_file_version(filename));
1076 break;
1077 case ERROR_SXS_CANT_GEN_ACTCTX:
1078 xprintf (" %s=dll is missing the requested side-by-side version\n", dllname);
1079 break;
1080 default:
1081 xprintf (" %s=load error %u\n", dllname, err);
1082 break;
1086 if (actctx != INVALID_HANDLE_VALUE)
1088 pDeactivateActCtx(0, cookie);
1089 pReleaseActCtx(actctx);
1091 return TRUE;
1094 static char *
1095 run_tests (char *logname, char *outdir)
1097 int i;
1098 char *strres, *eol, *nextline;
1099 DWORD strsize;
1100 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1101 BOOL newdir;
1102 DWORD needed;
1103 HMODULE kernel32;
1105 /* Get the current PATH only once */
1106 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1107 curpath = xalloc(needed);
1108 GetEnvironmentVariableA("PATH", curpath, needed);
1110 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1112 if (!GetTempPathA( MAX_PATH, tmppath ))
1113 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1115 if (logname)
1117 if (!strcmp(logname, "-")) logfile = GetStdHandle( STD_OUTPUT_HANDLE );
1118 else logfile = create_output_file( logname );
1120 else
1122 static char tmpname[MAX_PATH];
1123 logfile = create_temp_file( tmpname );
1124 logname = tmpname;
1126 report (R_OUT, "%s", logname);
1128 if (logfile == INVALID_HANDLE_VALUE)
1129 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1131 if (outdir)
1133 /* Get a full path so it is still valid after a chdir */
1134 GetFullPathNameA( outdir, ARRAY_SIZE(tempdir), tempdir, NULL );
1136 else
1138 strcpy( tempdir, tmppath );
1139 strcat( tempdir, "wct" ); /* try stable path for ZoneAlarm */
1141 newdir = CreateDirectoryA( tempdir, NULL );
1142 if (!newdir && !outdir)
1144 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1145 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1146 DeleteFileA( tempdir );
1147 newdir = CreateDirectoryA( tempdir, NULL );
1149 if (!newdir && (!outdir || GetLastError() != ERROR_ALREADY_EXISTS))
1150 report (R_FATAL, "Could not create directory %s (%d)", tempdir, GetLastError());
1152 report (R_DIR, "%s", tempdir);
1154 xprintf ("Version 4\n");
1155 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1156 xprintf ("Archive: -\n"); /* no longer used */
1157 xprintf ("Tag: %s\n", tag);
1158 xprintf ("Build info:\n");
1159 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1160 while (strres) {
1161 eol = memchr (strres, '\n', strsize);
1162 if (!eol) {
1163 nextline = NULL;
1164 eol = strres + strsize;
1165 } else {
1166 strsize -= eol - strres + 1;
1167 nextline = strsize?eol+1:NULL;
1168 if (eol > strres && *(eol-1) == '\r') eol--;
1170 xprintf (" %.*s\n", eol-strres, strres);
1171 strres = nextline;
1173 xprintf ("Operating system version:\n");
1174 print_version ();
1175 print_language ();
1176 xprintf ("Dll info:\n" );
1178 report (R_STATUS, "Counting tests");
1179 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1180 report (R_FATAL, "Can't enumerate test files: %d",
1181 GetLastError ());
1182 wine_tests = xalloc(nr_of_files * sizeof wine_tests[0]);
1184 /* Do this only once during extraction (and version checking) */
1185 hmscoree = LoadLibraryA("mscoree.dll");
1186 pLoadLibraryShim = NULL;
1187 if (hmscoree)
1188 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1189 kernel32 = GetModuleHandleA("kernel32.dll");
1190 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1191 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1192 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1193 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1195 report (R_STATUS, "Extracting tests");
1196 report (R_PROGRESS, 0, nr_of_files);
1197 nr_of_files = 0;
1198 nr_of_tests = 0;
1199 nr_of_skips = 0;
1200 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1201 report (R_FATAL, "Can't enumerate test files: %d",
1202 GetLastError ());
1204 FreeLibrary(hmscoree);
1206 if (aborting) return logname;
1208 xprintf ("Test output:\n" );
1210 report (R_DELTA, 0, "Extracting: Done");
1212 if (nr_native_dlls)
1213 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1215 report (R_STATUS, "Running tests");
1216 report (R_PROGRESS, 1, nr_of_tests);
1217 for (i = 0; i < nr_of_files; i++) {
1218 struct wine_test *test = wine_tests + i;
1219 int j;
1221 if (aborting) break;
1223 if (test->maindllpath) {
1224 /* We need to add the path (to the main dll) to PATH */
1225 append_path(test->maindllpath);
1228 for (j = 0; j < test->subtest_count; j++) {
1229 if (aborting) break;
1230 run_test (test, test->subtests[j], logfile, tempdir);
1233 if (test->maindllpath) {
1234 /* Restore PATH again */
1235 SetEnvironmentVariableA("PATH", curpath);
1238 report (R_DELTA, 0, "Running: Done");
1240 report (R_STATUS, "Cleaning up - %u failures", failures);
1241 if (strcmp(logname, "-") != 0) CloseHandle( logfile );
1242 logfile = 0;
1243 if (newdir)
1244 remove_dir (tempdir);
1245 free(wine_tests);
1246 free(curpath);
1248 return logname;
1251 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1253 if (ctrl_type == CTRL_C_EVENT) {
1254 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1255 return TRUE;
1258 return FALSE;
1262 static BOOL CALLBACK
1263 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1265 const char *target_dir = (const char *)lParam;
1266 char filename[MAX_PATH];
1268 if (test_filtered_out( lpszName, NULL )) return TRUE;
1270 strcpy(filename, lpszName);
1271 CharLowerA(filename);
1273 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1274 nr_of_files++;
1275 return TRUE;
1278 static void extract_only (const char *target_dir)
1280 BOOL res;
1282 report (R_DIR, target_dir);
1283 res = CreateDirectoryA( target_dir, NULL );
1284 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1285 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1287 nr_of_files = 0;
1288 report (R_STATUS, "Counting tests");
1289 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1290 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1292 wine_tests = xalloc(nr_of_files * sizeof wine_tests[0] );
1294 report (R_STATUS, "Extracting tests");
1295 report (R_PROGRESS, 0, nr_of_files);
1296 nr_of_files = 0;
1297 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1298 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1300 report (R_DELTA, 0, "Extracting: Done");
1303 static void
1304 usage (void)
1306 fprintf (stderr,
1307 "Usage: winetest [OPTION]... [TESTS]\n\n"
1308 " --help print this message and exit\n"
1309 " --version print the build version and exit\n"
1310 " -c console mode, no GUI\n"
1311 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1312 " -e preserve the environment\n"
1313 " -h print this message and exit\n"
1314 " -i INFO an optional description of the test platform\n"
1315 " -m MAIL an email address to enable developers to contact you\n"
1316 " -n exclude the specified tests\n"
1317 " -p shutdown when the tests are done\n"
1318 " -q quiet mode, no output at all\n"
1319 " -o FILE put report into FILE, do not submit\n"
1320 " -s FILE submit FILE, do not run tests\n"
1321 " -S URL URL to submit the results to\n"
1322 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1323 " -u URL include TestBot URL in the report\n"
1324 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1327 int __cdecl main( int argc, char *argv[] )
1329 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1330 char *logname = NULL, *outdir = NULL;
1331 const char *extract = NULL;
1332 const char *cp, *submit = NULL, *submiturl = NULL;
1333 int reset_env = 1;
1334 int poweroff = 0;
1335 int interactive = 1;
1336 int prev_crash_dialog = 0;
1337 int i;
1339 InitCommonControls();
1341 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1343 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1344 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1346 for (i = 1; i < argc && argv[i]; i++)
1348 if (!strcmp(argv[i], "--help")) {
1349 usage ();
1350 exit (0);
1352 else if (!strcmp(argv[i], "--version")) {
1353 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1354 exit (0);
1356 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1357 add_filter( argv[i] );
1359 else switch (argv[i][1]) {
1360 case 'c':
1361 report (R_TEXTMODE);
1362 interactive = 0;
1363 break;
1364 case 'e':
1365 reset_env = 0;
1366 break;
1367 case 'h':
1368 case '?':
1369 usage ();
1370 exit (0);
1371 case 'i':
1372 if (!(description = argv[++i]))
1374 usage();
1375 exit( 2 );
1377 break;
1378 case 'm':
1379 if (!(email = argv[++i]))
1381 usage();
1382 exit( 2 );
1384 break;
1385 case 'n':
1386 exclude_tests = TRUE;
1387 break;
1388 case 'p':
1389 poweroff = 1;
1390 break;
1391 case 'q':
1392 report (R_QUIET);
1393 interactive = 0;
1394 quiet_mode++;
1395 break;
1396 case 's':
1397 if (!(submit = argv[++i]))
1399 usage();
1400 exit( 2 );
1402 break;
1403 case 'S':
1404 if (!(submiturl = argv[++i]))
1406 usage();
1407 exit( 2 );
1409 break;
1410 case 'o':
1411 if (!(logname = argv[++i]))
1413 usage();
1414 exit( 2 );
1416 break;
1417 case 't':
1418 if (!(tag = argv[++i]))
1420 usage();
1421 exit( 2 );
1423 if (strlen (tag) > MAXTAGLEN)
1424 report (R_FATAL, "tag is too long (maximum %d characters)",
1425 MAXTAGLEN);
1426 cp = findbadtagchar (tag);
1427 if (cp) {
1428 report (R_ERROR, "invalid char in tag: %c", *cp);
1429 usage ();
1430 exit (2);
1432 break;
1433 case 'u':
1434 if (!(url = argv[++i]))
1436 usage();
1437 exit( 2 );
1439 break;
1440 case 'x':
1441 report (R_TEXTMODE);
1442 if (!(extract = argv[++i]))
1443 extract = ".\\wct";
1445 extract_only (extract);
1446 break;
1447 case 'd':
1448 outdir = argv[++i];
1449 break;
1450 default:
1451 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1452 usage ();
1453 exit (2);
1456 if (submit) {
1457 if (tag)
1458 report (R_WARNING, "ignoring tag for submission");
1459 send_file (submiturl, submit);
1461 } else if (!extract) {
1462 int is_win9x = (GetVersion() & 0x80000000) != 0;
1464 report (R_STATUS, "Starting up");
1466 if (is_win9x)
1467 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1469 if (!running_on_visible_desktop ())
1470 report (R_FATAL, "Tests must be run on a visible desktop");
1472 if (running_under_wine())
1474 if (!check_mount_mgr())
1475 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1477 if (!check_wow64_registry())
1478 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1480 if (!check_display_driver())
1481 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1483 if (!interactive) prev_crash_dialog = disable_crash_dialog();
1486 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1488 if (reset_env)
1490 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1491 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1492 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1493 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1496 if (nb_filters && !exclude_tests)
1498 run_tests( logname, outdir );
1499 exit( failures ? 3 : 0 );
1502 while (!tag) {
1503 if (!interactive)
1504 report (R_FATAL, "Please specify a tag (-t option) if "
1505 "running noninteractive!");
1506 if (guiAskTag () == IDABORT) exit (1);
1508 report (R_TAG);
1510 while (!email) {
1511 if (!interactive)
1513 if (url) break;
1514 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1515 " to contact you about your report if necessary.");
1517 if (guiAskEmail () == IDABORT) exit (1);
1520 if (!build_id[0])
1521 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1522 "To submit results, winetest needs to be built from a git checkout." );
1524 if (!logname) {
1525 logname = run_tests (NULL, outdir);
1526 if (aborting) {
1527 DeleteFileA(logname);
1528 exit (0);
1530 if (failures > FAILURES_LIMIT)
1531 report( R_WARNING,
1532 "%d tests failed. There is probably something broken with your setup.\n"
1533 "You need to address this before submitting results.", failures );
1535 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1536 !nr_native_dlls && !is_win9x &&
1537 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1539 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1540 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1541 else
1542 failures = 0; /* return success */
1545 else
1547 run_tests (logname, outdir);
1548 report (R_STATUS, "Finished - %u failures", failures);
1550 if (prev_crash_dialog) restore_crash_dialog( prev_crash_dialog );
1552 if (poweroff)
1554 HANDLE hToken;
1555 TOKEN_PRIVILEGES npr;
1557 /* enable the shutdown privilege for the current process */
1558 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1560 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1561 npr.PrivilegeCount = 1;
1562 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1563 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1564 CloseHandle(hToken);
1566 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1568 exit( failures ? 3 : 0 );