include: Add ID2D1DeviceContext1 definition.
[wine/zf.git] / programs / winetest / main.c
blob107151c927f8037d56bff531b42150a03dec54eb
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 <winternl.h>
33 #include <mshtml.h>
35 #include "winetest.h"
36 #include "resource.h"
38 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
39 #define SKIP_LIMIT 10
41 /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
42 #define FAILURES_LIMIT 50
44 struct wine_test
46 char *name;
47 int subtest_count;
48 char **subtests;
49 char *exename;
50 char *maindllpath;
53 char *tag = NULL;
54 char *description = NULL;
55 char *url = NULL;
56 char *email = NULL;
57 BOOL aborting = FALSE;
58 static struct wine_test *wine_tests;
59 static int nr_of_files, nr_of_tests, nr_of_skips;
60 static int nr_native_dlls;
61 static const char whitespace[] = " \t\r\n";
62 static const char testexe[] = "_test.exe";
63 static char build_id[64];
64 static BOOL is_wow64;
65 static int failures;
67 /* filters for running only specific tests */
68 static char *filters[64];
69 static unsigned int nb_filters = 0;
70 static BOOL exclude_tests = FALSE;
72 /* Needed to check for .NET dlls */
73 static HMODULE hmscoree;
74 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
76 /* For SxS DLLs e.g. msvcr90 */
77 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
78 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
79 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
80 static void (WINAPI *pReleaseActCtx)(HANDLE);
82 /* To store the current PATH setting (related to .NET only provided dlls) */
83 static char *curpath;
85 /* check if test is being filtered out */
86 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
88 char *p, dllname[MAX_PATH];
89 unsigned int i, len;
91 strcpy( dllname, module );
92 CharLowerA( dllname );
93 p = strstr( dllname, testexe );
94 if (p) *p = 0;
95 len = strlen(dllname);
97 if (!nb_filters) return exclude_tests;
98 for (i = 0; i < nb_filters; i++)
100 if (!strncmp( dllname, filters[i], len ))
102 if (!filters[i][len]) return exclude_tests;
103 if (filters[i][len] != ':') continue;
104 if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
105 if (!testname && !exclude_tests) return FALSE;
108 return !exclude_tests;
111 static char * get_file_version(char * file_name)
113 static char version[32];
114 DWORD size;
115 DWORD handle;
117 size = GetFileVersionInfoSizeA(file_name, &handle);
118 if (size) {
119 char * data = heap_alloc(size);
120 if (data) {
121 if (GetFileVersionInfoA(file_name, handle, size, data)) {
122 static const char backslash[] = "\\";
123 VS_FIXEDFILEINFO *pFixedVersionInfo;
124 UINT len;
125 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
126 sprintf(version, "%d.%d.%d.%d",
127 pFixedVersionInfo->dwFileVersionMS >> 16,
128 pFixedVersionInfo->dwFileVersionMS & 0xffff,
129 pFixedVersionInfo->dwFileVersionLS >> 16,
130 pFixedVersionInfo->dwFileVersionLS & 0xffff);
131 } else
132 sprintf(version, "version not found");
133 } else
134 sprintf(version, "version error %u", GetLastError());
135 heap_free(data);
136 } else
137 sprintf(version, "version error %u", ERROR_OUTOFMEMORY);
138 } else if (GetLastError() == ERROR_FILE_NOT_FOUND)
139 sprintf(version, "dll is missing");
140 else
141 sprintf(version, "version not present %u", GetLastError());
143 return version;
146 static BOOL running_under_wine (void)
148 HMODULE module = GetModuleHandleA("ntdll.dll");
150 if (!module) return FALSE;
151 return (GetProcAddress(module, "wine_server_call") != NULL);
154 static BOOL check_mount_mgr(void)
156 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
157 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
158 if (handle == INVALID_HANDLE_VALUE) return FALSE;
159 CloseHandle( handle );
160 return TRUE;
163 static BOOL check_wow64_registry(void)
165 char buffer[MAX_PATH];
166 DWORD type, size = MAX_PATH;
167 HKEY hkey;
168 BOOL ret;
170 if (!is_wow64) return TRUE;
171 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey ))
172 return FALSE;
173 ret = !RegQueryValueExA( hkey, "ProgramFilesDir (x86)", NULL, &type, (BYTE *)buffer, &size );
174 RegCloseKey( hkey );
175 return ret;
178 static BOOL check_display_driver(void)
180 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
181 0, 0, GetModuleHandleA(0), 0 );
182 if (!hwnd) return FALSE;
183 DestroyWindow( hwnd );
184 return TRUE;
187 static BOOL running_on_visible_desktop (void)
189 HWND desktop;
190 HMODULE huser32 = GetModuleHandleA("user32.dll");
191 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
192 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
194 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
195 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
197 desktop = GetDesktopWindow();
198 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
199 return IsWindowVisible(desktop);
201 if (pGetProcessWindowStation && pGetUserObjectInformationA)
203 DWORD len;
204 HWINSTA wstation;
205 USEROBJECTFLAGS uoflags;
207 wstation = pGetProcessWindowStation();
208 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
209 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
211 return IsWindowVisible(desktop);
214 static int running_as_admin (void)
216 PSID administrators = NULL;
217 SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
218 HANDLE token;
219 DWORD groups_size;
220 PTOKEN_GROUPS groups;
221 DWORD group_index;
223 /* Create a well-known SID for the Administrators group. */
224 if (! AllocateAndInitializeSid(&nt_authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
225 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
226 &administrators))
227 return -1;
229 /* Get the process token */
230 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
232 FreeSid(administrators);
233 return -1;
236 /* Get the group info from the token */
237 groups_size = 0;
238 GetTokenInformation(token, TokenGroups, NULL, 0, &groups_size);
239 groups = heap_alloc(groups_size);
240 if (groups == NULL)
242 CloseHandle(token);
243 FreeSid(administrators);
244 return -1;
246 if (! GetTokenInformation(token, TokenGroups, groups, groups_size, &groups_size))
248 heap_free(groups);
249 CloseHandle(token);
250 FreeSid(administrators);
251 return -1;
253 CloseHandle(token);
255 /* Now check if the token groups include the Administrators group */
256 for (group_index = 0; group_index < groups->GroupCount; group_index++)
258 if (EqualSid(groups->Groups[group_index].Sid, administrators))
260 heap_free(groups);
261 FreeSid(administrators);
262 return 1;
266 /* If we end up here we didn't find the Administrators group */
267 heap_free(groups);
268 FreeSid(administrators);
269 return 0;
272 static int running_elevated (void)
274 HANDLE token;
275 TOKEN_ELEVATION elevation_info;
276 DWORD size;
278 /* Get the process token */
279 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
280 return -1;
282 /* Get the elevation info from the token */
283 if (! GetTokenInformation(token, TokenElevation, &elevation_info,
284 sizeof(TOKEN_ELEVATION), &size))
286 CloseHandle(token);
287 return -1;
289 CloseHandle(token);
291 return elevation_info.TokenIsElevated;
294 /* check for native dll when running under wine */
295 static BOOL is_native_dll( HMODULE module )
297 static const char builtin_signature[] = "Wine builtin DLL";
298 static const char fakedll_signature[] = "Wine placeholder DLL";
299 const IMAGE_DOS_HEADER *dos;
301 if (!running_under_wine()) return FALSE;
302 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
303 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
304 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
305 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
306 if (dos->e_lfanew >= sizeof(*dos) + 32)
308 if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) )) return FALSE;
309 if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
311 return TRUE;
315 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
316 * to install that component. To bypass this check we need to look at the version resource.
318 static BOOL is_stub_dll(const char *filename)
320 DWORD size, ver;
321 BOOL isstub = FALSE;
322 char *p, *data;
324 size = GetFileVersionInfoSizeA(filename, &ver);
325 if (!size) return FALSE;
327 data = HeapAlloc(GetProcessHeap(), 0, size);
328 if (!data) return FALSE;
330 if (GetFileVersionInfoA(filename, ver, size, data))
332 char buf[256];
334 sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
335 if (VerQueryValueA(data, buf, (void**)&p, &size))
336 isstub = !lstrcmpiA("wcodstub.dll", p);
338 HeapFree(GetProcessHeap(), 0, data);
340 return isstub;
343 static void print_version (void)
345 #ifdef __i386__
346 static const char platform[] = "i386";
347 #elif defined(__x86_64__)
348 static const char platform[] = "x86_64";
349 #elif defined(__arm__)
350 static const char platform[] = "arm";
351 #elif defined(__aarch64__)
352 static const char platform[] = "arm64";
353 #else
354 # error CPU unknown
355 #endif
356 OSVERSIONINFOEXA ver;
357 RTL_OSVERSIONINFOEXW rtlver;
358 BOOL ext;
359 int is_win2k3_r2, is_admin, is_elevated;
360 const char *(CDECL *wine_get_build_id)(void);
361 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
362 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
363 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
364 NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
366 ver.dwOSVersionInfoSize = sizeof(ver);
367 if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
369 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
370 if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
371 report (R_FATAL, "Can't get OS version.");
374 /* try to get non-faked values */
375 if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
377 rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
379 pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
380 pRtlGetVersion(&rtlver);
382 ver.dwMajorVersion = rtlver.dwMajorVersion;
383 ver.dwMinorVersion = rtlver.dwMinorVersion;
384 ver.dwBuildNumber = rtlver.dwBuildNumber;
385 ver.dwPlatformId = rtlver.dwPlatformId;
386 ver.wServicePackMajor = rtlver.wServicePackMajor;
387 ver.wServicePackMinor = rtlver.wServicePackMinor;
388 ver.wSuiteMask = rtlver.wSuiteMask;
389 ver.wProductType = rtlver.wProductType;
391 WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
394 xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
395 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
396 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
397 is_admin = running_as_admin ();
398 if (0 <= is_admin)
400 xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
401 is_elevated = running_elevated ();
402 if (0 <= is_elevated)
403 xprintf(", %s", is_elevated ? "elevated" : "not elevated");
404 xprintf ("\n");
406 xprintf (" Submitter=%s\n", email );
407 if (description)
408 xprintf (" Description=%s\n", description );
409 if (url)
410 xprintf (" URL=%s\n", url );
411 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
412 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
413 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
414 ver.dwPlatformId, ver.szCSDVersion);
416 wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
417 wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
418 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
419 if (wine_get_host_version)
421 const char *sysname, *release;
422 wine_get_host_version( &sysname, &release );
423 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
425 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
426 if(is_win2k3_r2)
427 xprintf(" R2 build number=%d\n", is_win2k3_r2);
429 if (!ext) return;
431 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
432 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
433 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
434 ver.wProductType, ver.wReserved);
436 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
437 if (pGetProductInfo && !running_under_wine())
439 DWORD prodtype = 0;
441 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
442 xprintf(" dwProductInfo=%u\n", prodtype);
446 static void print_language(void)
448 HMODULE hkernel32;
449 BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
450 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
451 LANGID (WINAPI *pGetThreadUILanguage)(void);
453 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
454 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
455 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
457 hkernel32 = GetModuleHandleA("kernel32.dll");
458 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
459 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
460 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
462 if (pGetSystemPreferredUILanguages && !running_under_wine())
464 WCHAR langW[32];
465 ULONG num, size = ARRAY_SIZE(langW);
466 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
468 char lang[32], *p = lang;
469 WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
470 for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
471 xprintf (" SystemPreferredUILanguages=%s\n", lang);
474 if (pGetUserDefaultUILanguage)
475 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
476 if (pGetThreadUILanguage)
477 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
480 static inline BOOL is_dot_dir(const char* x)
482 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
485 static void remove_dir (const char *dir)
487 HANDLE hFind;
488 WIN32_FIND_DATAA wfd;
489 char path[MAX_PATH];
490 size_t dirlen = strlen (dir);
492 /* Make sure the directory exists before going further */
493 memcpy (path, dir, dirlen);
494 strcpy (path + dirlen++, "\\*");
495 hFind = FindFirstFileA (path, &wfd);
496 if (hFind == INVALID_HANDLE_VALUE) return;
498 do {
499 char *lp = wfd.cFileName;
501 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
502 if (is_dot_dir (lp)) continue;
503 strcpy (path + dirlen, lp);
504 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
505 remove_dir(path);
506 else if (!DeleteFileA(path))
507 report (R_WARNING, "Can't delete file %s: error %d",
508 path, GetLastError ());
509 } while (FindNextFileA(hFind, &wfd));
510 FindClose (hFind);
511 if (!RemoveDirectoryA(dir))
512 report (R_WARNING, "Can't remove directory %s: error %d",
513 dir, GetLastError ());
516 static const char* get_test_source_file(const char* test, const char* subtest)
518 static char buffer[MAX_PATH];
519 int len = strlen(test);
521 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
523 len = sprintf(buffer, "programs/%s", test) - 4;
524 buffer[len] = 0;
526 else len = sprintf(buffer, "dlls/%s", test);
528 sprintf(buffer + len, "/tests/%s.c", subtest);
529 return buffer;
532 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
534 HRSRC rsrc;
535 HGLOBAL hdl;
536 LPVOID addr;
538 if (!(rsrc = FindResourceA(NULL, name, type)) ||
539 !(*size = SizeofResource (0, rsrc)) ||
540 !(hdl = LoadResource (0, rsrc)) ||
541 !(addr = LockResource (hdl)))
542 return NULL;
543 return addr;
546 /* Fills in the name and exename fields */
547 static void
548 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
550 BYTE* code;
551 DWORD size;
552 char *exepos;
553 HANDLE hfile;
554 DWORD written;
556 code = extract_rcdata (res_name, "TESTRES", &size);
557 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
558 res_name, GetLastError ());
559 test->name = heap_strdup( res_name );
560 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
561 exepos = strstr (test->name, testexe);
562 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
563 *exepos = 0;
564 test->name = heap_realloc (test->name, exepos - test->name + 1);
565 report (R_STEP, "Extracting: %s", test->name);
567 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
568 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
569 if (hfile == INVALID_HANDLE_VALUE)
570 report (R_FATAL, "Failed to open file %s.", test->exename);
572 if (!WriteFile(hfile, code, size, &written, NULL))
573 report (R_FATAL, "Failed to write file %s.", test->exename);
575 CloseHandle(hfile);
578 static DWORD wait_process( HANDLE process, DWORD timeout )
580 DWORD wait, diff = 0, start = GetTickCount();
581 MSG msg;
583 while (diff < timeout)
585 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
586 if (wait != WAIT_OBJECT_0 + 1) return wait;
587 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
588 diff = GetTickCount() - start;
590 return WAIT_TIMEOUT;
593 static void append_path( const char *path)
595 char *newpath;
597 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
598 strcpy(newpath, curpath);
599 strcat(newpath, ";");
600 strcat(newpath, path);
601 SetEnvironmentVariableA("PATH", newpath);
603 heap_free(newpath);
606 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
607 stdout to there.
609 Return the exit status, -2 if can't create process or the return
610 value of WaitForSingleObject.
612 static int
613 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritical, DWORD* pid)
615 STARTUPINFOA si;
616 PROCESS_INFORMATION pi;
617 DWORD wait, status, flags;
618 UINT old_errmode;
620 /* Flush to disk so we know which test caused Windows to crash if it does */
621 if (out_file)
622 FlushFileBuffers(out_file);
624 GetStartupInfoA (&si);
625 si.dwFlags = STARTF_USESTDHANDLES;
626 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
627 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
628 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
629 if (nocritical)
631 old_errmode = SetErrorMode(0);
632 SetErrorMode(old_errmode | SEM_FAILCRITICALERRORS);
633 flags = 0;
635 else
636 flags = CREATE_DEFAULT_ERROR_MODE;
638 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, flags,
639 NULL, tempdir, &si, &pi))
641 if (nocritical) SetErrorMode(old_errmode);
642 if (pid) *pid = 0;
643 return -2;
646 if (nocritical) SetErrorMode(old_errmode);
647 CloseHandle (pi.hThread);
648 if (pid) *pid = pi.dwProcessId;
649 status = wait_process( pi.hProcess, ms );
650 switch (status)
652 case WAIT_OBJECT_0:
653 GetExitCodeProcess (pi.hProcess, &status);
654 CloseHandle (pi.hProcess);
655 return status;
656 case WAIT_FAILED:
657 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
658 break;
659 case WAIT_TIMEOUT:
660 break;
661 default:
662 report (R_ERROR, "Wait returned %d", status);
663 break;
665 if (!TerminateProcess (pi.hProcess, 257))
666 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
667 wait = wait_process( pi.hProcess, 5000 );
668 switch (wait)
670 case WAIT_OBJECT_0:
671 break;
672 case WAIT_FAILED:
673 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
674 break;
675 case WAIT_TIMEOUT:
676 report (R_ERROR, "Can't kill process '%s'", cmd);
677 break;
678 default:
679 report (R_ERROR, "Waiting for termination: %d", wait);
680 break;
682 CloseHandle (pi.hProcess);
683 return status;
686 static DWORD
687 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
689 char *cmd;
690 HANDLE subfile;
691 DWORD err, total;
692 char buffer[8192], *index;
693 static const char header[] = "Valid test names:";
694 int status, allocated;
695 char tmpdir[MAX_PATH], subname[MAX_PATH];
696 SECURITY_ATTRIBUTES sa;
698 test->subtest_count = 0;
700 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
701 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
702 report (R_FATAL, "Can't name subtests file.");
704 /* make handle inheritable */
705 sa.nLength = sizeof(sa);
706 sa.lpSecurityDescriptor = NULL;
707 sa.bInheritHandle = TRUE;
709 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
710 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
711 &sa, CREATE_ALWAYS, 0, NULL );
713 if ((subfile == INVALID_HANDLE_VALUE) &&
714 (GetLastError() == ERROR_INVALID_PARAMETER)) {
715 /* FILE_SHARE_DELETE not supported on win9x */
716 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
717 FILE_SHARE_READ | FILE_SHARE_WRITE,
718 &sa, CREATE_ALWAYS, 0, NULL );
720 if (subfile == INVALID_HANDLE_VALUE) {
721 err = GetLastError();
722 report (R_ERROR, "Can't open subtests output of %s: %u",
723 test->name, GetLastError());
724 goto quit;
727 cmd = strmake (NULL, "%s --list", test->exename);
728 if (test->maindllpath) {
729 /* We need to add the path (to the main dll) to PATH */
730 append_path(test->maindllpath);
732 status = run_ex (cmd, subfile, tempdir, 5000, TRUE, NULL);
733 err = GetLastError();
734 if (test->maindllpath) {
735 /* Restore PATH again */
736 SetEnvironmentVariableA("PATH", curpath);
738 heap_free (cmd);
740 if (status)
742 if (status == -2)
743 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
744 else
745 err = status;
746 CloseHandle( subfile );
747 goto quit;
750 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
751 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
752 CloseHandle( subfile );
753 if (sizeof buffer == total) {
754 report (R_ERROR, "Subtest list of %s too big.",
755 test->name, sizeof buffer);
756 err = ERROR_OUTOFMEMORY;
757 goto quit;
759 buffer[total] = 0;
761 index = strstr (buffer, header);
762 if (!index) {
763 report (R_ERROR, "Can't parse subtests output of %s",
764 test->name);
765 err = ERROR_INTERNAL_ERROR;
766 goto quit;
768 index += sizeof header;
770 allocated = 10;
771 test->subtests = heap_alloc (allocated * sizeof(char*));
772 index = strtok (index, whitespace);
773 while (index) {
774 if (test->subtest_count == allocated) {
775 allocated *= 2;
776 test->subtests = heap_realloc (test->subtests,
777 allocated * sizeof(char*));
779 test->subtests[test->subtest_count++] = heap_strdup(index);
780 index = strtok (NULL, whitespace);
782 test->subtests = heap_realloc (test->subtests,
783 test->subtest_count * sizeof(char*));
784 err = 0;
786 quit:
787 if (!DeleteFileA (subname))
788 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
789 return err;
792 static void
793 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
795 /* Build the source filename so analysis tools can link to it */
796 const char* file = get_test_source_file(test->name, subtest);
798 if (test_filtered_out( test->name, subtest ))
800 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
801 xprintf ("%s:%s skipped %s\n", test->name, subtest, file);
802 nr_of_skips++;
804 else
806 int status;
807 DWORD pid, start = GetTickCount();
808 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
809 report (R_STEP, "Running: %s:%s", test->name, subtest);
810 xprintf ("%s:%s start %s\n", test->name, subtest, file);
811 status = run_ex (cmd, out_file, tempdir, 120000, FALSE, &pid);
812 heap_free (cmd);
813 xprintf ("%s:%s:%04x done (%d) in %ds\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000);
814 if (status) failures++;
816 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
819 static BOOL CALLBACK
820 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
821 LPSTR lpszName, LONG_PTR lParam)
823 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
824 return TRUE;
827 static const struct clsid_mapping
829 const char *name;
830 CLSID clsid;
831 } clsid_list[] =
833 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
834 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
838 static BOOL get_main_clsid(const char *name, CLSID *clsid)
840 const struct clsid_mapping *mapping;
842 for(mapping = clsid_list; mapping->name; mapping++)
844 if(!strcasecmp(name, mapping->name))
846 *clsid = mapping->clsid;
847 return TRUE;
850 return FALSE;
853 static HMODULE load_com_dll(const char *name, char **path, char *filename)
855 HMODULE dll = NULL;
856 HKEY hkey;
857 char keyname[100];
858 char dllname[MAX_PATH];
859 char *p;
860 CLSID clsid;
862 if(!get_main_clsid(name, &clsid)) return NULL;
864 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
865 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
866 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
867 clsid.Data4[6], clsid.Data4[7]);
869 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
871 LONG size = sizeof(dllname);
872 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
874 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
876 strcpy( filename, dllname );
877 p = strrchr(dllname, '\\');
878 if (p) *p = 0;
879 *path = heap_strdup( dllname );
882 RegCloseKey(hkey);
885 return dll;
888 static void get_dll_path(HMODULE dll, char **path, char *filename)
890 char dllpath[MAX_PATH];
892 GetModuleFileNameA(dll, dllpath, MAX_PATH);
893 strcpy(filename, dllpath);
894 *strrchr(dllpath, '\\') = '\0';
895 *path = heap_strdup( dllpath );
898 static BOOL CALLBACK
899 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
901 const char *tempdir = (const char *)lParam;
902 char dllname[MAX_PATH];
903 char filename[MAX_PATH];
904 WCHAR dllnameW[MAX_PATH];
905 HMODULE dll;
906 DWORD err;
907 HANDLE actctx;
908 ULONG_PTR cookie;
909 BOOL run;
911 if (aborting) return TRUE;
913 /* Check if the main dll is present on this system */
914 CharLowerA(lpszName);
915 strcpy(dllname, lpszName);
916 *strstr(dllname, testexe) = 0;
918 if (test_filtered_out( lpszName, NULL ))
920 nr_of_skips++;
921 return TRUE;
923 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
925 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
926 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
928 ACTCTXA actctxinfo;
929 memset(&actctxinfo, 0, sizeof(ACTCTXA));
930 actctxinfo.cbSize = sizeof(ACTCTXA);
931 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
932 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
933 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
934 actctx = pCreateActCtxA(&actctxinfo);
935 if (actctx != INVALID_HANDLE_VALUE &&
936 ! pActivateActCtx(actctx, &cookie))
938 pReleaseActCtx(actctx);
939 actctx = INVALID_HANDLE_VALUE;
941 } else actctx = INVALID_HANDLE_VALUE;
943 wine_tests[nr_of_files].maindllpath = NULL;
944 strcpy(filename, dllname);
945 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
947 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
949 if (!dll && pLoadLibraryShim)
951 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
952 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
954 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
955 FreeLibrary(dll);
956 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
958 else dll = 0;
961 run = TRUE;
962 if (dll)
964 if (is_stub_dll(dllname))
966 xprintf (" %s=dll is a stub\n", dllname);
967 run = FALSE;
969 else if (is_native_dll(dll))
971 xprintf (" %s=dll is native\n", dllname);
972 nr_native_dlls++;
973 run = FALSE;
975 FreeLibrary(dll);
978 if (run)
980 err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
981 switch (err)
983 case 0:
984 xprintf (" %s=%s\n", dllname, get_file_version(filename));
985 nr_of_tests += wine_tests[nr_of_files].subtest_count;
986 nr_of_files++;
987 break;
988 case STATUS_DLL_NOT_FOUND:
989 xprintf (" %s=dll is missing\n", dllname);
990 /* or it is a side-by-side dll but the test has no manifest */
991 break;
992 case STATUS_ORDINAL_NOT_FOUND:
993 xprintf (" %s=dll is missing an ordinal (%s)\n", dllname, get_file_version(filename));
994 break;
995 case STATUS_ENTRYPOINT_NOT_FOUND:
996 xprintf (" %s=dll is missing an entrypoint (%s)\n", dllname, get_file_version(filename));
997 break;
998 case ERROR_SXS_CANT_GEN_ACTCTX:
999 xprintf (" %s=dll is missing the requested side-by-side version\n", dllname);
1000 break;
1001 default:
1002 xprintf (" %s=load error %u\n", dllname, err);
1003 break;
1007 if (actctx != INVALID_HANDLE_VALUE)
1009 pDeactivateActCtx(0, cookie);
1010 pReleaseActCtx(actctx);
1012 return TRUE;
1015 static char *
1016 run_tests (char *logname, char *outdir)
1018 int i;
1019 char *strres, *eol, *nextline;
1020 DWORD strsize;
1021 SECURITY_ATTRIBUTES sa;
1022 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1023 DWORD needed;
1024 HMODULE kernel32;
1026 /* Get the current PATH only once */
1027 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1028 curpath = heap_alloc(needed);
1029 GetEnvironmentVariableA("PATH", curpath, needed);
1031 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1033 if (!GetTempPathA( MAX_PATH, tmppath ))
1034 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1036 if (!logname) {
1037 static char tmpname[MAX_PATH];
1038 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1039 report (R_FATAL, "Can't name logfile.");
1040 logname = tmpname;
1042 report (R_OUT, logname);
1044 /* make handle inheritable */
1045 sa.nLength = sizeof(sa);
1046 sa.lpSecurityDescriptor = NULL;
1047 sa.bInheritHandle = TRUE;
1049 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1050 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1051 &sa, CREATE_ALWAYS, 0, NULL );
1053 if ((logfile == INVALID_HANDLE_VALUE) &&
1054 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1055 /* FILE_SHARE_DELETE not supported on win9x */
1056 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1057 FILE_SHARE_READ | FILE_SHARE_WRITE,
1058 &sa, CREATE_ALWAYS, 0, NULL );
1060 if (logfile == INVALID_HANDLE_VALUE)
1061 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1063 /* try stable path for ZoneAlarm */
1064 if (!outdir) {
1065 strcpy( tempdir, tmppath );
1066 strcat( tempdir, "wct" );
1068 if (!CreateDirectoryA( tempdir, NULL ))
1070 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1071 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1072 DeleteFileA( tempdir );
1073 if (!CreateDirectoryA( tempdir, NULL ))
1074 report (R_FATAL, "Could not create directory: %s", tempdir);
1077 else
1078 strcpy( tempdir, outdir);
1080 report (R_DIR, tempdir);
1082 xprintf ("Version 4\n");
1083 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1084 xprintf ("Archive: -\n"); /* no longer used */
1085 xprintf ("Tag: %s\n", tag);
1086 xprintf ("Build info:\n");
1087 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1088 while (strres) {
1089 eol = memchr (strres, '\n', strsize);
1090 if (!eol) {
1091 nextline = NULL;
1092 eol = strres + strsize;
1093 } else {
1094 strsize -= eol - strres + 1;
1095 nextline = strsize?eol+1:NULL;
1096 if (eol > strres && *(eol-1) == '\r') eol--;
1098 xprintf (" %.*s\n", eol-strres, strres);
1099 strres = nextline;
1101 xprintf ("Operating system version:\n");
1102 print_version ();
1103 print_language ();
1104 xprintf ("Dll info:\n" );
1106 report (R_STATUS, "Counting tests");
1107 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1108 report (R_FATAL, "Can't enumerate test files: %d",
1109 GetLastError ());
1110 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1112 /* Do this only once during extraction (and version checking) */
1113 hmscoree = LoadLibraryA("mscoree.dll");
1114 pLoadLibraryShim = NULL;
1115 if (hmscoree)
1116 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1117 kernel32 = GetModuleHandleA("kernel32.dll");
1118 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1119 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1120 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1121 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1123 report (R_STATUS, "Extracting tests");
1124 report (R_PROGRESS, 0, nr_of_files);
1125 nr_of_files = 0;
1126 nr_of_tests = 0;
1127 nr_of_skips = 0;
1128 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1129 report (R_FATAL, "Can't enumerate test files: %d",
1130 GetLastError ());
1132 FreeLibrary(hmscoree);
1134 if (aborting) return logname;
1136 xprintf ("Test output:\n" );
1138 report (R_DELTA, 0, "Extracting: Done");
1140 if (nr_native_dlls)
1141 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1143 report (R_STATUS, "Running tests");
1144 report (R_PROGRESS, 1, nr_of_tests);
1145 for (i = 0; i < nr_of_files; i++) {
1146 struct wine_test *test = wine_tests + i;
1147 int j;
1149 if (aborting) break;
1151 if (test->maindllpath) {
1152 /* We need to add the path (to the main dll) to PATH */
1153 append_path(test->maindllpath);
1156 for (j = 0; j < test->subtest_count; j++) {
1157 if (aborting) break;
1158 run_test (test, test->subtests[j], logfile, tempdir);
1161 if (test->maindllpath) {
1162 /* Restore PATH again */
1163 SetEnvironmentVariableA("PATH", curpath);
1166 report (R_DELTA, 0, "Running: Done");
1168 report (R_STATUS, "Cleaning up - %u failures", failures);
1169 CloseHandle( logfile );
1170 logfile = 0;
1171 if (!outdir)
1172 remove_dir (tempdir);
1173 heap_free(wine_tests);
1174 heap_free(curpath);
1176 return logname;
1179 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1181 if (ctrl_type == CTRL_C_EVENT) {
1182 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1183 return TRUE;
1186 return FALSE;
1190 static BOOL CALLBACK
1191 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1193 const char *target_dir = (const char *)lParam;
1194 char filename[MAX_PATH];
1196 if (test_filtered_out( lpszName, NULL )) return TRUE;
1198 strcpy(filename, lpszName);
1199 CharLowerA(filename);
1201 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1202 nr_of_files++;
1203 return TRUE;
1206 static void extract_only (const char *target_dir)
1208 BOOL res;
1210 report (R_DIR, target_dir);
1211 res = CreateDirectoryA( target_dir, NULL );
1212 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1213 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1215 nr_of_files = 0;
1216 report (R_STATUS, "Counting tests");
1217 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1218 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1220 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1222 report (R_STATUS, "Extracting tests");
1223 report (R_PROGRESS, 0, nr_of_files);
1224 nr_of_files = 0;
1225 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1226 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1228 report (R_DELTA, 0, "Extracting: Done");
1231 static void
1232 usage (void)
1234 fprintf (stderr,
1235 "Usage: winetest [OPTION]... [TESTS]\n\n"
1236 " --help print this message and exit\n"
1237 " --version print the build version and exit\n"
1238 " -c console mode, no GUI\n"
1239 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1240 " -e preserve the environment\n"
1241 " -h print this message and exit\n"
1242 " -i INFO an optional description of the test platform\n"
1243 " -m MAIL an email address to enable developers to contact you\n"
1244 " -n exclude the specified tests\n"
1245 " -p shutdown when the tests are done\n"
1246 " -q quiet mode, no output at all\n"
1247 " -o FILE put report into FILE, do not submit\n"
1248 " -s FILE submit FILE, do not run tests\n"
1249 " -S URL URL to submit the results to\n"
1250 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1251 " -u URL include TestBot URL in the report\n"
1252 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1255 int __cdecl main( int argc, char *argv[] )
1257 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1258 char *logname = NULL, *outdir = NULL;
1259 const char *extract = NULL;
1260 const char *cp, *submit = NULL, *submiturl = NULL;
1261 int reset_env = 1;
1262 int poweroff = 0;
1263 int interactive = 1;
1264 int i;
1266 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1268 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1269 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1271 for (i = 1; i < argc && argv[i]; i++)
1273 if (!strcmp(argv[i], "--help")) {
1274 usage ();
1275 exit (0);
1277 else if (!strcmp(argv[i], "--version")) {
1278 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1279 exit (0);
1281 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1282 if (nb_filters == ARRAY_SIZE(filters))
1284 report (R_ERROR, "Too many test filters specified");
1285 exit (2);
1287 filters[nb_filters++] = argv[i];
1289 else switch (argv[i][1]) {
1290 case 'c':
1291 report (R_TEXTMODE);
1292 interactive = 0;
1293 break;
1294 case 'e':
1295 reset_env = 0;
1296 break;
1297 case 'h':
1298 case '?':
1299 usage ();
1300 exit (0);
1301 case 'i':
1302 if (!(description = argv[++i]))
1304 usage();
1305 exit( 2 );
1307 break;
1308 case 'm':
1309 if (!(email = argv[++i]))
1311 usage();
1312 exit( 2 );
1314 break;
1315 case 'n':
1316 exclude_tests = TRUE;
1317 break;
1318 case 'p':
1319 poweroff = 1;
1320 break;
1321 case 'q':
1322 report (R_QUIET);
1323 interactive = 0;
1324 break;
1325 case 's':
1326 if (!(submit = argv[++i]))
1328 usage();
1329 exit( 2 );
1331 break;
1332 case 'S':
1333 if (!(submiturl = argv[++i]))
1335 usage();
1336 exit( 2 );
1338 break;
1339 case 'o':
1340 if (!(logname = argv[++i]))
1342 usage();
1343 exit( 2 );
1345 break;
1346 case 't':
1347 if (!(tag = argv[++i]))
1349 usage();
1350 exit( 2 );
1352 if (strlen (tag) > MAXTAGLEN)
1353 report (R_FATAL, "tag is too long (maximum %d characters)",
1354 MAXTAGLEN);
1355 cp = findbadtagchar (tag);
1356 if (cp) {
1357 report (R_ERROR, "invalid char in tag: %c", *cp);
1358 usage ();
1359 exit (2);
1361 break;
1362 case 'u':
1363 if (!(url = argv[++i]))
1365 usage();
1366 exit( 2 );
1368 break;
1369 case 'x':
1370 report (R_TEXTMODE);
1371 if (!(extract = argv[++i]))
1372 extract = ".\\wct";
1374 extract_only (extract);
1375 break;
1376 case 'd':
1377 outdir = argv[++i];
1378 break;
1379 default:
1380 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1381 usage ();
1382 exit (2);
1385 if (submit) {
1386 if (tag)
1387 report (R_WARNING, "ignoring tag for submission");
1388 send_file (submiturl, submit);
1390 } else if (!extract) {
1391 int is_win9x = (GetVersion() & 0x80000000) != 0;
1393 report (R_STATUS, "Starting up");
1395 if (is_win9x)
1396 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1398 if (!running_on_visible_desktop ())
1399 report (R_FATAL, "Tests must be run on a visible desktop");
1401 if (running_under_wine())
1403 if (!check_mount_mgr())
1404 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1406 if (!check_wow64_registry())
1407 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1409 if (!check_display_driver())
1410 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1413 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1415 if (reset_env)
1417 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1418 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1419 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1420 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1423 if (nb_filters && !exclude_tests)
1425 run_tests( logname, outdir );
1426 exit(0);
1429 while (!tag) {
1430 if (!interactive)
1431 report (R_FATAL, "Please specify a tag (-t option) if "
1432 "running noninteractive!");
1433 if (guiAskTag () == IDABORT) exit (1);
1435 report (R_TAG);
1437 while (!email) {
1438 if (!interactive)
1439 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1440 " to contact you about your report if necessary.");
1441 if (guiAskEmail () == IDABORT) exit (1);
1444 if (!build_id[0])
1445 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1446 "To submit results, winetest needs to be built from a git checkout." );
1448 if (!logname) {
1449 logname = run_tests (NULL, outdir);
1450 if (aborting) {
1451 DeleteFileA(logname);
1452 exit (0);
1454 if (failures > FAILURES_LIMIT)
1455 report( R_WARNING,
1456 "%d tests failed. There is probably something broken with your setup.\n"
1457 "You need to address this before submitting results.", failures );
1459 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1460 !nr_native_dlls && !is_win9x &&
1461 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1462 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1463 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1464 } else run_tests (logname, outdir);
1465 report (R_STATUS, "Finished - %u failures", failures);
1467 if (poweroff)
1469 HANDLE hToken;
1470 TOKEN_PRIVILEGES npr;
1472 /* enable the shutdown privilege for the current process */
1473 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1475 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1476 npr.PrivilegeCount = 1;
1477 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1478 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1479 CloseHandle(hToken);
1481 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1483 exit (0);