hidclass.sys: Pass sizeof(packet) as input for IOCTL_HID_SET_OUTPUT_REPORT.
[wine.git] / programs / winetest / main.c
blob7ced565447bd0de30d4c39089a8ed47c7bb96118
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 struct wine_test
47 char *name;
48 int subtest_count;
49 char **subtests;
50 char *exename;
51 char *maindllpath;
54 char *tag = NULL;
55 char *description = NULL;
56 char *url = NULL;
57 char *email = NULL;
58 BOOL aborting = FALSE;
59 static struct wine_test *wine_tests;
60 static int nr_of_files, nr_of_tests, nr_of_skips;
61 static int nr_native_dlls;
62 static const char whitespace[] = " \t\r\n";
63 static const char testexe[] = "_test.exe";
64 static char build_id[64];
65 static BOOL is_wow64;
66 static int failures;
68 /* filters for running only specific tests */
69 static char *filters[64];
70 static unsigned int nb_filters = 0;
71 static BOOL exclude_tests = FALSE;
73 /* Needed to check for .NET dlls */
74 static HMODULE hmscoree;
75 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
77 /* For SxS DLLs e.g. msvcr90 */
78 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
79 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
80 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
81 static void (WINAPI *pReleaseActCtx)(HANDLE);
83 /* To store the current PATH setting (related to .NET only provided dlls) */
84 static char *curpath;
86 /* check if test is being filtered out */
87 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
89 char *p, dllname[MAX_PATH];
90 unsigned int i, len;
92 strcpy( dllname, module );
93 CharLowerA( dllname );
94 p = strstr( dllname, testexe );
95 if (p) *p = 0;
96 len = strlen(dllname);
98 if (!nb_filters) return exclude_tests;
99 for (i = 0; i < nb_filters; i++)
101 if (!strncmp( dllname, filters[i], len ))
103 if (!filters[i][len]) return exclude_tests;
104 if (filters[i][len] != ':') continue;
105 if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
106 if (!testname && !exclude_tests) return FALSE;
109 return !exclude_tests;
112 static char * get_file_version(char * file_name)
114 static char version[32];
115 DWORD size;
116 DWORD handle;
118 size = GetFileVersionInfoSizeA(file_name, &handle);
119 if (size) {
120 char * data = heap_alloc(size);
121 if (data) {
122 if (GetFileVersionInfoA(file_name, handle, size, data)) {
123 static const char backslash[] = "\\";
124 VS_FIXEDFILEINFO *pFixedVersionInfo;
125 UINT len;
126 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
127 sprintf(version, "%d.%d.%d.%d",
128 pFixedVersionInfo->dwFileVersionMS >> 16,
129 pFixedVersionInfo->dwFileVersionMS & 0xffff,
130 pFixedVersionInfo->dwFileVersionLS >> 16,
131 pFixedVersionInfo->dwFileVersionLS & 0xffff);
132 } else
133 sprintf(version, "version not found");
134 } else
135 sprintf(version, "version error %u", GetLastError());
136 heap_free(data);
137 } else
138 sprintf(version, "version error %u", ERROR_OUTOFMEMORY);
139 } else if (GetLastError() == ERROR_FILE_NOT_FOUND)
140 sprintf(version, "dll is missing");
141 else
142 sprintf(version, "version not present %u", GetLastError());
144 return version;
147 static BOOL running_under_wine (void)
149 HMODULE module = GetModuleHandleA("ntdll.dll");
151 if (!module) return FALSE;
152 return (GetProcAddress(module, "wine_server_call") != NULL);
155 static BOOL check_mount_mgr(void)
157 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
158 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
159 if (handle == INVALID_HANDLE_VALUE) return FALSE;
160 CloseHandle( handle );
161 return TRUE;
164 static BOOL check_wow64_registry(void)
166 char buffer[MAX_PATH];
167 DWORD type, size = MAX_PATH;
168 HKEY hkey;
169 BOOL ret;
171 if (!is_wow64) return TRUE;
172 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey ))
173 return FALSE;
174 ret = !RegQueryValueExA( hkey, "ProgramFilesDir (x86)", NULL, &type, (BYTE *)buffer, &size );
175 RegCloseKey( hkey );
176 return ret;
179 static BOOL check_display_driver(void)
181 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
182 0, 0, GetModuleHandleA(0), 0 );
183 if (!hwnd) return FALSE;
184 DestroyWindow( hwnd );
185 return TRUE;
188 static BOOL running_on_visible_desktop (void)
190 HWND desktop;
191 HMODULE huser32 = GetModuleHandleA("user32.dll");
192 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
193 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
195 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
196 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
198 desktop = GetDesktopWindow();
199 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
200 return IsWindowVisible(desktop);
202 if (pGetProcessWindowStation && pGetUserObjectInformationA)
204 DWORD len;
205 HWINSTA wstation;
206 USEROBJECTFLAGS uoflags;
208 wstation = pGetProcessWindowStation();
209 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
210 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
212 return IsWindowVisible(desktop);
215 static int running_as_admin (void)
217 PSID administrators = NULL;
218 SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
219 HANDLE token;
220 DWORD groups_size;
221 PTOKEN_GROUPS groups;
222 DWORD group_index;
224 /* Create a well-known SID for the Administrators group. */
225 if (! AllocateAndInitializeSid(&nt_authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
226 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
227 &administrators))
228 return -1;
230 /* Get the process token */
231 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
233 FreeSid(administrators);
234 return -1;
237 /* Get the group info from the token */
238 groups_size = 0;
239 GetTokenInformation(token, TokenGroups, NULL, 0, &groups_size);
240 groups = heap_alloc(groups_size);
241 if (groups == NULL)
243 CloseHandle(token);
244 FreeSid(administrators);
245 return -1;
247 if (! GetTokenInformation(token, TokenGroups, groups, groups_size, &groups_size))
249 heap_free(groups);
250 CloseHandle(token);
251 FreeSid(administrators);
252 return -1;
254 CloseHandle(token);
256 /* Now check if the token groups include the Administrators group */
257 for (group_index = 0; group_index < groups->GroupCount; group_index++)
259 if (EqualSid(groups->Groups[group_index].Sid, administrators))
261 heap_free(groups);
262 FreeSid(administrators);
263 return 1;
267 /* If we end up here we didn't find the Administrators group */
268 heap_free(groups);
269 FreeSid(administrators);
270 return 0;
273 static int running_elevated (void)
275 HANDLE token;
276 TOKEN_ELEVATION elevation_info;
277 DWORD size;
279 /* Get the process token */
280 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
281 return -1;
283 /* Get the elevation info from the token */
284 if (! GetTokenInformation(token, TokenElevation, &elevation_info,
285 sizeof(TOKEN_ELEVATION), &size))
287 CloseHandle(token);
288 return -1;
290 CloseHandle(token);
292 return elevation_info.TokenIsElevated;
295 /* check for native dll when running under wine */
296 static BOOL is_native_dll( HMODULE module )
298 static const char builtin_signature[] = "Wine builtin DLL";
299 static const char fakedll_signature[] = "Wine placeholder DLL";
300 const IMAGE_DOS_HEADER *dos;
302 if (!running_under_wine()) return FALSE;
303 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
304 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
305 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
306 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
307 if (dos->e_lfanew >= sizeof(*dos) + 32)
309 if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) )) return FALSE;
310 if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
312 return TRUE;
316 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
317 * to install that component. To bypass this check we need to look at the version resource.
319 static BOOL is_stub_dll(const char *filename)
321 DWORD size, ver;
322 BOOL isstub = FALSE;
323 char *p, *data;
325 size = GetFileVersionInfoSizeA(filename, &ver);
326 if (!size) return FALSE;
328 data = HeapAlloc(GetProcessHeap(), 0, size);
329 if (!data) return FALSE;
331 if (GetFileVersionInfoA(filename, ver, size, data))
333 char buf[256];
335 sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
336 if (VerQueryValueA(data, buf, (void**)&p, &size))
337 isstub = !lstrcmpiA("wcodstub.dll", p);
339 HeapFree(GetProcessHeap(), 0, data);
341 return isstub;
344 static void print_version (void)
346 #ifdef __i386__
347 static const char platform[] = "i386";
348 #elif defined(__x86_64__)
349 static const char platform[] = "x86_64";
350 #elif defined(__arm__)
351 static const char platform[] = "arm";
352 #elif defined(__aarch64__)
353 static const char platform[] = "arm64";
354 #else
355 # error CPU unknown
356 #endif
357 OSVERSIONINFOEXA ver;
358 RTL_OSVERSIONINFOEXW rtlver;
359 BOOL ext;
360 int is_win2k3_r2, is_admin, is_elevated;
361 const char *(CDECL *wine_get_build_id)(void);
362 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
363 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
364 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
365 NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
367 ver.dwOSVersionInfoSize = sizeof(ver);
368 if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
370 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
371 if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
372 report (R_FATAL, "Can't get OS version.");
375 /* try to get non-faked values */
376 if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
378 rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
380 pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
381 pRtlGetVersion(&rtlver);
383 ver.dwMajorVersion = rtlver.dwMajorVersion;
384 ver.dwMinorVersion = rtlver.dwMinorVersion;
385 ver.dwBuildNumber = rtlver.dwBuildNumber;
386 ver.dwPlatformId = rtlver.dwPlatformId;
387 ver.wServicePackMajor = rtlver.wServicePackMajor;
388 ver.wServicePackMinor = rtlver.wServicePackMinor;
389 ver.wSuiteMask = rtlver.wSuiteMask;
390 ver.wProductType = rtlver.wProductType;
392 WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
395 xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
396 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
397 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
398 is_admin = running_as_admin ();
399 if (0 <= is_admin)
401 xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
402 is_elevated = running_elevated ();
403 if (0 <= is_elevated)
404 xprintf(", %s", is_elevated ? "elevated" : "not elevated");
405 xprintf ("\n");
407 xprintf (" Submitter=%s\n", email );
408 if (description)
409 xprintf (" Description=%s\n", description );
410 if (url)
411 xprintf (" URL=%s\n", url );
412 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
413 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
414 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
415 ver.dwPlatformId, ver.szCSDVersion);
417 wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
418 wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
419 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
420 if (wine_get_host_version)
422 const char *sysname, *release;
423 wine_get_host_version( &sysname, &release );
424 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
426 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
427 if(is_win2k3_r2)
428 xprintf(" R2 build number=%d\n", is_win2k3_r2);
430 if (!ext) return;
432 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
433 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
434 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
435 ver.wProductType, ver.wReserved);
437 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
438 if (pGetProductInfo && !running_under_wine())
440 DWORD prodtype = 0;
442 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
443 xprintf(" dwProductInfo=%u\n", prodtype);
447 static void print_language(void)
449 HMODULE hkernel32;
450 BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
451 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
452 LANGID (WINAPI *pGetThreadUILanguage)(void);
454 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
455 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
456 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
458 hkernel32 = GetModuleHandleA("kernel32.dll");
459 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
460 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
461 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
463 if (pGetSystemPreferredUILanguages && !running_under_wine())
465 WCHAR langW[32];
466 ULONG num, size = ARRAY_SIZE(langW);
467 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
469 char lang[32], *p = lang;
470 WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
471 for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
472 xprintf (" SystemPreferredUILanguages=%s\n", lang);
475 if (pGetUserDefaultUILanguage)
476 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
477 if (pGetThreadUILanguage)
478 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
481 static inline BOOL is_dot_dir(const char* x)
483 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
486 static void remove_dir (const char *dir)
488 HANDLE hFind;
489 WIN32_FIND_DATAA wfd;
490 char path[MAX_PATH];
491 size_t dirlen = strlen (dir);
493 /* Make sure the directory exists before going further */
494 memcpy (path, dir, dirlen);
495 strcpy (path + dirlen++, "\\*");
496 hFind = FindFirstFileA (path, &wfd);
497 if (hFind == INVALID_HANDLE_VALUE) return;
499 do {
500 char *lp = wfd.cFileName;
502 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
503 if (is_dot_dir (lp)) continue;
504 strcpy (path + dirlen, lp);
505 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
506 remove_dir(path);
507 else if (!DeleteFileA(path))
508 report (R_WARNING, "Can't delete file %s: error %d",
509 path, GetLastError ());
510 } while (FindNextFileA(hFind, &wfd));
511 FindClose (hFind);
512 if (!RemoveDirectoryA(dir))
513 report (R_WARNING, "Can't remove directory %s: error %d",
514 dir, GetLastError ());
517 static const char* get_test_source_file(const char* test, const char* subtest)
519 static char buffer[MAX_PATH];
520 int len = strlen(test);
522 if (len > 4 && !strcmp( test + len - 4, ".exe" ) &&
523 strcmp( test, "ntoskrnl.exe" )) /* the one exception! */
525 len = sprintf(buffer, "programs/%s", test) - 4;
526 buffer[len] = 0;
528 else len = sprintf(buffer, "dlls/%s", test);
530 sprintf(buffer + len, "/tests/%s.c", subtest);
531 return buffer;
534 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
536 HRSRC rsrc;
537 HGLOBAL hdl;
538 LPVOID addr;
540 if (!(rsrc = FindResourceA(NULL, name, type)) ||
541 !(*size = SizeofResource (0, rsrc)) ||
542 !(hdl = LoadResource (0, rsrc)) ||
543 !(addr = LockResource (hdl)))
544 return NULL;
545 return addr;
548 /* Fills in the name and exename fields */
549 static void
550 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
552 BYTE* code;
553 DWORD size;
554 char *exepos;
555 HANDLE hfile;
556 DWORD written;
558 code = extract_rcdata (res_name, "TESTRES", &size);
559 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
560 res_name, GetLastError ());
561 test->name = heap_strdup( res_name );
562 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
563 exepos = strstr (test->name, testexe);
564 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
565 *exepos = 0;
566 test->name = heap_realloc (test->name, exepos - test->name + 1);
567 report (R_STEP, "Extracting: %s", test->name);
569 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
570 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
571 if (hfile == INVALID_HANDLE_VALUE)
572 report (R_FATAL, "Failed to open file %s.", test->exename);
574 if (!WriteFile(hfile, code, size, &written, NULL))
575 report (R_FATAL, "Failed to write file %s.", test->exename);
577 CloseHandle(hfile);
580 static DWORD wait_process( HANDLE process, DWORD timeout )
582 DWORD wait, diff = 0, start = GetTickCount();
583 MSG msg;
585 while (diff < timeout)
587 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
588 if (wait != WAIT_OBJECT_0 + 1) return wait;
589 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
590 diff = GetTickCount() - start;
592 return WAIT_TIMEOUT;
595 static void append_path( const char *path)
597 char *newpath;
599 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
600 strcpy(newpath, curpath);
601 strcat(newpath, ";");
602 strcat(newpath, path);
603 SetEnvironmentVariableA("PATH", newpath);
605 heap_free(newpath);
608 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
609 stdout to there.
611 Return the exit status, -2 if can't create process or the return
612 value of WaitForSingleObject.
614 static int
615 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritical, DWORD* pid)
617 STARTUPINFOA si;
618 PROCESS_INFORMATION pi;
619 DWORD wait, status, flags;
620 UINT old_errmode;
622 /* Flush to disk so we know which test caused Windows to crash if it does */
623 if (out_file)
624 FlushFileBuffers(out_file);
626 GetStartupInfoA (&si);
627 si.dwFlags = STARTF_USESTDHANDLES;
628 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
629 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
630 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
631 if (nocritical)
633 old_errmode = SetErrorMode(0);
634 SetErrorMode(old_errmode | SEM_FAILCRITICALERRORS);
635 flags = 0;
637 else
638 flags = CREATE_DEFAULT_ERROR_MODE;
640 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, flags,
641 NULL, tempdir, &si, &pi))
643 if (nocritical) SetErrorMode(old_errmode);
644 if (pid) *pid = 0;
645 return -2;
648 if (nocritical) SetErrorMode(old_errmode);
649 CloseHandle (pi.hThread);
650 if (pid) *pid = pi.dwProcessId;
651 status = wait_process( pi.hProcess, ms );
652 switch (status)
654 case WAIT_OBJECT_0:
655 GetExitCodeProcess (pi.hProcess, &status);
656 CloseHandle (pi.hProcess);
657 return status;
658 case WAIT_FAILED:
659 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
660 break;
661 case WAIT_TIMEOUT:
662 break;
663 default:
664 report (R_ERROR, "Wait returned %d", status);
665 break;
667 if (!TerminateProcess (pi.hProcess, 257))
668 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
669 wait = wait_process( pi.hProcess, 5000 );
670 switch (wait)
672 case WAIT_OBJECT_0:
673 break;
674 case WAIT_FAILED:
675 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
676 break;
677 case WAIT_TIMEOUT:
678 report (R_ERROR, "Can't kill process '%s'", cmd);
679 break;
680 default:
681 report (R_ERROR, "Waiting for termination: %d", wait);
682 break;
684 CloseHandle (pi.hProcess);
685 return status;
688 static DWORD
689 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
691 char *cmd;
692 HANDLE subfile;
693 DWORD err, total;
694 char buffer[8192], *index;
695 static const char header[] = "Valid test names:";
696 int status, allocated;
697 char tmpdir[MAX_PATH], subname[MAX_PATH];
698 SECURITY_ATTRIBUTES sa;
700 test->subtest_count = 0;
702 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
703 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
704 report (R_FATAL, "Can't name subtests file.");
706 /* make handle inheritable */
707 sa.nLength = sizeof(sa);
708 sa.lpSecurityDescriptor = NULL;
709 sa.bInheritHandle = TRUE;
711 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
712 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
713 &sa, CREATE_ALWAYS, 0, NULL );
715 if ((subfile == INVALID_HANDLE_VALUE) &&
716 (GetLastError() == ERROR_INVALID_PARAMETER)) {
717 /* FILE_SHARE_DELETE not supported on win9x */
718 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
719 FILE_SHARE_READ | FILE_SHARE_WRITE,
720 &sa, CREATE_ALWAYS, 0, NULL );
722 if (subfile == INVALID_HANDLE_VALUE) {
723 err = GetLastError();
724 report (R_ERROR, "Can't open subtests output of %s: %u",
725 test->name, GetLastError());
726 goto quit;
729 cmd = strmake (NULL, "%s --list", test->exename);
730 if (test->maindllpath) {
731 /* We need to add the path (to the main dll) to PATH */
732 append_path(test->maindllpath);
734 status = run_ex (cmd, subfile, tempdir, 5000, TRUE, NULL);
735 err = GetLastError();
736 if (test->maindllpath) {
737 /* Restore PATH again */
738 SetEnvironmentVariableA("PATH", curpath);
740 heap_free (cmd);
742 if (status)
744 if (status == -2)
745 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
746 else
747 err = status;
748 CloseHandle( subfile );
749 goto quit;
752 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
753 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
754 CloseHandle( subfile );
755 if (sizeof buffer == total) {
756 report (R_ERROR, "Subtest list of %s too big.",
757 test->name, sizeof buffer);
758 err = ERROR_OUTOFMEMORY;
759 goto quit;
761 buffer[total] = 0;
763 index = strstr (buffer, header);
764 if (!index) {
765 report (R_ERROR, "Can't parse subtests output of %s",
766 test->name);
767 err = ERROR_INTERNAL_ERROR;
768 goto quit;
770 index += sizeof header;
772 allocated = 10;
773 test->subtests = heap_alloc (allocated * sizeof(char*));
774 index = strtok (index, whitespace);
775 while (index) {
776 if (test->subtest_count == allocated) {
777 allocated *= 2;
778 test->subtests = heap_realloc (test->subtests,
779 allocated * sizeof(char*));
781 test->subtests[test->subtest_count++] = heap_strdup(index);
782 index = strtok (NULL, whitespace);
784 test->subtests = heap_realloc (test->subtests,
785 test->subtest_count * sizeof(char*));
786 err = 0;
788 quit:
789 if (!DeleteFileA (subname))
790 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
791 return err;
794 static void
795 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
797 /* Build the source filename so analysis tools can link to it */
798 const char* file = get_test_source_file(test->name, subtest);
800 if (test_filtered_out( test->name, subtest ))
802 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
803 xprintf ("%s:%s skipped %s\n", test->name, subtest, file);
804 nr_of_skips++;
806 else
808 int status;
809 DWORD pid, start = GetTickCount();
810 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
811 report (R_STEP, "Running: %s:%s", test->name, subtest);
812 xprintf ("%s:%s start %s\n", test->name, subtest, file);
813 status = run_ex (cmd, out_file, tempdir, 120000, FALSE, &pid);
814 if (status == -2) status = -GetLastError();
815 heap_free (cmd);
816 xprintf ("%s:%s:%04x done (%d) in %ds\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000);
817 if (status) failures++;
819 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
822 static BOOL CALLBACK
823 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
824 LPSTR lpszName, LONG_PTR lParam)
826 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
827 return TRUE;
830 static const struct clsid_mapping
832 const char *name;
833 CLSID clsid;
834 } clsid_list[] =
836 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
837 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
841 static BOOL get_main_clsid(const char *name, CLSID *clsid)
843 const struct clsid_mapping *mapping;
845 for(mapping = clsid_list; mapping->name; mapping++)
847 if(!strcasecmp(name, mapping->name))
849 *clsid = mapping->clsid;
850 return TRUE;
853 return FALSE;
856 static HMODULE load_com_dll(const char *name, char **path, char *filename)
858 HMODULE dll = NULL;
859 HKEY hkey;
860 char keyname[100];
861 char dllname[MAX_PATH];
862 char *p;
863 CLSID clsid;
865 if(!get_main_clsid(name, &clsid)) return NULL;
867 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
868 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
869 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
870 clsid.Data4[6], clsid.Data4[7]);
872 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
874 LONG size = sizeof(dllname);
875 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
877 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
879 strcpy( filename, dllname );
880 p = strrchr(dllname, '\\');
881 if (p) *p = 0;
882 *path = heap_strdup( dllname );
885 RegCloseKey(hkey);
888 return dll;
891 static void get_dll_path(HMODULE dll, char **path, char *filename)
893 char dllpath[MAX_PATH];
895 GetModuleFileNameA(dll, dllpath, MAX_PATH);
896 strcpy(filename, dllpath);
897 *strrchr(dllpath, '\\') = '\0';
898 *path = heap_strdup( dllpath );
901 static BOOL CALLBACK
902 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
904 const char *tempdir = (const char *)lParam;
905 char dllname[MAX_PATH];
906 char filename[MAX_PATH];
907 WCHAR dllnameW[MAX_PATH];
908 HMODULE dll;
909 DWORD err;
910 HANDLE actctx;
911 ULONG_PTR cookie;
912 BOOL run;
914 if (aborting) return TRUE;
916 /* Check if the main dll is present on this system */
917 CharLowerA(lpszName);
918 strcpy(dllname, lpszName);
919 *strstr(dllname, testexe) = 0;
921 if (test_filtered_out( lpszName, NULL ))
923 nr_of_skips++;
924 if (exclude_tests) xprintf (" %s=skipped\n", dllname);
925 return TRUE;
927 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
929 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
930 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
932 ACTCTXA actctxinfo;
933 memset(&actctxinfo, 0, sizeof(ACTCTXA));
934 actctxinfo.cbSize = sizeof(ACTCTXA);
935 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
936 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
937 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
938 actctx = pCreateActCtxA(&actctxinfo);
939 if (actctx != INVALID_HANDLE_VALUE &&
940 ! pActivateActCtx(actctx, &cookie))
942 pReleaseActCtx(actctx);
943 actctx = INVALID_HANDLE_VALUE;
945 } else actctx = INVALID_HANDLE_VALUE;
947 wine_tests[nr_of_files].maindllpath = NULL;
948 strcpy(filename, dllname);
949 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
951 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
953 if (!dll && pLoadLibraryShim)
955 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
956 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
958 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
959 FreeLibrary(dll);
960 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
962 else dll = 0;
965 run = TRUE;
966 if (dll)
968 if (is_stub_dll(dllname))
970 xprintf (" %s=dll is a stub\n", dllname);
971 run = FALSE;
973 else if (is_native_dll(dll))
975 xprintf (" %s=dll is native\n", dllname);
976 nr_native_dlls++;
977 run = FALSE;
979 FreeLibrary(dll);
982 if (run)
984 err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
985 switch (err)
987 case 0:
988 xprintf (" %s=%s\n", dllname, get_file_version(filename));
989 nr_of_tests += wine_tests[nr_of_files].subtest_count;
990 nr_of_files++;
991 break;
992 case STATUS_DLL_NOT_FOUND:
993 xprintf (" %s=dll is missing\n", dllname);
994 /* or it is a side-by-side dll but the test has no manifest */
995 break;
996 case STATUS_ORDINAL_NOT_FOUND:
997 xprintf (" %s=dll is missing an ordinal (%s)\n", dllname, get_file_version(filename));
998 break;
999 case STATUS_ENTRYPOINT_NOT_FOUND:
1000 xprintf (" %s=dll is missing an entrypoint (%s)\n", dllname, get_file_version(filename));
1001 break;
1002 case ERROR_SXS_CANT_GEN_ACTCTX:
1003 xprintf (" %s=dll is missing the requested side-by-side version\n", dllname);
1004 break;
1005 default:
1006 xprintf (" %s=load error %u\n", dllname, err);
1007 break;
1011 if (actctx != INVALID_HANDLE_VALUE)
1013 pDeactivateActCtx(0, cookie);
1014 pReleaseActCtx(actctx);
1016 return TRUE;
1019 static char *
1020 run_tests (char *logname, char *outdir)
1022 int i;
1023 char *strres, *eol, *nextline;
1024 DWORD strsize;
1025 SECURITY_ATTRIBUTES sa;
1026 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1027 BOOL newdir;
1028 DWORD needed;
1029 HMODULE kernel32;
1031 /* Get the current PATH only once */
1032 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1033 curpath = heap_alloc(needed);
1034 GetEnvironmentVariableA("PATH", curpath, needed);
1036 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1038 if (!GetTempPathA( MAX_PATH, tmppath ))
1039 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1041 if (!logname) {
1042 static char tmpname[MAX_PATH];
1043 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1044 report (R_FATAL, "Can't name logfile.");
1045 logname = tmpname;
1047 report (R_OUT, logname);
1049 /* make handle inheritable */
1050 sa.nLength = sizeof(sa);
1051 sa.lpSecurityDescriptor = NULL;
1052 sa.bInheritHandle = TRUE;
1054 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1055 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1056 &sa, CREATE_ALWAYS, 0, NULL );
1058 if ((logfile == INVALID_HANDLE_VALUE) &&
1059 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1060 /* FILE_SHARE_DELETE not supported on win9x */
1061 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1062 FILE_SHARE_READ | FILE_SHARE_WRITE,
1063 &sa, CREATE_ALWAYS, 0, NULL );
1065 if (logfile == INVALID_HANDLE_VALUE)
1066 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1068 if (outdir)
1070 /* Get a full path so it is still valid after a chdir */
1071 GetFullPathNameA( outdir, ARRAY_SIZE(tempdir), tempdir, NULL );
1073 else
1075 strcpy( tempdir, tmppath );
1076 strcat( tempdir, "wct" ); /* try stable path for ZoneAlarm */
1078 newdir = CreateDirectoryA( tempdir, NULL );
1079 if (!newdir && !outdir)
1081 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1082 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1083 DeleteFileA( tempdir );
1084 newdir = CreateDirectoryA( tempdir, NULL );
1086 if (!newdir && (!outdir || GetLastError() != ERROR_ALREADY_EXISTS))
1087 report (R_FATAL, "Could not create directory %s (%d)", tempdir, GetLastError());
1089 report (R_DIR, tempdir);
1091 xprintf ("Version 4\n");
1092 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1093 xprintf ("Archive: -\n"); /* no longer used */
1094 xprintf ("Tag: %s\n", tag);
1095 xprintf ("Build info:\n");
1096 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1097 while (strres) {
1098 eol = memchr (strres, '\n', strsize);
1099 if (!eol) {
1100 nextline = NULL;
1101 eol = strres + strsize;
1102 } else {
1103 strsize -= eol - strres + 1;
1104 nextline = strsize?eol+1:NULL;
1105 if (eol > strres && *(eol-1) == '\r') eol--;
1107 xprintf (" %.*s\n", eol-strres, strres);
1108 strres = nextline;
1110 xprintf ("Operating system version:\n");
1111 print_version ();
1112 print_language ();
1113 xprintf ("Dll info:\n" );
1115 report (R_STATUS, "Counting tests");
1116 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1117 report (R_FATAL, "Can't enumerate test files: %d",
1118 GetLastError ());
1119 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1121 /* Do this only once during extraction (and version checking) */
1122 hmscoree = LoadLibraryA("mscoree.dll");
1123 pLoadLibraryShim = NULL;
1124 if (hmscoree)
1125 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1126 kernel32 = GetModuleHandleA("kernel32.dll");
1127 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1128 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1129 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1130 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1132 report (R_STATUS, "Extracting tests");
1133 report (R_PROGRESS, 0, nr_of_files);
1134 nr_of_files = 0;
1135 nr_of_tests = 0;
1136 nr_of_skips = 0;
1137 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1138 report (R_FATAL, "Can't enumerate test files: %d",
1139 GetLastError ());
1141 FreeLibrary(hmscoree);
1143 if (aborting) return logname;
1145 xprintf ("Test output:\n" );
1147 report (R_DELTA, 0, "Extracting: Done");
1149 if (nr_native_dlls)
1150 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1152 report (R_STATUS, "Running tests");
1153 report (R_PROGRESS, 1, nr_of_tests);
1154 for (i = 0; i < nr_of_files; i++) {
1155 struct wine_test *test = wine_tests + i;
1156 int j;
1158 if (aborting) break;
1160 if (test->maindllpath) {
1161 /* We need to add the path (to the main dll) to PATH */
1162 append_path(test->maindllpath);
1165 for (j = 0; j < test->subtest_count; j++) {
1166 if (aborting) break;
1167 run_test (test, test->subtests[j], logfile, tempdir);
1170 if (test->maindllpath) {
1171 /* Restore PATH again */
1172 SetEnvironmentVariableA("PATH", curpath);
1175 report (R_DELTA, 0, "Running: Done");
1177 report (R_STATUS, "Cleaning up - %u failures", failures);
1178 CloseHandle( logfile );
1179 logfile = 0;
1180 if (newdir)
1181 remove_dir (tempdir);
1182 heap_free(wine_tests);
1183 heap_free(curpath);
1185 return logname;
1188 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1190 if (ctrl_type == CTRL_C_EVENT) {
1191 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1192 return TRUE;
1195 return FALSE;
1199 static BOOL CALLBACK
1200 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1202 const char *target_dir = (const char *)lParam;
1203 char filename[MAX_PATH];
1205 if (test_filtered_out( lpszName, NULL )) return TRUE;
1207 strcpy(filename, lpszName);
1208 CharLowerA(filename);
1210 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1211 nr_of_files++;
1212 return TRUE;
1215 static void extract_only (const char *target_dir)
1217 BOOL res;
1219 report (R_DIR, target_dir);
1220 res = CreateDirectoryA( target_dir, NULL );
1221 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1222 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1224 nr_of_files = 0;
1225 report (R_STATUS, "Counting tests");
1226 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1227 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1229 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1231 report (R_STATUS, "Extracting tests");
1232 report (R_PROGRESS, 0, nr_of_files);
1233 nr_of_files = 0;
1234 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1235 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1237 report (R_DELTA, 0, "Extracting: Done");
1240 static void
1241 usage (void)
1243 fprintf (stderr,
1244 "Usage: winetest [OPTION]... [TESTS]\n\n"
1245 " --help print this message and exit\n"
1246 " --version print the build version and exit\n"
1247 " -c console mode, no GUI\n"
1248 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1249 " -e preserve the environment\n"
1250 " -h print this message and exit\n"
1251 " -i INFO an optional description of the test platform\n"
1252 " -m MAIL an email address to enable developers to contact you\n"
1253 " -n exclude the specified tests\n"
1254 " -p shutdown when the tests are done\n"
1255 " -q quiet mode, no output at all\n"
1256 " -o FILE put report into FILE, do not submit\n"
1257 " -s FILE submit FILE, do not run tests\n"
1258 " -S URL URL to submit the results to\n"
1259 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1260 " -u URL include TestBot URL in the report\n"
1261 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1264 int __cdecl main( int argc, char *argv[] )
1266 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1267 char *logname = NULL, *outdir = NULL;
1268 const char *extract = NULL;
1269 const char *cp, *submit = NULL, *submiturl = NULL;
1270 int reset_env = 1;
1271 int poweroff = 0;
1272 int interactive = 1;
1273 int i;
1275 InitCommonControls();
1277 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1279 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1280 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1282 for (i = 1; i < argc && argv[i]; i++)
1284 if (!strcmp(argv[i], "--help")) {
1285 usage ();
1286 exit (0);
1288 else if (!strcmp(argv[i], "--version")) {
1289 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1290 exit (0);
1292 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1293 if (nb_filters == ARRAY_SIZE(filters))
1295 report (R_ERROR, "Too many test filters specified");
1296 exit (2);
1298 filters[nb_filters++] = argv[i];
1300 else switch (argv[i][1]) {
1301 case 'c':
1302 report (R_TEXTMODE);
1303 interactive = 0;
1304 break;
1305 case 'e':
1306 reset_env = 0;
1307 break;
1308 case 'h':
1309 case '?':
1310 usage ();
1311 exit (0);
1312 case 'i':
1313 if (!(description = argv[++i]))
1315 usage();
1316 exit( 2 );
1318 break;
1319 case 'm':
1320 if (!(email = argv[++i]))
1322 usage();
1323 exit( 2 );
1325 break;
1326 case 'n':
1327 exclude_tests = TRUE;
1328 break;
1329 case 'p':
1330 poweroff = 1;
1331 break;
1332 case 'q':
1333 report (R_QUIET);
1334 interactive = 0;
1335 break;
1336 case 's':
1337 if (!(submit = argv[++i]))
1339 usage();
1340 exit( 2 );
1342 break;
1343 case 'S':
1344 if (!(submiturl = argv[++i]))
1346 usage();
1347 exit( 2 );
1349 break;
1350 case 'o':
1351 if (!(logname = argv[++i]))
1353 usage();
1354 exit( 2 );
1356 break;
1357 case 't':
1358 if (!(tag = argv[++i]))
1360 usage();
1361 exit( 2 );
1363 if (strlen (tag) > MAXTAGLEN)
1364 report (R_FATAL, "tag is too long (maximum %d characters)",
1365 MAXTAGLEN);
1366 cp = findbadtagchar (tag);
1367 if (cp) {
1368 report (R_ERROR, "invalid char in tag: %c", *cp);
1369 usage ();
1370 exit (2);
1372 break;
1373 case 'u':
1374 if (!(url = argv[++i]))
1376 usage();
1377 exit( 2 );
1379 break;
1380 case 'x':
1381 report (R_TEXTMODE);
1382 if (!(extract = argv[++i]))
1383 extract = ".\\wct";
1385 extract_only (extract);
1386 break;
1387 case 'd':
1388 outdir = argv[++i];
1389 break;
1390 default:
1391 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1392 usage ();
1393 exit (2);
1396 if (submit) {
1397 if (tag)
1398 report (R_WARNING, "ignoring tag for submission");
1399 send_file (submiturl, submit);
1401 } else if (!extract) {
1402 int is_win9x = (GetVersion() & 0x80000000) != 0;
1404 report (R_STATUS, "Starting up");
1406 if (is_win9x)
1407 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1409 if (!running_on_visible_desktop ())
1410 report (R_FATAL, "Tests must be run on a visible desktop");
1412 if (running_under_wine())
1414 if (!check_mount_mgr())
1415 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1417 if (!check_wow64_registry())
1418 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1420 if (!check_display_driver())
1421 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1424 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1426 if (reset_env)
1428 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1429 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1430 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1431 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1434 if (nb_filters && !exclude_tests)
1436 run_tests( logname, outdir );
1437 exit(0);
1440 while (!tag) {
1441 if (!interactive)
1442 report (R_FATAL, "Please specify a tag (-t option) if "
1443 "running noninteractive!");
1444 if (guiAskTag () == IDABORT) exit (1);
1446 report (R_TAG);
1448 while (!email) {
1449 if (!interactive)
1450 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1451 " to contact you about your report if necessary.");
1452 if (guiAskEmail () == IDABORT) exit (1);
1455 if (!build_id[0])
1456 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1457 "To submit results, winetest needs to be built from a git checkout." );
1459 if (!logname) {
1460 logname = run_tests (NULL, outdir);
1461 if (aborting) {
1462 DeleteFileA(logname);
1463 exit (0);
1465 if (failures > FAILURES_LIMIT)
1466 report( R_WARNING,
1467 "%d tests failed. There is probably something broken with your setup.\n"
1468 "You need to address this before submitting results.", failures );
1470 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1471 !nr_native_dlls && !is_win9x &&
1472 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1473 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1474 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1475 } else run_tests (logname, outdir);
1476 report (R_STATUS, "Finished - %u failures", failures);
1478 if (poweroff)
1480 HANDLE hToken;
1481 TOKEN_PRIVILEGES npr;
1483 /* enable the shutdown privilege for the current process */
1484 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1486 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1487 npr.PrivilegeCount = 1;
1488 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1489 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1490 CloseHandle(hToken);
1492 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1494 exit (0);