fusion/tests: Do not use an hardcoded path for the windows directory.
[wine/hacks.git] / programs / winetest / main.c
blobe53502d9551ad1875fa266d979f15220899c3d9b
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;
49 char *tag = NULL;
50 static struct wine_test *wine_tests;
51 static int nr_of_files, nr_of_tests;
52 static const char whitespace[] = " \t\r\n";
53 static const char testexe[] = "_test.exe";
54 static char build_id[64];
56 /* filters for running only specific tests */
57 static char *filters[64];
58 static unsigned int nb_filters = 0;
60 /* Needed to check for .NET dlls */
61 static HMODULE hmscoree;
62 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
64 /* check if test is being filtered out */
65 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
67 char *p, dllname[MAX_PATH];
68 unsigned int i, len;
70 strcpy( dllname, module );
71 CharLowerA( dllname );
72 p = strstr( dllname, testexe );
73 if (p) *p = 0;
74 len = strlen(dllname);
76 if (!nb_filters) return FALSE;
77 for (i = 0; i < nb_filters; i++)
79 if (!strncmp( dllname, filters[i], len ))
81 if (!filters[i][len]) return FALSE;
82 if (filters[i][len] != ':') continue;
83 if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
86 return TRUE;
89 static char * get_file_version(char * file_name)
91 static char version[32];
92 DWORD size;
93 DWORD handle;
95 size = GetFileVersionInfoSizeA(file_name, &handle);
96 if (size) {
97 char * data = xmalloc(size);
98 if (data) {
99 if (GetFileVersionInfoA(file_name, handle, size, data)) {
100 static char backslash[] = "\\";
101 VS_FIXEDFILEINFO *pFixedVersionInfo;
102 UINT len;
103 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
104 sprintf(version, "%d.%d.%d.%d",
105 pFixedVersionInfo->dwFileVersionMS >> 16,
106 pFixedVersionInfo->dwFileVersionMS & 0xffff,
107 pFixedVersionInfo->dwFileVersionLS >> 16,
108 pFixedVersionInfo->dwFileVersionLS & 0xffff);
109 } else
110 sprintf(version, "version not available");
111 } else
112 sprintf(version, "unknown");
113 free(data);
114 } else
115 sprintf(version, "failed");
116 } else
117 sprintf(version, "version not available");
119 return version;
122 static int running_under_wine (void)
124 HMODULE module = GetModuleHandleA("ntdll.dll");
126 if (!module) return 0;
127 return (GetProcAddress(module, "wine_server_call") != NULL);
130 static int running_on_visible_desktop (void)
132 HWND desktop;
133 HMODULE huser32 = GetModuleHandle("user32.dll");
134 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
135 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
137 desktop = GetDesktopWindow();
138 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
139 return IsWindowVisible(desktop);
141 if (pGetProcessWindowStation && pGetUserObjectInformationA)
143 DWORD len;
144 HWINSTA wstation;
145 USEROBJECTFLAGS uoflags;
147 wstation = (HWINSTA)pGetProcessWindowStation();
148 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
149 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
151 return IsWindowVisible(desktop);
154 /* check if Gecko is present, trying to trigger the install if not */
155 static BOOL gecko_check(void)
157 HMODULE mshtml;
158 HRESULT (WINAPI *pDllGetClassObject)(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
159 IClassFactory *factory = NULL;
160 IHTMLDocument2 *doc = NULL;
161 IHTMLElement *body;
162 BOOL ret = FALSE;
164 if (!(mshtml = LoadLibraryA( "mshtml.dll" ))) return FALSE;
165 if (!(pDllGetClassObject = (void *)GetProcAddress( mshtml, "DllGetClassObject" )))
166 goto done;
167 if (FAILED(pDllGetClassObject( &CLSID_HTMLDocument, &IID_IClassFactory, (void **)&factory )))
168 goto done;
169 if (FAILED(IClassFactory_CreateInstance( factory, NULL, &IID_IHTMLDocument2, (void **)&doc )))
170 goto done;
171 if (FAILED(IHTMLDocument2_get_body( doc, &body )))
172 goto done;
173 IHTMLElement_Release( body );
174 ret = TRUE;
175 done:
176 if (doc) IHTMLDocument_Release( doc );
177 if (factory) IClassFactory_Release( factory );
178 FreeLibrary( mshtml );
179 return ret;
182 static void print_version (void)
184 #ifdef __i386__
185 static const char platform[] = "i386";
186 #elif defined(__x86_64__)
187 static const char platform[] = "x86_64";
188 #elif defined(__sparc__)
189 static const char platform[] = "sparc";
190 #elif defined(__ALPHA__)
191 static const char platform[] = "alpha";
192 #elif defined(__powerpc__)
193 static const char platform[] = "powerpc";
194 #endif
195 OSVERSIONINFOEX ver;
196 BOOL ext, wow64;
197 int is_win2k3_r2;
198 const char *(CDECL *wine_get_build_id)(void);
199 void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
200 BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
202 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
203 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
205 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
206 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
207 report (R_FATAL, "Can't get OS version.");
209 pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
210 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
212 xprintf (" Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
213 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
214 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
215 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
216 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
217 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
218 ver.dwPlatformId, ver.szCSDVersion);
220 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
221 wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
222 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
223 if (wine_get_host_version)
225 const char *sysname, *release;
226 wine_get_host_version( &sysname, &release );
227 xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
229 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
230 if(is_win2k3_r2)
231 xprintf(" R2 build number=%d\n", is_win2k3_r2);
233 if (!ext) return;
235 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
236 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
237 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
238 ver.wProductType, ver.wReserved);
241 static inline int is_dot_dir(const char* x)
243 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
246 static void remove_dir (const char *dir)
248 HANDLE hFind;
249 WIN32_FIND_DATA wfd;
250 char path[MAX_PATH];
251 size_t dirlen = strlen (dir);
253 /* Make sure the directory exists before going further */
254 memcpy (path, dir, dirlen);
255 strcpy (path + dirlen++, "\\*");
256 hFind = FindFirstFile (path, &wfd);
257 if (hFind == INVALID_HANDLE_VALUE) return;
259 do {
260 char *lp = wfd.cFileName;
262 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
263 if (is_dot_dir (lp)) continue;
264 strcpy (path + dirlen, lp);
265 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
266 remove_dir(path);
267 else if (!DeleteFile (path))
268 report (R_WARNING, "Can't delete file %s: error %d",
269 path, GetLastError ());
270 } while (FindNextFile (hFind, &wfd));
271 FindClose (hFind);
272 if (!RemoveDirectory (dir))
273 report (R_WARNING, "Can't remove directory %s: error %d",
274 dir, GetLastError ());
277 static const char* get_test_source_file(const char* test, const char* subtest)
279 static const char* special_dirs[][2] = {
280 { 0, 0 }
282 static char buffer[MAX_PATH];
283 int i;
285 for (i = 0; special_dirs[i][0]; i++) {
286 if (strcmp(test, special_dirs[i][0]) == 0) {
287 test = special_dirs[i][1];
288 break;
292 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
293 return buffer;
296 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
298 HRSRC rsrc;
299 HGLOBAL hdl;
300 LPVOID addr;
302 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
303 !(*size = SizeofResource (0, rsrc)) ||
304 !(hdl = LoadResource (0, rsrc)) ||
305 !(addr = LockResource (hdl)))
306 return NULL;
307 return addr;
310 /* Fills in the name and exename fields */
311 static void
312 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
314 BYTE* code;
315 DWORD size;
316 char *exepos;
317 HANDLE hfile;
318 DWORD written;
320 code = extract_rcdata (res_name, TESTRES, &size);
321 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
322 res_name, GetLastError ());
323 test->name = xstrdup( res_name );
324 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
325 exepos = strstr (test->name, testexe);
326 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
327 *exepos = 0;
328 test->name = xrealloc (test->name, exepos - test->name + 1);
329 report (R_STEP, "Extracting: %s", test->name);
331 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
332 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
333 if (hfile == INVALID_HANDLE_VALUE)
334 report (R_FATAL, "Failed to open file %s.", test->exename);
336 if (!WriteFile(hfile, code, size, &written, NULL))
337 report (R_FATAL, "Failed to write file %s.", test->exename);
339 CloseHandle(hfile);
342 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
343 stdout to there.
345 Return the exit status, -2 if can't create process or the return
346 value of WaitForSingleObject.
348 static int
349 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
351 STARTUPINFO si;
352 PROCESS_INFORMATION pi;
353 DWORD wait, status;
355 GetStartupInfo (&si);
356 si.dwFlags = STARTF_USESTDHANDLES;
357 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
358 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
359 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
361 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
362 NULL, tempdir, &si, &pi)) {
363 status = -2;
364 } else {
365 CloseHandle (pi.hThread);
366 wait = WaitForSingleObject (pi.hProcess, ms);
367 if (wait == WAIT_OBJECT_0) {
368 GetExitCodeProcess (pi.hProcess, &status);
369 } else {
370 switch (wait) {
371 case WAIT_FAILED:
372 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
373 GetLastError ());
374 break;
375 case WAIT_TIMEOUT:
376 report (R_ERROR, "Process '%s' timed out.", cmd);
377 break;
378 default:
379 report (R_ERROR, "Wait returned %d", wait);
381 status = wait;
382 if (!TerminateProcess (pi.hProcess, 257))
383 report (R_ERROR, "TerminateProcess failed: %d",
384 GetLastError ());
385 wait = WaitForSingleObject (pi.hProcess, 5000);
386 switch (wait) {
387 case WAIT_FAILED:
388 report (R_ERROR,
389 "Wait for termination of '%s' failed: %d",
390 cmd, GetLastError ());
391 break;
392 case WAIT_OBJECT_0:
393 break;
394 case WAIT_TIMEOUT:
395 report (R_ERROR, "Can't kill process '%s'", cmd);
396 break;
397 default:
398 report (R_ERROR, "Waiting for termination: %d",
399 wait);
402 CloseHandle (pi.hProcess);
405 return status;
408 static DWORD
409 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
411 char *cmd;
412 HANDLE subfile;
413 DWORD err, total;
414 char buffer[8192], *index;
415 static const char header[] = "Valid test names:";
416 int status, allocated;
417 char tmpdir[MAX_PATH], subname[MAX_PATH];
418 SECURITY_ATTRIBUTES sa;
420 test->subtest_count = 0;
422 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
423 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
424 report (R_FATAL, "Can't name subtests file.");
426 /* make handle inheritable */
427 sa.nLength = sizeof(sa);
428 sa.lpSecurityDescriptor = NULL;
429 sa.bInheritHandle = TRUE;
431 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
432 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
433 &sa, CREATE_ALWAYS, 0, NULL );
435 if ((subfile == INVALID_HANDLE_VALUE) &&
436 (GetLastError() == ERROR_INVALID_PARAMETER)) {
437 /* FILE_SHARE_DELETE not supported on win9x */
438 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
439 FILE_SHARE_READ | FILE_SHARE_WRITE,
440 &sa, CREATE_ALWAYS, 0, NULL );
442 if (subfile == INVALID_HANDLE_VALUE) {
443 err = GetLastError();
444 report (R_ERROR, "Can't open subtests output of %s: %u",
445 test->name, GetLastError());
446 goto quit;
449 extract_test (test, tempdir, res_name);
450 cmd = strmake (NULL, "%s --list", test->exename);
451 status = run_ex (cmd, subfile, tempdir, 5000);
452 err = GetLastError();
453 free (cmd);
455 if (status == -2)
457 report (R_ERROR, "Cannot run %s error %u", test->exename, err);
458 goto quit;
461 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
462 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
463 CloseHandle( subfile );
464 if (sizeof buffer == total) {
465 report (R_ERROR, "Subtest list of %s too big.",
466 test->name, sizeof buffer);
467 err = ERROR_OUTOFMEMORY;
468 goto quit;
470 buffer[total] = 0;
472 index = strstr (buffer, header);
473 if (!index) {
474 report (R_ERROR, "Can't parse subtests output of %s",
475 test->name);
476 err = ERROR_INTERNAL_ERROR;
477 goto quit;
479 index += sizeof header;
481 allocated = 10;
482 test->subtests = xmalloc (allocated * sizeof(char*));
483 index = strtok (index, whitespace);
484 while (index) {
485 if (test->subtest_count == allocated) {
486 allocated *= 2;
487 test->subtests = xrealloc (test->subtests,
488 allocated * sizeof(char*));
490 if (!test_filtered_out( test->name, index ))
491 test->subtests[test->subtest_count++] = xstrdup(index);
492 index = strtok (NULL, whitespace);
494 test->subtests = xrealloc (test->subtests,
495 test->subtest_count * sizeof(char*));
496 err = 0;
498 quit:
499 if (!DeleteFileA (subname))
500 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
501 return err;
504 static void
505 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
507 int status;
508 const char* file = get_test_source_file(test->name, subtest);
509 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
511 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
512 status = run_ex (cmd, out_file, tempdir, 120000);
513 free (cmd);
514 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
517 static BOOL CALLBACK
518 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
519 LPTSTR lpszName, LONG_PTR lParam)
521 if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
522 return TRUE;
525 static BOOL CALLBACK
526 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
527 LPTSTR lpszName, LONG_PTR lParam)
529 const char *tempdir = (const char *)lParam;
530 char dllname[MAX_PATH];
531 char filename[MAX_PATH];
532 WCHAR dllnameW[MAX_PATH];
533 HMODULE dll;
534 DWORD err;
536 if (test_filtered_out( lpszName, NULL )) return TRUE;
538 /* Check if the main dll is present on this system */
539 CharLowerA(lpszName);
540 strcpy(dllname, lpszName);
541 *strstr(dllname, testexe) = 0;
543 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
544 if (!dll && pLoadLibraryShim)
546 MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
547 if (FAILED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) )) dll = 0;
549 if (!dll) {
550 xprintf (" %s=dll is missing\n", dllname);
551 return TRUE;
553 if (!strcmp( dllname, "mshtml" ) && running_under_wine() && !gecko_check())
555 FreeLibrary(dll);
556 xprintf (" %s=load error Gecko is not installed\n", dllname);
557 return TRUE;
559 GetModuleFileNameA(dll, filename, MAX_PATH);
560 FreeLibrary(dll);
562 if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
564 xprintf (" %s=%s\n", dllname, get_file_version(filename));
565 nr_of_tests += wine_tests[nr_of_files].subtest_count;
566 nr_of_files++;
568 else
570 xprintf (" %s=load error %u\n", dllname, err);
572 return TRUE;
575 static char *
576 run_tests (char *logname)
578 int i;
579 char *strres, *eol, *nextline;
580 DWORD strsize;
581 SECURITY_ATTRIBUTES sa;
582 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
584 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
586 if (!GetTempPathA( MAX_PATH, tmppath ))
587 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
589 if (!logname) {
590 static char tmpname[MAX_PATH];
591 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
592 report (R_FATAL, "Can't name logfile.");
593 logname = tmpname;
595 report (R_OUT, logname);
597 /* make handle inheritable */
598 sa.nLength = sizeof(sa);
599 sa.lpSecurityDescriptor = NULL;
600 sa.bInheritHandle = TRUE;
602 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
603 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
604 &sa, CREATE_ALWAYS, 0, NULL );
606 if ((logfile == INVALID_HANDLE_VALUE) &&
607 (GetLastError() == ERROR_INVALID_PARAMETER)) {
608 /* FILE_SHARE_DELETE not supported on win9x */
609 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
610 FILE_SHARE_READ | FILE_SHARE_WRITE,
611 &sa, CREATE_ALWAYS, 0, NULL );
613 if (logfile == INVALID_HANDLE_VALUE)
614 report (R_FATAL, "Could not open logfile: %u", GetLastError());
616 if (!GetTempPathA( MAX_PATH, tmppath ))
617 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
619 /* try stable path for ZoneAlarm */
620 strcpy( tempdir, tmppath );
621 strcat( tempdir, "wct" );
622 if (!CreateDirectoryA( tempdir, NULL ))
624 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
625 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
626 DeleteFileA( tempdir );
627 if (!CreateDirectoryA( tempdir, NULL ))
628 report (R_FATAL, "Could not create directory: %s", tempdir);
630 report (R_DIR, tempdir);
632 xprintf ("Version 4\n");
633 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
634 xprintf ("Archive: -\n"); /* no longer used */
635 xprintf ("Tag: %s\n", tag);
636 xprintf ("Build info:\n");
637 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
638 while (strres) {
639 eol = memchr (strres, '\n', strsize);
640 if (!eol) {
641 nextline = NULL;
642 eol = strres + strsize;
643 } else {
644 strsize -= eol - strres + 1;
645 nextline = strsize?eol+1:NULL;
646 if (eol > strres && *(eol-1) == '\r') eol--;
648 xprintf (" %.*s\n", eol-strres, strres);
649 strres = nextline;
651 xprintf ("Operating system version:\n");
652 print_version ();
653 xprintf ("Dll info:\n" );
655 report (R_STATUS, "Counting tests");
656 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
657 EnumTestFileProc, (LPARAM)&nr_of_files))
658 report (R_FATAL, "Can't enumerate test files: %d",
659 GetLastError ());
660 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
662 /* Do this only once during extraction (and version checking) */
663 hmscoree = LoadLibraryA("mscoree.dll");
664 pLoadLibraryShim = NULL;
665 if (hmscoree)
666 pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
668 report (R_STATUS, "Extracting tests");
669 report (R_PROGRESS, 0, nr_of_files);
670 nr_of_files = 0;
671 nr_of_tests = 0;
672 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
673 extract_test_proc, (LPARAM)tempdir))
674 report (R_FATAL, "Can't enumerate test files: %d",
675 GetLastError ());
677 FreeLibrary(hmscoree);
679 xprintf ("Test output:\n" );
681 report (R_DELTA, 0, "Extracting: Done");
683 report (R_STATUS, "Running tests");
684 report (R_PROGRESS, 1, nr_of_tests);
685 for (i = 0; i < nr_of_files; i++) {
686 struct wine_test *test = wine_tests + i;
687 int j;
689 for (j = 0; j < test->subtest_count; j++) {
690 report (R_STEP, "Running: %s:%s", test->name,
691 test->subtests[j]);
692 run_test (test, test->subtests[j], logfile, tempdir);
695 report (R_DELTA, 0, "Running: Done");
697 report (R_STATUS, "Cleaning up");
698 CloseHandle( logfile );
699 logfile = 0;
700 remove_dir (tempdir);
701 free (wine_tests);
703 return logname;
706 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
708 if (ctrl_type == CTRL_C_EVENT) {
709 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
710 return TRUE;
713 return FALSE;
716 static void
717 usage (void)
719 fprintf (stderr,
720 "Usage: winetest [OPTION]... [TESTS]\n\n"
721 " -c console mode, no GUI\n"
722 " -e preserve the environment\n"
723 " -h print this message and exit\n"
724 " -p shutdown when the tests are done\n"
725 " -q quiet mode, no output at all\n"
726 " -o FILE put report into FILE, do not submit\n"
727 " -s FILE submit FILE, do not run tests\n"
728 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
731 int main( int argc, char *argv[] )
733 char *logname = NULL;
734 const char *cp, *submit = NULL;
735 int reset_env = 1;
736 int poweroff = 0;
737 int interactive = 1;
738 int i;
740 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
742 for (i = 1; argv[i]; i++)
744 if (argv[i][0] != '-' || argv[i][2]) {
745 if (nb_filters == sizeof(filters)/sizeof(filters[0]))
747 report (R_ERROR, "Too many test filters specified");
748 exit (2);
750 filters[nb_filters++] = argv[i];
752 else switch (argv[i][1]) {
753 case 'c':
754 report (R_TEXTMODE);
755 interactive = 0;
756 break;
757 case 'e':
758 reset_env = 0;
759 break;
760 case 'h':
761 case '?':
762 usage ();
763 exit (0);
764 case 'p':
765 poweroff = 1;
766 break;
767 case 'q':
768 report (R_QUIET);
769 interactive = 0;
770 break;
771 case 's':
772 if (!(submit = argv[++i]))
774 usage();
775 exit( 2 );
777 if (tag)
778 report (R_WARNING, "ignoring tag for submission");
779 send_file (submit);
780 break;
781 case 'o':
782 if (!(logname = argv[++i]))
784 usage();
785 exit( 2 );
787 break;
788 case 't':
789 if (!(tag = argv[++i]))
791 usage();
792 exit( 2 );
794 if (strlen (tag) > MAXTAGLEN)
795 report (R_FATAL, "tag is too long (maximum %d characters)",
796 MAXTAGLEN);
797 cp = findbadtagchar (tag);
798 if (cp) {
799 report (R_ERROR, "invalid char in tag: %c", *cp);
800 usage ();
801 exit (2);
803 break;
804 default:
805 report (R_ERROR, "invalid option: -%c", argv[i][1]);
806 usage ();
807 exit (2);
810 if (!submit) {
811 report (R_STATUS, "Starting up");
813 if (!running_on_visible_desktop ())
814 report (R_FATAL, "Tests must be run on a visible desktop");
816 SetConsoleCtrlHandler(ctrl_handler, TRUE);
818 if (reset_env)
820 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
821 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
822 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
823 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
826 if (!nb_filters) /* don't submit results when filtering */
828 while (!tag) {
829 if (!interactive)
830 report (R_FATAL, "Please specify a tag (-t option) if "
831 "running noninteractive!");
832 if (guiAskTag () == IDABORT) exit (1);
834 report (R_TAG);
836 if (!build_id[0])
837 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
838 "To submit results, winetest needs to be built from a git checkout." );
841 if (!logname) {
842 logname = run_tests (NULL);
843 if (build_id[0] && !nb_filters &&
844 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
845 if (!send_file (logname) && !DeleteFileA(logname))
846 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
847 } else run_tests (logname);
848 report (R_STATUS, "Finished");
850 if (poweroff)
852 HANDLE hToken;
853 TOKEN_PRIVILEGES npr;
855 /* enable the shutdown privilege for the current process */
856 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
858 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
859 npr.PrivilegeCount = 1;
860 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
861 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
862 CloseHandle(hToken);
864 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
866 exit (0);