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"
48 static struct wine_test *wine_tests;
49 static int nr_of_files, nr_of_tests;
50 static const char whitespace[] = " \t\r\n";
51 static const char testexe[] = "_test.exe";
52 static char build_id[64];
54 static char * get_file_version(char * file_name)
56 static char version[32];
60 size = GetFileVersionInfoSizeA(file_name, &handle);
62 char * data = xmalloc(size);
64 if (GetFileVersionInfoA(file_name, handle, size, data)) {
65 static char backslash[] = "\\";
66 VS_FIXEDFILEINFO *pFixedVersionInfo;
68 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
69 sprintf(version, "%d.%d.%d.%d",
70 pFixedVersionInfo->dwFileVersionMS >> 16,
71 pFixedVersionInfo->dwFileVersionMS & 0xffff,
72 pFixedVersionInfo->dwFileVersionLS >> 16,
73 pFixedVersionInfo->dwFileVersionLS & 0xffff);
75 sprintf(version, "version not available");
77 sprintf(version, "unknown");
80 sprintf(version, "failed");
82 sprintf(version, "version not available");
87 static int running_under_wine (void)
89 HMODULE module = GetModuleHandleA("ntdll.dll");
91 if (!module) return 0;
92 return (GetProcAddress(module, "wine_server_call") != NULL);
95 static int running_on_visible_desktop (void)
98 HMODULE huser32 = GetModuleHandle("user32.dll");
99 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
100 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
102 desktop = GetDesktopWindow();
103 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
104 return IsWindowVisible(desktop);
106 if (pGetProcessWindowStation && pGetUserObjectInformationA)
110 USEROBJECTFLAGS uoflags;
112 wstation = (HWINSTA)pGetProcessWindowStation();
113 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
114 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
116 return IsWindowVisible(desktop);
119 static void print_version (void)
124 const char *(*wine_get_build_id)(void);
126 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
127 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
129 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
130 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
131 report (R_FATAL, "Can't get OS version.");
134 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
135 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
136 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
137 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
138 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
139 ver.dwPlatformId, ver.szCSDVersion);
141 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
142 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
144 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
146 xprintf(" R2 build number=%d\n", is_win2k3_r2);
150 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
151 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
152 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
153 ver.wProductType, ver.wReserved);
156 static inline int is_dot_dir(const char* x)
158 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
161 static void remove_dir (const char *dir)
166 size_t dirlen = strlen (dir);
168 /* Make sure the directory exists before going further */
169 memcpy (path, dir, dirlen);
170 strcpy (path + dirlen++, "\\*");
171 hFind = FindFirstFile (path, &wfd);
172 if (hFind == INVALID_HANDLE_VALUE) return;
175 char *lp = wfd.cFileName;
177 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
178 if (is_dot_dir (lp)) continue;
179 strcpy (path + dirlen, lp);
180 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
182 else if (!DeleteFile (path))
183 report (R_WARNING, "Can't delete file %s: error %d",
184 path, GetLastError ());
185 } while (FindNextFile (hFind, &wfd));
187 if (!RemoveDirectory (dir))
188 report (R_WARNING, "Can't remove directory %s: error %d",
189 dir, GetLastError ());
192 static const char* get_test_source_file(const char* test, const char* subtest)
194 static const char* special_dirs[][2] = {
197 static char buffer[MAX_PATH];
200 for (i = 0; special_dirs[i][0]; i++) {
201 if (strcmp(test, special_dirs[i][0]) == 0) {
202 test = special_dirs[i][1];
207 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
211 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
217 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
218 !(*size = SizeofResource (0, rsrc)) ||
219 !(hdl = LoadResource (0, rsrc)) ||
220 !(addr = LockResource (hdl)))
225 /* Fills in the name and exename fields */
227 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
235 code = extract_rcdata (res_name, TESTRES, &size);
236 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
237 res_name, GetLastError ());
238 test->name = xstrdup( res_name );
239 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
240 exepos = strstr (test->name, testexe);
241 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
243 test->name = xrealloc (test->name, exepos - test->name + 1);
244 report (R_STEP, "Extracting: %s", test->name);
246 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
247 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
248 if (hfile == INVALID_HANDLE_VALUE)
249 report (R_FATAL, "Failed to open file %s.", test->exename);
251 if (!WriteFile(hfile, code, size, &written, NULL))
252 report (R_FATAL, "Failed to write file %s.", test->exename);
257 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
260 Return the exit status, -2 if can't create process or the return
261 value of WaitForSingleObject.
264 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
267 PROCESS_INFORMATION pi;
270 GetStartupInfo (&si);
271 si.dwFlags = STARTF_USESTDHANDLES;
272 si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
273 si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
274 si.hStdError = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
276 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
277 NULL, tempdir, &si, &pi)) {
280 CloseHandle (pi.hThread);
281 wait = WaitForSingleObject (pi.hProcess, ms);
282 if (wait == WAIT_OBJECT_0) {
283 GetExitCodeProcess (pi.hProcess, &status);
287 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
291 report (R_ERROR, "Process '%s' timed out.", cmd);
294 report (R_ERROR, "Wait returned %d", wait);
297 if (!TerminateProcess (pi.hProcess, 257))
298 report (R_ERROR, "TerminateProcess failed: %d",
300 wait = WaitForSingleObject (pi.hProcess, 5000);
304 "Wait for termination of '%s' failed: %d",
305 cmd, GetLastError ());
310 report (R_ERROR, "Can't kill process '%s'", cmd);
313 report (R_ERROR, "Waiting for termination: %d",
317 CloseHandle (pi.hProcess);
324 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
329 char buffer[8192], *index;
330 static const char header[] = "Valid test names:";
332 char tmpdir[MAX_PATH], subname[MAX_PATH];
333 SECURITY_ATTRIBUTES sa;
335 test->subtest_count = 0;
337 if (!GetTempPathA( MAX_PATH, tmpdir ) ||
338 !GetTempFileNameA( tmpdir, "sub", 0, subname ))
339 report (R_FATAL, "Can't name subtests file.");
341 /* make handle inheritable */
342 sa.nLength = sizeof(sa);
343 sa.lpSecurityDescriptor = NULL;
344 sa.bInheritHandle = TRUE;
346 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
347 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
348 &sa, CREATE_ALWAYS, 0, NULL );
350 if ((subfile == INVALID_HANDLE_VALUE) &&
351 (GetLastError() == ERROR_INVALID_PARAMETER)) {
352 /* FILE_SHARE_DELETE not supported on win9x */
353 subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
354 FILE_SHARE_READ | FILE_SHARE_WRITE,
355 &sa, CREATE_ALWAYS, 0, NULL );
357 if (subfile == INVALID_HANDLE_VALUE) {
358 report (R_ERROR, "Can't open subtests output of %s: %u",
359 test->name, GetLastError());
363 extract_test (test, tempdir, res_name);
364 cmd = strmake (NULL, "%s --list", test->exename);
365 run_ex (cmd, subfile, tempdir, 5000);
368 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
369 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
370 CloseHandle( subfile );
371 if (sizeof buffer == total) {
372 report (R_ERROR, "Subtest list of %s too big.",
373 test->name, sizeof buffer);
378 index = strstr (buffer, header);
380 report (R_ERROR, "Can't parse subtests output of %s",
384 index += sizeof header;
387 test->subtests = xmalloc (allocated * sizeof(char*));
388 index = strtok (index, whitespace);
390 if (test->subtest_count == allocated) {
392 test->subtests = xrealloc (test->subtests,
393 allocated * sizeof(char*));
395 test->subtests[test->subtest_count++] = strdup (index);
396 index = strtok (NULL, whitespace);
398 test->subtests = xrealloc (test->subtests,
399 test->subtest_count * sizeof(char*));
402 if (!DeleteFileA (subname))
403 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
407 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
410 const char* file = get_test_source_file(test->name, subtest);
411 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
413 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
414 status = run_ex (cmd, out_file, tempdir, 120000);
416 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
420 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
421 LPTSTR lpszName, LONG_PTR lParam)
428 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
429 LPTSTR lpszName, LONG_PTR lParam)
431 const char *tempdir = (const char *)lParam;
432 char dllname[MAX_PATH];
435 /* Check if the main dll is present on this system */
436 CharLowerA(lpszName);
437 strcpy(dllname, lpszName);
438 *strstr(dllname, testexe) = 0;
440 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
442 xprintf (" %s=dll is missing\n", dllname);
447 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
449 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
450 nr_of_tests += wine_tests[nr_of_files].subtest_count;
456 run_tests (char *logname)
459 char *strres, *eol, *nextline;
461 SECURITY_ATTRIBUTES sa;
462 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
464 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
466 if (!GetTempPathA( MAX_PATH, tmppath ))
467 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
470 static char tmpname[MAX_PATH];
471 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
472 report (R_FATAL, "Can't name logfile.");
475 report (R_OUT, logname);
477 /* make handle inheritable */
478 sa.nLength = sizeof(sa);
479 sa.lpSecurityDescriptor = NULL;
480 sa.bInheritHandle = TRUE;
482 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
483 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
484 &sa, CREATE_ALWAYS, 0, NULL );
486 if ((logfile == INVALID_HANDLE_VALUE) &&
487 (GetLastError() == ERROR_INVALID_PARAMETER)) {
488 /* FILE_SHARE_DELETE not supported on win9x */
489 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
490 FILE_SHARE_READ | FILE_SHARE_WRITE,
491 &sa, CREATE_ALWAYS, 0, NULL );
493 if (logfile == INVALID_HANDLE_VALUE)
494 report (R_FATAL, "Could not open logfile: %u", GetLastError());
496 if (!GetTempPathA( MAX_PATH, tmppath ))
497 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
499 /* try stable path for ZoneAlarm */
500 strcpy( tempdir, tmppath );
501 strcat( tempdir, "wct" );
502 if (!CreateDirectoryA( tempdir, NULL ))
504 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
505 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
506 DeleteFileA( tempdir );
507 if (!CreateDirectoryA( tempdir, NULL ))
508 report (R_FATAL, "Could not create directory: %s", tempdir);
510 report (R_DIR, tempdir);
512 xprintf ("Version 4\n");
513 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
514 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
515 xprintf ("Archive: ");
516 if (strres) xprintf ("%.*s", strsize, strres);
517 else xprintf ("-\n");
518 xprintf ("Tag: %s\n", tag);
519 xprintf ("Build info:\n");
520 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
522 eol = memchr (strres, '\n', strsize);
525 eol = strres + strsize;
527 strsize -= eol - strres + 1;
528 nextline = strsize?eol+1:NULL;
529 if (eol > strres && *(eol-1) == '\r') eol--;
531 xprintf (" %.*s\n", eol-strres, strres);
534 xprintf ("Operating system version:\n");
536 xprintf ("Dll info:\n" );
538 report (R_STATUS, "Counting tests");
539 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
540 EnumTestFileProc, (LPARAM)&nr_of_files))
541 report (R_FATAL, "Can't enumerate test files: %d",
543 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
545 report (R_STATUS, "Extracting tests");
546 report (R_PROGRESS, 0, nr_of_files);
549 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
550 extract_test_proc, (LPARAM)tempdir))
551 report (R_FATAL, "Can't enumerate test files: %d",
554 xprintf ("Test output:\n" );
556 report (R_DELTA, 0, "Extracting: Done");
558 report (R_STATUS, "Running tests");
559 report (R_PROGRESS, 1, nr_of_tests);
560 for (i = 0; i < nr_of_files; i++) {
561 struct wine_test *test = wine_tests + i;
564 for (j = 0; j < test->subtest_count; j++) {
565 report (R_STEP, "Running: %s:%s", test->name,
567 run_test (test, test->subtests[j], logfile, tempdir);
570 report (R_DELTA, 0, "Running: Done");
572 report (R_STATUS, "Cleaning up");
573 CloseHandle( logfile );
575 remove_dir (tempdir);
585 "Usage: winetest [OPTION]...\n\n"
586 " -c console mode, no GUI\n"
587 " -e preserve the environment\n"
588 " -h print this message and exit\n"
589 " -p shutdown when the tests are done\n"
590 " -q quiet mode, no output at all\n"
591 " -o FILE put report into FILE, do not submit\n"
592 " -s FILE submit FILE, do not run tests\n"
593 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
596 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
597 LPSTR cmdLine, int cmdShow)
599 char *logname = NULL;
600 const char *cp, *submit = NULL;
605 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
607 cmdLine = strtok (cmdLine, whitespace);
609 if (cmdLine[0] != '-' || cmdLine[2]) {
610 report (R_ERROR, "Not a single letter option: %s", cmdLine);
614 switch (cmdLine[1]) {
634 submit = strtok (NULL, whitespace);
636 report (R_WARNING, "ignoring tag for submission");
640 logname = strtok (NULL, whitespace);
643 tag = strtok (NULL, whitespace);
644 if (strlen (tag) > MAXTAGLEN)
645 report (R_FATAL, "tag is too long (maximum %d characters)",
647 cp = findbadtagchar (tag);
649 report (R_ERROR, "invalid char in tag: %c", *cp);
655 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
659 cmdLine = strtok (NULL, whitespace);
662 report (R_STATUS, "Starting up");
664 if (!running_on_visible_desktop ())
665 report (R_FATAL, "Tests must be run on a visible desktop");
669 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
670 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
671 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
672 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
677 report (R_FATAL, "Please specify a tag (-t option) if "
678 "running noninteractive!");
679 if (guiAskTag () == IDABORT) exit (1);
684 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
685 "To submit results, winetest needs to be built from a git checkout." );
688 logname = run_tests (NULL);
690 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
691 if (!send_file (logname) && !DeleteFileA(logname))
692 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
693 } else run_tests (logname);
694 report (R_STATUS, "Finished");
699 TOKEN_PRIVILEGES npr;
701 /* enable the shutdown privilege for the current process */
702 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
704 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
705 npr.PrivilegeCount = 1;
706 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
707 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
710 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);