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.
29 #include "wine/port.h"
51 static struct wine_test *wine_tests;
52 static int nr_of_files, nr_of_tests;
53 static const char whitespace[] = " \t\r\n";
54 static const char testexe[] = "_test.exe";
55 static char build_id[64];
57 /* filters for running only specific tests */
58 static char *filters[64];
59 static unsigned int nb_filters = 0;
61 /* Needed to check for .NET dlls */
62 static HMODULE hmscoree;
63 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
65 /* To store the current PATH setting (related to .NET only provided dlls) */
68 /* check if test is being filtered out */
69 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
71 char *p, dllname[MAX_PATH];
74 strcpy( dllname, module );
75 CharLowerA( dllname );
76 p = strstr( dllname, testexe );
78 len = strlen(dllname);
80 if (!nb_filters) return FALSE;
81 for (i = 0; i < nb_filters; i++)
83 if (!strncmp( dllname, filters[i], len ))
85 if (!filters[i][len]) return FALSE;
86 if (filters[i][len] != ':') continue;
87 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
93 static char * get_file_version(char * file_name)
95 static char version[32];
99 size = GetFileVersionInfoSizeA(file_name, &handle);
101 char * data = heap_alloc(size);
103 if (GetFileVersionInfoA(file_name, handle, size, data)) {
104 static char backslash[] = "\\";
105 VS_FIXEDFILEINFO *pFixedVersionInfo;
107 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
108 sprintf(version, "%d.%d.%d.%d",
109 pFixedVersionInfo->dwFileVersionMS >> 16,
110 pFixedVersionInfo->dwFileVersionMS & 0xffff,
111 pFixedVersionInfo->dwFileVersionLS >> 16,
112 pFixedVersionInfo->dwFileVersionLS & 0xffff);
114 sprintf(version, "version not available");
116 sprintf(version, "unknown");
119 sprintf(version, "failed");
121 sprintf(version, "version not available");
126 static int running_under_wine (void)
128 HMODULE module = GetModuleHandleA("ntdll.dll");
130 if (!module) return 0;
131 return (GetProcAddress(module, "wine_server_call") != NULL);
134 static int running_on_visible_desktop (void)
137 HMODULE huser32 = GetModuleHandle("user32.dll");
138 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
139 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
141 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
142 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
144 desktop = GetDesktopWindow();
145 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
146 return IsWindowVisible(desktop);
148 if (pGetProcessWindowStation && pGetUserObjectInformationA)
152 USEROBJECTFLAGS uoflags;
154 wstation = (HWINSTA)pGetProcessWindowStation();
155 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
156 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
158 return IsWindowVisible(desktop);
161 /* check for wine fake dll module */
162 static BOOL is_fake_dll( HMODULE module )
164 static const char fakedll_signature[] = "Wine placeholder DLL";
165 const IMAGE_DOS_HEADER *dos;
167 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
168 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
169 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
170 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
171 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return TRUE;
175 /* check if Gecko is present, trying to trigger the install if not */
176 static BOOL gecko_check(void)
182 CoInitialize( NULL );
183 if (FAILED( CoCreateInstance( &CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
184 &IID_IHTMLDocument2, (void **)&doc ))) return FALSE;
185 if ((ret = SUCCEEDED( IHTMLDocument2_get_body( doc, &body )))) IHTMLElement_Release( body );
186 IHTMLDocument_Release( doc );
190 static void print_version (void)
193 static const char platform[] = "i386";
194 #elif defined(__x86_64__)
195 static const char platform[] = "x86_64";
196 #elif defined(__sparc__)
197 static const char platform[] = "sparc";
198 #elif defined(__ALPHA__)
199 static const char platform[] = "alpha";
200 #elif defined(__powerpc__)
201 static const char platform[] = "powerpc";
206 const char *(CDECL *wine_get_build_id)(void);
207 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
208 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
210 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
211 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
213 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
214 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
215 report (R_FATAL, "Can't get OS version.");
217 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
218 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
220 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
221 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
222 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
223 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
224 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
225 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
226 ver.dwPlatformId, ver.szCSDVersion);
228 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
229 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
230 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
231 if (wine_get_host_version)
233 const char *sysname, *release;
234 wine_get_host_version( &sysname, &release );
235 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
237 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
239 xprintf(" R2 build number=%d\n", is_win2k3_r2);
243 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
244 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
245 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
246 ver.wProductType, ver.wReserved);
249 static inline int is_dot_dir(const char* x)
251 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
254 static void remove_dir (const char *dir)
259 size_t dirlen = strlen (dir);
261 /* Make sure the directory exists before going further */
262 memcpy (path, dir, dirlen);
263 strcpy (path + dirlen++, "\\*");
264 hFind = FindFirstFile (path, &wfd);
265 if (hFind == INVALID_HANDLE_VALUE) return;
268 char *lp = wfd.cFileName;
270 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
271 if (is_dot_dir (lp)) continue;
272 strcpy (path + dirlen, lp);
273 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
275 else if (!DeleteFile (path))
276 report (R_WARNING, "Can't delete file %s: error %d",
277 path, GetLastError ());
278 } while (FindNextFile (hFind, &wfd));
280 if (!RemoveDirectory (dir))
281 report (R_WARNING, "Can't remove directory %s: error %d",
282 dir, GetLastError ());
285 static const char* get_test_source_file(const char* test, const char* subtest)
287 static const char* special_dirs[][2] = {
290 static char buffer[MAX_PATH];
293 for (i = 0; special_dirs[i][0]; i++) {
294 if (strcmp(test, special_dirs[i][0]) == 0) {
295 test = special_dirs[i][1];
300 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
304 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
310 if (!(rsrc = FindResource (NULL, name, type)) ||
311 !(*size = SizeofResource (0, rsrc)) ||
312 !(hdl = LoadResource (0, rsrc)) ||
313 !(addr = LockResource (hdl)))
318 /* Fills in the name and exename fields */
320 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
328 code = extract_rcdata (res_name, "TESTRES", &size);
329 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
330 res_name, GetLastError ());
331 test->name = heap_strdup( res_name );
332 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
333 exepos = strstr (test->name, testexe);
334 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
336 test->name = heap_realloc (test->name, exepos - test->name + 1);
337 report (R_STEP, "Extracting: %s", test->name);
339 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
340 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
341 if (hfile == INVALID_HANDLE_VALUE)
342 report (R_FATAL, "Failed to open file %s.", test->exename);
344 if (!WriteFile(hfile, code, size, &written, NULL))
345 report (R_FATAL, "Failed to write file %s.", test->exename);
350 static DWORD wait_process( HANDLE process, DWORD timeout )
352 DWORD wait, diff = 0, start = GetTickCount();
355 while (diff < timeout)
357 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
358 if (wait != WAIT_OBJECT_0 + 1) return wait;
359 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
360 diff = GetTickCount() - start;
365 static void append_path( const char *path)
369 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
370 strcpy(newpath, curpath);
371 strcat(newpath, ";");
372 strcat(newpath, path);
373 SetEnvironmentVariableA("PATH", newpath);
378 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
381 Return the exit status, -2 if can't create process or the return
382 value of WaitForSingleObject.
385 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
388 PROCESS_INFORMATION pi;
391 GetStartupInfo (&si);
392 si.dwFlags = STARTF_USESTDHANDLES;
393 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
394 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
395 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
397 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
398 NULL, tempdir, &si, &pi))
401 CloseHandle (pi.hThread);
402 status = wait_process( pi.hProcess, ms );
406 GetExitCodeProcess (pi.hProcess, &status);
407 CloseHandle (pi.hProcess);
410 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
415 report (R_ERROR, "Wait returned %d", status);
418 if (!TerminateProcess (pi.hProcess, 257))
419 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
420 wait = wait_process( pi.hProcess, 5000 );
426 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
429 report (R_ERROR, "Can't kill process '%s'", cmd);
432 report (R_ERROR, "Waiting for termination: %d", wait);
435 CloseHandle (pi.hProcess);
440 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
445 char buffer[8192], *index;
446 static const char header[] = "Valid test names:";
447 int status, allocated;
448 char tmpdir[MAX_PATH], subname[MAX_PATH];
449 SECURITY_ATTRIBUTES sa;
451 test->subtest_count = 0;
453 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
454 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
455 report (R_FATAL, "Can't name subtests file.");
457 /* make handle inheritable */
458 sa.nLength = sizeof(sa);
459 sa.lpSecurityDescriptor = NULL;
460 sa.bInheritHandle = TRUE;
462 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
463 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
464 &sa, CREATE_ALWAYS, 0, NULL );
466 if ((subfile == INVALID_HANDLE_VALUE) &&
467 (GetLastError() == ERROR_INVALID_PARAMETER)) {
468 /* FILE_SHARE_DELETE not supported on win9x */
469 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
470 FILE_SHARE_READ | FILE_SHARE_WRITE,
471 &sa, CREATE_ALWAYS, 0, NULL );
473 if (subfile == INVALID_HANDLE_VALUE) {
474 err = GetLastError();
475 report (R_ERROR, "Can't open subtests output of %s: %u",
476 test->name, GetLastError());
480 extract_test (test, tempdir, res_name);
481 cmd = strmake (NULL, "%s --list", test->exename);
482 if (test->maindllpath) {
483 /* We need to add the path (to the main dll) to PATH */
484 append_path(test->maindllpath);
486 status = run_ex (cmd, subfile, tempdir, 5000);
487 err = GetLastError();
488 if (test->maindllpath) {
489 /* Restore PATH again */
490 SetEnvironmentVariableA("PATH", curpath);
496 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
500 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
501 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
502 CloseHandle( subfile );
503 if (sizeof buffer == total) {
504 report (R_ERROR, "Subtest list of %s too big.",
505 test->name, sizeof buffer);
506 err = ERROR_OUTOFMEMORY;
511 index = strstr (buffer, header);
513 report (R_ERROR, "Can't parse subtests output of %s",
515 err = ERROR_INTERNAL_ERROR;
518 index += sizeof header;
521 test->subtests = heap_alloc (allocated * sizeof(char*));
522 index = strtok (index, whitespace);
524 if (test->subtest_count == allocated) {
526 test->subtests = heap_realloc (test->subtests,
527 allocated * sizeof(char*));
529 if (!test_filtered_out( test->name, index ))
530 test->subtests[test->subtest_count++] = heap_strdup(index);
531 index = strtok (NULL, whitespace);
533 test->subtests = heap_realloc (test->subtests,
534 test->subtest_count * sizeof(char*));
538 if (!DeleteFileA (subname))
539 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
544 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
547 const char* file = get_test_source_file(test->name, subtest);
548 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
550 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
551 status = run_ex (cmd, out_file, tempdir, 120000);
553 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
557 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
558 LPTSTR lpszName, LONG_PTR lParam)
560 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
564 static const struct clsid_mapping
570 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
571 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
575 static BOOL get_main_clsid(const char *name, CLSID *clsid)
577 const struct clsid_mapping *mapping;
579 for(mapping = clsid_list; mapping->name; mapping++)
581 if(!strcasecmp(name, mapping->name))
583 *clsid = mapping->clsid;
590 static HMODULE load_com_dll(const char *name, char **path, char *filename)
595 char dllname[MAX_PATH];
599 if(!get_main_clsid(name, &clsid)) return NULL;
601 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
602 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
603 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
604 clsid.Data4[6], clsid.Data4[7]);
606 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
608 LONG size = sizeof(dllname);
609 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
611 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
613 strcpy( filename, dllname );
614 p = strrchr(dllname, '\\');
616 *path = heap_strdup( dllname );
625 static void get_dll_path(HMODULE dll, char **path, char *filename)
627 char dllpath[MAX_PATH];
629 GetModuleFileNameA(dll, dllpath, MAX_PATH);
630 strcpy(filename, dllpath);
631 *strrchr(dllpath, '\\') = '\0';
632 *path = heap_strdup( dllpath );
636 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
637 LPTSTR lpszName, LONG_PTR lParam)
639 const char *tempdir = (const char *)lParam;
640 char dllname[MAX_PATH];
641 char filename[MAX_PATH];
642 WCHAR dllnameW[MAX_PATH];
646 if (test_filtered_out( lpszName, NULL )) return TRUE;
648 /* Check if the main dll is present on this system */
649 CharLowerA(lpszName);
650 strcpy(dllname, lpszName);
651 *strstr(dllname, testexe) = 0;
653 wine_tests[nr_of_files].maindllpath = NULL;
654 strcpy(filename, dllname);
655 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
657 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
659 if (dll && running_under_wine() && ((ULONG_PTR)dll & 1))
661 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
662 if (!is_fake_dll(dll))
665 xprintf (" %s=load error Configured as native\n", dllname);
670 if (!dll && pLoadLibraryShim)
672 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
673 if (FAILED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ))
676 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
681 xprintf (" %s=dll is missing\n", dllname);
684 if (!strcmp( dllname, "mshtml" ) && running_under_wine() && !gecko_check())
687 xprintf (" %s=load error Gecko is not installed\n", dllname);
692 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
694 xprintf (" %s=%s\n", dllname, get_file_version(filename));
695 nr_of_tests += wine_tests[nr_of_files].subtest_count;
700 xprintf (" %s=load error %u\n", dllname, err);
706 run_tests (char *logname, char *outdir)
709 char *strres, *eol, *nextline;
711 SECURITY_ATTRIBUTES sa;
712 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
715 /* Get the current PATH only once */
716 needed = GetEnvironmentVariableA("PATH", NULL, 0);
717 curpath = heap_alloc(needed);
718 GetEnvironmentVariableA("PATH", curpath, needed);
720 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
722 if (!GetTempPathA( MAX_PATH, tmppath ))
723 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
726 static char tmpname[MAX_PATH];
727 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
728 report (R_FATAL, "Can't name logfile.");
731 report (R_OUT, logname);
733 /* make handle inheritable */
734 sa.nLength = sizeof(sa);
735 sa.lpSecurityDescriptor = NULL;
736 sa.bInheritHandle = TRUE;
738 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
739 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
740 &sa, CREATE_ALWAYS, 0, NULL );
742 if ((logfile == INVALID_HANDLE_VALUE) &&
743 (GetLastError() == ERROR_INVALID_PARAMETER)) {
744 /* FILE_SHARE_DELETE not supported on win9x */
745 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
746 FILE_SHARE_READ | FILE_SHARE_WRITE,
747 &sa, CREATE_ALWAYS, 0, NULL );
749 if (logfile == INVALID_HANDLE_VALUE)
750 report (R_FATAL, "Could not open logfile: %u", GetLastError());
752 /* try stable path for ZoneAlarm */
754 strcpy( tempdir, tmppath );
755 strcat( tempdir, "wct" );
757 if (!CreateDirectoryA( tempdir, NULL ))
759 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
760 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
761 DeleteFileA( tempdir );
762 if (!CreateDirectoryA( tempdir, NULL ))
763 report (R_FATAL, "Could not create directory: %s", tempdir);
767 strcpy( tempdir, outdir);
769 report (R_DIR, tempdir);
771 xprintf ("Version 4\n");
772 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
773 xprintf ("Archive: -\n"); /* no longer used */
774 xprintf ("Tag: %s\n", tag);
775 xprintf ("Build info:\n");
776 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
778 eol = memchr (strres, '\n', strsize);
781 eol = strres + strsize;
783 strsize -= eol - strres + 1;
784 nextline = strsize?eol+1:NULL;
785 if (eol > strres && *(eol-1) == '\r') eol--;
787 xprintf (" %.*s\n", eol-strres, strres);
790 xprintf ("Operating system version:\n");
792 xprintf ("Dll info:\n" );
794 report (R_STATUS, "Counting tests");
795 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
796 report (R_FATAL, "Can't enumerate test files: %d",
798 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
800 /* Do this only once during extraction (and version checking) */
801 hmscoree = LoadLibraryA("mscoree.dll");
802 pLoadLibraryShim = NULL;
804 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
806 report (R_STATUS, "Extracting tests");
807 report (R_PROGRESS, 0, nr_of_files);
810 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
811 report (R_FATAL, "Can't enumerate test files: %d",
814 FreeLibrary(hmscoree);
816 xprintf ("Test output:\n" );
818 report (R_DELTA, 0, "Extracting: Done");
820 report (R_STATUS, "Running tests");
821 report (R_PROGRESS, 1, nr_of_tests);
822 for (i = 0; i < nr_of_files; i++) {
823 struct wine_test *test = wine_tests + i;
826 if (test->maindllpath) {
827 /* We need to add the path (to the main dll) to PATH */
828 append_path(test->maindllpath);
831 for (j = 0; j < test->subtest_count; j++) {
832 report (R_STEP, "Running: %s:%s", test->name,
834 run_test (test, test->subtests[j], logfile, tempdir);
837 if (test->maindllpath) {
838 /* Restore PATH again */
839 SetEnvironmentVariableA("PATH", curpath);
842 report (R_DELTA, 0, "Running: Done");
844 report (R_STATUS, "Cleaning up");
845 CloseHandle( logfile );
848 remove_dir (tempdir);
849 heap_free(wine_tests);
855 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
857 if (ctrl_type == CTRL_C_EVENT) {
858 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
867 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
869 const char *target_dir = (const char *)lParam;
870 char filename[MAX_PATH];
872 if (test_filtered_out( lpszName, NULL )) return TRUE;
874 strcpy(filename, lpszName);
875 CharLowerA(filename);
877 extract_test( &wine_tests[nr_of_files], target_dir, filename );
882 static void extract_only (const char *target_dir)
886 report (R_DIR, target_dir);
887 res = CreateDirectoryA( target_dir, NULL );
888 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
889 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
892 report (R_STATUS, "Counting tests");
893 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
894 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
896 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
898 report (R_STATUS, "Extracting tests");
899 report (R_PROGRESS, 0, nr_of_files);
901 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
902 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
904 report (R_DELTA, 0, "Extracting: Done");
911 "Usage: winetest [OPTION]... [TESTS]\n\n"
912 " --help print this message and exit\n"
913 " --version print the build version and exit\n"
914 " -c console mode, no GUI\n"
915 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
916 " -e preserve the environment\n"
917 " -h print this message and exit\n"
918 " -p shutdown when the tests are done\n"
919 " -q quiet mode, no output at all\n"
920 " -o FILE put report into FILE, do not submit\n"
921 " -s FILE submit FILE, do not run tests\n"
922 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
923 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
926 int main( int argc, char *argv[] )
928 char *logname = NULL, *outdir = NULL;
929 const char *extract = NULL;
930 const char *cp, *submit = NULL;
936 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
938 for (i = 1; i < argc && argv[i]; i++)
940 if (!strcmp(argv[i], "--help")) {
944 else if (!strcmp(argv[i], "--version")) {
945 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
948 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
949 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
951 report (R_ERROR, "Too many test filters specified");
954 filters[nb_filters++] = argv[i];
956 else switch (argv[i][1]) {
976 if (!(submit = argv[++i]))
982 report (R_WARNING, "ignoring tag for submission");
986 if (!(logname = argv[++i]))
993 if (!(tag = argv[++i]))
998 if (strlen (tag) > MAXTAGLEN)
999 report (R_FATAL, "tag is too long (maximum %d characters)",
1001 cp = findbadtagchar (tag);
1003 report (R_ERROR, "invalid char in tag: %c", *cp);
1009 report (R_TEXTMODE);
1010 if (!(extract = argv[++i]))
1013 extract_only (extract);
1019 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1024 if (!submit && !extract) {
1025 report (R_STATUS, "Starting up");
1027 if (!running_on_visible_desktop ())
1028 report (R_FATAL, "Tests must be run on a visible desktop");
1030 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1034 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1035 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1036 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1037 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1040 if (!nb_filters) /* don't submit results when filtering */
1044 report (R_FATAL, "Please specify a tag (-t option) if "
1045 "running noninteractive!");
1046 if (guiAskTag () == IDABORT) exit (1);
1051 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1052 "To submit results, winetest needs to be built from a git checkout." );
1056 logname = run_tests (NULL, outdir);
1057 if (build_id[0] && !nb_filters &&
1058 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1059 if (!send_file (logname) && !DeleteFileA(logname))
1060 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1061 } else run_tests (logname, outdir);
1062 report (R_STATUS, "Finished");
1067 TOKEN_PRIVILEGES npr;
1069 /* enable the shutdown privilege for the current process */
1070 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1072 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1073 npr.PrivilegeCount = 1;
1074 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1075 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1076 CloseHandle(hToken);
1078 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);