mfplat: Add support for GUID attributes.
[wine.git] / programs / winetest / main.c
blob3d6cc660ec8168ba8096f7916296ce69ba656061
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 #include "config.h"
29 #include "wine/port.h"
31 #define COBJMACROS
32 #include <stdio.h>
33 #include <assert.h>
34 #include <windows.h>
35 #include <winternl.h>
36 #include <mshtml.h>
38 #include "winetest.h"
39 #include "resource.h"
41 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
42 #define SKIP_LIMIT 10
44 /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
45 #define FAILURES_LIMIT 50
47 struct wine_test
49 char *name;
50 int subtest_count;
51 char **subtests;
52 char *exename;
53 char *maindllpath;
56 char *tag = NULL;
57 char *description = NULL;
58 char *url = NULL;
59 char *email = NULL;
60 BOOL aborting = FALSE;
61 static struct wine_test *wine_tests;
62 static int nr_of_files, nr_of_tests, nr_of_skips;
63 static int nr_native_dlls;
64 static const char whitespace[] = " \t\r\n";
65 static const char testexe[] = "_test.exe";
66 static char build_id[64];
67 static BOOL is_wow64;
68 static int failures;
70 /* filters for running only specific tests */
71 static char *filters[64];
72 static unsigned int nb_filters = 0;
73 static BOOL exclude_tests = FALSE;
75 /* Needed to check for .NET dlls */
76 static HMODULE hmscoree;
77 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
79 /* For SxS DLLs e.g. msvcr90 */
80 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
81 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
82 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
83 static void (WINAPI *pReleaseActCtx)(HANDLE);
85 /* To store the current PATH setting (related to .NET only provided dlls) */
86 static char *curpath;
88 /* check if test is being filtered out */
89 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
91 char *p, dllname[MAX_PATH];
92 unsigned int i, len;
94 strcpy( dllname, module );
95 CharLowerA( dllname );
96 p = strstr( dllname, testexe );
97 if (p) *p = 0;
98 len = strlen(dllname);
100 if (!nb_filters) return exclude_tests;
101 for (i = 0; i < nb_filters; i++)
103 if (!strncmp( dllname, filters[i], len ))
105 if (!filters[i][len]) return exclude_tests;
106 if (filters[i][len] != ':') continue;
107 if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
108 if (!testname && !exclude_tests) return FALSE;
111 return !exclude_tests;
114 static char * get_file_version(char * file_name)
116 static char version[32];
117 DWORD size;
118 DWORD handle;
120 size = GetFileVersionInfoSizeA(file_name, &handle);
121 if (size) {
122 char * data = heap_alloc(size);
123 if (data) {
124 if (GetFileVersionInfoA(file_name, handle, size, data)) {
125 static const char backslash[] = "\\";
126 VS_FIXEDFILEINFO *pFixedVersionInfo;
127 UINT len;
128 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
129 sprintf(version, "%d.%d.%d.%d",
130 pFixedVersionInfo->dwFileVersionMS >> 16,
131 pFixedVersionInfo->dwFileVersionMS & 0xffff,
132 pFixedVersionInfo->dwFileVersionLS >> 16,
133 pFixedVersionInfo->dwFileVersionLS & 0xffff);
134 } else
135 sprintf(version, "version not available");
136 } else
137 sprintf(version, "unknown");
138 heap_free(data);
139 } else
140 sprintf(version, "failed");
141 } else
142 sprintf(version, "version not available");
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 = (HWINSTA)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 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) + sizeof(fakedll_signature) &&
307 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
308 return TRUE;
312 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
313 * to install that component. To bypass this check we need to look at the version resource.
315 static BOOL is_stub_dll(const char *filename)
317 DWORD size, ver;
318 BOOL isstub = FALSE;
319 char *p, *data;
321 size = GetFileVersionInfoSizeA(filename, &ver);
322 if (!size) return FALSE;
324 data = HeapAlloc(GetProcessHeap(), 0, size);
325 if (!data) return FALSE;
327 if (GetFileVersionInfoA(filename, ver, size, data))
329 char buf[256];
331 sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
332 if (VerQueryValueA(data, buf, (void**)&p, &size))
333 isstub = !lstrcmpiA("wcodstub.dll", p);
335 HeapFree(GetProcessHeap(), 0, data);
337 return isstub;
340 static void print_version (void)
342 #ifdef __i386__
343 static const char platform[] = "i386";
344 #elif defined(__x86_64__)
345 static const char platform[] = "x86_64";
346 #elif defined(__powerpc__)
347 static const char platform[] = "powerpc";
348 #elif defined(__arm__)
349 static const char platform[] = "arm";
350 #elif defined(__aarch64__)
351 static const char platform[] = "arm64";
352 #else
353 # error CPU unknown
354 #endif
355 OSVERSIONINFOEXA ver;
356 RTL_OSVERSIONINFOEXW rtlver;
357 BOOL ext;
358 int is_win2k3_r2, is_admin, is_elevated;
359 const char *(CDECL *wine_get_build_id)(void);
360 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
361 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
362 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
363 NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
365 ver.dwOSVersionInfoSize = sizeof(ver);
366 if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
368 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
369 if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
370 report (R_FATAL, "Can't get OS version.");
373 /* try to get non-faked values */
374 if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
376 rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
378 pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
379 pRtlGetVersion(&rtlver);
381 ver.dwMajorVersion = rtlver.dwMajorVersion;
382 ver.dwMinorVersion = rtlver.dwMinorVersion;
383 ver.dwBuildNumber = rtlver.dwBuildNumber;
384 ver.dwPlatformId = rtlver.dwPlatformId;
385 ver.wServicePackMajor = rtlver.wServicePackMajor;
386 ver.wServicePackMinor = rtlver.wServicePackMinor;
387 ver.wSuiteMask = rtlver.wSuiteMask;
388 ver.wProductType = rtlver.wProductType;
390 WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
393 xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
394 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
395 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
396 is_admin = running_as_admin ();
397 if (0 <= is_admin)
399 xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
400 is_elevated = running_elevated ();
401 if (0 <= is_elevated)
402 xprintf(", %s", is_elevated ? "elevated" : "not elevated");
403 xprintf ("\n");
405 xprintf (" Submitter=%s\n", email );
406 if (description)
407 xprintf (" Description=%s\n", description );
408 if (url)
409 xprintf (" URL=%s\n", url );
410 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
411 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
412 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
413 ver.dwPlatformId, ver.szCSDVersion);
415 wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
416 wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
417 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
418 if (wine_get_host_version)
420 const char *sysname, *release;
421 wine_get_host_version( &sysname, &release );
422 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
424 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
425 if(is_win2k3_r2)
426 xprintf(" R2 build number=%d\n", is_win2k3_r2);
428 if (!ext) return;
430 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
431 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
432 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
433 ver.wProductType, ver.wReserved);
435 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
436 if (pGetProductInfo && !running_under_wine())
438 DWORD prodtype = 0;
440 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
441 xprintf(" dwProductInfo=%u\n", prodtype);
445 static void print_language(void)
447 HMODULE hkernel32;
448 BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
449 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
450 LANGID (WINAPI *pGetThreadUILanguage)(void);
452 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
453 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
454 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
456 hkernel32 = GetModuleHandleA("kernel32.dll");
457 pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
458 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
459 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
461 if (pGetSystemPreferredUILanguages && !running_under_wine())
463 WCHAR langW[32];
464 ULONG num, size = ARRAY_SIZE(langW);
465 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
467 char lang[32], *p = lang;
468 WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
469 for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
470 xprintf (" SystemPreferredUILanguages=%s\n", lang);
473 if (pGetUserDefaultUILanguage)
474 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
475 if (pGetThreadUILanguage)
476 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
479 static inline BOOL is_dot_dir(const char* x)
481 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
484 static void remove_dir (const char *dir)
486 HANDLE hFind;
487 WIN32_FIND_DATAA wfd;
488 char path[MAX_PATH];
489 size_t dirlen = strlen (dir);
491 /* Make sure the directory exists before going further */
492 memcpy (path, dir, dirlen);
493 strcpy (path + dirlen++, "\\*");
494 hFind = FindFirstFileA (path, &wfd);
495 if (hFind == INVALID_HANDLE_VALUE) return;
497 do {
498 char *lp = wfd.cFileName;
500 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
501 if (is_dot_dir (lp)) continue;
502 strcpy (path + dirlen, lp);
503 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
504 remove_dir(path);
505 else if (!DeleteFileA(path))
506 report (R_WARNING, "Can't delete file %s: error %d",
507 path, GetLastError ());
508 } while (FindNextFileA(hFind, &wfd));
509 FindClose (hFind);
510 if (!RemoveDirectoryA(dir))
511 report (R_WARNING, "Can't remove directory %s: error %d",
512 dir, GetLastError ());
515 static const char* get_test_source_file(const char* test, const char* subtest)
517 static char buffer[MAX_PATH];
518 int len = strlen(test);
520 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
522 len = sprintf(buffer, "programs/%s", test) - 4;
523 buffer[len] = 0;
525 else len = sprintf(buffer, "dlls/%s", test);
527 sprintf(buffer + len, "/tests/%s.c", subtest);
528 return buffer;
531 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
533 HRSRC rsrc;
534 HGLOBAL hdl;
535 LPVOID addr;
537 if (!(rsrc = FindResourceA(NULL, name, type)) ||
538 !(*size = SizeofResource (0, rsrc)) ||
539 !(hdl = LoadResource (0, rsrc)) ||
540 !(addr = LockResource (hdl)))
541 return NULL;
542 return addr;
545 /* Fills in the name and exename fields */
546 static void
547 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
549 BYTE* code;
550 DWORD size;
551 char *exepos;
552 HANDLE hfile;
553 DWORD written;
555 code = extract_rcdata (res_name, "TESTRES", &size);
556 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
557 res_name, GetLastError ());
558 test->name = heap_strdup( res_name );
559 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
560 exepos = strstr (test->name, testexe);
561 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
562 *exepos = 0;
563 test->name = heap_realloc (test->name, exepos - test->name + 1);
564 report (R_STEP, "Extracting: %s", test->name);
566 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
567 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
568 if (hfile == INVALID_HANDLE_VALUE)
569 report (R_FATAL, "Failed to open file %s.", test->exename);
571 if (!WriteFile(hfile, code, size, &written, NULL))
572 report (R_FATAL, "Failed to write file %s.", test->exename);
574 CloseHandle(hfile);
577 static DWORD wait_process( HANDLE process, DWORD timeout )
579 DWORD wait, diff = 0, start = GetTickCount();
580 MSG msg;
582 while (diff < timeout)
584 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
585 if (wait != WAIT_OBJECT_0 + 1) return wait;
586 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
587 diff = GetTickCount() - start;
589 return WAIT_TIMEOUT;
592 static void append_path( const char *path)
594 char *newpath;
596 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
597 strcpy(newpath, curpath);
598 strcat(newpath, ";");
599 strcat(newpath, path);
600 SetEnvironmentVariableA("PATH", newpath);
602 heap_free(newpath);
605 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
606 stdout to there.
608 Return the exit status, -2 if can't create process or the return
609 value of WaitForSingleObject.
611 static int
612 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, DWORD* pid)
614 STARTUPINFOA si;
615 PROCESS_INFORMATION pi;
616 DWORD wait, status;
618 /* Flush to disk so we know which test caused Windows to crash if it does */
619 if (out_file)
620 FlushFileBuffers(out_file);
622 GetStartupInfoA (&si);
623 si.dwFlags = STARTF_USESTDHANDLES;
624 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
625 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
626 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
628 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
629 NULL, tempdir, &si, &pi))
631 if (pid) *pid = 0;
632 return -2;
635 CloseHandle (pi.hThread);
636 if (pid) *pid = pi.dwProcessId;
637 status = wait_process( pi.hProcess, ms );
638 switch (status)
640 case WAIT_OBJECT_0:
641 GetExitCodeProcess (pi.hProcess, &status);
642 CloseHandle (pi.hProcess);
643 return status;
644 case WAIT_FAILED:
645 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
646 break;
647 case WAIT_TIMEOUT:
648 break;
649 default:
650 report (R_ERROR, "Wait returned %d", status);
651 break;
653 if (!TerminateProcess (pi.hProcess, 257))
654 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
655 wait = wait_process( pi.hProcess, 5000 );
656 switch (wait)
658 case WAIT_OBJECT_0:
659 break;
660 case WAIT_FAILED:
661 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
662 break;
663 case WAIT_TIMEOUT:
664 report (R_ERROR, "Can't kill process '%s'", cmd);
665 break;
666 default:
667 report (R_ERROR, "Waiting for termination: %d", wait);
668 break;
670 CloseHandle (pi.hProcess);
671 return status;
674 static DWORD
675 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
677 char *cmd;
678 HANDLE subfile;
679 DWORD err, total;
680 char buffer[8192], *index;
681 static const char header[] = "Valid test names:";
682 int status, allocated;
683 char tmpdir[MAX_PATH], subname[MAX_PATH];
684 SECURITY_ATTRIBUTES sa;
686 test->subtest_count = 0;
688 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
689 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
690 report (R_FATAL, "Can't name subtests file.");
692 /* make handle inheritable */
693 sa.nLength = sizeof(sa);
694 sa.lpSecurityDescriptor = NULL;
695 sa.bInheritHandle = TRUE;
697 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
698 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
699 &sa, CREATE_ALWAYS, 0, NULL );
701 if ((subfile == INVALID_HANDLE_VALUE) &&
702 (GetLastError() == ERROR_INVALID_PARAMETER)) {
703 /* FILE_SHARE_DELETE not supported on win9x */
704 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
705 FILE_SHARE_READ | FILE_SHARE_WRITE,
706 &sa, CREATE_ALWAYS, 0, NULL );
708 if (subfile == INVALID_HANDLE_VALUE) {
709 err = GetLastError();
710 report (R_ERROR, "Can't open subtests output of %s: %u",
711 test->name, GetLastError());
712 goto quit;
715 cmd = strmake (NULL, "%s --list", test->exename);
716 if (test->maindllpath) {
717 /* We need to add the path (to the main dll) to PATH */
718 append_path(test->maindllpath);
720 status = run_ex (cmd, subfile, tempdir, 5000, NULL);
721 err = GetLastError();
722 if (test->maindllpath) {
723 /* Restore PATH again */
724 SetEnvironmentVariableA("PATH", curpath);
726 heap_free (cmd);
728 if (status == -2)
730 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
731 CloseHandle( subfile );
732 goto quit;
735 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
736 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
737 CloseHandle( subfile );
738 if (sizeof buffer == total) {
739 report (R_ERROR, "Subtest list of %s too big.",
740 test->name, sizeof buffer);
741 err = ERROR_OUTOFMEMORY;
742 goto quit;
744 buffer[total] = 0;
746 index = strstr (buffer, header);
747 if (!index) {
748 report (R_ERROR, "Can't parse subtests output of %s",
749 test->name);
750 err = ERROR_INTERNAL_ERROR;
751 goto quit;
753 index += sizeof header;
755 allocated = 10;
756 test->subtests = heap_alloc (allocated * sizeof(char*));
757 index = strtok (index, whitespace);
758 while (index) {
759 if (test->subtest_count == allocated) {
760 allocated *= 2;
761 test->subtests = heap_realloc (test->subtests,
762 allocated * sizeof(char*));
764 test->subtests[test->subtest_count++] = heap_strdup(index);
765 index = strtok (NULL, whitespace);
767 test->subtests = heap_realloc (test->subtests,
768 test->subtest_count * sizeof(char*));
769 err = 0;
771 quit:
772 if (!DeleteFileA (subname))
773 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
774 return err;
777 static void
778 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
780 /* Build the source filename so analysis tools can link to it */
781 const char* file = get_test_source_file(test->name, subtest);
783 if (test_filtered_out( test->name, subtest ))
785 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
786 xprintf ("%s:%s skipped %s -\n", test->name, subtest, file);
787 nr_of_skips++;
789 else
791 int status;
792 DWORD pid, start = GetTickCount();
793 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
794 report (R_STEP, "Running: %s:%s", test->name, subtest);
795 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
796 status = run_ex (cmd, out_file, tempdir, 120000, &pid);
797 heap_free (cmd);
798 xprintf ("%s:%s:%04x done (%d) in %ds\n", test->name, subtest, pid, status, (GetTickCount()-start)/1000);
799 if (status) failures++;
801 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
804 static BOOL CALLBACK
805 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
806 LPSTR lpszName, LONG_PTR lParam)
808 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
809 return TRUE;
812 static const struct clsid_mapping
814 const char *name;
815 CLSID clsid;
816 } clsid_list[] =
818 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
819 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
823 static BOOL get_main_clsid(const char *name, CLSID *clsid)
825 const struct clsid_mapping *mapping;
827 for(mapping = clsid_list; mapping->name; mapping++)
829 if(!strcasecmp(name, mapping->name))
831 *clsid = mapping->clsid;
832 return TRUE;
835 return FALSE;
838 static HMODULE load_com_dll(const char *name, char **path, char *filename)
840 HMODULE dll = NULL;
841 HKEY hkey;
842 char keyname[100];
843 char dllname[MAX_PATH];
844 char *p;
845 CLSID clsid;
847 if(!get_main_clsid(name, &clsid)) return NULL;
849 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
850 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
851 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
852 clsid.Data4[6], clsid.Data4[7]);
854 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
856 LONG size = sizeof(dllname);
857 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
859 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
861 strcpy( filename, dllname );
862 p = strrchr(dllname, '\\');
863 if (p) *p = 0;
864 *path = heap_strdup( dllname );
867 RegCloseKey(hkey);
870 return dll;
873 static void get_dll_path(HMODULE dll, char **path, char *filename)
875 char dllpath[MAX_PATH];
877 GetModuleFileNameA(dll, dllpath, MAX_PATH);
878 strcpy(filename, dllpath);
879 *strrchr(dllpath, '\\') = '\0';
880 *path = heap_strdup( dllpath );
883 static BOOL CALLBACK
884 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
886 const char *tempdir = (const char *)lParam;
887 char dllname[MAX_PATH];
888 char filename[MAX_PATH];
889 WCHAR dllnameW[MAX_PATH];
890 HMODULE dll;
891 DWORD err;
892 HANDLE actctx;
893 ULONG_PTR cookie;
895 if (aborting) return TRUE;
897 /* Check if the main dll is present on this system */
898 CharLowerA(lpszName);
899 strcpy(dllname, lpszName);
900 *strstr(dllname, testexe) = 0;
902 if (test_filtered_out( lpszName, NULL ))
904 nr_of_skips++;
905 return TRUE;
907 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
909 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
910 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
912 ACTCTXA actctxinfo;
913 memset(&actctxinfo, 0, sizeof(ACTCTXA));
914 actctxinfo.cbSize = sizeof(ACTCTXA);
915 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
916 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
917 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
918 actctx = pCreateActCtxA(&actctxinfo);
919 if (actctx != INVALID_HANDLE_VALUE &&
920 ! pActivateActCtx(actctx, &cookie))
922 pReleaseActCtx(actctx);
923 actctx = INVALID_HANDLE_VALUE;
925 } else actctx = INVALID_HANDLE_VALUE;
927 wine_tests[nr_of_files].maindllpath = NULL;
928 strcpy(filename, dllname);
929 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
931 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
933 if (!dll && pLoadLibraryShim)
935 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
936 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
938 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
939 FreeLibrary(dll);
940 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
942 else dll = 0;
945 if (!dll)
947 xprintf (" %s=dll is missing\n", dllname);
948 if (actctx != INVALID_HANDLE_VALUE)
950 pDeactivateActCtx(0, cookie);
951 pReleaseActCtx(actctx);
953 return TRUE;
955 if(is_stub_dll(dllname))
957 FreeLibrary(dll);
958 xprintf (" %s=dll is a stub\n", dllname);
959 if (actctx != INVALID_HANDLE_VALUE)
961 pDeactivateActCtx(0, cookie);
962 pReleaseActCtx(actctx);
964 return TRUE;
966 if (is_native_dll(dll))
968 FreeLibrary(dll);
969 xprintf (" %s=load error Configured as native\n", dllname);
970 nr_native_dlls++;
971 if (actctx != INVALID_HANDLE_VALUE)
973 pDeactivateActCtx(0, cookie);
974 pReleaseActCtx(actctx);
976 return TRUE;
978 FreeLibrary(dll);
980 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
982 xprintf (" %s=%s\n", dllname, get_file_version(filename));
983 nr_of_tests += wine_tests[nr_of_files].subtest_count;
984 nr_of_files++;
986 else
988 xprintf (" %s=load error %u\n", dllname, err);
991 if (actctx != INVALID_HANDLE_VALUE)
993 pDeactivateActCtx(0, cookie);
994 pReleaseActCtx(actctx);
996 return TRUE;
999 static char *
1000 run_tests (char *logname, char *outdir)
1002 int i;
1003 char *strres, *eol, *nextline;
1004 DWORD strsize;
1005 SECURITY_ATTRIBUTES sa;
1006 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
1007 DWORD needed;
1008 HMODULE kernel32;
1010 /* Get the current PATH only once */
1011 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1012 curpath = heap_alloc(needed);
1013 GetEnvironmentVariableA("PATH", curpath, needed);
1015 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1017 if (!GetTempPathA( MAX_PATH, tmppath ))
1018 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1020 if (!logname) {
1021 static char tmpname[MAX_PATH];
1022 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1023 report (R_FATAL, "Can't name logfile.");
1024 logname = tmpname;
1026 report (R_OUT, logname);
1028 /* make handle inheritable */
1029 sa.nLength = sizeof(sa);
1030 sa.lpSecurityDescriptor = NULL;
1031 sa.bInheritHandle = TRUE;
1033 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1034 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1035 &sa, CREATE_ALWAYS, 0, NULL );
1037 if ((logfile == INVALID_HANDLE_VALUE) &&
1038 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1039 /* FILE_SHARE_DELETE not supported on win9x */
1040 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1041 FILE_SHARE_READ | FILE_SHARE_WRITE,
1042 &sa, CREATE_ALWAYS, 0, NULL );
1044 if (logfile == INVALID_HANDLE_VALUE)
1045 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1047 /* try stable path for ZoneAlarm */
1048 if (!outdir) {
1049 strcpy( tempdir, tmppath );
1050 strcat( tempdir, "wct" );
1052 if (!CreateDirectoryA( tempdir, NULL ))
1054 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1055 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1056 DeleteFileA( tempdir );
1057 if (!CreateDirectoryA( tempdir, NULL ))
1058 report (R_FATAL, "Could not create directory: %s", tempdir);
1061 else
1062 strcpy( tempdir, outdir);
1064 report (R_DIR, tempdir);
1066 xprintf ("Version 4\n");
1067 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1068 xprintf ("Archive: -\n"); /* no longer used */
1069 xprintf ("Tag: %s\n", tag);
1070 xprintf ("Build info:\n");
1071 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1072 while (strres) {
1073 eol = memchr (strres, '\n', strsize);
1074 if (!eol) {
1075 nextline = NULL;
1076 eol = strres + strsize;
1077 } else {
1078 strsize -= eol - strres + 1;
1079 nextline = strsize?eol+1:NULL;
1080 if (eol > strres && *(eol-1) == '\r') eol--;
1082 xprintf (" %.*s\n", eol-strres, strres);
1083 strres = nextline;
1085 xprintf ("Operating system version:\n");
1086 print_version ();
1087 print_language ();
1088 xprintf ("Dll info:\n" );
1090 report (R_STATUS, "Counting tests");
1091 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1092 report (R_FATAL, "Can't enumerate test files: %d",
1093 GetLastError ());
1094 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1096 /* Do this only once during extraction (and version checking) */
1097 hmscoree = LoadLibraryA("mscoree.dll");
1098 pLoadLibraryShim = NULL;
1099 if (hmscoree)
1100 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1101 kernel32 = GetModuleHandleA("kernel32.dll");
1102 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1103 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1104 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1105 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1107 report (R_STATUS, "Extracting tests");
1108 report (R_PROGRESS, 0, nr_of_files);
1109 nr_of_files = 0;
1110 nr_of_tests = 0;
1111 nr_of_skips = 0;
1112 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1113 report (R_FATAL, "Can't enumerate test files: %d",
1114 GetLastError ());
1116 FreeLibrary(hmscoree);
1118 if (aborting) return logname;
1120 xprintf ("Test output:\n" );
1122 report (R_DELTA, 0, "Extracting: Done");
1124 if (nr_native_dlls)
1125 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1127 report (R_STATUS, "Running tests");
1128 report (R_PROGRESS, 1, nr_of_tests);
1129 for (i = 0; i < nr_of_files; i++) {
1130 struct wine_test *test = wine_tests + i;
1131 int j;
1133 if (aborting) break;
1135 if (test->maindllpath) {
1136 /* We need to add the path (to the main dll) to PATH */
1137 append_path(test->maindllpath);
1140 for (j = 0; j < test->subtest_count; j++) {
1141 if (aborting) break;
1142 run_test (test, test->subtests[j], logfile, tempdir);
1145 if (test->maindllpath) {
1146 /* Restore PATH again */
1147 SetEnvironmentVariableA("PATH", curpath);
1150 report (R_DELTA, 0, "Running: Done");
1152 report (R_STATUS, "Cleaning up - %u failures", failures);
1153 CloseHandle( logfile );
1154 logfile = 0;
1155 if (!outdir)
1156 remove_dir (tempdir);
1157 heap_free(wine_tests);
1158 heap_free(curpath);
1160 return logname;
1163 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1165 if (ctrl_type == CTRL_C_EVENT) {
1166 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1167 return TRUE;
1170 return FALSE;
1174 static BOOL CALLBACK
1175 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1177 const char *target_dir = (const char *)lParam;
1178 char filename[MAX_PATH];
1180 if (test_filtered_out( lpszName, NULL )) return TRUE;
1182 strcpy(filename, lpszName);
1183 CharLowerA(filename);
1185 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1186 nr_of_files++;
1187 return TRUE;
1190 static void extract_only (const char *target_dir)
1192 BOOL res;
1194 report (R_DIR, target_dir);
1195 res = CreateDirectoryA( target_dir, NULL );
1196 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1197 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1199 nr_of_files = 0;
1200 report (R_STATUS, "Counting tests");
1201 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1202 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1204 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1206 report (R_STATUS, "Extracting tests");
1207 report (R_PROGRESS, 0, nr_of_files);
1208 nr_of_files = 0;
1209 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1210 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1212 report (R_DELTA, 0, "Extracting: Done");
1215 static void
1216 usage (void)
1218 fprintf (stderr,
1219 "Usage: winetest [OPTION]... [TESTS]\n\n"
1220 " --help print this message and exit\n"
1221 " --version print the build version and exit\n"
1222 " -c console mode, no GUI\n"
1223 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1224 " -e preserve the environment\n"
1225 " -h print this message and exit\n"
1226 " -i INFO an optional description of the test platform\n"
1227 " -m MAIL an email address to enable developers to contact you\n"
1228 " -n exclude the specified tests\n"
1229 " -p shutdown when the tests are done\n"
1230 " -q quiet mode, no output at all\n"
1231 " -o FILE put report into FILE, do not submit\n"
1232 " -s FILE submit FILE, do not run tests\n"
1233 " -S URL URL to submit the results to\n"
1234 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1235 " -u URL include TestBot URL in the report\n"
1236 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1239 int main( int argc, char *argv[] )
1241 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1242 char *logname = NULL, *outdir = NULL;
1243 const char *extract = NULL;
1244 const char *cp, *submit = NULL, *submiturl = NULL;
1245 int reset_env = 1;
1246 int poweroff = 0;
1247 int interactive = 1;
1248 int i;
1250 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1252 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1253 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1255 for (i = 1; i < argc && argv[i]; i++)
1257 if (!strcmp(argv[i], "--help")) {
1258 usage ();
1259 exit (0);
1261 else if (!strcmp(argv[i], "--version")) {
1262 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1263 exit (0);
1265 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1266 if (nb_filters == ARRAY_SIZE(filters))
1268 report (R_ERROR, "Too many test filters specified");
1269 exit (2);
1271 filters[nb_filters++] = argv[i];
1273 else switch (argv[i][1]) {
1274 case 'c':
1275 report (R_TEXTMODE);
1276 interactive = 0;
1277 break;
1278 case 'e':
1279 reset_env = 0;
1280 break;
1281 case 'h':
1282 case '?':
1283 usage ();
1284 exit (0);
1285 case 'i':
1286 if (!(description = argv[++i]))
1288 usage();
1289 exit( 2 );
1291 break;
1292 case 'm':
1293 if (!(email = argv[++i]))
1295 usage();
1296 exit( 2 );
1298 break;
1299 case 'n':
1300 exclude_tests = TRUE;
1301 break;
1302 case 'p':
1303 poweroff = 1;
1304 break;
1305 case 'q':
1306 report (R_QUIET);
1307 interactive = 0;
1308 break;
1309 case 's':
1310 if (!(submit = argv[++i]))
1312 usage();
1313 exit( 2 );
1315 break;
1316 case 'S':
1317 if (!(submiturl = argv[++i]))
1319 usage();
1320 exit( 2 );
1322 break;
1323 case 'o':
1324 if (!(logname = argv[++i]))
1326 usage();
1327 exit( 2 );
1329 break;
1330 case 't':
1331 if (!(tag = argv[++i]))
1333 usage();
1334 exit( 2 );
1336 if (strlen (tag) > MAXTAGLEN)
1337 report (R_FATAL, "tag is too long (maximum %d characters)",
1338 MAXTAGLEN);
1339 cp = findbadtagchar (tag);
1340 if (cp) {
1341 report (R_ERROR, "invalid char in tag: %c", *cp);
1342 usage ();
1343 exit (2);
1345 break;
1346 case 'u':
1347 if (!(url = argv[++i]))
1349 usage();
1350 exit( 2 );
1352 break;
1353 case 'x':
1354 report (R_TEXTMODE);
1355 if (!(extract = argv[++i]))
1356 extract = ".\\wct";
1358 extract_only (extract);
1359 break;
1360 case 'd':
1361 outdir = argv[++i];
1362 break;
1363 default:
1364 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1365 usage ();
1366 exit (2);
1369 if (submit) {
1370 if (tag)
1371 report (R_WARNING, "ignoring tag for submission");
1372 send_file (submiturl, submit);
1374 } else if (!extract) {
1375 int is_win9x = (GetVersion() & 0x80000000) != 0;
1377 report (R_STATUS, "Starting up");
1379 if (is_win9x)
1380 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1382 if (!running_on_visible_desktop ())
1383 report (R_FATAL, "Tests must be run on a visible desktop");
1385 if (running_under_wine())
1387 if (!check_mount_mgr())
1388 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1390 if (!check_wow64_registry())
1391 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1393 if (!check_display_driver())
1394 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1397 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1399 if (reset_env)
1401 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1402 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1403 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1404 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1407 if (nb_filters && !exclude_tests)
1409 run_tests( logname, outdir );
1410 exit(0);
1413 while (!tag) {
1414 if (!interactive)
1415 report (R_FATAL, "Please specify a tag (-t option) if "
1416 "running noninteractive!");
1417 if (guiAskTag () == IDABORT) exit (1);
1419 report (R_TAG);
1421 while (!email) {
1422 if (!interactive)
1423 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1424 " to contact you about your report if necessary.");
1425 if (guiAskEmail () == IDABORT) exit (1);
1428 if (!build_id[0])
1429 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1430 "To submit results, winetest needs to be built from a git checkout." );
1432 if (!logname) {
1433 logname = run_tests (NULL, outdir);
1434 if (aborting) {
1435 DeleteFileA(logname);
1436 exit (0);
1438 if (failures > FAILURES_LIMIT)
1439 report( R_WARNING,
1440 "%d tests failed. There is probably something broken with your setup.\n"
1441 "You need to address this before submitting results.", failures );
1443 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1444 !nr_native_dlls && !is_win9x &&
1445 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1446 if (!send_file (submiturl, logname) && !DeleteFileA(logname))
1447 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1448 } else run_tests (logname, outdir);
1449 report (R_STATUS, "Finished - %u failures", failures);
1451 if (poweroff)
1453 HANDLE hToken;
1454 TOKEN_PRIVILEGES npr;
1456 /* enable the shutdown privilege for the current process */
1457 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1459 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1460 npr.PrivilegeCount = 1;
1461 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1462 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1463 CloseHandle(hToken);
1465 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1467 exit (0);