fusion: Add version resource.
[wine.git] / programs / winetest / main.c
blob021ec96ee355176d83ac75a0e01d19d29373402e
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 <mshtml.h>
37 #include "winetest.h"
38 #include "resource.h"
40 struct wine_test
42 char *name;
43 int resource;
44 int subtest_count;
45 char **subtests;
46 char *exename;
47 char *maindllpath;
50 char *tag = NULL;
51 char *description = NULL;
52 char *email = NULL;
53 BOOL aborting = FALSE;
54 static struct wine_test *wine_tests;
55 static int nr_of_files, nr_of_tests;
56 static int nr_native_dlls;
57 static const char whitespace[] = " \t\r\n";
58 static const char testexe[] = "_test.exe";
59 static char build_id[64];
61 /* filters for running only specific tests */
62 static char *filters[64];
63 static unsigned int nb_filters = 0;
64 static BOOL exclude_tests = FALSE;
66 /* Needed to check for .NET dlls */
67 static HMODULE hmscoree;
68 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
70 /* For SxS DLLs e.g. msvcr90 */
71 static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
72 static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
73 static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
74 static void (WINAPI *pReleaseActCtx)(HANDLE);
76 /* To store the current PATH setting (related to .NET only provided dlls) */
77 static char *curpath;
79 /* check if test is being filtered out */
80 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
82 char *p, dllname[MAX_PATH];
83 unsigned int i, len;
85 strcpy( dllname, module );
86 CharLowerA( dllname );
87 p = strstr( dllname, testexe );
88 if (p) *p = 0;
89 len = strlen(dllname);
91 if (!nb_filters) return exclude_tests;
92 for (i = 0; i < nb_filters; i++)
94 if (!strncmp( dllname, filters[i], len ))
96 if (!filters[i][len]) return exclude_tests;
97 if (filters[i][len] != ':') continue;
98 if (!testname || !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
101 return !exclude_tests;
104 static char * get_file_version(char * file_name)
106 static char version[32];
107 DWORD size;
108 DWORD handle;
110 size = GetFileVersionInfoSizeA(file_name, &handle);
111 if (size) {
112 char * data = heap_alloc(size);
113 if (data) {
114 if (GetFileVersionInfoA(file_name, handle, size, data)) {
115 static char backslash[] = "\\";
116 VS_FIXEDFILEINFO *pFixedVersionInfo;
117 UINT len;
118 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
119 sprintf(version, "%d.%d.%d.%d",
120 pFixedVersionInfo->dwFileVersionMS >> 16,
121 pFixedVersionInfo->dwFileVersionMS & 0xffff,
122 pFixedVersionInfo->dwFileVersionLS >> 16,
123 pFixedVersionInfo->dwFileVersionLS & 0xffff);
124 } else
125 sprintf(version, "version not available");
126 } else
127 sprintf(version, "unknown");
128 heap_free(data);
129 } else
130 sprintf(version, "failed");
131 } else
132 sprintf(version, "version not available");
134 return version;
137 static int running_under_wine (void)
139 HMODULE module = GetModuleHandleA("ntdll.dll");
141 if (!module) return 0;
142 return (GetProcAddress(module, "wine_server_call") != NULL);
145 static int check_mount_mgr(void)
147 if (running_under_wine())
149 HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
150 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
151 if (handle == INVALID_HANDLE_VALUE) return FALSE;
152 CloseHandle( handle );
154 return TRUE;
157 static int check_display_driver(void)
159 if (running_under_wine())
161 HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
162 0, 0, GetModuleHandleA(0), 0 );
163 if (!hwnd) return FALSE;
164 DestroyWindow( hwnd );
166 return TRUE;
169 static int running_on_visible_desktop (void)
171 HWND desktop;
172 HMODULE huser32 = GetModuleHandle("user32.dll");
173 HWINSTA (WINAPI *pGetProcessWindowStation)(void);
174 BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
176 pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
177 pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
179 desktop = GetDesktopWindow();
180 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
181 return IsWindowVisible(desktop);
183 if (pGetProcessWindowStation && pGetUserObjectInformationA)
185 DWORD len;
186 HWINSTA wstation;
187 USEROBJECTFLAGS uoflags;
189 wstation = (HWINSTA)pGetProcessWindowStation();
190 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
191 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
193 return IsWindowVisible(desktop);
196 /* check for native dll when running under wine */
197 static BOOL is_native_dll( HMODULE module )
199 static const char fakedll_signature[] = "Wine placeholder DLL";
200 const IMAGE_DOS_HEADER *dos;
202 if (!running_under_wine()) return FALSE;
203 if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
204 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
205 dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
206 if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
207 if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
208 !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
209 return TRUE;
212 static void print_version (void)
214 #ifdef __i386__
215 static const char platform[] = "i386";
216 #elif defined(__x86_64__)
217 static const char platform[] = "x86_64";
218 #elif defined(__sparc__)
219 static const char platform[] = "sparc";
220 #elif defined(__ALPHA__)
221 static const char platform[] = "alpha";
222 #elif defined(__powerpc__)
223 static const char platform[] = "powerpc";
224 #elif defined(__arm__)
225 static const char platform[] = "arm";
226 #else
227 # error CPU unknown
228 #endif
229 OSVERSIONINFOEX ver;
230 BOOL ext, wow64;
231 int is_win2k3_r2;
232 const char *(CDECL *wine_get_build_id)(void);
233 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
234 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
235 BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
237 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
238 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
240 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
241 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
242 report (R_FATAL, "Can't get OS version.");
244 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
245 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
247 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
248 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
249 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
250 xprintf (" Submitter=%s\n", email );
251 if (description)
252 xprintf (" Description=%s\n", description );
253 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
254 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
255 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
256 ver.dwPlatformId, ver.szCSDVersion);
258 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
259 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
260 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
261 if (wine_get_host_version)
263 const char *sysname, *release;
264 wine_get_host_version( &sysname, &release );
265 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
267 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
268 if(is_win2k3_r2)
269 xprintf(" R2 build number=%d\n", is_win2k3_r2);
271 if (!ext) return;
273 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
274 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
275 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
276 ver.wProductType, ver.wReserved);
278 pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
279 if (pGetProductInfo && !running_under_wine())
281 DWORD prodtype = 0;
283 pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
284 xprintf(" dwProductInfo=%u\n", prodtype);
288 static inline int is_dot_dir(const char* x)
290 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
293 static void remove_dir (const char *dir)
295 HANDLE hFind;
296 WIN32_FIND_DATA wfd;
297 char path[MAX_PATH];
298 size_t dirlen = strlen (dir);
300 /* Make sure the directory exists before going further */
301 memcpy (path, dir, dirlen);
302 strcpy (path + dirlen++, "\\*");
303 hFind = FindFirstFile (path, &wfd);
304 if (hFind == INVALID_HANDLE_VALUE) return;
306 do {
307 char *lp = wfd.cFileName;
309 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
310 if (is_dot_dir (lp)) continue;
311 strcpy (path + dirlen, lp);
312 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
313 remove_dir(path);
314 else if (!DeleteFile (path))
315 report (R_WARNING, "Can't delete file %s: error %d",
316 path, GetLastError ());
317 } while (FindNextFile (hFind, &wfd));
318 FindClose (hFind);
319 if (!RemoveDirectory (dir))
320 report (R_WARNING, "Can't remove directory %s: error %d",
321 dir, GetLastError ());
324 static const char* get_test_source_file(const char* test, const char* subtest)
326 static const char* special_dirs[][2] = {
327 { 0, 0 }
329 static char buffer[MAX_PATH];
330 int i, len = strlen(test);
332 if (len > 4 && !strcmp( test + len - 4, ".exe" ))
334 len = sprintf(buffer, "programs/%s", test) - 4;
335 buffer[len] = 0;
337 else len = sprintf(buffer, "dlls/%s", test);
339 for (i = 0; special_dirs[i][0]; i++) {
340 if (strcmp(test, special_dirs[i][0]) == 0) {
341 strcpy( buffer, special_dirs[i][1] );
342 len = strlen(buffer);
343 break;
347 sprintf(buffer + len, "/tests/%s.c", subtest);
348 return buffer;
351 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
353 HRSRC rsrc;
354 HGLOBAL hdl;
355 LPVOID addr;
357 if (!(rsrc = FindResource (NULL, name, type)) ||
358 !(*size = SizeofResource (0, rsrc)) ||
359 !(hdl = LoadResource (0, rsrc)) ||
360 !(addr = LockResource (hdl)))
361 return NULL;
362 return addr;
365 /* Fills in the name and exename fields */
366 static void
367 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
369 BYTE* code;
370 DWORD size;
371 char *exepos;
372 HANDLE hfile;
373 DWORD written;
375 code = extract_rcdata (res_name, "TESTRES", &size);
376 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
377 res_name, GetLastError ());
378 test->name = heap_strdup( res_name );
379 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
380 exepos = strstr (test->name, testexe);
381 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
382 *exepos = 0;
383 test->name = heap_realloc (test->name, exepos - test->name + 1);
384 report (R_STEP, "Extracting: %s", test->name);
386 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
387 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
388 if (hfile == INVALID_HANDLE_VALUE)
389 report (R_FATAL, "Failed to open file %s.", test->exename);
391 if (!WriteFile(hfile, code, size, &written, NULL))
392 report (R_FATAL, "Failed to write file %s.", test->exename);
394 CloseHandle(hfile);
397 static DWORD wait_process( HANDLE process, DWORD timeout )
399 DWORD wait, diff = 0, start = GetTickCount();
400 MSG msg;
402 while (diff < timeout)
404 wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
405 if (wait != WAIT_OBJECT_0 + 1) return wait;
406 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
407 diff = GetTickCount() - start;
409 return WAIT_TIMEOUT;
412 static void append_path( const char *path)
414 char *newpath;
416 newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
417 strcpy(newpath, curpath);
418 strcat(newpath, ";");
419 strcat(newpath, path);
420 SetEnvironmentVariableA("PATH", newpath);
422 heap_free(newpath);
425 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
426 stdout to there.
428 Return the exit status, -2 if can't create process or the return
429 value of WaitForSingleObject.
431 static int
432 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
434 STARTUPINFO si;
435 PROCESS_INFORMATION pi;
436 DWORD wait, status;
438 GetStartupInfo (&si);
439 si.dwFlags = STARTF_USESTDHANDLES;
440 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
441 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
442 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
444 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
445 NULL, tempdir, &si, &pi))
446 return -2;
448 CloseHandle (pi.hThread);
449 status = wait_process( pi.hProcess, ms );
450 switch (status)
452 case WAIT_OBJECT_0:
453 GetExitCodeProcess (pi.hProcess, &status);
454 CloseHandle (pi.hProcess);
455 return status;
456 case WAIT_FAILED:
457 report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
458 break;
459 case WAIT_TIMEOUT:
460 break;
461 default:
462 report (R_ERROR, "Wait returned %d", status);
463 break;
465 if (!TerminateProcess (pi.hProcess, 257))
466 report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
467 wait = wait_process( pi.hProcess, 5000 );
468 switch (wait)
470 case WAIT_OBJECT_0:
471 break;
472 case WAIT_FAILED:
473 report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
474 break;
475 case WAIT_TIMEOUT:
476 report (R_ERROR, "Can't kill process '%s'", cmd);
477 break;
478 default:
479 report (R_ERROR, "Waiting for termination: %d", wait);
480 break;
482 CloseHandle (pi.hProcess);
483 return status;
486 static DWORD
487 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
489 char *cmd;
490 HANDLE subfile;
491 DWORD err, total;
492 char buffer[8192], *index;
493 static const char header[] = "Valid test names:";
494 int status, allocated;
495 char tmpdir[MAX_PATH], subname[MAX_PATH];
496 SECURITY_ATTRIBUTES sa;
498 test->subtest_count = 0;
500 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
501 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
502 report (R_FATAL, "Can't name subtests file.");
504 /* make handle inheritable */
505 sa.nLength = sizeof(sa);
506 sa.lpSecurityDescriptor = NULL;
507 sa.bInheritHandle = TRUE;
509 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
510 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
511 &sa, CREATE_ALWAYS, 0, NULL );
513 if ((subfile == INVALID_HANDLE_VALUE) &&
514 (GetLastError() == ERROR_INVALID_PARAMETER)) {
515 /* FILE_SHARE_DELETE not supported on win9x */
516 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
517 FILE_SHARE_READ | FILE_SHARE_WRITE,
518 &sa, CREATE_ALWAYS, 0, NULL );
520 if (subfile == INVALID_HANDLE_VALUE) {
521 err = GetLastError();
522 report (R_ERROR, "Can't open subtests output of %s: %u",
523 test->name, GetLastError());
524 goto quit;
527 cmd = strmake (NULL, "%s --list", test->exename);
528 if (test->maindllpath) {
529 /* We need to add the path (to the main dll) to PATH */
530 append_path(test->maindllpath);
532 status = run_ex (cmd, subfile, tempdir, 5000);
533 err = GetLastError();
534 if (test->maindllpath) {
535 /* Restore PATH again */
536 SetEnvironmentVariableA("PATH", curpath);
538 heap_free (cmd);
540 if (status == -2)
542 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
543 goto quit;
546 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
547 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
548 CloseHandle( subfile );
549 if (sizeof buffer == total) {
550 report (R_ERROR, "Subtest list of %s too big.",
551 test->name, sizeof buffer);
552 err = ERROR_OUTOFMEMORY;
553 goto quit;
555 buffer[total] = 0;
557 index = strstr (buffer, header);
558 if (!index) {
559 report (R_ERROR, "Can't parse subtests output of %s",
560 test->name);
561 err = ERROR_INTERNAL_ERROR;
562 goto quit;
564 index += sizeof header;
566 allocated = 10;
567 test->subtests = heap_alloc (allocated * sizeof(char*));
568 index = strtok (index, whitespace);
569 while (index) {
570 if (test->subtest_count == allocated) {
571 allocated *= 2;
572 test->subtests = heap_realloc (test->subtests,
573 allocated * sizeof(char*));
575 if (!test_filtered_out( test->name, index ))
576 test->subtests[test->subtest_count++] = heap_strdup(index);
577 index = strtok (NULL, whitespace);
579 test->subtests = heap_realloc (test->subtests,
580 test->subtest_count * sizeof(char*));
581 err = 0;
583 quit:
584 if (!DeleteFileA (subname))
585 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
586 return err;
589 static void
590 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
592 int status;
593 const char* file = get_test_source_file(test->name, subtest);
594 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
596 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
597 status = run_ex (cmd, out_file, tempdir, 120000);
598 heap_free (cmd);
599 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
602 static BOOL CALLBACK
603 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
604 LPTSTR lpszName, LONG_PTR lParam)
606 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
607 return TRUE;
610 static const struct clsid_mapping
612 const char *name;
613 CLSID clsid;
614 } clsid_list[] =
616 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
617 {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
621 static BOOL get_main_clsid(const char *name, CLSID *clsid)
623 const struct clsid_mapping *mapping;
625 for(mapping = clsid_list; mapping->name; mapping++)
627 if(!strcasecmp(name, mapping->name))
629 *clsid = mapping->clsid;
630 return TRUE;
633 return FALSE;
636 static HMODULE load_com_dll(const char *name, char **path, char *filename)
638 HMODULE dll = NULL;
639 HKEY hkey;
640 char keyname[100];
641 char dllname[MAX_PATH];
642 char *p;
643 CLSID clsid;
645 if(!get_main_clsid(name, &clsid)) return NULL;
647 sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
648 clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
649 clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
650 clsid.Data4[6], clsid.Data4[7]);
652 if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
654 LONG size = sizeof(dllname);
655 if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
657 if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
659 strcpy( filename, dllname );
660 p = strrchr(dllname, '\\');
661 if (p) *p = 0;
662 *path = heap_strdup( dllname );
665 RegCloseKey(hkey);
668 return dll;
671 static void get_dll_path(HMODULE dll, char **path, char *filename)
673 char dllpath[MAX_PATH];
675 GetModuleFileNameA(dll, dllpath, MAX_PATH);
676 strcpy(filename, dllpath);
677 *strrchr(dllpath, '\\') = '\0';
678 *path = heap_strdup( dllpath );
681 static BOOL CALLBACK
682 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
683 LPTSTR lpszName, LONG_PTR lParam)
685 const char *tempdir = (const char *)lParam;
686 char dllname[MAX_PATH];
687 char filename[MAX_PATH];
688 WCHAR dllnameW[MAX_PATH];
689 HMODULE dll;
690 DWORD err;
691 HANDLE actctx;
692 ULONG_PTR cookie;
694 if (aborting) return TRUE;
695 if (test_filtered_out( lpszName, NULL )) return TRUE;
697 CharLowerA(lpszName);
698 extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
700 /* Check if the main dll is present on this system */
701 strcpy(dllname, lpszName);
702 *strstr(dllname, testexe) = 0;
704 if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
705 pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
707 ACTCTXA actctxinfo;
708 memset(&actctxinfo, 0, sizeof(ACTCTXA));
709 actctxinfo.cbSize = sizeof(ACTCTXA);
710 actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
711 actctxinfo.lpSource = wine_tests[nr_of_files].exename;
712 actctxinfo.lpResourceName = CREATEPROCESS_MANIFEST_RESOURCE_ID;
713 actctx = pCreateActCtxA(&actctxinfo);
714 if (actctx != INVALID_HANDLE_VALUE &&
715 ! pActivateActCtx(actctx, &cookie))
717 pReleaseActCtx(actctx);
718 actctx = INVALID_HANDLE_VALUE;
720 } else actctx = INVALID_HANDLE_VALUE;
722 wine_tests[nr_of_files].maindllpath = NULL;
723 strcpy(filename, dllname);
724 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
726 if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
728 if (!dll && pLoadLibraryShim)
730 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
731 if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
733 get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
734 FreeLibrary(dll);
735 dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
737 else dll = 0;
740 if (!dll)
742 xprintf (" %s=dll is missing\n", dllname);
743 if (actctx != INVALID_HANDLE_VALUE)
745 pDeactivateActCtx(0, cookie);
746 pReleaseActCtx(actctx);
748 return TRUE;
750 if (is_native_dll(dll))
752 FreeLibrary(dll);
753 xprintf (" %s=load error Configured as native\n", dllname);
754 nr_native_dlls++;
755 if (actctx != INVALID_HANDLE_VALUE)
757 pDeactivateActCtx(0, cookie);
758 pReleaseActCtx(actctx);
760 return TRUE;
762 FreeLibrary(dll);
764 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
766 xprintf (" %s=%s\n", dllname, get_file_version(filename));
767 nr_of_tests += wine_tests[nr_of_files].subtest_count;
768 nr_of_files++;
770 else
772 xprintf (" %s=load error %u\n", dllname, err);
775 if (actctx != INVALID_HANDLE_VALUE)
777 pDeactivateActCtx(0, cookie);
778 pReleaseActCtx(actctx);
780 return TRUE;
783 static char *
784 run_tests (char *logname, char *outdir)
786 int i;
787 char *strres, *eol, *nextline;
788 DWORD strsize;
789 SECURITY_ATTRIBUTES sa;
790 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
791 DWORD needed;
792 HMODULE kernel32;
794 /* Get the current PATH only once */
795 needed = GetEnvironmentVariableA("PATH", NULL, 0);
796 curpath = heap_alloc(needed);
797 GetEnvironmentVariableA("PATH", curpath, needed);
799 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
801 if (!GetTempPathA( MAX_PATH, tmppath ))
802 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
804 if (!logname) {
805 static char tmpname[MAX_PATH];
806 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
807 report (R_FATAL, "Can't name logfile.");
808 logname = tmpname;
810 report (R_OUT, logname);
812 /* make handle inheritable */
813 sa.nLength = sizeof(sa);
814 sa.lpSecurityDescriptor = NULL;
815 sa.bInheritHandle = TRUE;
817 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
818 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
819 &sa, CREATE_ALWAYS, 0, NULL );
821 if ((logfile == INVALID_HANDLE_VALUE) &&
822 (GetLastError() == ERROR_INVALID_PARAMETER)) {
823 /* FILE_SHARE_DELETE not supported on win9x */
824 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
825 FILE_SHARE_READ | FILE_SHARE_WRITE,
826 &sa, CREATE_ALWAYS, 0, NULL );
828 if (logfile == INVALID_HANDLE_VALUE)
829 report (R_FATAL, "Could not open logfile: %u", GetLastError());
831 /* try stable path for ZoneAlarm */
832 if (!outdir) {
833 strcpy( tempdir, tmppath );
834 strcat( tempdir, "wct" );
836 if (!CreateDirectoryA( tempdir, NULL ))
838 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
839 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
840 DeleteFileA( tempdir );
841 if (!CreateDirectoryA( tempdir, NULL ))
842 report (R_FATAL, "Could not create directory: %s", tempdir);
845 else
846 strcpy( tempdir, outdir);
848 report (R_DIR, tempdir);
850 xprintf ("Version 4\n");
851 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
852 xprintf ("Archive: -\n"); /* no longer used */
853 xprintf ("Tag: %s\n", tag);
854 xprintf ("Build info:\n");
855 strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
856 while (strres) {
857 eol = memchr (strres, '\n', strsize);
858 if (!eol) {
859 nextline = NULL;
860 eol = strres + strsize;
861 } else {
862 strsize -= eol - strres + 1;
863 nextline = strsize?eol+1:NULL;
864 if (eol > strres && *(eol-1) == '\r') eol--;
866 xprintf (" %.*s\n", eol-strres, strres);
867 strres = nextline;
869 xprintf ("Operating system version:\n");
870 print_version ();
871 xprintf ("Dll info:\n" );
873 report (R_STATUS, "Counting tests");
874 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
875 report (R_FATAL, "Can't enumerate test files: %d",
876 GetLastError ());
877 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
879 /* Do this only once during extraction (and version checking) */
880 hmscoree = LoadLibraryA("mscoree.dll");
881 pLoadLibraryShim = NULL;
882 if (hmscoree)
883 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
884 kernel32 = GetModuleHandleA("kernel32.dll");
885 pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
886 pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
887 pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
888 pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
890 report (R_STATUS, "Extracting tests");
891 report (R_PROGRESS, 0, nr_of_files);
892 nr_of_files = 0;
893 nr_of_tests = 0;
894 if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
895 report (R_FATAL, "Can't enumerate test files: %d",
896 GetLastError ());
898 FreeLibrary(hmscoree);
900 if (aborting) return logname;
902 xprintf ("Test output:\n" );
904 report (R_DELTA, 0, "Extracting: Done");
906 if (nr_native_dlls)
907 report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
909 report (R_STATUS, "Running tests");
910 report (R_PROGRESS, 1, nr_of_tests);
911 for (i = 0; i < nr_of_files; i++) {
912 struct wine_test *test = wine_tests + i;
913 int j;
915 if (aborting) break;
917 if (test->maindllpath) {
918 /* We need to add the path (to the main dll) to PATH */
919 append_path(test->maindllpath);
922 for (j = 0; j < test->subtest_count; j++) {
923 if (aborting) break;
924 report (R_STEP, "Running: %s:%s", test->name,
925 test->subtests[j]);
926 run_test (test, test->subtests[j], logfile, tempdir);
929 if (test->maindllpath) {
930 /* Restore PATH again */
931 SetEnvironmentVariableA("PATH", curpath);
934 report (R_DELTA, 0, "Running: Done");
936 report (R_STATUS, "Cleaning up");
937 CloseHandle( logfile );
938 logfile = 0;
939 if (!outdir)
940 remove_dir (tempdir);
941 heap_free(wine_tests);
942 heap_free(curpath);
944 return logname;
947 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
949 if (ctrl_type == CTRL_C_EVENT) {
950 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
951 return TRUE;
954 return FALSE;
958 static BOOL CALLBACK
959 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
961 const char *target_dir = (const char *)lParam;
962 char filename[MAX_PATH];
964 if (test_filtered_out( lpszName, NULL )) return TRUE;
966 strcpy(filename, lpszName);
967 CharLowerA(filename);
969 extract_test( &wine_tests[nr_of_files], target_dir, filename );
970 nr_of_files++;
971 return TRUE;
974 static void extract_only (const char *target_dir)
976 BOOL res;
978 report (R_DIR, target_dir);
979 res = CreateDirectoryA( target_dir, NULL );
980 if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
981 report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
983 nr_of_files = 0;
984 report (R_STATUS, "Counting tests");
985 if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
986 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
988 wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
990 report (R_STATUS, "Extracting tests");
991 report (R_PROGRESS, 0, nr_of_files);
992 nr_of_files = 0;
993 if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
994 report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
996 report (R_DELTA, 0, "Extracting: Done");
999 static void
1000 usage (void)
1002 fprintf (stderr,
1003 "Usage: winetest [OPTION]... [TESTS]\n\n"
1004 " --help print this message and exit\n"
1005 " --version print the build version and exit\n"
1006 " -c console mode, no GUI\n"
1007 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1008 " -e preserve the environment\n"
1009 " -h print this message and exit\n"
1010 " -i INFO an optional description of the test platform\n"
1011 " -m MAIL an email address to enable developers to contact you\n"
1012 " -n exclude the specified tests\n"
1013 " -p shutdown when the tests are done\n"
1014 " -q quiet mode, no output at all\n"
1015 " -o FILE put report into FILE, do not submit\n"
1016 " -s FILE submit FILE, do not run tests\n"
1017 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1018 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1021 int main( int argc, char *argv[] )
1023 char *logname = NULL, *outdir = NULL;
1024 const char *extract = NULL;
1025 const char *cp, *submit = NULL;
1026 int reset_env = 1;
1027 int poweroff = 0;
1028 int interactive = 1;
1029 int i;
1031 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
1033 for (i = 1; i < argc && argv[i]; i++)
1035 if (!strcmp(argv[i], "--help")) {
1036 usage ();
1037 exit (0);
1039 else if (!strcmp(argv[i], "--version")) {
1040 printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
1041 exit (0);
1043 else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
1044 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
1046 report (R_ERROR, "Too many test filters specified");
1047 exit (2);
1049 filters[nb_filters++] = argv[i];
1051 else switch (argv[i][1]) {
1052 case 'c':
1053 report (R_TEXTMODE);
1054 interactive = 0;
1055 break;
1056 case 'e':
1057 reset_env = 0;
1058 break;
1059 case 'h':
1060 case '?':
1061 usage ();
1062 exit (0);
1063 case 'i':
1064 if (!(description = argv[++i]))
1066 usage();
1067 exit( 2 );
1069 break;
1070 case 'm':
1071 if (!(email = argv[++i]))
1073 usage();
1074 exit( 2 );
1076 break;
1077 case 'n':
1078 exclude_tests = TRUE;
1079 break;
1080 case 'p':
1081 poweroff = 1;
1082 break;
1083 case 'q':
1084 report (R_QUIET);
1085 interactive = 0;
1086 break;
1087 case 's':
1088 if (!(submit = argv[++i]))
1090 usage();
1091 exit( 2 );
1093 if (tag)
1094 report (R_WARNING, "ignoring tag for submission");
1095 send_file (submit);
1096 break;
1097 case 'o':
1098 if (!(logname = argv[++i]))
1100 usage();
1101 exit( 2 );
1103 break;
1104 case 't':
1105 if (!(tag = argv[++i]))
1107 usage();
1108 exit( 2 );
1110 if (strlen (tag) > MAXTAGLEN)
1111 report (R_FATAL, "tag is too long (maximum %d characters)",
1112 MAXTAGLEN);
1113 cp = findbadtagchar (tag);
1114 if (cp) {
1115 report (R_ERROR, "invalid char in tag: %c", *cp);
1116 usage ();
1117 exit (2);
1119 break;
1120 case 'x':
1121 report (R_TEXTMODE);
1122 if (!(extract = argv[++i]))
1123 extract = ".\\wct";
1125 extract_only (extract);
1126 break;
1127 case 'd':
1128 outdir = argv[++i];
1129 break;
1130 default:
1131 report (R_ERROR, "invalid option: -%c", argv[i][1]);
1132 usage ();
1133 exit (2);
1136 if (!submit && !extract) {
1137 report (R_STATUS, "Starting up");
1139 if (!running_on_visible_desktop ())
1140 report (R_FATAL, "Tests must be run on a visible desktop");
1142 if (!check_mount_mgr())
1143 report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1145 if (!check_display_driver())
1146 report (R_FATAL, "Unable to create a window, the display driver is not working.");
1148 SetConsoleCtrlHandler(ctrl_handler, TRUE);
1150 if (reset_env)
1152 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1153 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1154 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1155 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1158 if (!nb_filters) /* don't submit results when filtering */
1160 while (!tag) {
1161 if (!interactive)
1162 report (R_FATAL, "Please specify a tag (-t option) if "
1163 "running noninteractive!");
1164 if (guiAskTag () == IDABORT) exit (1);
1166 report (R_TAG);
1168 while (!email) {
1169 if (!interactive)
1170 report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
1171 " to contact you about your report if necessary.");
1172 if (guiAskEmail () == IDABORT) exit (1);
1175 if (!build_id[0])
1176 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1177 "To submit results, winetest needs to be built from a git checkout." );
1180 if (!logname) {
1181 logname = run_tests (NULL, outdir);
1182 if (aborting) {
1183 DeleteFileA(logname);
1184 exit (0);
1186 if (build_id[0] && !nb_filters && !nr_native_dlls &&
1187 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1188 if (!send_file (logname) && !DeleteFileA(logname))
1189 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1190 } else run_tests (logname, outdir);
1191 report (R_STATUS, "Finished");
1193 if (poweroff)
1195 HANDLE hToken;
1196 TOKEN_PRIVILEGES npr;
1198 /* enable the shutdown privilege for the current process */
1199 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1201 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1202 npr.PrivilegeCount = 1;
1203 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1204 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1205 CloseHandle(hToken);
1207 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1209 exit (0);