winegstreamer: Move seeking to the Unix library.
[wine.git] / programs / winetest / main.c
blob1731850bfdb30bf44a2f7f2213b1fb3c01e5c7a9
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 available");
133 } else
134 sprintf(version, "unknown");
135 heap_free(data);
136 } else
137 sprintf(version, "failed");
138 } else
139 sprintf(version, "version not available");
141 return version;
144 static BOOL running_under_wine (void)
146 HMODULE module = GetModuleHandleA("ntdll.dll");
148 if (!module) return FALSE;
149 return (GetProcAddress(module, "wine_server_call") != NULL);
152 static BOOL check_mount_mgr(void)
154 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
155 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
156 if (handle == INVALID_HANDLE_VALUE) return FALSE;
157 CloseHandle( handle );
158 return TRUE;
161 static BOOL check_wow64_registry(void)
163 char buffer[MAX_PATH];
164 DWORD type, size = MAX_PATH;
165 HKEY hkey;
166 BOOL ret;
168 if (!is_wow64) return TRUE;
169 if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey ))
170 return FALSE;
171 ret = !RegQueryValueExA( hkey, "ProgramFilesDir (x86)", NULL, &type, (BYTE *)buffer, &size );
172 RegCloseKey( hkey );
173 return ret;
176 static BOOL check_display_driver(void)
178 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
179 0, 0, GetModuleHandleA(0), 0 );
180 if (!hwnd) return FALSE;
181 DestroyWindow( hwnd );
182 return TRUE;
185 static BOOL running_on_visible_desktop (void)
187 HWND desktop;
188 HMODULE huser32 = GetModuleHandleA("user32.dll");
189 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
190 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
192 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
193 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
195 desktop = GetDesktopWindow();
196 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
197 return IsWindowVisible(desktop);
199 if (pGetProcessWindowStation && pGetUserObjectInformationA)
201 DWORD len;
202 HWINSTA wstation;
203 USEROBJECTFLAGS uoflags;
205 wstation = pGetProcessWindowStation();
206 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
207 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
209 return IsWindowVisible(desktop);
212 static int running_as_admin (void)
214 PSID administrators = NULL;
215 SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
216 HANDLE token;
217 DWORD groups_size;
218 PTOKEN_GROUPS groups;
219 DWORD group_index;
221 /* Create a well-known SID for the Administrators group. */
222 if (! AllocateAndInitializeSid(&nt_authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
223 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
224 &administrators))
225 return -1;
227 /* Get the process token */
228 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
230 FreeSid(administrators);
231 return -1;
234 /* Get the group info from the token */
235 groups_size = 0;
236 GetTokenInformation(token, TokenGroups, NULL, 0, &groups_size);
237 groups = heap_alloc(groups_size);
238 if (groups == NULL)
240 CloseHandle(token);
241 FreeSid(administrators);
242 return -1;
244 if (! GetTokenInformation(token, TokenGroups, groups, groups_size, &groups_size))
246 heap_free(groups);
247 CloseHandle(token);
248 FreeSid(administrators);
249 return -1;
251 CloseHandle(token);
253 /* Now check if the token groups include the Administrators group */
254 for (group_index = 0; group_index < groups->GroupCount; group_index++)
256 if (EqualSid(groups->Groups[group_index].Sid, administrators))
258 heap_free(groups);
259 FreeSid(administrators);
260 return 1;
264 /* If we end up here we didn't find the Administrators group */
265 heap_free(groups);
266 FreeSid(administrators);
267 return 0;
270 static int running_elevated (void)
272 HANDLE token;
273 TOKEN_ELEVATION elevation_info;
274 DWORD size;
276 /* Get the process token */
277 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
278 return -1;
280 /* Get the elevation info from the token */
281 if (! GetTokenInformation(token, TokenElevation, &elevation_info,
282 sizeof(TOKEN_ELEVATION), &size))
284 CloseHandle(token);
285 return -1;
287 CloseHandle(token);
289 return elevation_info.TokenIsElevated;
292 /* check for native dll when running under wine */
293 static BOOL is_native_dll( HMODULE module )
295 static const char builtin_signature[] = "Wine builtin DLL";
296 static const char fakedll_signature[] = "Wine placeholder DLL";
297 const IMAGE_DOS_HEADER *dos;
299 if (!running_under_wine()) return FALSE;
300 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
301 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
302 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
303 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
304 if (dos->e_lfanew >= sizeof(*dos) + 32)
306 if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) )) return FALSE;
307 if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
309 return TRUE;
313 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
314 * to install that component. To bypass this check we need to look at the version resource.
316 static BOOL is_stub_dll(const char *filename)
318 DWORD size, ver;
319 BOOL isstub = FALSE;
320 char *p, *data;
322 size = GetFileVersionInfoSizeA(filename, &ver);
323 if (!size) return FALSE;
325 data = HeapAlloc(GetProcessHeap(), 0, size);
326 if (!data) return FALSE;
328 if (GetFileVersionInfoA(filename, ver, size, data))
330 char buf[256];
332 sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
333 if (VerQueryValueA(data, buf, (void**)&p, &size))
334 isstub = !lstrcmpiA("wcodstub.dll", p);
336 HeapFree(GetProcessHeap(), 0, data);
338 return isstub;
341 static void print_version (void)
343 #ifdef __i386__
344 static const char platform[] = "i386";
345 #elif defined(__x86_64__)
346 static const char platform[] = "x86_64";
347 #elif defined(__arm__)
348 static const char platform[] = "arm";
349 #elif defined(__aarch64__)
350 static const char platform[] = "arm64";
351 #else
352 # error CPU unknown
353 #endif
354 OSVERSIONINFOEXA ver;
355 RTL_OSVERSIONINFOEXW rtlver;
356 BOOL ext;
357 int is_win2k3_r2, is_admin, is_elevated;
358 const char *(CDECL *wine_get_build_id)(void);
359 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
360 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
361 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
362 NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
364 ver.dwOSVersionInfoSize = sizeof(ver);
365 if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
367 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
368 if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
369 report (R_FATAL, "Can't get OS version.");
372 /* try to get non-faked values */
373 if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
375 rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
377 pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
378 pRtlGetVersion(&rtlver);
380 ver.dwMajorVersion = rtlver.dwMajorVersion;
381 ver.dwMinorVersion = rtlver.dwMinorVersion;
382 ver.dwBuildNumber = rtlver.dwBuildNumber;
383 ver.dwPlatformId = rtlver.dwPlatformId;
384 ver.wServicePackMajor = rtlver.wServicePackMajor;
385 ver.wServicePackMinor = rtlver.wServicePackMinor;
386 ver.wSuiteMask = rtlver.wSuiteMask;
387 ver.wProductType = rtlver.wProductType;
389 WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
392 xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
393 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
394 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
395 is_admin = running_as_admin ();
396 if (0 <= is_admin)
398 xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
399 is_elevated = running_elevated ();
400 if (0 <= is_elevated)
401 xprintf(", %s", is_elevated ? "elevated" : "not elevated");
402 xprintf ("\n");
404 xprintf (" Submitter=%s\n", email );
405 if (description)
406 xprintf (" Description=%s\n", description );
407 if (url)
408 xprintf (" URL=%s\n", url );
409 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
410 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
411 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
412 ver.dwPlatformId, ver.szCSDVersion);
414 wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
415 wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
416 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
417 if (wine_get_host_version)
419 const char *sysname, *release;
420 wine_get_host_version( &sysname, &release );
421 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
423 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
424 if(is_win2k3_r2)
425 xprintf(" R2 build number=%d\n", is_win2k3_r2);
427 if (!ext) return;
429 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
430 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
431 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
432 ver.wProductType, ver.wReserved);
434 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
435 if (pGetProductInfo && !running_under_wine())
437 DWORD prodtype = 0;
439 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
440 xprintf(" dwProductInfo=%u\n", prodtype);
444 static void print_language(void)
446 HMODULE hkernel32;
447 BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
448 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
449 LANGID (WINAPI *pGetThreadUILanguage)(void);
451 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
452 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
453 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
455 hkernel32 = GetModuleHandleA("kernel32.dll");
456 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
457 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
458 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
460 if (pGetSystemPreferredUILanguages && !running_under_wine())
462 WCHAR langW[32];
463 ULONG num, size = ARRAY_SIZE(langW);
464 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
466 char lang[32], *p = lang;
467 WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
468 for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
469 xprintf (" SystemPreferredUILanguages=%s\n", lang);
472 if (pGetUserDefaultUILanguage)
473 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
474 if (pGetThreadUILanguage)
475 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
478 static inline BOOL is_dot_dir(const char* x)
480 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
483 static void remove_dir (const char *dir)
485 HANDLE hFind;
486 WIN32_FIND_DATAA wfd;
487 char path[MAX_PATH];
488 size_t dirlen = strlen (dir);
490 /* Make sure the directory exists before going further */
491 memcpy (path, dir, dirlen);
492 strcpy (path + dirlen++, "\\*");
493 hFind = FindFirstFileA (path, &wfd);
494 if (hFind == INVALID_HANDLE_VALUE) return;
496 do {
497 char *lp = wfd.cFileName;
499 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
500 if (is_dot_dir (lp)) continue;
501 strcpy (path + dirlen, lp);
502 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
503 remove_dir(path);
504 else if (!DeleteFileA(path))
505 report (R_WARNING, "Can't delete file %s: error %d",
506 path, GetLastError ());
507 } while (FindNextFileA(hFind, &wfd));
508 FindClose (hFind);
509 if (!RemoveDirectoryA(dir))
510 report (R_WARNING, "Can't remove directory %s: error %d",
511 dir, GetLastError ());
514 static const char* get_test_source_file(const char* test, const char* subtest)
516 static char buffer[MAX_PATH];
517 int len = strlen(test);
519 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
521 len = sprintf(buffer, "programs/%s", test) - 4;
522 buffer[len] = 0;
524 else len = sprintf(buffer, "dlls/%s", test);
526 sprintf(buffer + len, "/tests/%s.c", subtest);
527 return buffer;
530 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
532 HRSRC rsrc;
533 HGLOBAL hdl;
534 LPVOID addr;
536 if (!(rsrc = FindResourceA(NULL, name, type)) ||
537 !(*size = SizeofResource (0, rsrc)) ||
538 !(hdl = LoadResource (0, rsrc)) ||
539 !(addr = LockResource (hdl)))
540 return NULL;
541 return addr;
544 /* Fills in the name and exename fields */
545 static void
546 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
548 BYTE* code;
549 DWORD size;
550 char *exepos;
551 HANDLE hfile;
552 DWORD written;
554 code = extract_rcdata (res_name, "TESTRES", &size);
555 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
556 res_name, GetLastError ());
557 test->name = heap_strdup( res_name );
558 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
559 exepos = strstr (test->name, testexe);
560 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
561 *exepos = 0;
562 test->name = heap_realloc (test->name, exepos - test->name + 1);
563 report (R_STEP, "Extracting: %s", test->name);
565 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
566 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
567 if (hfile == INVALID_HANDLE_VALUE)
568 report (R_FATAL, "Failed to open file %s.", test->exename);
570 if (!WriteFile(hfile, code, size, &written, NULL))
571 report (R_FATAL, "Failed to write file %s.", test->exename);
573 CloseHandle(hfile);
576 static DWORD wait_process( HANDLE process, DWORD timeout )
578 DWORD wait, diff = 0, start = GetTickCount();
579 MSG msg;
581 while (diff < timeout)
583 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
584 if (wait != WAIT_OBJECT_0 + 1) return wait;
585 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
586 diff = GetTickCount() - start;
588 return WAIT_TIMEOUT;
591 static void append_path( const char *path)
593 char *newpath;
595 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
596 strcpy(newpath, curpath);
597 strcat(newpath, ";");
598 strcat(newpath, path);
599 SetEnvironmentVariableA("PATH", newpath);
601 heap_free(newpath);
604 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
605 stdout to there.
607 Return the exit status, -2 if can't create process or the return
608 value of WaitForSingleObject.
610 static int
611 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, DWORD* pid)
613 STARTUPINFOA si;
614 PROCESS_INFORMATION pi;
615 DWORD wait, status;
617 /* Flush to disk so we know which test caused Windows to crash if it does */
618 if (out_file)
619 FlushFileBuffers(out_file);
621 GetStartupInfoA (&si);
622 si.dwFlags = STARTF_USESTDHANDLES;
623 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
624 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
625 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
627 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
628 NULL, tempdir, &si, &pi))
630 if (pid) *pid = 0;
631 return -2;
634 CloseHandle (pi.hThread);
635 if (pid) *pid = pi.dwProcessId;
636 status = wait_process( pi.hProcess, ms );
637 switch (status)
639 case WAIT_OBJECT_0:
640 GetExitCodeProcess (pi.hProcess, &status);
641 CloseHandle (pi.hProcess);
642 return status;
643 case WAIT_FAILED:
644 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
645 break;
646 case WAIT_TIMEOUT:
647 break;
648 default:
649 report (R_ERROR, "Wait returned %d", status);
650 break;
652 if (!TerminateProcess (pi.hProcess, 257))
653 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
654 wait = wait_process( pi.hProcess, 5000 );
655 switch (wait)
657 case WAIT_OBJECT_0:
658 break;
659 case WAIT_FAILED:
660 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
661 break;
662 case WAIT_TIMEOUT:
663 report (R_ERROR, "Can't kill process '%s'", cmd);
664 break;
665 default:
666 report (R_ERROR, "Waiting for termination: %d", wait);
667 break;
669 CloseHandle (pi.hProcess);
670 return status;
673 static DWORD
674 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
676 char *cmd;
677 HANDLE subfile;
678 DWORD err, total;
679 char buffer[8192], *index;
680 static const char header[] = "Valid test names:";
681 int status, allocated;
682 char tmpdir[MAX_PATH], subname[MAX_PATH];
683 SECURITY_ATTRIBUTES sa;
685 test->subtest_count = 0;
687 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
688 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
689 report (R_FATAL, "Can't name subtests file.");
691 /* make handle inheritable */
692 sa.nLength = sizeof(sa);
693 sa.lpSecurityDescriptor = NULL;
694 sa.bInheritHandle = TRUE;
696 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
697 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
698 &sa, CREATE_ALWAYS, 0, NULL );
700 if ((subfile == INVALID_HANDLE_VALUE) &&
701 (GetLastError() == ERROR_INVALID_PARAMETER)) {
702 /* FILE_SHARE_DELETE not supported on win9x */
703 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
704 FILE_SHARE_READ | FILE_SHARE_WRITE,
705 &sa, CREATE_ALWAYS, 0, NULL );
707 if (subfile == INVALID_HANDLE_VALUE) {
708 err = GetLastError();
709 report (R_ERROR, "Can't open subtests output of %s: %u",
710 test->name, GetLastError());
711 goto quit;
714 cmd = strmake (NULL, "%s --list", test->exename);
715 if (test->maindllpath) {
716 /* We need to add the path (to the main dll) to PATH */
717 append_path(test->maindllpath);
719 status = run_ex (cmd, subfile, tempdir, 5000, NULL);
720 err = GetLastError();
721 if (test->maindllpath) {
722 /* Restore PATH again */
723 SetEnvironmentVariableA("PATH", curpath);
725 heap_free (cmd);
727 if (status == -2)
729 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
730 CloseHandle( subfile );
731 goto quit;
734 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
735 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
736 CloseHandle( subfile );
737 if (sizeof buffer == total) {
738 report (R_ERROR, "Subtest list of %s too big.",
739 test->name, sizeof buffer);
740 err = ERROR_OUTOFMEMORY;
741 goto quit;
743 buffer[total] = 0;
745 index = strstr (buffer, header);
746 if (!index) {
747 report (R_ERROR, "Can't parse subtests output of %s",
748 test->name);
749 err = ERROR_INTERNAL_ERROR;
750 goto quit;
752 index += sizeof header;
754 allocated = 10;
755 test->subtests = heap_alloc (allocated * sizeof(char*));
756 index = strtok (index, whitespace);
757 while (index) {
758 if (test->subtest_count == allocated) {
759 allocated *= 2;
760 test->subtests = heap_realloc (test->subtests,
761 allocated * sizeof(char*));
763 test->subtests[test->subtest_count++] = heap_strdup(index);
764 index = strtok (NULL, whitespace);
766 test->subtests = heap_realloc (test->subtests,
767 test->subtest_count * sizeof(char*));
768 err = 0;
770 quit:
771 if (!DeleteFileA (subname))
772 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
773 return err;
776 static void
777 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
779 /* Build the source filename so analysis tools can link to it */
780 const char* file = get_test_source_file(test->name, subtest);
782 if (test_filtered_out( test->name, subtest ))
784 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
785 xprintf ("%s:%s skipped %s -\n", test->name, subtest, file);
786 nr_of_skips++;
788 else
790 int status;
791 DWORD pid, start = GetTickCount();
792 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
793 report (R_STEP, "Running: %s:%s", test->name, subtest);
794 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
795 status = run_ex (cmd, out_file, tempdir, 120000, &pid);
796 heap_free (cmd);
797 xprintf ("%s:%s:%04x done (%d) in %ds\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000);
798 if (status) failures++;
800 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
803 static BOOL CALLBACK
804 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
805 LPSTR lpszName, LONG_PTR lParam)
807 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
808 return TRUE;
811 static const struct clsid_mapping
813 const char *name;
814 CLSID clsid;
815 } clsid_list[] =
817 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
818 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
822 static BOOL get_main_clsid(const char *name, CLSID *clsid)
824 const struct clsid_mapping *mapping;
826 for(mapping = clsid_list; mapping->name; mapping++)
828 if(!strcasecmp(name, mapping->name))
830 *clsid = mapping->clsid;
831 return TRUE;
834 return FALSE;
837 static HMODULE load_com_dll(const char *name, char **path, char *filename)
839 HMODULE dll = NULL;
840 HKEY hkey;
841 char keyname[100];
842 char dllname[MAX_PATH];
843 char *p;
844 CLSID clsid;
846 if(!get_main_clsid(name, &clsid)) return NULL;
848 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
849 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
850 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
851 clsid.Data4[6], clsid.Data4[7]);
853 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
855 LONG size = sizeof(dllname);
856 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
858 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
860 strcpy( filename, dllname );
861 p = strrchr(dllname, '\\');
862 if (p) *p = 0;
863 *path = heap_strdup( dllname );
866 RegCloseKey(hkey);
869 return dll;
872 static void get_dll_path(HMODULE dll, char **path, char *filename)
874 char dllpath[MAX_PATH];
876 GetModuleFileNameA(dll, dllpath, MAX_PATH);
877 strcpy(filename, dllpath);
878 *strrchr(dllpath, '\\') = '\0';
879 *path = heap_strdup( dllpath );
882 static BOOL CALLBACK
883 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
885 const char *tempdir = (const char *)lParam;
886 char dllname[MAX_PATH];
887 char filename[MAX_PATH];
888 WCHAR dllnameW[MAX_PATH];
889 HMODULE dll;
890 DWORD err;
891 HANDLE actctx;
892 ULONG_PTR cookie;
894 if (aborting) return TRUE;
896 /* Check if the main dll is present on this system */
897 CharLowerA(lpszName);
898 strcpy(dllname, lpszName);
899 *strstr(dllname, testexe) = 0;
901 if (test_filtered_out( lpszName, NULL ))
903 nr_of_skips++;
904 return TRUE;
906 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
908 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
909 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
911 ACTCTXA actctxinfo;
912 memset(&actctxinfo, 0, sizeof(ACTCTXA));
913 actctxinfo.cbSize = sizeof(ACTCTXA);
914 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
915 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
916 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
917 actctx = pCreateActCtxA(&actctxinfo);
918 if (actctx != INVALID_HANDLE_VALUE &&
919 ! pActivateActCtx(actctx, &cookie))
921 pReleaseActCtx(actctx);
922 actctx = INVALID_HANDLE_VALUE;
924 } else actctx = INVALID_HANDLE_VALUE;
926 wine_tests[nr_of_files].maindllpath = NULL;
927 strcpy(filename, dllname);
928 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
930 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
932 if (!dll && pLoadLibraryShim)
934 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
935 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
937 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
938 FreeLibrary(dll);
939 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
941 else dll = 0;
944 if (!dll)
946 xprintf (" %s=dll is missing\n", dllname);
947 if (actctx != INVALID_HANDLE_VALUE)
949 pDeactivateActCtx(0, cookie);
950 pReleaseActCtx(actctx);
952 return TRUE;
954 if(is_stub_dll(dllname))
956 FreeLibrary(dll);
957 xprintf (" %s=dll is a stub\n", dllname);
958 if (actctx != INVALID_HANDLE_VALUE)
960 pDeactivateActCtx(0, cookie);
961 pReleaseActCtx(actctx);
963 return TRUE;
965 if (is_native_dll(dll))
967 FreeLibrary(dll);
968 xprintf (" %s=load error Configured as native\n", dllname);
969 nr_native_dlls++;
970 if (actctx != INVALID_HANDLE_VALUE)
972 pDeactivateActCtx(0, cookie);
973 pReleaseActCtx(actctx);
975 return TRUE;
977 FreeLibrary(dll);
979 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
981 xprintf (" %s=%s\n", dllname, get_file_version(filename));
982 nr_of_tests += wine_tests[nr_of_files].subtest_count;
983 nr_of_files++;
985 else
987 xprintf (" %s=load error %u\n", dllname, err);
990 if (actctx != INVALID_HANDLE_VALUE)
992 pDeactivateActCtx(0, cookie);
993 pReleaseActCtx(actctx);
995 return TRUE;
998 static char *
999 run_tests (char *logname, char *outdir)
1001 int i;
1002 char *strres, *eol, *nextline;
1003 DWORD strsize;
1004 SECURITY_ATTRIBUTES sa;
1005 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1006 DWORD needed;
1007 HMODULE kernel32;
1009 /* Get the current PATH only once */
1010 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1011 curpath = heap_alloc(needed);
1012 GetEnvironmentVariableA("PATH", curpath, needed);
1014 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1016 if (!GetTempPathA( MAX_PATH, tmppath ))
1017 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1019 if (!logname) {
1020 static char tmpname[MAX_PATH];
1021 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1022 report (R_FATAL, "Can't name logfile.");
1023 logname = tmpname;
1025 report (R_OUT, logname);
1027 /* make handle inheritable */
1028 sa.nLength = sizeof(sa);
1029 sa.lpSecurityDescriptor = NULL;
1030 sa.bInheritHandle = TRUE;
1032 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1033 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1034 &sa, CREATE_ALWAYS, 0, NULL );
1036 if ((logfile == INVALID_HANDLE_VALUE) &&
1037 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1038 /* FILE_SHARE_DELETE not supported on win9x */
1039 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1040 FILE_SHARE_READ | FILE_SHARE_WRITE,
1041 &sa, CREATE_ALWAYS, 0, NULL );
1043 if (logfile == INVALID_HANDLE_VALUE)
1044 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1046 /* try stable path for ZoneAlarm */
1047 if (!outdir) {
1048 strcpy( tempdir, tmppath );
1049 strcat( tempdir, "wct" );
1051 if (!CreateDirectoryA( tempdir, NULL ))
1053 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1054 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1055 DeleteFileA( tempdir );
1056 if (!CreateDirectoryA( tempdir, NULL ))
1057 report (R_FATAL, "Could not create directory: %s", tempdir);
1060 else
1061 strcpy( tempdir, outdir);
1063 report (R_DIR, tempdir);
1065 xprintf ("Version 4\n");
1066 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1067 xprintf ("Archive: -\n"); /* no longer used */
1068 xprintf ("Tag: %s\n", tag);
1069 xprintf ("Build info:\n");
1070 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1071 while (strres) {
1072 eol = memchr (strres, '\n', strsize);
1073 if (!eol) {
1074 nextline = NULL;
1075 eol = strres + strsize;
1076 } else {
1077 strsize -= eol - strres + 1;
1078 nextline = strsize?eol+1:NULL;
1079 if (eol > strres && *(eol-1) == '\r') eol--;
1081 xprintf (" %.*s\n", eol-strres, strres);
1082 strres = nextline;
1084 xprintf ("Operating system version:\n");
1085 print_version ();
1086 print_language ();
1087 xprintf ("Dll info:\n" );
1089 report (R_STATUS, "Counting tests");
1090 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1091 report (R_FATAL, "Can't enumerate test files: %d",
1092 GetLastError ());
1093 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1095 /* Do this only once during extraction (and version checking) */
1096 hmscoree = LoadLibraryA("mscoree.dll");
1097 pLoadLibraryShim = NULL;
1098 if (hmscoree)
1099 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1100 kernel32 = GetModuleHandleA("kernel32.dll");
1101 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1102 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1103 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1104 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1106 report (R_STATUS, "Extracting tests");
1107 report (R_PROGRESS, 0, nr_of_files);
1108 nr_of_files = 0;
1109 nr_of_tests = 0;
1110 nr_of_skips = 0;
1111 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1112 report (R_FATAL, "Can't enumerate test files: %d",
1113 GetLastError ());
1115 FreeLibrary(hmscoree);
1117 if (aborting) return logname;
1119 xprintf ("Test output:\n" );
1121 report (R_DELTA, 0, "Extracting: Done");
1123 if (nr_native_dlls)
1124 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1126 report (R_STATUS, "Running tests");
1127 report (R_PROGRESS, 1, nr_of_tests);
1128 for (i = 0; i < nr_of_files; i++) {
1129 struct wine_test *test = wine_tests + i;
1130 int j;
1132 if (aborting) break;
1134 if (test->maindllpath) {
1135 /* We need to add the path (to the main dll) to PATH */
1136 append_path(test->maindllpath);
1139 for (j = 0; j < test->subtest_count; j++) {
1140 if (aborting) break;
1141 run_test (test, test->subtests[j], logfile, tempdir);
1144 if (test->maindllpath) {
1145 /* Restore PATH again */
1146 SetEnvironmentVariableA("PATH", curpath);
1149 report (R_DELTA, 0, "Running: Done");
1151 report (R_STATUS, "Cleaning up - %u failures", failures);
1152 CloseHandle( logfile );
1153 logfile = 0;
1154 if (!outdir)
1155 remove_dir (tempdir);
1156 heap_free(wine_tests);
1157 heap_free(curpath);
1159 return logname;
1162 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1164 if (ctrl_type == CTRL_C_EVENT) {
1165 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1166 return TRUE;
1169 return FALSE;
1173 static BOOL CALLBACK
1174 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1176 const char *target_dir = (const char *)lParam;
1177 char filename[MAX_PATH];
1179 if (test_filtered_out( lpszName, NULL )) return TRUE;
1181 strcpy(filename, lpszName);
1182 CharLowerA(filename);
1184 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1185 nr_of_files++;
1186 return TRUE;
1189 static void extract_only (const char *target_dir)
1191 BOOL res;
1193 report (R_DIR, target_dir);
1194 res = CreateDirectoryA( target_dir, NULL );
1195 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1196 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1198 nr_of_files = 0;
1199 report (R_STATUS, "Counting tests");
1200 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1201 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1203 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1205 report (R_STATUS, "Extracting tests");
1206 report (R_PROGRESS, 0, nr_of_files);
1207 nr_of_files = 0;
1208 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1209 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1211 report (R_DELTA, 0, "Extracting: Done");
1214 static void
1215 usage (void)
1217 fprintf (stderr,
1218 "Usage: winetest [OPTION]... [TESTS]\n\n"
1219 " --help print this message and exit\n"
1220 " --version print the build version and exit\n"
1221 " -c console mode, no GUI\n"
1222 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1223 " -e preserve the environment\n"
1224 " -h print this message and exit\n"
1225 " -i INFO an optional description of the test platform\n"
1226 " -m MAIL an email address to enable developers to contact you\n"
1227 " -n exclude the specified tests\n"
1228 " -p shutdown when the tests are done\n"
1229 " -q quiet mode, no output at all\n"
1230 " -o FILE put report into FILE, do not submit\n"
1231 " -s FILE submit FILE, do not run tests\n"
1232 " -S URL URL to submit the results to\n"
1233 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1234 " -u URL include TestBot URL in the report\n"
1235 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1238 int __cdecl main( int argc, char *argv[] )
1240 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1241 char *logname = NULL, *outdir = NULL;
1242 const char *extract = NULL;
1243 const char *cp, *submit = NULL, *submiturl = NULL;
1244 int reset_env = 1;
1245 int poweroff = 0;
1246 int interactive = 1;
1247 int i;
1249 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1251 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1252 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1254 for (i = 1; i < argc && argv[i]; i++)
1256 if (!strcmp(argv[i], "--help")) {
1257 usage ();
1258 exit (0);
1260 else if (!strcmp(argv[i], "--version")) {
1261 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1262 exit (0);
1264 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1265 if (nb_filters == ARRAY_SIZE(filters))
1267 report (R_ERROR, "Too many test filters specified");
1268 exit (2);
1270 filters[nb_filters++] = argv[i];
1272 else switch (argv[i][1]) {
1273 case 'c':
1274 report (R_TEXTMODE);
1275 interactive = 0;
1276 break;
1277 case 'e':
1278 reset_env = 0;
1279 break;
1280 case 'h':
1281 case '?':
1282 usage ();
1283 exit (0);
1284 case 'i':
1285 if (!(description = argv[++i]))
1287 usage();
1288 exit( 2 );
1290 break;
1291 case 'm':
1292 if (!(email = argv[++i]))
1294 usage();
1295 exit( 2 );
1297 break;
1298 case 'n':
1299 exclude_tests = TRUE;
1300 break;
1301 case 'p':
1302 poweroff = 1;
1303 break;
1304 case 'q':
1305 report (R_QUIET);
1306 interactive = 0;
1307 break;
1308 case 's':
1309 if (!(submit = argv[++i]))
1311 usage();
1312 exit( 2 );
1314 break;
1315 case 'S':
1316 if (!(submiturl = argv[++i]))
1318 usage();
1319 exit( 2 );
1321 break;
1322 case 'o':
1323 if (!(logname = argv[++i]))
1325 usage();
1326 exit( 2 );
1328 break;
1329 case 't':
1330 if (!(tag = argv[++i]))
1332 usage();
1333 exit( 2 );
1335 if (strlen (tag) > MAXTAGLEN)
1336 report (R_FATAL, "tag is too long (maximum %d characters)",
1337 MAXTAGLEN);
1338 cp = findbadtagchar (tag);
1339 if (cp) {
1340 report (R_ERROR, "invalid char in tag: %c", *cp);
1341 usage ();
1342 exit (2);
1344 break;
1345 case 'u':
1346 if (!(url = argv[++i]))
1348 usage();
1349 exit( 2 );
1351 break;
1352 case 'x':
1353 report (R_TEXTMODE);
1354 if (!(extract = argv[++i]))
1355 extract = ".\\wct";
1357 extract_only (extract);
1358 break;
1359 case 'd':
1360 outdir = argv[++i];
1361 break;
1362 default:
1363 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1364 usage ();
1365 exit (2);
1368 if (submit) {
1369 if (tag)
1370 report (R_WARNING, "ignoring tag for submission");
1371 send_file (submiturl, submit);
1373 } else if (!extract) {
1374 int is_win9x = (GetVersion() & 0x80000000) != 0;
1376 report (R_STATUS, "Starting up");
1378 if (is_win9x)
1379 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1381 if (!running_on_visible_desktop ())
1382 report (R_FATAL, "Tests must be run on a visible desktop");
1384 if (running_under_wine())
1386 if (!check_mount_mgr())
1387 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1389 if (!check_wow64_registry())
1390 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1392 if (!check_display_driver())
1393 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1396 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1398 if (reset_env)
1400 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1401 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1402 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1403 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1406 if (nb_filters && !exclude_tests)
1408 run_tests( logname, outdir );
1409 exit(0);
1412 while (!tag) {
1413 if (!interactive)
1414 report (R_FATAL, "Please specify a tag (-t option) if "
1415 "running noninteractive!");
1416 if (guiAskTag () == IDABORT) exit (1);
1418 report (R_TAG);
1420 while (!email) {
1421 if (!interactive)
1422 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1423 " to contact you about your report if necessary.");
1424 if (guiAskEmail () == IDABORT) exit (1);
1427 if (!build_id[0])
1428 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1429 "To submit results, winetest needs to be built from a git checkout." );
1431 if (!logname) {
1432 logname = run_tests (NULL, outdir);
1433 if (aborting) {
1434 DeleteFileA(logname);
1435 exit (0);
1437 if (failures > FAILURES_LIMIT)
1438 report( R_WARNING,
1439 "%d tests failed. There is probably something broken with your setup.\n"
1440 "You need to address this before submitting results.", failures );
1442 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1443 !nr_native_dlls && !is_win9x &&
1444 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1445 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1446 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1447 } else run_tests (logname, outdir);
1448 report (R_STATUS, "Finished - %u failures", failures);
1450 if (poweroff)
1452 HANDLE hToken;
1453 TOKEN_PRIVILEGES npr;
1455 /* enable the shutdown privilege for the current process */
1456 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1458 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1459 npr.PrivilegeCount = 1;
1460 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1461 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1462 CloseHandle(hToken);
1464 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1466 exit (0);