po: Fix a mistake in Dutch translation.
[wine.git] / programs / winetest / main.c
blob014937708866d81dcd57a7699fe6aaa5e9b8ce93
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 LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
449 LANGID (WINAPI *pGetThreadUILanguage)(void);
451 xprintf (" SystemDefaultLCID=%x\n", GetSystemDefaultLCID());
452 xprintf (" UserDefaultLCID=%x\n", GetUserDefaultLCID());
453 xprintf (" ThreadLocale=%x\n", GetThreadLocale());
455 hkernel32 = GetModuleHandleA("kernel32.dll");
456 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
457 pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
458 if (pGetUserDefaultUILanguage)
459 xprintf (" UserDefaultUILanguage=%x\n", pGetUserDefaultUILanguage());
460 if (pGetThreadUILanguage)
461 xprintf (" ThreadUILanguage=%x\n", pGetThreadUILanguage());
464 static inline BOOL is_dot_dir(const char* x)
466 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
469 static void remove_dir (const char *dir)
471 HANDLE hFind;
472 WIN32_FIND_DATAA wfd;
473 char path[MAX_PATH];
474 size_t dirlen = strlen (dir);
476 /* Make sure the directory exists before going further */
477 memcpy (path, dir, dirlen);
478 strcpy (path + dirlen++, "\\*");
479 hFind = FindFirstFileA (path, &wfd);
480 if (hFind == INVALID_HANDLE_VALUE) return;
482 do {
483 char *lp = wfd.cFileName;
485 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
486 if (is_dot_dir (lp)) continue;
487 strcpy (path + dirlen, lp);
488 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
489 remove_dir(path);
490 else if (!DeleteFileA(path))
491 report (R_WARNING, "Can't delete file %s: error %d",
492 path, GetLastError ());
493 } while (FindNextFileA(hFind, &wfd));
494 FindClose (hFind);
495 if (!RemoveDirectoryA(dir))
496 report (R_WARNING, "Can't remove directory %s: error %d",
497 dir, GetLastError ());
500 static const char* get_test_source_file(const char* test, const char* subtest)
502 static const char* special_dirs[][2] = {
503 { 0, 0 }
505 static char buffer[MAX_PATH];
506 int i, len = strlen(test);
508 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
510 len = sprintf(buffer, "programs/%s", test) - 4;
511 buffer[len] = 0;
513 else len = sprintf(buffer, "dlls/%s", test);
515 for (i = 0; special_dirs[i][0]; i++) {
516 if (strcmp(test, special_dirs[i][0]) == 0) {
517 strcpy( buffer, special_dirs[i][1] );
518 len = strlen(buffer);
519 break;
523 sprintf(buffer + len, "/tests/%s.c", subtest);
524 return buffer;
527 static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
529 HRSRC rsrc;
530 HGLOBAL hdl;
531 LPVOID addr;
533 if (!(rsrc = FindResourceA(NULL, name, type)) ||
534 !(*size = SizeofResource (0, rsrc)) ||
535 !(hdl = LoadResource (0, rsrc)) ||
536 !(addr = LockResource (hdl)))
537 return NULL;
538 return addr;
541 /* Fills in the name and exename fields */
542 static void
543 extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
545 BYTE* code;
546 DWORD size;
547 char *exepos;
548 HANDLE hfile;
549 DWORD written;
551 code = extract_rcdata (res_name, "TESTRES", &size);
552 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
553 res_name, GetLastError ());
554 test->name = heap_strdup( res_name );
555 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
556 exepos = strstr (test->name, testexe);
557 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
558 *exepos = 0;
559 test->name = heap_realloc (test->name, exepos - test->name + 1);
560 report (R_STEP, "Extracting: %s", test->name);
562 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
563 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
564 if (hfile == INVALID_HANDLE_VALUE)
565 report (R_FATAL, "Failed to open file %s.", test->exename);
567 if (!WriteFile(hfile, code, size, &written, NULL))
568 report (R_FATAL, "Failed to write file %s.", test->exename);
570 CloseHandle(hfile);
573 static DWORD wait_process( HANDLE process, DWORD timeout )
575 DWORD wait, diff = 0, start = GetTickCount();
576 MSG msg;
578 while (diff < timeout)
580 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
581 if (wait != WAIT_OBJECT_0 + 1) return wait;
582 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
583 diff = GetTickCount() - start;
585 return WAIT_TIMEOUT;
588 static void append_path( const char *path)
590 char *newpath;
592 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
593 strcpy(newpath, curpath);
594 strcat(newpath, ";");
595 strcat(newpath, path);
596 SetEnvironmentVariableA("PATH", newpath);
598 heap_free(newpath);
601 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
602 stdout to there.
604 Return the exit status, -2 if can't create process or the return
605 value of WaitForSingleObject.
607 static int
608 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
610 STARTUPINFOA si;
611 PROCESS_INFORMATION pi;
612 DWORD wait, status;
614 GetStartupInfoA (&si);
615 si.dwFlags = STARTF_USESTDHANDLES;
616 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
617 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
618 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
620 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
621 NULL, tempdir, &si, &pi))
622 return -2;
624 CloseHandle (pi.hThread);
625 status = wait_process( pi.hProcess, ms );
626 switch (status)
628 case WAIT_OBJECT_0:
629 GetExitCodeProcess (pi.hProcess, &status);
630 CloseHandle (pi.hProcess);
631 return status;
632 case WAIT_FAILED:
633 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
634 break;
635 case WAIT_TIMEOUT:
636 break;
637 default:
638 report (R_ERROR, "Wait returned %d", status);
639 break;
641 if (!TerminateProcess (pi.hProcess, 257))
642 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
643 wait = wait_process( pi.hProcess, 5000 );
644 switch (wait)
646 case WAIT_OBJECT_0:
647 break;
648 case WAIT_FAILED:
649 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
650 break;
651 case WAIT_TIMEOUT:
652 report (R_ERROR, "Can't kill process '%s'", cmd);
653 break;
654 default:
655 report (R_ERROR, "Waiting for termination: %d", wait);
656 break;
658 CloseHandle (pi.hProcess);
659 return status;
662 static DWORD
663 get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
665 char *cmd;
666 HANDLE subfile;
667 DWORD err, total;
668 char buffer[8192], *index;
669 static const char header[] = "Valid test names:";
670 int status, allocated;
671 char tmpdir[MAX_PATH], subname[MAX_PATH];
672 SECURITY_ATTRIBUTES sa;
674 test->subtest_count = 0;
676 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
677 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
678 report (R_FATAL, "Can't name subtests file.");
680 /* make handle inheritable */
681 sa.nLength = sizeof(sa);
682 sa.lpSecurityDescriptor = NULL;
683 sa.bInheritHandle = TRUE;
685 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
686 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
687 &sa, CREATE_ALWAYS, 0, NULL );
689 if ((subfile == INVALID_HANDLE_VALUE) &&
690 (GetLastError() == ERROR_INVALID_PARAMETER)) {
691 /* FILE_SHARE_DELETE not supported on win9x */
692 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
693 FILE_SHARE_READ | FILE_SHARE_WRITE,
694 &sa, CREATE_ALWAYS, 0, NULL );
696 if (subfile == INVALID_HANDLE_VALUE) {
697 err = GetLastError();
698 report (R_ERROR, "Can't open subtests output of %s: %u",
699 test->name, GetLastError());
700 goto quit;
703 cmd = strmake (NULL, "%s --list", test->exename);
704 if (test->maindllpath) {
705 /* We need to add the path (to the main dll) to PATH */
706 append_path(test->maindllpath);
708 status = run_ex (cmd, subfile, tempdir, 5000);
709 err = GetLastError();
710 if (test->maindllpath) {
711 /* Restore PATH again */
712 SetEnvironmentVariableA("PATH", curpath);
714 heap_free (cmd);
716 if (status == -2)
718 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
719 CloseHandle( subfile );
720 goto quit;
723 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
724 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
725 CloseHandle( subfile );
726 if (sizeof buffer == total) {
727 report (R_ERROR, "Subtest list of %s too big.",
728 test->name, sizeof buffer);
729 err = ERROR_OUTOFMEMORY;
730 goto quit;
732 buffer[total] = 0;
734 index = strstr (buffer, header);
735 if (!index) {
736 report (R_ERROR, "Can't parse subtests output of %s",
737 test->name);
738 err = ERROR_INTERNAL_ERROR;
739 goto quit;
741 index += sizeof header;
743 allocated = 10;
744 test->subtests = heap_alloc (allocated * sizeof(char*));
745 index = strtok (index, whitespace);
746 while (index) {
747 if (test->subtest_count == allocated) {
748 allocated *= 2;
749 test->subtests = heap_realloc (test->subtests,
750 allocated * sizeof(char*));
752 test->subtests[test->subtest_count++] = heap_strdup(index);
753 index = strtok (NULL, whitespace);
755 test->subtests = heap_realloc (test->subtests,
756 test->subtest_count * sizeof(char*));
757 err = 0;
759 quit:
760 if (!DeleteFileA (subname))
761 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
762 return err;
765 static void
766 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
768 const char* file = get_test_source_file(test->name, subtest);
770 if (test_filtered_out( test->name, subtest ))
772 report (R_STEP, "Skipping: %s:%s", test->name, subtest);
773 xprintf ("%s:%s skipped %s -\n", test->name, subtest, file);
774 nr_of_skips++;
776 else
778 int status;
779 DWORD start = GetTickCount();
780 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
781 report (R_STEP, "Running: %s:%s", test->name, subtest);
782 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
783 status = run_ex (cmd, out_file, tempdir, 120000);
784 heap_free (cmd);
785 xprintf ("%s:%s done (%d) in %ds\n", test->name, subtest, status, (GetTickCount()-start)/1000);
786 if (status) failures++;
788 if (failures) report (R_STATUS, "Running tests - %u failures", failures);
791 static BOOL CALLBACK
792 EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
793 LPSTR lpszName, LONG_PTR lParam)
795 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
796 return TRUE;
799 static const struct clsid_mapping
801 const char *name;
802 CLSID clsid;
803 } clsid_list[] =
805 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
806 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
810 static BOOL get_main_clsid(const char *name, CLSID *clsid)
812 const struct clsid_mapping *mapping;
814 for(mapping = clsid_list; mapping->name; mapping++)
816 if(!strcasecmp(name, mapping->name))
818 *clsid = mapping->clsid;
819 return TRUE;
822 return FALSE;
825 static HMODULE load_com_dll(const char *name, char **path, char *filename)
827 HMODULE dll = NULL;
828 HKEY hkey;
829 char keyname[100];
830 char dllname[MAX_PATH];
831 char *p;
832 CLSID clsid;
834 if(!get_main_clsid(name, &clsid)) return NULL;
836 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
837 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
838 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
839 clsid.Data4[6], clsid.Data4[7]);
841 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
843 LONG size = sizeof(dllname);
844 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
846 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
848 strcpy( filename, dllname );
849 p = strrchr(dllname, '\\');
850 if (p) *p = 0;
851 *path = heap_strdup( dllname );
854 RegCloseKey(hkey);
857 return dll;
860 static void get_dll_path(HMODULE dll, char **path, char *filename)
862 char dllpath[MAX_PATH];
864 GetModuleFileNameA(dll, dllpath, MAX_PATH);
865 strcpy(filename, dllpath);
866 *strrchr(dllpath, '\\') = '\0';
867 *path = heap_strdup( dllpath );
870 static BOOL CALLBACK
871 extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
873 const char *tempdir = (const char *)lParam;
874 char dllname[MAX_PATH];
875 char filename[MAX_PATH];
876 WCHAR dllnameW[MAX_PATH];
877 HMODULE dll;
878 DWORD err;
879 HANDLE actctx;
880 ULONG_PTR cookie;
882 if (aborting) return TRUE;
884 /* Check if the main dll is present on this system */
885 CharLowerA(lpszName);
886 strcpy(dllname, lpszName);
887 *strstr(dllname, testexe) = 0;
889 if (test_filtered_out( lpszName, NULL ))
891 nr_of_skips++;
892 xprintf (" %s=skipped\n", dllname);
893 return TRUE;
895 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
897 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
898 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
900 ACTCTXA actctxinfo;
901 memset(&actctxinfo, 0, sizeof(ACTCTXA));
902 actctxinfo.cbSize = sizeof(ACTCTXA);
903 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
904 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
905 actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
906 actctx = pCreateActCtxA(&actctxinfo);
907 if (actctx != INVALID_HANDLE_VALUE &&
908 ! pActivateActCtx(actctx, &cookie))
910 pReleaseActCtx(actctx);
911 actctx = INVALID_HANDLE_VALUE;
913 } else actctx = INVALID_HANDLE_VALUE;
915 wine_tests[nr_of_files].maindllpath = NULL;
916 strcpy(filename, dllname);
917 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
919 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
921 if (!dll && pLoadLibraryShim)
923 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
924 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
926 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
927 FreeLibrary(dll);
928 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
930 else dll = 0;
933 if (!dll)
935 xprintf (" %s=dll is missing\n", dllname);
936 if (actctx != INVALID_HANDLE_VALUE)
938 pDeactivateActCtx(0, cookie);
939 pReleaseActCtx(actctx);
941 return TRUE;
943 if(is_stub_dll(dllname))
945 FreeLibrary(dll);
946 xprintf (" %s=dll is a stub\n", dllname);
947 if (actctx != INVALID_HANDLE_VALUE)
949 pDeactivateActCtx(0, cookie);
950 pReleaseActCtx(actctx);
952 return TRUE;
954 if (is_native_dll(dll))
956 FreeLibrary(dll);
957 xprintf (" %s=load error Configured as native\n", dllname);
958 nr_native_dlls++;
959 if (actctx != INVALID_HANDLE_VALUE)
961 pDeactivateActCtx(0, cookie);
962 pReleaseActCtx(actctx);
964 return TRUE;
966 FreeLibrary(dll);
968 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
970 xprintf (" %s=%s\n", dllname, get_file_version(filename));
971 nr_of_tests += wine_tests[nr_of_files].subtest_count;
972 nr_of_files++;
974 else
976 xprintf (" %s=load error %u\n", dllname, err);
979 if (actctx != INVALID_HANDLE_VALUE)
981 pDeactivateActCtx(0, cookie);
982 pReleaseActCtx(actctx);
984 return TRUE;
987 static char *
988 run_tests (char *logname, char *outdir)
990 int i;
991 char *strres, *eol, *nextline;
992 DWORD strsize;
993 SECURITY_ATTRIBUTES sa;
994 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
995 DWORD needed;
996 HMODULE kernel32;
998 /* Get the current PATH only once */
999 needed = GetEnvironmentVariableA("PATH", NULL, 0);
1000 curpath = heap_alloc(needed);
1001 GetEnvironmentVariableA("PATH", curpath, needed);
1003 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
1005 if (!GetTempPathA( MAX_PATH, tmppath ))
1006 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1008 if (!logname) {
1009 static char tmpname[MAX_PATH];
1010 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
1011 report (R_FATAL, "Can't name logfile.");
1012 logname = tmpname;
1014 report (R_OUT, logname);
1016 /* make handle inheritable */
1017 sa.nLength = sizeof(sa);
1018 sa.lpSecurityDescriptor = NULL;
1019 sa.bInheritHandle = TRUE;
1021 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1022 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1023 &sa, CREATE_ALWAYS, 0, NULL );
1025 if ((logfile == INVALID_HANDLE_VALUE) &&
1026 (GetLastError() == ERROR_INVALID_PARAMETER)) {
1027 /* FILE_SHARE_DELETE not supported on win9x */
1028 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
1029 FILE_SHARE_READ | FILE_SHARE_WRITE,
1030 &sa, CREATE_ALWAYS, 0, NULL );
1032 if (logfile == INVALID_HANDLE_VALUE)
1033 report (R_FATAL, "Could not open logfile: %u", GetLastError());
1035 /* try stable path for ZoneAlarm */
1036 if (!outdir) {
1037 strcpy( tempdir, tmppath );
1038 strcat( tempdir, "wct" );
1040 if (!CreateDirectoryA( tempdir, NULL ))
1042 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
1043 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
1044 DeleteFileA( tempdir );
1045 if (!CreateDirectoryA( tempdir, NULL ))
1046 report (R_FATAL, "Could not create directory: %s", tempdir);
1049 else
1050 strcpy( tempdir, outdir);
1052 report (R_DIR, tempdir);
1054 xprintf ("Version 4\n");
1055 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
1056 xprintf ("Archive: -\n"); /* no longer used */
1057 xprintf ("Tag: %s\n", tag);
1058 xprintf ("Build info:\n");
1059 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
1060 while (strres) {
1061 eol = memchr (strres, '\n', strsize);
1062 if (!eol) {
1063 nextline = NULL;
1064 eol = strres + strsize;
1065 } else {
1066 strsize -= eol - strres + 1;
1067 nextline = strsize?eol+1:NULL;
1068 if (eol > strres && *(eol-1) == '\r') eol--;
1070 xprintf (" %.*s\n", eol-strres, strres);
1071 strres = nextline;
1073 xprintf ("Operating system version:\n");
1074 print_version ();
1075 print_language ();
1076 xprintf ("Dll info:\n" );
1078 report (R_STATUS, "Counting tests");
1079 if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1080 report (R_FATAL, "Can't enumerate test files: %d",
1081 GetLastError ());
1082 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
1084 /* Do this only once during extraction (and version checking) */
1085 hmscoree = LoadLibraryA("mscoree.dll");
1086 pLoadLibraryShim = NULL;
1087 if (hmscoree)
1088 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
1089 kernel32 = GetModuleHandleA("kernel32.dll");
1090 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
1091 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
1092 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
1093 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
1095 report (R_STATUS, "Extracting tests");
1096 report (R_PROGRESS, 0, nr_of_files);
1097 nr_of_files = 0;
1098 nr_of_tests = 0;
1099 nr_of_skips = 0;
1100 if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
1101 report (R_FATAL, "Can't enumerate test files: %d",
1102 GetLastError ());
1104 FreeLibrary(hmscoree);
1106 if (aborting) return logname;
1108 xprintf ("Test output:\n" );
1110 report (R_DELTA, 0, "Extracting: Done");
1112 if (nr_native_dlls)
1113 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
1115 report (R_STATUS, "Running tests");
1116 report (R_PROGRESS, 1, nr_of_tests);
1117 for (i = 0; i < nr_of_files; i++) {
1118 struct wine_test *test = wine_tests + i;
1119 int j;
1121 if (aborting) break;
1123 if (test->maindllpath) {
1124 /* We need to add the path (to the main dll) to PATH */
1125 append_path(test->maindllpath);
1128 for (j = 0; j < test->subtest_count; j++) {
1129 if (aborting) break;
1130 run_test (test, test->subtests[j], logfile, tempdir);
1133 if (test->maindllpath) {
1134 /* Restore PATH again */
1135 SetEnvironmentVariableA("PATH", curpath);
1138 report (R_DELTA, 0, "Running: Done");
1140 report (R_STATUS, "Cleaning up - %u failures", failures);
1141 CloseHandle( logfile );
1142 logfile = 0;
1143 if (!outdir)
1144 remove_dir (tempdir);
1145 heap_free(wine_tests);
1146 heap_free(curpath);
1148 return logname;
1151 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
1153 if (ctrl_type == CTRL_C_EVENT) {
1154 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1155 return TRUE;
1158 return FALSE;
1162 static BOOL CALLBACK
1163 extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
1165 const char *target_dir = (const char *)lParam;
1166 char filename[MAX_PATH];
1168 if (test_filtered_out( lpszName, NULL )) return TRUE;
1170 strcpy(filename, lpszName);
1171 CharLowerA(filename);
1173 extract_test( &wine_tests[nr_of_files], target_dir, filename );
1174 nr_of_files++;
1175 return TRUE;
1178 static void extract_only (const char *target_dir)
1180 BOOL res;
1182 report (R_DIR, target_dir);
1183 res = CreateDirectoryA( target_dir, NULL );
1184 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
1185 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
1187 nr_of_files = 0;
1188 report (R_STATUS, "Counting tests");
1189 if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
1190 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1192 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
1194 report (R_STATUS, "Extracting tests");
1195 report (R_PROGRESS, 0, nr_of_files);
1196 nr_of_files = 0;
1197 if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
1198 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
1200 report (R_DELTA, 0, "Extracting: Done");
1203 static void
1204 usage (void)
1206 fprintf (stderr,
1207 "Usage: winetest [OPTION]... [TESTS]\n\n"
1208 " --help print this message and exit\n"
1209 " --version print the build version and exit\n"
1210 " -c console mode, no GUI\n"
1211 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1212 " -e preserve the environment\n"
1213 " -h print this message and exit\n"
1214 " -i INFO an optional description of the test platform\n"
1215 " -m MAIL an email address to enable developers to contact you\n"
1216 " -n exclude the specified tests\n"
1217 " -p shutdown when the tests are done\n"
1218 " -q quiet mode, no output at all\n"
1219 " -o FILE put report into FILE, do not submit\n"
1220 " -s FILE submit FILE, do not run tests\n"
1221 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1222 " -u URL include TestBot URL in the report\n"
1223 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1226 int main( int argc, char *argv[] )
1228 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
1229 char *logname = NULL, *outdir = NULL;
1230 const char *extract = NULL;
1231 const char *cp, *submit = NULL;
1232 int reset_env = 1;
1233 int poweroff = 0;
1234 int interactive = 1;
1235 int i;
1237 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1239 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1240 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1242 for (i = 1; i < argc && argv[i]; i++)
1244 if (!strcmp(argv[i], "--help")) {
1245 usage ();
1246 exit (0);
1248 else if (!strcmp(argv[i], "--version")) {
1249 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1250 exit (0);
1252 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1253 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
1255 report (R_ERROR, "Too many test filters specified");
1256 exit (2);
1258 filters[nb_filters++] = argv[i];
1260 else switch (argv[i][1]) {
1261 case 'c':
1262 report (R_TEXTMODE);
1263 interactive = 0;
1264 break;
1265 case 'e':
1266 reset_env = 0;
1267 break;
1268 case 'h':
1269 case '?':
1270 usage ();
1271 exit (0);
1272 case 'i':
1273 if (!(description = argv[++i]))
1275 usage();
1276 exit( 2 );
1278 break;
1279 case 'm':
1280 if (!(email = argv[++i]))
1282 usage();
1283 exit( 2 );
1285 break;
1286 case 'n':
1287 exclude_tests = TRUE;
1288 break;
1289 case 'p':
1290 poweroff = 1;
1291 break;
1292 case 'q':
1293 report (R_QUIET);
1294 interactive = 0;
1295 break;
1296 case 's':
1297 if (!(submit = argv[++i]))
1299 usage();
1300 exit( 2 );
1302 if (tag)
1303 report (R_WARNING, "ignoring tag for submission");
1304 send_file (submit);
1305 break;
1306 case 'o':
1307 if (!(logname = argv[++i]))
1309 usage();
1310 exit( 2 );
1312 break;
1313 case 't':
1314 if (!(tag = argv[++i]))
1316 usage();
1317 exit( 2 );
1319 if (strlen (tag) > MAXTAGLEN)
1320 report (R_FATAL, "tag is too long (maximum %d characters)",
1321 MAXTAGLEN);
1322 cp = findbadtagchar (tag);
1323 if (cp) {
1324 report (R_ERROR, "invalid char in tag: %c", *cp);
1325 usage ();
1326 exit (2);
1328 break;
1329 case 'u':
1330 if (!(url = argv[++i]))
1332 usage();
1333 exit( 2 );
1335 break;
1336 case 'x':
1337 report (R_TEXTMODE);
1338 if (!(extract = argv[++i]))
1339 extract = ".\\wct";
1341 extract_only (extract);
1342 break;
1343 case 'd':
1344 outdir = argv[++i];
1345 break;
1346 default:
1347 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1348 usage ();
1349 exit (2);
1352 if (!submit && !extract) {
1353 int is_win9x = (GetVersion() & 0x80000000) != 0;
1355 report (R_STATUS, "Starting up");
1357 if (is_win9x)
1358 report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
1360 if (!running_on_visible_desktop ())
1361 report (R_FATAL, "Tests must be run on a visible desktop");
1363 if (running_under_wine())
1365 if (!check_mount_mgr())
1366 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1368 if (!check_wow64_registry())
1369 report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1371 if (!check_display_driver())
1372 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1375 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1377 if (reset_env)
1379 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1380 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1381 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1382 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1385 while (!tag) {
1386 if (!interactive)
1387 report (R_FATAL, "Please specify a tag (-t option) if "
1388 "running noninteractive!");
1389 if (guiAskTag () == IDABORT) exit (1);
1391 report (R_TAG);
1393 while (!email) {
1394 if (!interactive)
1395 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1396 " to contact you about your report if necessary.");
1397 if (guiAskEmail () == IDABORT) exit (1);
1400 if (!build_id[0])
1401 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1402 "To submit results, winetest needs to be built from a git checkout." );
1404 if (!logname) {
1405 logname = run_tests (NULL, outdir);
1406 if (aborting) {
1407 DeleteFileA(logname);
1408 exit (0);
1410 if (failures > FAILURES_LIMIT)
1411 report( R_WARNING,
1412 "%d tests failed, there's probably something broken with your setup.\n"
1413 "You need to address this before submitting results.", failures );
1415 if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
1416 !nr_native_dlls && !is_win9x &&
1417 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1418 if (!send_file (logname) && !DeleteFileA(logname))
1419 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1420 } else run_tests (logname, outdir);
1421 report (R_STATUS, "Finished - %u failures", failures);
1423 if (poweroff)
1425 HANDLE hToken;
1426 TOKEN_PRIVILEGES npr;
1428 /* enable the shutdown privilege for the current process */
1429 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1431 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
1432 npr.PrivilegeCount = 1;
1433 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1434 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1435 CloseHandle(hToken);
1437 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1439 exit (0);