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"
53 static struct wine_test *wine_tests;
54 static int nr_of_files, nr_of_tests;
55 static const char whitespace[] = " \t\r\n";
56 static const char testexe[] = "_test.exe";
57 static char build_id[64];
59 static char * get_file_version(char * file_name)
61 static char version[32];
65 size = GetFileVersionInfoSizeA(file_name, &handle);
67 char * data = xmalloc(size);
69 if (GetFileVersionInfoA(file_name, handle, size, data)) {
70 static char backslash[] = "\\";
71 VS_FIXEDFILEINFO *pFixedVersionInfo;
73 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
74 sprintf(version, "%d.%d.%d.%d",
75 pFixedVersionInfo->dwFileVersionMS >> 16,
76 pFixedVersionInfo->dwFileVersionMS & 0xffff,
77 pFixedVersionInfo->dwFileVersionLS >> 16,
78 pFixedVersionInfo->dwFileVersionLS & 0xffff);
80 sprintf(version, "version not available");
82 sprintf(version, "unknown");
85 sprintf(version, "failed");
87 sprintf(version, "version not available");
92 static int running_under_wine (void)
94 HMODULE module = GetModuleHandleA("ntdll.dll");
96 if (!module) return 0;
97 return (GetProcAddress(module, "wine_server_call") != NULL);
100 static int running_on_visible_desktop (void)
103 HMODULE huser32 = GetModuleHandle("user32.dll");
104 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
105 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
107 desktop = GetDesktopWindow();
108 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
109 return IsWindowVisible(desktop);
111 if (pGetProcessWindowStation && pGetUserObjectInformationA)
115 USEROBJECTFLAGS uoflags;
117 wstation = (HWINSTA)pGetProcessWindowStation();
118 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
119 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
121 return IsWindowVisible(desktop);
124 static void print_version (void)
129 const char *(*wine_get_build_id)(void);
131 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
132 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
134 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
135 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
136 report (R_FATAL, "Can't get OS version.");
139 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
140 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
141 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
142 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
143 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
144 ver.dwPlatformId, ver.szCSDVersion);
146 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
147 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
149 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
151 xprintf(" R2 build number=%d\n", is_win2k3_r2);
155 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
156 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
157 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
158 ver.wProductType, ver.wReserved);
161 static inline int is_dot_dir(const char* x)
163 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
166 static void remove_dir (const char *dir)
171 size_t dirlen = strlen (dir);
173 /* Make sure the directory exists before going further */
174 memcpy (path, dir, dirlen);
175 strcpy (path + dirlen++, "\\*");
176 hFind = FindFirstFile (path, &wfd);
177 if (hFind == INVALID_HANDLE_VALUE) return;
180 char *lp = wfd.cFileName;
182 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
183 if (is_dot_dir (lp)) continue;
184 strcpy (path + dirlen, lp);
185 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
187 else if (!DeleteFile (path))
188 report (R_WARNING, "Can't delete file %s: error %d",
189 path, GetLastError ());
190 } while (FindNextFile (hFind, &wfd));
192 if (!RemoveDirectory (dir))
193 report (R_WARNING, "Can't remove directory %s: error %d",
194 dir, GetLastError ());
197 static const char* get_test_source_file(const char* test, const char* subtest)
199 static const char* special_dirs[][2] = {
202 static char buffer[MAX_PATH];
205 for (i = 0; special_dirs[i][0]; i++) {
206 if (strcmp(test, special_dirs[i][0]) == 0) {
207 test = special_dirs[i][1];
212 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
216 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
222 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
223 !(*size = SizeofResource (0, rsrc)) ||
224 !(hdl = LoadResource (0, rsrc)) ||
225 !(addr = LockResource (hdl)))
230 /* Fills in the name and exename fields */
232 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
240 code = extract_rcdata (res_name, TESTRES, &size);
241 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
242 res_name, GetLastError ());
243 test->name = xstrdup( res_name );
244 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
245 exepos = strstr (test->name, testexe);
246 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
248 test->name = xrealloc (test->name, exepos - test->name + 1);
249 report (R_STEP, "Extracting: %s", test->name);
251 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
252 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
253 if (hfile == INVALID_HANDLE_VALUE)
254 report (R_FATAL, "Failed to open file %s.", test->exename);
256 if (!WriteFile(hfile, code, size, &written, NULL))
257 report (R_FATAL, "Failed to write file %s.", test->exename);
262 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
265 Return the exit status, -2 if can't create process or the return
266 value of WaitForSingleObject.
269 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
272 PROCESS_INFORMATION pi;
273 int fd, oldstdout = -1;
276 GetStartupInfo (&si);
280 fd = open (out, O_WRONLY | O_CREAT, 0666);
282 report (R_FATAL, "Can't open '%s': %d", out, errno);
285 report (R_FATAL, "Can't save stdout: %d", errno);
286 if (-1 == dup2 (fd, 1))
287 report (R_FATAL, "Can't redirect stdout: %d", errno);
291 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
292 NULL, tempdir, &si, &pi)) {
295 CloseHandle (pi.hThread);
296 wait = WaitForSingleObject (pi.hProcess, ms);
297 if (wait == WAIT_OBJECT_0) {
298 GetExitCodeProcess (pi.hProcess, &status);
302 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
306 report (R_ERROR, "Process '%s' timed out.", cmd);
309 report (R_ERROR, "Wait returned %d", wait);
312 if (!TerminateProcess (pi.hProcess, 257))
313 report (R_ERROR, "TerminateProcess failed: %d",
315 wait = WaitForSingleObject (pi.hProcess, 5000);
319 "Wait for termination of '%s' failed: %d",
320 cmd, GetLastError ());
325 report (R_ERROR, "Can't kill process '%s'", cmd);
328 report (R_ERROR, "Waiting for termination: %d",
332 CloseHandle (pi.hProcess);
337 if (-1 == dup2 (oldstdout, 1))
338 report (R_FATAL, "Can't recover stdout: %d", errno);
345 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
350 char buffer[8192], *index;
351 static const char header[] = "Valid test names:";
354 test->subtest_count = 0;
356 subname = tempnam (0, "sub");
357 if (!subname) report (R_FATAL, "Can't name subtests file.");
359 extract_test (test, tempdir, res_name);
360 cmd = strmake (NULL, "%s --list", test->exename);
361 run_ex (cmd, subname, tempdir, 5000);
364 subfile = fopen (subname, "r");
366 report (R_ERROR, "Can't open subtests output of %s: %d",
370 total = fread (buffer, 1, sizeof buffer, subfile);
372 if (sizeof buffer == total) {
373 report (R_ERROR, "Subtest list of %s too big.",
374 test->name, sizeof buffer);
379 index = strstr (buffer, header);
381 report (R_ERROR, "Can't parse subtests output of %s",
385 index += sizeof header;
388 test->subtests = xmalloc (allocated * sizeof(char*));
389 index = strtok (index, whitespace);
391 if (test->subtest_count == allocated) {
393 test->subtests = xrealloc (test->subtests,
394 allocated * sizeof(char*));
396 test->subtests[test->subtest_count++] = strdup (index);
397 index = strtok (NULL, whitespace);
399 test->subtests = xrealloc (test->subtests,
400 test->subtest_count * sizeof(char*));
403 if (remove (subname))
404 report (R_WARNING, "Can't delete file '%s': %d",
410 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
413 const char* file = get_test_source_file(test->name, subtest);
414 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
416 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
417 status = run_ex (cmd, NULL, tempdir, 120000);
419 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
423 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
424 LPTSTR lpszName, LONG_PTR lParam)
431 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
432 LPTSTR lpszName, LONG_PTR lParam)
434 const char *tempdir = (const char *)lParam;
435 char dllname[MAX_PATH];
438 /* Check if the main dll is present on this system */
439 CharLowerA(lpszName);
440 strcpy(dllname, lpszName);
441 *strstr(dllname, testexe) = 0;
443 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
445 xprintf (" %s=dll is missing\n", dllname);
450 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
452 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
453 nr_of_tests += wine_tests[nr_of_files].subtest_count;
459 run_tests (char *logname)
462 char *tempdir, *shorttempdir;
464 char *strres, *eol, *nextline;
467 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
470 logname = tempnam (0, "res");
471 if (!logname) report (R_FATAL, "Can't name logfile.");
473 report (R_OUT, logname);
475 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
479 report (R_FATAL, "File %s already exists.", logname);
480 else report (R_FATAL, "Could not open logfile: %d", errno);
482 if (-1 == dup2 (logfile, 1))
483 report (R_FATAL, "Can't redirect stdout: %d", errno);
486 tempdir = tempnam (0, "wct");
488 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
489 shorttempdir = strdup (tempdir);
490 if (shorttempdir) { /* try stable path for ZoneAlarm */
491 strstr (shorttempdir, "wct")[3] = 0;
492 if (CreateDirectoryA (shorttempdir, NULL)) {
494 tempdir = shorttempdir;
495 } else free (shorttempdir);
497 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
498 report (R_FATAL, "Could not create directory: %s", tempdir);
499 report (R_DIR, tempdir);
501 xprintf ("Version 4\n");
502 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
503 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
504 xprintf ("Archive: ");
505 if (strres) xprintf ("%.*s", strsize, strres);
506 else xprintf ("-\n");
507 xprintf ("Tag: %s\n", tag);
508 xprintf ("Build info:\n");
509 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
511 eol = memchr (strres, '\n', strsize);
514 eol = strres + strsize;
516 strsize -= eol - strres + 1;
517 nextline = strsize?eol+1:NULL;
518 if (eol > strres && *(eol-1) == '\r') eol--;
520 xprintf (" %.*s\n", eol-strres, strres);
523 xprintf ("Operating system version:\n");
525 xprintf ("Dll info:\n" );
527 report (R_STATUS, "Counting tests");
528 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
529 EnumTestFileProc, (LPARAM)&nr_of_files))
530 report (R_FATAL, "Can't enumerate test files: %d",
532 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
534 report (R_STATUS, "Extracting tests");
535 report (R_PROGRESS, 0, nr_of_files);
538 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
539 extract_test_proc, (LPARAM)tempdir))
540 report (R_FATAL, "Can't enumerate test files: %d",
543 xprintf ("Test output:\n" );
545 report (R_DELTA, 0, "Extracting: Done");
547 report (R_STATUS, "Running tests");
548 report (R_PROGRESS, 1, nr_of_tests);
549 for (i = 0; i < nr_of_files; i++) {
550 struct wine_test *test = wine_tests + i;
553 for (j = 0; j < test->subtest_count; j++) {
554 report (R_STEP, "Running: %s:%s", test->name,
556 run_test (test, test->subtests[j], tempdir);
559 report (R_DELTA, 0, "Running: Done");
561 report (R_STATUS, "Cleaning up");
563 remove_dir (tempdir);
574 "Usage: winetest [OPTION]...\n\n"
575 " -c console mode, no GUI\n"
576 " -e preserve the environment\n"
577 " -h print this message and exit\n"
578 " -p shutdown when the tests are done\n"
579 " -q quiet mode, no output at all\n"
580 " -o FILE put report into FILE, do not submit\n"
581 " -s FILE submit FILE, do not run tests\n"
582 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
585 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
586 LPSTR cmdLine, int cmdShow)
588 char *logname = NULL;
589 const char *cp, *submit = NULL;
594 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
596 cmdLine = strtok (cmdLine, whitespace);
598 if (cmdLine[0] != '-' || cmdLine[2]) {
599 report (R_ERROR, "Not a single letter option: %s", cmdLine);
603 switch (cmdLine[1]) {
623 submit = strtok (NULL, whitespace);
625 report (R_WARNING, "ignoring tag for submission");
629 logname = strtok (NULL, whitespace);
632 tag = strtok (NULL, whitespace);
633 if (strlen (tag) > MAXTAGLEN)
634 report (R_FATAL, "tag is too long (maximum %d characters)",
636 cp = findbadtagchar (tag);
638 report (R_ERROR, "invalid char in tag: %c", *cp);
644 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
648 cmdLine = strtok (NULL, whitespace);
651 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
652 platform_wine[] = "WINETEST_PLATFORM=wine",
653 debug_yes[] = "WINETEST_DEBUG=1",
654 interactive_no[] = "WINETEST_INTERACTIVE=0",
655 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
658 report (R_STATUS, "Starting up");
660 if (!running_on_visible_desktop ())
661 report (R_FATAL, "Tests must be run on a visible desktop");
663 platform = running_under_wine () ? platform_wine : platform_windows;
665 if (reset_env && (putenv (platform) ||
666 putenv (debug_yes) ||
667 putenv (interactive_no) ||
668 putenv (report_success_no)))
669 report (R_FATAL, "Could not reset environment: %d", errno);
673 report (R_FATAL, "Please specify a tag (-t option) if "
674 "running noninteractive!");
675 if (guiAskTag () == IDABORT) exit (1);
680 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
681 "To submit results, winetest needs to be built from a git checkout." );
684 logname = run_tests (NULL);
686 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
687 if (!send_file (logname) && remove (logname))
688 report (R_WARNING, "Can't remove logfile: %d.", errno);
690 } else run_tests (logname);
691 report (R_STATUS, "Finished");
696 TOKEN_PRIVILEGES npr;
698 /* enable the shutdown privilege for the current process */
699 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
701 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
702 npr.PrivilegeCount = 1;
703 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
704 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
707 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);