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"
52 BOOL aborting = FALSE;
53 static struct wine_test *wine_tests;
54 static int nr_of_files, nr_of_tests;
55 static int nr_native_dlls;
56 static const char whitespace[] = " \t\r\n";
57 static const char testexe[] = "_test.exe";
58 static char build_id[64];
60 /* filters for running only specific tests */
61 static char *filters[64];
62 static unsigned int nb_filters = 0;
64 /* Needed to check for .NET dlls */
65 static HMODULE hmscoree;
66 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
68 /* For SxS DLLs e.g. msvcr90 */
69 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
70 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
71 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
72 static void (WINAPI *pReleaseActCtx)(HANDLE);
74 /* To store the current PATH setting (related to .NET only provided dlls) */
77 /* check if test is being filtered out */
78 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
80 char *p, dllname[MAX_PATH];
83 strcpy( dllname, module );
84 CharLowerA( dllname );
85 p = strstr( dllname, testexe );
87 len = strlen(dllname);
89 if (!nb_filters) return FALSE;
90 for (i = 0; i < nb_filters; i++)
92 if (!strncmp( dllname, filters[i], len ))
94 if (!filters[i][len]) return FALSE;
95 if (filters[i][len] != ':') continue;
96 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
102 static char * get_file_version(char * file_name)
104 static char version[32];
108 size = GetFileVersionInfoSizeA(file_name, &handle);
110 char * data = heap_alloc(size);
112 if (GetFileVersionInfoA(file_name, handle, size, data)) {
113 static char backslash[] = "\\";
114 VS_FIXEDFILEINFO *pFixedVersionInfo;
116 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
117 sprintf(version, "%d.%d.%d.%d",
118 pFixedVersionInfo->dwFileVersionMS >> 16,
119 pFixedVersionInfo->dwFileVersionMS & 0xffff,
120 pFixedVersionInfo->dwFileVersionLS >> 16,
121 pFixedVersionInfo->dwFileVersionLS & 0xffff);
123 sprintf(version, "version not available");
125 sprintf(version, "unknown");
128 sprintf(version, "failed");
130 sprintf(version, "version not available");
135 static int running_under_wine (void)
137 HMODULE module = GetModuleHandleA("ntdll.dll");
139 if (!module) return 0;
140 return (GetProcAddress(module, "wine_server_call") != NULL);
143 static int check_mount_mgr(void)
145 if (running_under_wine())
147 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
148 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
149 if (handle == INVALID_HANDLE_VALUE) return FALSE;
150 CloseHandle( handle );
155 static int check_display_driver(void)
157 if (running_under_wine())
159 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
160 0, 0, GetModuleHandleA(0), 0 );
161 if (!hwnd) return FALSE;
162 DestroyWindow( hwnd );
167 static int running_on_visible_desktop (void)
170 HMODULE huser32 = GetModuleHandle("user32.dll");
171 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
172 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
174 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
175 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
177 desktop = GetDesktopWindow();
178 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
179 return IsWindowVisible(desktop);
181 if (pGetProcessWindowStation && pGetUserObjectInformationA)
185 USEROBJECTFLAGS uoflags;
187 wstation = (HWINSTA)pGetProcessWindowStation();
188 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
189 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
191 return IsWindowVisible(desktop);
194 /* check for native dll when running under wine */
195 static BOOL is_native_dll( HMODULE module )
197 static const char fakedll_signature[] = "Wine placeholder DLL";
198 const IMAGE_DOS_HEADER *dos;
200 if (!running_under_wine()) return FALSE;
201 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
202 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
203 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
204 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
205 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
206 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
210 static void print_version (void)
213 static const char platform[] = "i386";
214 #elif defined(__x86_64__)
215 static const char platform[] = "x86_64";
216 #elif defined(__sparc__)
217 static const char platform[] = "sparc";
218 #elif defined(__ALPHA__)
219 static const char platform[] = "alpha";
220 #elif defined(__powerpc__)
221 static const char platform[] = "powerpc";
222 #elif defined(__arm__)
223 static const char platform[] = "arm";
230 const char *(CDECL *wine_get_build_id)(void);
231 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
232 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
233 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
235 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
236 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
238 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
239 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
240 report (R_FATAL, "Can't get OS version.");
242 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
243 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
245 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
246 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
247 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
248 xprintf (" Submitter=%s\n", email );
249 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
250 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
251 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
252 ver.dwPlatformId, ver.szCSDVersion);
254 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
255 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
256 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
257 if (wine_get_host_version)
259 const char *sysname, *release;
260 wine_get_host_version( &sysname, &release );
261 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
263 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
265 xprintf(" R2 build number=%d\n", is_win2k3_r2);
269 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
270 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
271 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
272 ver.wProductType, ver.wReserved);
274 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
275 if (pGetProductInfo && !running_under_wine())
279 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
280 xprintf(" dwProductInfo=%u\n", prodtype);
284 static inline int is_dot_dir(const char* x)
286 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
289 static void remove_dir (const char *dir)
294 size_t dirlen = strlen (dir);
296 /* Make sure the directory exists before going further */
297 memcpy (path, dir, dirlen);
298 strcpy (path + dirlen++, "\\*");
299 hFind = FindFirstFile (path, &wfd);
300 if (hFind == INVALID_HANDLE_VALUE) return;
303 char *lp = wfd.cFileName;
305 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
306 if (is_dot_dir (lp)) continue;
307 strcpy (path + dirlen, lp);
308 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
310 else if (!DeleteFile (path))
311 report (R_WARNING, "Can't delete file %s: error %d",
312 path, GetLastError ());
313 } while (FindNextFile (hFind, &wfd));
315 if (!RemoveDirectory (dir))
316 report (R_WARNING, "Can't remove directory %s: error %d",
317 dir, GetLastError ());
320 static const char* get_test_source_file(const char* test, const char* subtest)
322 static const char* special_dirs[][2] = {
325 static char buffer[MAX_PATH];
326 int i, len = strlen(test);
328 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
330 len = sprintf(buffer, "programs/%s", test) - 4;
333 else len = sprintf(buffer, "dlls/%s", test);
335 for (i = 0; special_dirs[i][0]; i++) {
336 if (strcmp(test, special_dirs[i][0]) == 0) {
337 strcpy( buffer, special_dirs[i][1] );
338 len = strlen(buffer);
343 sprintf(buffer + len, "/tests/%s.c", subtest);
347 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
353 if (!(rsrc = FindResource (NULL, name, type)) ||
354 !(*size = SizeofResource (0, rsrc)) ||
355 !(hdl = LoadResource (0, rsrc)) ||
356 !(addr = LockResource (hdl)))
361 /* Fills in the name and exename fields */
363 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
371 code = extract_rcdata (res_name, "TESTRES", &size);
372 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
373 res_name, GetLastError ());
374 test->name = heap_strdup( res_name );
375 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
376 exepos = strstr (test->name, testexe);
377 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
379 test->name = heap_realloc (test->name, exepos - test->name + 1);
380 report (R_STEP, "Extracting: %s", test->name);
382 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
383 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
384 if (hfile == INVALID_HANDLE_VALUE)
385 report (R_FATAL, "Failed to open file %s.", test->exename);
387 if (!WriteFile(hfile, code, size, &written, NULL))
388 report (R_FATAL, "Failed to write file %s.", test->exename);
393 static DWORD wait_process( HANDLE process, DWORD timeout )
395 DWORD wait, diff = 0, start = GetTickCount();
398 while (diff < timeout)
400 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
401 if (wait != WAIT_OBJECT_0 + 1) return wait;
402 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
403 diff = GetTickCount() - start;
408 static void append_path( const char *path)
412 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
413 strcpy(newpath, curpath);
414 strcat(newpath, ";");
415 strcat(newpath, path);
416 SetEnvironmentVariableA("PATH", newpath);
421 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
424 Return the exit status, -2 if can't create process or the return
425 value of WaitForSingleObject.
428 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
431 PROCESS_INFORMATION pi;
434 GetStartupInfo (&si);
435 si.dwFlags = STARTF_USESTDHANDLES;
436 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
437 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
438 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
440 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
441 NULL, tempdir, &si, &pi))
444 CloseHandle (pi.hThread);
445 status = wait_process( pi.hProcess, ms );
449 GetExitCodeProcess (pi.hProcess, &status);
450 CloseHandle (pi.hProcess);
453 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
458 report (R_ERROR, "Wait returned %d", status);
461 if (!TerminateProcess (pi.hProcess, 257))
462 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
463 wait = wait_process( pi.hProcess, 5000 );
469 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
472 report (R_ERROR, "Can't kill process '%s'", cmd);
475 report (R_ERROR, "Waiting for termination: %d", wait);
478 CloseHandle (pi.hProcess);
483 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
488 char buffer[8192], *index;
489 static const char header[] = "Valid test names:";
490 int status, allocated;
491 char tmpdir[MAX_PATH], subname[MAX_PATH];
492 SECURITY_ATTRIBUTES sa;
494 test->subtest_count = 0;
496 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
497 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
498 report (R_FATAL, "Can't name subtests file.");
500 /* make handle inheritable */
501 sa.nLength = sizeof(sa);
502 sa.lpSecurityDescriptor = NULL;
503 sa.bInheritHandle = TRUE;
505 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
506 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
507 &sa, CREATE_ALWAYS, 0, NULL );
509 if ((subfile == INVALID_HANDLE_VALUE) &&
510 (GetLastError() == ERROR_INVALID_PARAMETER)) {
511 /* FILE_SHARE_DELETE not supported on win9x */
512 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
513 FILE_SHARE_READ | FILE_SHARE_WRITE,
514 &sa, CREATE_ALWAYS, 0, NULL );
516 if (subfile == INVALID_HANDLE_VALUE) {
517 err = GetLastError();
518 report (R_ERROR, "Can't open subtests output of %s: %u",
519 test->name, GetLastError());
523 cmd = strmake (NULL, "%s --list", test->exename);
524 if (test->maindllpath) {
525 /* We need to add the path (to the main dll) to PATH */
526 append_path(test->maindllpath);
528 status = run_ex (cmd, subfile, tempdir, 5000);
529 err = GetLastError();
530 if (test->maindllpath) {
531 /* Restore PATH again */
532 SetEnvironmentVariableA("PATH", curpath);
538 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
542 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
543 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
544 CloseHandle( subfile );
545 if (sizeof buffer == total) {
546 report (R_ERROR, "Subtest list of %s too big.",
547 test->name, sizeof buffer);
548 err = ERROR_OUTOFMEMORY;
553 index = strstr (buffer, header);
555 report (R_ERROR, "Can't parse subtests output of %s",
557 err = ERROR_INTERNAL_ERROR;
560 index += sizeof header;
563 test->subtests = heap_alloc (allocated * sizeof(char*));
564 index = strtok (index, whitespace);
566 if (test->subtest_count == allocated) {
568 test->subtests = heap_realloc (test->subtests,
569 allocated * sizeof(char*));
571 if (!test_filtered_out( test->name, index ))
572 test->subtests[test->subtest_count++] = heap_strdup(index);
573 index = strtok (NULL, whitespace);
575 test->subtests = heap_realloc (test->subtests,
576 test->subtest_count * sizeof(char*));
580 if (!DeleteFileA (subname))
581 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
586 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
589 const char* file = get_test_source_file(test->name, subtest);
590 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
592 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
593 status = run_ex (cmd, out_file, tempdir, 120000);
595 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
599 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
600 LPTSTR lpszName, LONG_PTR lParam)
602 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
606 static const struct clsid_mapping
612 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
613 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
617 static BOOL get_main_clsid(const char *name, CLSID *clsid)
619 const struct clsid_mapping *mapping;
621 for(mapping = clsid_list; mapping->name; mapping++)
623 if(!strcasecmp(name, mapping->name))
625 *clsid = mapping->clsid;
632 static HMODULE load_com_dll(const char *name, char **path, char *filename)
637 char dllname[MAX_PATH];
641 if(!get_main_clsid(name, &clsid)) return NULL;
643 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
644 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
645 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
646 clsid.Data4[6], clsid.Data4[7]);
648 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
650 LONG size = sizeof(dllname);
651 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
653 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
655 strcpy( filename, dllname );
656 p = strrchr(dllname, '\\');
658 *path = heap_strdup( dllname );
667 static void get_dll_path(HMODULE dll, char **path, char *filename)
669 char dllpath[MAX_PATH];
671 GetModuleFileNameA(dll, dllpath, MAX_PATH);
672 strcpy(filename, dllpath);
673 *strrchr(dllpath, '\\') = '\0';
674 *path = heap_strdup( dllpath );
678 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
679 LPTSTR lpszName, LONG_PTR lParam)
681 const char *tempdir = (const char *)lParam;
682 char dllname[MAX_PATH];
683 char filename[MAX_PATH];
684 WCHAR dllnameW[MAX_PATH];
690 if (aborting) return TRUE;
691 if (test_filtered_out( lpszName, NULL )) return TRUE;
693 CharLowerA(lpszName);
694 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
696 /* Check if the main dll is present on this system */
697 strcpy(dllname, lpszName);
698 *strstr(dllname, testexe) = 0;
700 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
701 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
704 memset(&actctxinfo, 0, sizeof(ACTCTXA));
705 actctxinfo.cbSize = sizeof(ACTCTXA);
706 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
707 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
708 actctxinfo.lpResourceName = CREATEPROCESS_MANIFEST_RESOURCE_ID;
709 actctx = pCreateActCtxA(&actctxinfo);
710 if (actctx != INVALID_HANDLE_VALUE &&
711 ! pActivateActCtx(actctx, &cookie))
713 pReleaseActCtx(actctx);
714 actctx = INVALID_HANDLE_VALUE;
716 } else actctx = INVALID_HANDLE_VALUE;
718 wine_tests[nr_of_files].maindllpath = NULL;
719 strcpy(filename, dllname);
720 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
722 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
724 if (!dll && pLoadLibraryShim)
726 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
727 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
729 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
731 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
738 xprintf (" %s=dll is missing\n", dllname);
739 if (actctx != INVALID_HANDLE_VALUE)
741 pDeactivateActCtx(0, cookie);
742 pReleaseActCtx(actctx);
746 if (is_native_dll(dll))
749 xprintf (" %s=load error Configured as native\n", dllname);
751 if (actctx != INVALID_HANDLE_VALUE)
753 pDeactivateActCtx(0, cookie);
754 pReleaseActCtx(actctx);
760 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
762 xprintf (" %s=%s\n", dllname, get_file_version(filename));
763 nr_of_tests += wine_tests[nr_of_files].subtest_count;
768 xprintf (" %s=load error %u\n", dllname, err);
771 if (actctx != INVALID_HANDLE_VALUE)
773 pDeactivateActCtx(0, cookie);
774 pReleaseActCtx(actctx);
780 run_tests (char *logname, char *outdir)
783 char *strres, *eol, *nextline;
785 SECURITY_ATTRIBUTES sa;
786 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
790 /* Get the current PATH only once */
791 needed = GetEnvironmentVariableA("PATH", NULL, 0);
792 curpath = heap_alloc(needed);
793 GetEnvironmentVariableA("PATH", curpath, needed);
795 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
797 if (!GetTempPathA( MAX_PATH, tmppath ))
798 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
801 static char tmpname[MAX_PATH];
802 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
803 report (R_FATAL, "Can't name logfile.");
806 report (R_OUT, logname);
808 /* make handle inheritable */
809 sa.nLength = sizeof(sa);
810 sa.lpSecurityDescriptor = NULL;
811 sa.bInheritHandle = TRUE;
813 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
814 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
815 &sa, CREATE_ALWAYS, 0, NULL );
817 if ((logfile == INVALID_HANDLE_VALUE) &&
818 (GetLastError() == ERROR_INVALID_PARAMETER)) {
819 /* FILE_SHARE_DELETE not supported on win9x */
820 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
821 FILE_SHARE_READ | FILE_SHARE_WRITE,
822 &sa, CREATE_ALWAYS, 0, NULL );
824 if (logfile == INVALID_HANDLE_VALUE)
825 report (R_FATAL, "Could not open logfile: %u", GetLastError());
827 /* try stable path for ZoneAlarm */
829 strcpy( tempdir, tmppath );
830 strcat( tempdir, "wct" );
832 if (!CreateDirectoryA( tempdir, NULL ))
834 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
835 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
836 DeleteFileA( tempdir );
837 if (!CreateDirectoryA( tempdir, NULL ))
838 report (R_FATAL, "Could not create directory: %s", tempdir);
842 strcpy( tempdir, outdir);
844 report (R_DIR, tempdir);
846 xprintf ("Version 4\n");
847 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
848 xprintf ("Archive: -\n"); /* no longer used */
849 xprintf ("Tag: %s\n", tag);
850 xprintf ("Build info:\n");
851 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
853 eol = memchr (strres, '\n', strsize);
856 eol = strres + strsize;
858 strsize -= eol - strres + 1;
859 nextline = strsize?eol+1:NULL;
860 if (eol > strres && *(eol-1) == '\r') eol--;
862 xprintf (" %.*s\n", eol-strres, strres);
865 xprintf ("Operating system version:\n");
867 xprintf ("Dll info:\n" );
869 report (R_STATUS, "Counting tests");
870 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
871 report (R_FATAL, "Can't enumerate test files: %d",
873 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
875 /* Do this only once during extraction (and version checking) */
876 hmscoree = LoadLibraryA("mscoree.dll");
877 pLoadLibraryShim = NULL;
879 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
880 kernel32 = GetModuleHandleA("kernel32.dll");
881 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
882 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
883 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
884 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
886 report (R_STATUS, "Extracting tests");
887 report (R_PROGRESS, 0, nr_of_files);
890 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
891 report (R_FATAL, "Can't enumerate test files: %d",
894 FreeLibrary(hmscoree);
896 if (aborting) return logname;
898 xprintf ("Test output:\n" );
900 report (R_DELTA, 0, "Extracting: Done");
903 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
905 report (R_STATUS, "Running tests");
906 report (R_PROGRESS, 1, nr_of_tests);
907 for (i = 0; i < nr_of_files; i++) {
908 struct wine_test *test = wine_tests + i;
913 if (test->maindllpath) {
914 /* We need to add the path (to the main dll) to PATH */
915 append_path(test->maindllpath);
918 for (j = 0; j < test->subtest_count; j++) {
920 report (R_STEP, "Running: %s:%s", test->name,
922 run_test (test, test->subtests[j], logfile, tempdir);
925 if (test->maindllpath) {
926 /* Restore PATH again */
927 SetEnvironmentVariableA("PATH", curpath);
930 report (R_DELTA, 0, "Running: Done");
932 report (R_STATUS, "Cleaning up");
933 CloseHandle( logfile );
936 remove_dir (tempdir);
937 heap_free(wine_tests);
943 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
945 if (ctrl_type == CTRL_C_EVENT) {
946 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
955 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
957 const char *target_dir = (const char *)lParam;
958 char filename[MAX_PATH];
960 if (test_filtered_out( lpszName, NULL )) return TRUE;
962 strcpy(filename, lpszName);
963 CharLowerA(filename);
965 extract_test( &wine_tests[nr_of_files], target_dir, filename );
970 static void extract_only (const char *target_dir)
974 report (R_DIR, target_dir);
975 res = CreateDirectoryA( target_dir, NULL );
976 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
977 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
980 report (R_STATUS, "Counting tests");
981 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
982 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
984 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
986 report (R_STATUS, "Extracting tests");
987 report (R_PROGRESS, 0, nr_of_files);
989 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
990 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
992 report (R_DELTA, 0, "Extracting: Done");
999 "Usage: winetest [OPTION]... [TESTS]\n\n"
1000 " --help print this message and exit\n"
1001 " --version print the build version and exit\n"
1002 " -c console mode, no GUI\n"
1003 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1004 " -e preserve the environment\n"
1005 " -h print this message and exit\n"
1006 " -m MAIL an email address to enable developers to contact you\n"
1007 " -p shutdown when the tests are done\n"
1008 " -q quiet mode, no output at all\n"
1009 " -o FILE put report into FILE, do not submit\n"
1010 " -s FILE submit FILE, do not run tests\n"
1011 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1012 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1015 int main( int argc, char *argv[] )
1017 char *logname = NULL, *outdir = NULL;
1018 const char *extract = NULL;
1019 const char *cp, *submit = NULL;
1022 int interactive = 1;
1025 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1027 for (i = 1; i < argc && argv[i]; i++)
1029 if (!strcmp(argv[i], "--help")) {
1033 else if (!strcmp(argv[i], "--version")) {
1034 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1037 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1038 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
1040 report (R_ERROR, "Too many test filters specified");
1043 filters[nb_filters++] = argv[i];
1045 else switch (argv[i][1]) {
1047 report (R_TEXTMODE);
1058 if (!(email = argv[++i]))
1072 if (!(submit = argv[++i]))
1078 report (R_WARNING, "ignoring tag for submission");
1082 if (!(logname = argv[++i]))
1089 if (!(tag = argv[++i]))
1094 if (strlen (tag) > MAXTAGLEN)
1095 report (R_FATAL, "tag is too long (maximum %d characters)",
1097 cp = findbadtagchar (tag);
1099 report (R_ERROR, "invalid char in tag: %c", *cp);
1105 report (R_TEXTMODE);
1106 if (!(extract = argv[++i]))
1109 extract_only (extract);
1115 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1120 if (!submit && !extract) {
1121 report (R_STATUS, "Starting up");
1123 if (!running_on_visible_desktop ())
1124 report (R_FATAL, "Tests must be run on a visible desktop");
1126 if (!check_mount_mgr())
1127 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1129 if (!check_display_driver())
1130 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1132 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1136 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1137 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1138 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1139 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1142 if (!nb_filters) /* don't submit results when filtering */
1146 report (R_FATAL, "Please specify a tag (-t option) if "
1147 "running noninteractive!");
1148 if (guiAskTag () == IDABORT) exit (1);
1154 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1155 " to contact you about your report if necessary.");
1156 if (guiAskEmail () == IDABORT) exit (1);
1160 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1161 "To submit results, winetest needs to be built from a git checkout." );
1165 logname = run_tests (NULL, outdir);
1167 DeleteFileA(logname);
1170 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1171 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1172 if (!send_file (logname) && !DeleteFileA(logname))
1173 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1174 } else run_tests (logname, outdir);
1175 report (R_STATUS, "Finished");
1180 TOKEN_PRIVILEGES npr;
1182 /* enable the shutdown privilege for the current process */
1183 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1185 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1186 npr.PrivilegeCount = 1;
1187 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1188 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1189 CloseHandle(hToken);
1191 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);