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 int nr_native_dlls;
54 static const char whitespace[] = " \t\r\n";
55 static const char testexe[] = "_test.exe";
56 static char build_id[64];
58 /* filters for running only specific tests */
59 static char *filters[64];
60 static unsigned int nb_filters = 0;
62 /* Needed to check for .NET dlls */
63 static HMODULE hmscoree;
64 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
66 /* To store the current PATH setting (related to .NET only provided dlls) */
69 /* check if test is being filtered out */
70 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
72 char *p, dllname[MAX_PATH];
75 strcpy( dllname, module );
76 CharLowerA( dllname );
77 p = strstr( dllname, testexe );
79 len = strlen(dllname);
81 if (!nb_filters) return FALSE;
82 for (i = 0; i < nb_filters; i++)
84 if (!strncmp( dllname, filters[i], len ))
86 if (!filters[i][len]) return FALSE;
87 if (filters[i][len] != ':') continue;
88 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
94 static char * get_file_version(char * file_name)
96 static char version[32];
100 size = GetFileVersionInfoSizeA(file_name, &handle);
102 char * data = heap_alloc(size);
104 if (GetFileVersionInfoA(file_name, handle, size, data)) {
105 static char backslash[] = "\\";
106 VS_FIXEDFILEINFO *pFixedVersionInfo;
108 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
109 sprintf(version, "%d.%d.%d.%d",
110 pFixedVersionInfo->dwFileVersionMS >> 16,
111 pFixedVersionInfo->dwFileVersionMS & 0xffff,
112 pFixedVersionInfo->dwFileVersionLS >> 16,
113 pFixedVersionInfo->dwFileVersionLS & 0xffff);
115 sprintf(version, "version not available");
117 sprintf(version, "unknown");
120 sprintf(version, "failed");
122 sprintf(version, "version not available");
127 static int running_under_wine (void)
129 HMODULE module = GetModuleHandleA("ntdll.dll");
131 if (!module) return 0;
132 return (GetProcAddress(module, "wine_server_call") != NULL);
135 static int running_on_visible_desktop (void)
138 HMODULE huser32 = GetModuleHandle("user32.dll");
139 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
140 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
142 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
143 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
145 desktop = GetDesktopWindow();
146 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
147 return IsWindowVisible(desktop);
149 if (pGetProcessWindowStation && pGetUserObjectInformationA)
153 USEROBJECTFLAGS uoflags;
155 wstation = (HWINSTA)pGetProcessWindowStation();
156 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
157 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
159 return IsWindowVisible(desktop);
162 /* check for native dll when running under wine */
163 static BOOL is_native_dll( HMODULE module )
165 static const char fakedll_signature[] = "Wine placeholder DLL";
166 const IMAGE_DOS_HEADER *dos;
168 if (!running_under_wine()) return FALSE;
169 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
170 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
171 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
172 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
173 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
174 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
178 static void print_version (void)
181 static const char platform[] = "i386";
182 #elif defined(__x86_64__)
183 static const char platform[] = "x86_64";
184 #elif defined(__sparc__)
185 static const char platform[] = "sparc";
186 #elif defined(__ALPHA__)
187 static const char platform[] = "alpha";
188 #elif defined(__powerpc__)
189 static const char platform[] = "powerpc";
194 const char *(CDECL *wine_get_build_id)(void);
195 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
196 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
197 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
199 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
200 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
202 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
203 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
204 report (R_FATAL, "Can't get OS version.");
206 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
207 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
209 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
210 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
211 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
212 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
213 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
214 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
215 ver.dwPlatformId, ver.szCSDVersion);
217 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
218 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
219 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
220 if (wine_get_host_version)
222 const char *sysname, *release;
223 wine_get_host_version( &sysname, &release );
224 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
226 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
228 xprintf(" R2 build number=%d\n", is_win2k3_r2);
232 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
233 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
234 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
235 ver.wProductType, ver.wReserved);
237 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
238 if (pGetProductInfo && !running_under_wine())
242 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
243 xprintf(" dwProductInfo=%u\n", prodtype);
247 static inline int is_dot_dir(const char* x)
249 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
252 static void remove_dir (const char *dir)
257 size_t dirlen = strlen (dir);
259 /* Make sure the directory exists before going further */
260 memcpy (path, dir, dirlen);
261 strcpy (path + dirlen++, "\\*");
262 hFind = FindFirstFile (path, &wfd);
263 if (hFind == INVALID_HANDLE_VALUE) return;
266 char *lp = wfd.cFileName;
268 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
269 if (is_dot_dir (lp)) continue;
270 strcpy (path + dirlen, lp);
271 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
273 else if (!DeleteFile (path))
274 report (R_WARNING, "Can't delete file %s: error %d",
275 path, GetLastError ());
276 } while (FindNextFile (hFind, &wfd));
278 if (!RemoveDirectory (dir))
279 report (R_WARNING, "Can't remove directory %s: error %d",
280 dir, GetLastError ());
283 static const char* get_test_source_file(const char* test, const char* subtest)
285 static const char* special_dirs[][2] = {
288 static char buffer[MAX_PATH];
291 for (i = 0; special_dirs[i][0]; i++) {
292 if (strcmp(test, special_dirs[i][0]) == 0) {
293 test = special_dirs[i][1];
298 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
302 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
308 if (!(rsrc = FindResource (NULL, name, type)) ||
309 !(*size = SizeofResource (0, rsrc)) ||
310 !(hdl = LoadResource (0, rsrc)) ||
311 !(addr = LockResource (hdl)))
316 /* Fills in the name and exename fields */
318 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
326 code = extract_rcdata (res_name, "TESTRES", &size);
327 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
328 res_name, GetLastError ());
329 test->name = heap_strdup( res_name );
330 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
331 exepos = strstr (test->name, testexe);
332 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
334 test->name = heap_realloc (test->name, exepos - test->name + 1);
335 report (R_STEP, "Extracting: %s", test->name);
337 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
338 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
339 if (hfile == INVALID_HANDLE_VALUE)
340 report (R_FATAL, "Failed to open file %s.", test->exename);
342 if (!WriteFile(hfile, code, size, &written, NULL))
343 report (R_FATAL, "Failed to write file %s.", test->exename);
348 static DWORD wait_process( HANDLE process, DWORD timeout )
350 DWORD wait, diff = 0, start = GetTickCount();
353 while (diff < timeout)
355 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
356 if (wait != WAIT_OBJECT_0 + 1) return wait;
357 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
358 diff = GetTickCount() - start;
363 static void append_path( const char *path)
367 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
368 strcpy(newpath, curpath);
369 strcat(newpath, ";");
370 strcat(newpath, path);
371 SetEnvironmentVariableA("PATH", newpath);
376 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
379 Return the exit status, -2 if can't create process or the return
380 value of WaitForSingleObject.
383 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
386 PROCESS_INFORMATION pi;
389 GetStartupInfo (&si);
390 si.dwFlags = STARTF_USESTDHANDLES;
391 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
392 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
393 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
395 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
396 NULL, tempdir, &si, &pi))
399 CloseHandle (pi.hThread);
400 status = wait_process( pi.hProcess, ms );
404 GetExitCodeProcess (pi.hProcess, &status);
405 CloseHandle (pi.hProcess);
408 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
413 report (R_ERROR, "Wait returned %d", status);
416 if (!TerminateProcess (pi.hProcess, 257))
417 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
418 wait = wait_process( pi.hProcess, 5000 );
424 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
427 report (R_ERROR, "Can't kill process '%s'", cmd);
430 report (R_ERROR, "Waiting for termination: %d", wait);
433 CloseHandle (pi.hProcess);
438 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
443 char buffer[8192], *index;
444 static const char header[] = "Valid test names:";
445 int status, allocated;
446 char tmpdir[MAX_PATH], subname[MAX_PATH];
447 SECURITY_ATTRIBUTES sa;
449 test->subtest_count = 0;
451 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
452 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
453 report (R_FATAL, "Can't name subtests file.");
455 /* make handle inheritable */
456 sa.nLength = sizeof(sa);
457 sa.lpSecurityDescriptor = NULL;
458 sa.bInheritHandle = TRUE;
460 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
461 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
462 &sa, CREATE_ALWAYS, 0, NULL );
464 if ((subfile == INVALID_HANDLE_VALUE) &&
465 (GetLastError() == ERROR_INVALID_PARAMETER)) {
466 /* FILE_SHARE_DELETE not supported on win9x */
467 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
468 FILE_SHARE_READ | FILE_SHARE_WRITE,
469 &sa, CREATE_ALWAYS, 0, NULL );
471 if (subfile == INVALID_HANDLE_VALUE) {
472 err = GetLastError();
473 report (R_ERROR, "Can't open subtests output of %s: %u",
474 test->name, GetLastError());
478 extract_test (test, tempdir, res_name);
479 cmd = strmake (NULL, "%s --list", test->exename);
480 if (test->maindllpath) {
481 /* We need to add the path (to the main dll) to PATH */
482 append_path(test->maindllpath);
484 status = run_ex (cmd, subfile, tempdir, 5000);
485 err = GetLastError();
486 if (test->maindllpath) {
487 /* Restore PATH again */
488 SetEnvironmentVariableA("PATH", curpath);
494 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
498 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
499 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
500 CloseHandle( subfile );
501 if (sizeof buffer == total) {
502 report (R_ERROR, "Subtest list of %s too big.",
503 test->name, sizeof buffer);
504 err = ERROR_OUTOFMEMORY;
509 index = strstr (buffer, header);
511 report (R_ERROR, "Can't parse subtests output of %s",
513 err = ERROR_INTERNAL_ERROR;
516 index += sizeof header;
519 test->subtests = heap_alloc (allocated * sizeof(char*));
520 index = strtok (index, whitespace);
522 if (test->subtest_count == allocated) {
524 test->subtests = heap_realloc (test->subtests,
525 allocated * sizeof(char*));
527 if (!test_filtered_out( test->name, index ))
528 test->subtests[test->subtest_count++] = heap_strdup(index);
529 index = strtok (NULL, whitespace);
531 test->subtests = heap_realloc (test->subtests,
532 test->subtest_count * sizeof(char*));
536 if (!DeleteFileA (subname))
537 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
542 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
545 const char* file = get_test_source_file(test->name, subtest);
546 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
548 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
549 status = run_ex (cmd, out_file, tempdir, 120000);
551 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
555 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
556 LPTSTR lpszName, LONG_PTR lParam)
558 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
562 static const struct clsid_mapping
568 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
569 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
573 static BOOL get_main_clsid(const char *name, CLSID *clsid)
575 const struct clsid_mapping *mapping;
577 for(mapping = clsid_list; mapping->name; mapping++)
579 if(!strcasecmp(name, mapping->name))
581 *clsid = mapping->clsid;
588 static HMODULE load_com_dll(const char *name, char **path, char *filename)
593 char dllname[MAX_PATH];
597 if(!get_main_clsid(name, &clsid)) return NULL;
599 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
600 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
601 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
602 clsid.Data4[6], clsid.Data4[7]);
604 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
606 LONG size = sizeof(dllname);
607 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
609 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
611 strcpy( filename, dllname );
612 p = strrchr(dllname, '\\');
614 *path = heap_strdup( dllname );
623 static void get_dll_path(HMODULE dll, char **path, char *filename)
625 char dllpath[MAX_PATH];
627 GetModuleFileNameA(dll, dllpath, MAX_PATH);
628 strcpy(filename, dllpath);
629 *strrchr(dllpath, '\\') = '\0';
630 *path = heap_strdup( dllpath );
634 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
635 LPTSTR lpszName, LONG_PTR lParam)
637 const char *tempdir = (const char *)lParam;
638 char dllname[MAX_PATH];
639 char filename[MAX_PATH];
640 WCHAR dllnameW[MAX_PATH];
644 if (test_filtered_out( lpszName, NULL )) return TRUE;
646 /* Check if the main dll is present on this system */
647 CharLowerA(lpszName);
648 strcpy(dllname, lpszName);
649 *strstr(dllname, testexe) = 0;
651 wine_tests[nr_of_files].maindllpath = NULL;
652 strcpy(filename, dllname);
653 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
655 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
657 if (!dll && pLoadLibraryShim)
659 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
660 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
662 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
664 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
671 xprintf (" %s=dll is missing\n", dllname);
674 if (is_native_dll(dll))
677 xprintf (" %s=load error Configured as native\n", dllname);
683 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
685 xprintf (" %s=%s\n", dllname, get_file_version(filename));
686 nr_of_tests += wine_tests[nr_of_files].subtest_count;
691 xprintf (" %s=load error %u\n", dllname, err);
697 run_tests (char *logname, char *outdir)
700 char *strres, *eol, *nextline;
702 SECURITY_ATTRIBUTES sa;
703 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
706 /* Get the current PATH only once */
707 needed = GetEnvironmentVariableA("PATH", NULL, 0);
708 curpath = heap_alloc(needed);
709 GetEnvironmentVariableA("PATH", curpath, needed);
711 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
713 if (!GetTempPathA( MAX_PATH, tmppath ))
714 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
717 static char tmpname[MAX_PATH];
718 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
719 report (R_FATAL, "Can't name logfile.");
722 report (R_OUT, logname);
724 /* make handle inheritable */
725 sa.nLength = sizeof(sa);
726 sa.lpSecurityDescriptor = NULL;
727 sa.bInheritHandle = TRUE;
729 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
730 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
731 &sa, CREATE_ALWAYS, 0, NULL );
733 if ((logfile == INVALID_HANDLE_VALUE) &&
734 (GetLastError() == ERROR_INVALID_PARAMETER)) {
735 /* FILE_SHARE_DELETE not supported on win9x */
736 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
737 FILE_SHARE_READ | FILE_SHARE_WRITE,
738 &sa, CREATE_ALWAYS, 0, NULL );
740 if (logfile == INVALID_HANDLE_VALUE)
741 report (R_FATAL, "Could not open logfile: %u", GetLastError());
743 /* try stable path for ZoneAlarm */
745 strcpy( tempdir, tmppath );
746 strcat( tempdir, "wct" );
748 if (!CreateDirectoryA( tempdir, NULL ))
750 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
751 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
752 DeleteFileA( tempdir );
753 if (!CreateDirectoryA( tempdir, NULL ))
754 report (R_FATAL, "Could not create directory: %s", tempdir);
758 strcpy( tempdir, outdir);
760 report (R_DIR, tempdir);
762 xprintf ("Version 4\n");
763 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
764 xprintf ("Archive: -\n"); /* no longer used */
765 xprintf ("Tag: %s\n", tag);
766 xprintf ("Build info:\n");
767 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
769 eol = memchr (strres, '\n', strsize);
772 eol = strres + strsize;
774 strsize -= eol - strres + 1;
775 nextline = strsize?eol+1:NULL;
776 if (eol > strres && *(eol-1) == '\r') eol--;
778 xprintf (" %.*s\n", eol-strres, strres);
781 xprintf ("Operating system version:\n");
783 xprintf ("Dll info:\n" );
785 report (R_STATUS, "Counting tests");
786 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
787 report (R_FATAL, "Can't enumerate test files: %d",
789 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
791 /* Do this only once during extraction (and version checking) */
792 hmscoree = LoadLibraryA("mscoree.dll");
793 pLoadLibraryShim = NULL;
795 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
797 report (R_STATUS, "Extracting tests");
798 report (R_PROGRESS, 0, nr_of_files);
801 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
802 report (R_FATAL, "Can't enumerate test files: %d",
805 FreeLibrary(hmscoree);
807 xprintf ("Test output:\n" );
809 report (R_DELTA, 0, "Extracting: Done");
812 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
814 report (R_STATUS, "Running tests");
815 report (R_PROGRESS, 1, nr_of_tests);
816 for (i = 0; i < nr_of_files; i++) {
817 struct wine_test *test = wine_tests + i;
820 if (test->maindllpath) {
821 /* We need to add the path (to the main dll) to PATH */
822 append_path(test->maindllpath);
825 for (j = 0; j < test->subtest_count; j++) {
826 report (R_STEP, "Running: %s:%s", test->name,
828 run_test (test, test->subtests[j], logfile, tempdir);
831 if (test->maindllpath) {
832 /* Restore PATH again */
833 SetEnvironmentVariableA("PATH", curpath);
836 report (R_DELTA, 0, "Running: Done");
838 report (R_STATUS, "Cleaning up");
839 CloseHandle( logfile );
842 remove_dir (tempdir);
843 heap_free(wine_tests);
849 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
851 if (ctrl_type == CTRL_C_EVENT) {
852 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
861 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
863 const char *target_dir = (const char *)lParam;
864 char filename[MAX_PATH];
866 if (test_filtered_out( lpszName, NULL )) return TRUE;
868 strcpy(filename, lpszName);
869 CharLowerA(filename);
871 extract_test( &wine_tests[nr_of_files], target_dir, filename );
876 static void extract_only (const char *target_dir)
880 report (R_DIR, target_dir);
881 res = CreateDirectoryA( target_dir, NULL );
882 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
883 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
886 report (R_STATUS, "Counting tests");
887 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
888 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
890 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
892 report (R_STATUS, "Extracting tests");
893 report (R_PROGRESS, 0, nr_of_files);
895 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
896 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
898 report (R_DELTA, 0, "Extracting: Done");
905 "Usage: winetest [OPTION]... [TESTS]\n\n"
906 " --help print this message and exit\n"
907 " --version print the build version and exit\n"
908 " -c console mode, no GUI\n"
909 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
910 " -e preserve the environment\n"
911 " -h print this message and exit\n"
912 " -p shutdown when the tests are done\n"
913 " -q quiet mode, no output at all\n"
914 " -o FILE put report into FILE, do not submit\n"
915 " -s FILE submit FILE, do not run tests\n"
916 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
917 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
920 int main( int argc, char *argv[] )
922 char *logname = NULL, *outdir = NULL;
923 const char *extract = NULL;
924 const char *cp, *submit = NULL;
930 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
932 for (i = 1; i < argc && argv[i]; i++)
934 if (!strcmp(argv[i], "--help")) {
938 else if (!strcmp(argv[i], "--version")) {
939 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
942 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
943 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
945 report (R_ERROR, "Too many test filters specified");
948 filters[nb_filters++] = argv[i];
950 else switch (argv[i][1]) {
970 if (!(submit = argv[++i]))
976 report (R_WARNING, "ignoring tag for submission");
980 if (!(logname = argv[++i]))
987 if (!(tag = argv[++i]))
992 if (strlen (tag) > MAXTAGLEN)
993 report (R_FATAL, "tag is too long (maximum %d characters)",
995 cp = findbadtagchar (tag);
997 report (R_ERROR, "invalid char in tag: %c", *cp);
1003 report (R_TEXTMODE);
1004 if (!(extract = argv[++i]))
1007 extract_only (extract);
1013 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1018 if (!submit && !extract) {
1019 report (R_STATUS, "Starting up");
1021 if (!running_on_visible_desktop ())
1022 report (R_FATAL, "Tests must be run on a visible desktop");
1024 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1028 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1029 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1030 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1031 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1034 if (!nb_filters) /* don't submit results when filtering */
1038 report (R_FATAL, "Please specify a tag (-t option) if "
1039 "running noninteractive!");
1040 if (guiAskTag () == IDABORT) exit (1);
1045 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1046 "To submit results, winetest needs to be built from a git checkout." );
1050 logname = run_tests (NULL, outdir);
1051 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1052 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1053 if (!send_file (logname) && !DeleteFileA(logname))
1054 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1055 } else run_tests (logname, outdir);
1056 report (R_STATUS, "Finished");
1061 TOKEN_PRIVILEGES npr;
1063 /* enable the shutdown privilege for the current process */
1064 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1066 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1067 npr.PrivilegeCount = 1;
1068 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1069 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1070 CloseHandle(hToken);
1072 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);