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 = 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 );
349 if (subfile == INVALID_HANDLE_VALUE) {
350 report (R_ERROR, "Can't open subtests output of %s: %u",
351 test->name, GetLastError());
355 extract_test (test, tempdir, res_name);
356 cmd = strmake (NULL, "%s --list", test->exename);
357 run_ex (cmd, subfile, tempdir, 5000);
360 SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
361 ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
362 CloseHandle( subfile );
363 if (sizeof buffer == total) {
364 report (R_ERROR, "Subtest list of %s too big.",
365 test->name, sizeof buffer);
370 index = strstr (buffer, header);
372 report (R_ERROR, "Can't parse subtests output of %s",
376 index += sizeof header;
379 test->subtests = xmalloc (allocated * sizeof(char*));
380 index = strtok (index, whitespace);
382 if (test->subtest_count == allocated) {
384 test->subtests = xrealloc (test->subtests,
385 allocated * sizeof(char*));
387 test->subtests[test->subtest_count++] = strdup (index);
388 index = strtok (NULL, whitespace);
390 test->subtests = xrealloc (test->subtests,
391 test->subtest_count * sizeof(char*));
394 if (!DeleteFileA (subname))
395 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
399 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
402 const char* file = get_test_source_file(test->name, subtest);
403 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
405 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
406 status = run_ex (cmd, out_file, tempdir, 120000);
408 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
412 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
413 LPTSTR lpszName, LONG_PTR lParam)
420 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
421 LPTSTR lpszName, LONG_PTR lParam)
423 const char *tempdir = (const char *)lParam;
424 char dllname[MAX_PATH];
427 /* Check if the main dll is present on this system */
428 CharLowerA(lpszName);
429 strcpy(dllname, lpszName);
430 *strstr(dllname, testexe) = 0;
432 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
434 xprintf (" %s=dll is missing\n", dllname);
439 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
441 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
442 nr_of_tests += wine_tests[nr_of_files].subtest_count;
448 run_tests (char *logname)
451 char *strres, *eol, *nextline;
453 SECURITY_ATTRIBUTES sa;
454 char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
456 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
458 if (!GetTempPathA( MAX_PATH, tmppath ))
459 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
462 static char tmpname[MAX_PATH];
463 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
464 report (R_FATAL, "Can't name logfile.");
467 report (R_OUT, logname);
469 /* make handle inheritable */
470 sa.nLength = sizeof(sa);
471 sa.lpSecurityDescriptor = NULL;
472 sa.bInheritHandle = TRUE;
474 logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
475 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
476 &sa, CREATE_ALWAYS, 0, NULL );
477 if (logfile == INVALID_HANDLE_VALUE)
478 report (R_FATAL, "Could not open logfile: %u", GetLastError());
480 if (!GetTempPathA( MAX_PATH, tmppath ))
481 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
483 /* try stable path for ZoneAlarm */
484 strcpy( tempdir, tmppath );
485 strcat( tempdir, "wct" );
486 if (!CreateDirectoryA( tempdir, NULL ))
488 if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
489 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
490 DeleteFileA( tempdir );
491 if (!CreateDirectoryA( tempdir, NULL ))
492 report (R_FATAL, "Could not create directory: %s", tempdir);
494 report (R_DIR, tempdir);
496 xprintf ("Version 4\n");
497 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
498 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
499 xprintf ("Archive: ");
500 if (strres) xprintf ("%.*s", strsize, strres);
501 else xprintf ("-\n");
502 xprintf ("Tag: %s\n", tag);
503 xprintf ("Build info:\n");
504 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
506 eol = memchr (strres, '\n', strsize);
509 eol = strres + strsize;
511 strsize -= eol - strres + 1;
512 nextline = strsize?eol+1:NULL;
513 if (eol > strres && *(eol-1) == '\r') eol--;
515 xprintf (" %.*s\n", eol-strres, strres);
518 xprintf ("Operating system version:\n");
520 xprintf ("Dll info:\n" );
522 report (R_STATUS, "Counting tests");
523 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
524 EnumTestFileProc, (LPARAM)&nr_of_files))
525 report (R_FATAL, "Can't enumerate test files: %d",
527 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
529 report (R_STATUS, "Extracting tests");
530 report (R_PROGRESS, 0, nr_of_files);
533 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
534 extract_test_proc, (LPARAM)tempdir))
535 report (R_FATAL, "Can't enumerate test files: %d",
538 xprintf ("Test output:\n" );
540 report (R_DELTA, 0, "Extracting: Done");
542 report (R_STATUS, "Running tests");
543 report (R_PROGRESS, 1, nr_of_tests);
544 for (i = 0; i < nr_of_files; i++) {
545 struct wine_test *test = wine_tests + i;
548 for (j = 0; j < test->subtest_count; j++) {
549 report (R_STEP, "Running: %s:%s", test->name,
551 run_test (test, test->subtests[j], logfile, tempdir);
554 report (R_DELTA, 0, "Running: Done");
556 report (R_STATUS, "Cleaning up");
557 CloseHandle( logfile );
559 remove_dir (tempdir);
569 "Usage: winetest [OPTION]...\n\n"
570 " -c console mode, no GUI\n"
571 " -e preserve the environment\n"
572 " -h print this message and exit\n"
573 " -p shutdown when the tests are done\n"
574 " -q quiet mode, no output at all\n"
575 " -o FILE put report into FILE, do not submit\n"
576 " -s FILE submit FILE, do not run tests\n"
577 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
580 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
581 LPSTR cmdLine, int cmdShow)
583 char *logname = NULL;
584 const char *cp, *submit = NULL;
589 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
591 cmdLine = strtok (cmdLine, whitespace);
593 if (cmdLine[0] != '-' || cmdLine[2]) {
594 report (R_ERROR, "Not a single letter option: %s", cmdLine);
598 switch (cmdLine[1]) {
618 submit = strtok (NULL, whitespace);
620 report (R_WARNING, "ignoring tag for submission");
624 logname = strtok (NULL, whitespace);
627 tag = strtok (NULL, whitespace);
628 if (strlen (tag) > MAXTAGLEN)
629 report (R_FATAL, "tag is too long (maximum %d characters)",
631 cp = findbadtagchar (tag);
633 report (R_ERROR, "invalid char in tag: %c", *cp);
639 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
643 cmdLine = strtok (NULL, whitespace);
646 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
647 platform_wine[] = "WINETEST_PLATFORM=wine",
648 debug_yes[] = "WINETEST_DEBUG=1",
649 interactive_no[] = "WINETEST_INTERACTIVE=0",
650 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
653 report (R_STATUS, "Starting up");
655 if (!running_on_visible_desktop ())
656 report (R_FATAL, "Tests must be run on a visible desktop");
658 platform = running_under_wine () ? platform_wine : platform_windows;
660 if (reset_env && (putenv (platform) ||
661 putenv (debug_yes) ||
662 putenv (interactive_no) ||
663 putenv (report_success_no)))
664 report (R_FATAL, "Could not reset environment");
668 report (R_FATAL, "Please specify a tag (-t option) if "
669 "running noninteractive!");
670 if (guiAskTag () == IDABORT) exit (1);
675 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
676 "To submit results, winetest needs to be built from a git checkout." );
679 logname = run_tests (NULL);
681 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
682 if (!send_file (logname) && !DeleteFileA(logname))
683 report (R_WARNING, "Can't remove logfile: %u", GetLastError());
684 } else run_tests (logname);
685 report (R_STATUS, "Finished");
690 TOKEN_PRIVILEGES npr;
692 /* enable the shutdown privilege for the current process */
693 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
695 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
696 npr.PrivilegeCount = 1;
697 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
698 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
701 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);