hid: Build link collection nodes in HidP_GetLinkCollectionNodes.
[wine.git] / programs / winetest / main.c
blob64a807b6c730041409e34118db6e60d14c5b1a6e
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 heap_free (cmd);
815 xprintf ("%s:%s:%04x done (%d) in %ds\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000);
816 if (status) failures++;
818 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
821 static BOOL CALLBACK
822 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
823 LPSTR lpszName, LONG_PTR lParam)
825 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
826 return TRUE;
829 static const struct clsid_mapping
831 const char *name;
832 CLSID clsid;
833 } clsid_list[] =
835 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
836 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
840 static BOOL get_main_clsid(const char *name, CLSID *clsid)
842 const struct clsid_mapping *mapping;
844 for(mapping = clsid_list; mapping->name; mapping++)
846 if(!strcasecmp(name, mapping->name))
848 *clsid = mapping->clsid;
849 return TRUE;
852 return FALSE;
855 static HMODULE load_com_dll(const char *name, char **path, char *filename)
857 HMODULE dll = NULL;
858 HKEY hkey;
859 char keyname[100];
860 char dllname[MAX_PATH];
861 char *p;
862 CLSID clsid;
864 if(!get_main_clsid(name, &clsid)) return NULL;
866 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
867 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
868 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
869 clsid.Data4[6], clsid.Data4[7]);
871 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
873 LONG size = sizeof(dllname);
874 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
876 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
878 strcpy( filename, dllname );
879 p = strrchr(dllname, '\\');
880 if (p) *p = 0;
881 *path = heap_strdup( dllname );
884 RegCloseKey(hkey);
887 return dll;
890 static void get_dll_path(HMODULE dll, char **path, char *filename)
892 char dllpath[MAX_PATH];
894 GetModuleFileNameA(dll, dllpath, MAX_PATH);
895 strcpy(filename, dllpath);
896 *strrchr(dllpath, '\\') = '\0';
897 *path = heap_strdup( dllpath );
900 static BOOL CALLBACK
901 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
903 const char *tempdir = (const char *)lParam;
904 char dllname[MAX_PATH];
905 char filename[MAX_PATH];
906 WCHAR dllnameW[MAX_PATH];
907 HMODULE dll;
908 DWORD err;
909 HANDLE actctx;
910 ULONG_PTR cookie;
911 BOOL run;
913 if (aborting) return TRUE;
915 /* Check if the main dll is present on this system */
916 CharLowerA(lpszName);
917 strcpy(dllname, lpszName);
918 *strstr(dllname, testexe) = 0;
920 if (test_filtered_out( lpszName, NULL ))
922 nr_of_skips++;
923 if (exclude_tests) xprintf (" %s=skipped\n", dllname);
924 return TRUE;
926 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
928 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
929 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
931 ACTCTXA actctxinfo;
932 memset(&actctxinfo, 0, sizeof(ACTCTXA));
933 actctxinfo.cbSize = sizeof(ACTCTXA);
934 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
935 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
936 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
937 actctx = pCreateActCtxA(&actctxinfo);
938 if (actctx != INVALID_HANDLE_VALUE &&
939 ! pActivateActCtx(actctx, &cookie))
941 pReleaseActCtx(actctx);
942 actctx = INVALID_HANDLE_VALUE;
944 } else actctx = INVALID_HANDLE_VALUE;
946 wine_tests[nr_of_files].maindllpath = NULL;
947 strcpy(filename, dllname);
948 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
950 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
952 if (!dll && pLoadLibraryShim)
954 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
955 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
957 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
958 FreeLibrary(dll);
959 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
961 else dll = 0;
964 run = TRUE;
965 if (dll)
967 if (is_stub_dll(dllname))
969 xprintf (" %s=dll is a stub\n", dllname);
970 run = FALSE;
972 else if (is_native_dll(dll))
974 xprintf (" %s=dll is native\n", dllname);
975 nr_native_dlls++;
976 run = FALSE;
978 FreeLibrary(dll);
981 if (run)
983 err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
984 switch (err)
986 case 0:
987 xprintf (" %s=%s\n", dllname, get_file_version(filename));
988 nr_of_tests += wine_tests[nr_of_files].subtest_count;
989 nr_of_files++;
990 break;
991 case STATUS_DLL_NOT_FOUND:
992 xprintf (" %s=dll is missing\n", dllname);
993 /* or it is a side-by-side dll but the test has no manifest */
994 break;
995 case STATUS_ORDINAL_NOT_FOUND:
996 xprintf (" %s=dll is missing an ordinal (%s)\n", dllname, get_file_version(filename));
997 break;
998 case STATUS_ENTRYPOINT_NOT_FOUND:
999 xprintf (" %s=dll is missing an entrypoint (%s)\n", dllname, get_file_version(filename));
1000 break;
1001 case ERROR_SXS_CANT_GEN_ACTCTX:
1002 xprintf (" %s=dll is missing the requested side-by-side version\n", dllname);
1003 break;
1004 default:
1005 xprintf (" %s=load error %u\n", dllname, err);
1006 break;
1010 if (actctx != INVALID_HANDLE_VALUE)
1012 pDeactivateActCtx(0, cookie);
1013 pReleaseActCtx(actctx);
1015 return TRUE;
1018 static char *
1019 run_tests (char *logname, char *outdir)
1021 int i;
1022 char *strres, *eol, *nextline;
1023 DWORD strsize;
1024 SECURITY_ATTRIBUTES sa;
1025 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1026 DWORD needed;
1027 HMODULE kernel32;
1029 /* Get the current PATH only once */
1030 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1031 curpath = heap_alloc(needed);
1032 GetEnvironmentVariableA("PATH", curpath, needed);
1034 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1036 if (!GetTempPathA( MAX_PATH, tmppath ))
1037 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1039 if (!logname) {
1040 static char tmpname[MAX_PATH];
1041 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1042 report (R_FATAL, "Can't name logfile.");
1043 logname = tmpname;
1045 report (R_OUT, logname);
1047 /* make handle inheritable */
1048 sa.nLength = sizeof(sa);
1049 sa.lpSecurityDescriptor = NULL;
1050 sa.bInheritHandle = TRUE;
1052 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1053 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1054 &sa, CREATE_ALWAYS, 0, NULL );
1056 if ((logfile == INVALID_HANDLE_VALUE) &&
1057 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1058 /* FILE_SHARE_DELETE not supported on win9x */
1059 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1060 FILE_SHARE_READ | FILE_SHARE_WRITE,
1061 &sa, CREATE_ALWAYS, 0, NULL );
1063 if (logfile == INVALID_HANDLE_VALUE)
1064 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1066 /* try stable path for ZoneAlarm */
1067 if (!outdir) {
1068 strcpy( tempdir, tmppath );
1069 strcat( tempdir, "wct" );
1071 if (!CreateDirectoryA( tempdir, NULL ))
1073 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1074 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1075 DeleteFileA( tempdir );
1076 if (!CreateDirectoryA( tempdir, NULL ))
1077 report (R_FATAL, "Could not create directory: %s", tempdir);
1080 else
1081 strcpy( tempdir, outdir);
1083 report (R_DIR, tempdir);
1085 xprintf ("Version 4\n");
1086 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1087 xprintf ("Archive: -\n"); /* no longer used */
1088 xprintf ("Tag: %s\n", tag);
1089 xprintf ("Build info:\n");
1090 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1091 while (strres) {
1092 eol = memchr (strres, '\n', strsize);
1093 if (!eol) {
1094 nextline = NULL;
1095 eol = strres + strsize;
1096 } else {
1097 strsize -= eol - strres + 1;
1098 nextline = strsize?eol+1:NULL;
1099 if (eol > strres && *(eol-1) == '\r') eol--;
1101 xprintf (" %.*s\n", eol-strres, strres);
1102 strres = nextline;
1104 xprintf ("Operating system version:\n");
1105 print_version ();
1106 print_language ();
1107 xprintf ("Dll info:\n" );
1109 report (R_STATUS, "Counting tests");
1110 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1111 report (R_FATAL, "Can't enumerate test files: %d",
1112 GetLastError ());
1113 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1115 /* Do this only once during extraction (and version checking) */
1116 hmscoree = LoadLibraryA("mscoree.dll");
1117 pLoadLibraryShim = NULL;
1118 if (hmscoree)
1119 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1120 kernel32 = GetModuleHandleA("kernel32.dll");
1121 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1122 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1123 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1124 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1126 report (R_STATUS, "Extracting tests");
1127 report (R_PROGRESS, 0, nr_of_files);
1128 nr_of_files = 0;
1129 nr_of_tests = 0;
1130 nr_of_skips = 0;
1131 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1132 report (R_FATAL, "Can't enumerate test files: %d",
1133 GetLastError ());
1135 FreeLibrary(hmscoree);
1137 if (aborting) return logname;
1139 xprintf ("Test output:\n" );
1141 report (R_DELTA, 0, "Extracting: Done");
1143 if (nr_native_dlls)
1144 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1146 report (R_STATUS, "Running tests");
1147 report (R_PROGRESS, 1, nr_of_tests);
1148 for (i = 0; i < nr_of_files; i++) {
1149 struct wine_test *test = wine_tests + i;
1150 int j;
1152 if (aborting) break;
1154 if (test->maindllpath) {
1155 /* We need to add the path (to the main dll) to PATH */
1156 append_path(test->maindllpath);
1159 for (j = 0; j < test->subtest_count; j++) {
1160 if (aborting) break;
1161 run_test (test, test->subtests[j], logfile, tempdir);
1164 if (test->maindllpath) {
1165 /* Restore PATH again */
1166 SetEnvironmentVariableA("PATH", curpath);
1169 report (R_DELTA, 0, "Running: Done");
1171 report (R_STATUS, "Cleaning up - %u failures", failures);
1172 CloseHandle( logfile );
1173 logfile = 0;
1174 if (!outdir)
1175 remove_dir (tempdir);
1176 heap_free(wine_tests);
1177 heap_free(curpath);
1179 return logname;
1182 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1184 if (ctrl_type == CTRL_C_EVENT) {
1185 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1186 return TRUE;
1189 return FALSE;
1193 static BOOL CALLBACK
1194 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1196 const char *target_dir = (const char *)lParam;
1197 char filename[MAX_PATH];
1199 if (test_filtered_out( lpszName, NULL )) return TRUE;
1201 strcpy(filename, lpszName);
1202 CharLowerA(filename);
1204 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1205 nr_of_files++;
1206 return TRUE;
1209 static void extract_only (const char *target_dir)
1211 BOOL res;
1213 report (R_DIR, target_dir);
1214 res = CreateDirectoryA( target_dir, NULL );
1215 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1216 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1218 nr_of_files = 0;
1219 report (R_STATUS, "Counting tests");
1220 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1221 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1223 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1225 report (R_STATUS, "Extracting tests");
1226 report (R_PROGRESS, 0, nr_of_files);
1227 nr_of_files = 0;
1228 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1229 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1231 report (R_DELTA, 0, "Extracting: Done");
1234 static void
1235 usage (void)
1237 fprintf (stderr,
1238 "Usage: winetest [OPTION]... [TESTS]\n\n"
1239 " --help print this message and exit\n"
1240 " --version print the build version and exit\n"
1241 " -c console mode, no GUI\n"
1242 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1243 " -e preserve the environment\n"
1244 " -h print this message and exit\n"
1245 " -i INFO an optional description of the test platform\n"
1246 " -m MAIL an email address to enable developers to contact you\n"
1247 " -n exclude the specified tests\n"
1248 " -p shutdown when the tests are done\n"
1249 " -q quiet mode, no output at all\n"
1250 " -o FILE put report into FILE, do not submit\n"
1251 " -s FILE submit FILE, do not run tests\n"
1252 " -S URL URL to submit the results to\n"
1253 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1254 " -u URL include TestBot URL in the report\n"
1255 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1258 int __cdecl main( int argc, char *argv[] )
1260 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1261 char *logname = NULL, *outdir = NULL;
1262 const char *extract = NULL;
1263 const char *cp, *submit = NULL, *submiturl = NULL;
1264 int reset_env = 1;
1265 int poweroff = 0;
1266 int interactive = 1;
1267 int i;
1269 InitCommonControls();
1271 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1273 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1274 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1276 for (i = 1; i < argc && argv[i]; i++)
1278 if (!strcmp(argv[i], "--help")) {
1279 usage ();
1280 exit (0);
1282 else if (!strcmp(argv[i], "--version")) {
1283 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1284 exit (0);
1286 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1287 if (nb_filters == ARRAY_SIZE(filters))
1289 report (R_ERROR, "Too many test filters specified");
1290 exit (2);
1292 filters[nb_filters++] = argv[i];
1294 else switch (argv[i][1]) {
1295 case 'c':
1296 report (R_TEXTMODE);
1297 interactive = 0;
1298 break;
1299 case 'e':
1300 reset_env = 0;
1301 break;
1302 case 'h':
1303 case '?':
1304 usage ();
1305 exit (0);
1306 case 'i':
1307 if (!(description = argv[++i]))
1309 usage();
1310 exit( 2 );
1312 break;
1313 case 'm':
1314 if (!(email = argv[++i]))
1316 usage();
1317 exit( 2 );
1319 break;
1320 case 'n':
1321 exclude_tests = TRUE;
1322 break;
1323 case 'p':
1324 poweroff = 1;
1325 break;
1326 case 'q':
1327 report (R_QUIET);
1328 interactive = 0;
1329 break;
1330 case 's':
1331 if (!(submit = argv[++i]))
1333 usage();
1334 exit( 2 );
1336 break;
1337 case 'S':
1338 if (!(submiturl = argv[++i]))
1340 usage();
1341 exit( 2 );
1343 break;
1344 case 'o':
1345 if (!(logname = argv[++i]))
1347 usage();
1348 exit( 2 );
1350 break;
1351 case 't':
1352 if (!(tag = argv[++i]))
1354 usage();
1355 exit( 2 );
1357 if (strlen (tag) > MAXTAGLEN)
1358 report (R_FATAL, "tag is too long (maximum %d characters)",
1359 MAXTAGLEN);
1360 cp = findbadtagchar (tag);
1361 if (cp) {
1362 report (R_ERROR, "invalid char in tag: %c", *cp);
1363 usage ();
1364 exit (2);
1366 break;
1367 case 'u':
1368 if (!(url = argv[++i]))
1370 usage();
1371 exit( 2 );
1373 break;
1374 case 'x':
1375 report (R_TEXTMODE);
1376 if (!(extract = argv[++i]))
1377 extract = ".\\wct";
1379 extract_only (extract);
1380 break;
1381 case 'd':
1382 outdir = argv[++i];
1383 break;
1384 default:
1385 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1386 usage ();
1387 exit (2);
1390 if (submit) {
1391 if (tag)
1392 report (R_WARNING, "ignoring tag for submission");
1393 send_file (submiturl, submit);
1395 } else if (!extract) {
1396 int is_win9x = (GetVersion() & 0x80000000) != 0;
1398 report (R_STATUS, "Starting up");
1400 if (is_win9x)
1401 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1403 if (!running_on_visible_desktop ())
1404 report (R_FATAL, "Tests must be run on a visible desktop");
1406 if (running_under_wine())
1408 if (!check_mount_mgr())
1409 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1411 if (!check_wow64_registry())
1412 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1414 if (!check_display_driver())
1415 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1418 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1420 if (reset_env)
1422 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1423 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1424 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1425 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1428 if (nb_filters && !exclude_tests)
1430 run_tests( logname, outdir );
1431 exit(0);
1434 while (!tag) {
1435 if (!interactive)
1436 report (R_FATAL, "Please specify a tag (-t option) if "
1437 "running noninteractive!");
1438 if (guiAskTag () == IDABORT) exit (1);
1440 report (R_TAG);
1442 while (!email) {
1443 if (!interactive)
1444 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1445 " to contact you about your report if necessary.");
1446 if (guiAskEmail () == IDABORT) exit (1);
1449 if (!build_id[0])
1450 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1451 "To submit results, winetest needs to be built from a git checkout." );
1453 if (!logname) {
1454 logname = run_tests (NULL, outdir);
1455 if (aborting) {
1456 DeleteFileA(logname);
1457 exit (0);
1459 if (failures > FAILURES_LIMIT)
1460 report( R_WARNING,
1461 "%d tests failed. There is probably something broken with your setup.\n"
1462 "You need to address this before submitting results.", failures );
1464 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1465 !nr_native_dlls && !is_win9x &&
1466 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1467 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1468 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1469 } else run_tests (logname, outdir);
1470 report (R_STATUS, "Finished - %u failures", failures);
1472 if (poweroff)
1474 HANDLE hToken;
1475 TOKEN_PRIVILEGES npr;
1477 /* enable the shutdown privilege for the current process */
1478 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1480 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1481 npr.PrivilegeCount = 1;
1482 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1483 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1484 CloseHandle(hToken);
1486 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1488 exit (0);