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"
59 static struct wine_test *wine_tests;
60 static int nr_of_files, nr_of_tests;
61 static struct rev_info *rev_infos = NULL;
62 static const char whitespace[] = " \t\r\n";
63 static const char testexe[] = "_test.exe";
65 static char * get_file_version(char * file_name)
67 static char version[32];
71 size = GetFileVersionInfoSizeA(file_name, &handle);
73 char * data = xmalloc(size);
75 if (GetFileVersionInfoA(file_name, handle, size, data)) {
76 static char backslash[] = "\\";
77 VS_FIXEDFILEINFO *pFixedVersionInfo;
79 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
80 sprintf(version, "%d.%d.%d.%d",
81 pFixedVersionInfo->dwFileVersionMS >> 16,
82 pFixedVersionInfo->dwFileVersionMS & 0xffff,
83 pFixedVersionInfo->dwFileVersionLS >> 16,
84 pFixedVersionInfo->dwFileVersionLS & 0xffff);
86 sprintf(version, "version not available");
88 sprintf(version, "unknown");
91 sprintf(version, "failed");
93 sprintf(version, "version not available");
98 static int running_under_wine (void)
100 HMODULE module = GetModuleHandleA("ntdll.dll");
102 if (!module) return 0;
103 return (GetProcAddress(module, "wine_server_call") != NULL);
106 static int running_on_visible_desktop (void)
109 HMODULE huser32 = GetModuleHandle("user32.dll");
110 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
111 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
113 desktop = GetDesktopWindow();
114 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
115 return IsWindowVisible(desktop);
117 if (pGetProcessWindowStation && pGetUserObjectInformationA)
121 USEROBJECTFLAGS uoflags;
123 wstation = (HWINSTA)pGetProcessWindowStation();
124 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
125 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
127 return IsWindowVisible(desktop);
130 static void print_version (void)
136 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
137 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
139 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
140 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
141 report (R_FATAL, "Can't get OS version.");
144 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
145 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
146 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
147 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
148 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
149 ver.dwPlatformId, ver.szCSDVersion);
151 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
153 xprintf(" R2 build number=%d\n", is_win2k3_r2);
157 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
158 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
159 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
160 ver.wProductType, ver.wReserved);
163 static inline int is_dot_dir(const char* x)
165 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
168 static void remove_dir (const char *dir)
173 size_t dirlen = strlen (dir);
175 /* Make sure the directory exists before going further */
176 memcpy (path, dir, dirlen);
177 strcpy (path + dirlen++, "\\*");
178 hFind = FindFirstFile (path, &wfd);
179 if (hFind == INVALID_HANDLE_VALUE) return;
182 char *lp = wfd.cFileName;
184 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
185 if (is_dot_dir (lp)) continue;
186 strcpy (path + dirlen, lp);
187 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
189 else if (!DeleteFile (path))
190 report (R_WARNING, "Can't delete file %s: error %d",
191 path, GetLastError ());
192 } while (FindNextFile (hFind, &wfd));
194 if (!RemoveDirectory (dir))
195 report (R_WARNING, "Can't remove directory %s: error %d",
196 dir, GetLastError ());
199 static const char* get_test_source_file(const char* test, const char* subtest)
201 static const char* special_dirs[][2] = {
204 static char buffer[MAX_PATH];
207 for (i = 0; special_dirs[i][0]; i++) {
208 if (strcmp(test, special_dirs[i][0]) == 0) {
209 test = special_dirs[i][1];
214 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
218 static const char* get_file_rev(const char* file)
220 const struct rev_info* rev;
222 for(rev = rev_infos; rev->file; rev++) {
223 if (strcmp(rev->file, file) == 0) return rev->rev;
229 static void extract_rev_infos (void)
231 char revinfo[256], *p;
234 HMODULE module = GetModuleHandle (NULL);
236 for (i = 0; TRUE; i++) {
239 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
241 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
243 len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
244 if (len == 0) break; /* end of revision info */
245 if (len >= sizeof(revinfo) - 1)
246 report (R_FATAL, "Revision info too long.");
247 if(!(p = strrchr(revinfo, ':')))
248 report (R_FATAL, "Revision info malformed (i=%d)", i);
250 rev_infos[i].file = strdup(revinfo);
251 rev_infos[i].rev = strdup(p + 1);
255 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
261 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
262 !(*size = SizeofResource (0, rsrc)) ||
263 !(hdl = LoadResource (0, rsrc)) ||
264 !(addr = LockResource (hdl)))
269 /* Fills in the name and exename fields */
271 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
278 code = extract_rcdata (res_name, TESTRES, &size);
279 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
280 res_name, GetLastError ());
281 test->name = xstrdup( res_name );
282 test->exename = strmake (NULL, "%s/%s", dir, test->name);
283 exepos = strstr (test->name, testexe);
284 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
286 test->name = xrealloc (test->name, exepos - test->name + 1);
287 report (R_STEP, "Extracting: %s", test->name);
289 if (!(fout = fopen (test->exename, "wb")) ||
290 (fwrite (code, size, 1, fout) != 1) ||
291 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
295 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
298 Return the exit status, -2 if can't create process or the return
299 value of WaitForSingleObject.
302 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
305 PROCESS_INFORMATION pi;
306 int fd, oldstdout = -1;
309 GetStartupInfo (&si);
313 fd = open (out, O_WRONLY | O_CREAT, 0666);
315 report (R_FATAL, "Can't open '%s': %d", out, errno);
318 report (R_FATAL, "Can't save stdout: %d", errno);
319 if (-1 == dup2 (fd, 1))
320 report (R_FATAL, "Can't redirect stdout: %d", errno);
324 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
325 NULL, tempdir, &si, &pi)) {
328 CloseHandle (pi.hThread);
329 wait = WaitForSingleObject (pi.hProcess, ms);
330 if (wait == WAIT_OBJECT_0) {
331 GetExitCodeProcess (pi.hProcess, &status);
335 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
339 report (R_ERROR, "Process '%s' timed out.", cmd);
342 report (R_ERROR, "Wait returned %d", wait);
345 if (!TerminateProcess (pi.hProcess, 257))
346 report (R_ERROR, "TerminateProcess failed: %d",
348 wait = WaitForSingleObject (pi.hProcess, 5000);
352 "Wait for termination of '%s' failed: %d",
353 cmd, GetLastError ());
358 report (R_ERROR, "Can't kill process '%s'", cmd);
361 report (R_ERROR, "Waiting for termination: %d",
365 CloseHandle (pi.hProcess);
370 if (-1 == dup2 (oldstdout, 1))
371 report (R_FATAL, "Can't recover stdout: %d", errno);
378 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
383 char buffer[8192], *index;
384 static const char header[] = "Valid test names:";
387 test->subtest_count = 0;
389 subname = tempnam (0, "sub");
390 if (!subname) report (R_FATAL, "Can't name subtests file.");
392 extract_test (test, tempdir, res_name);
393 cmd = strmake (NULL, "%s --list", test->exename);
394 run_ex (cmd, subname, tempdir, 5000);
397 subfile = fopen (subname, "r");
399 report (R_ERROR, "Can't open subtests output of %s: %d",
403 total = fread (buffer, 1, sizeof buffer, subfile);
405 if (sizeof buffer == total) {
406 report (R_ERROR, "Subtest list of %s too big.",
407 test->name, sizeof buffer);
412 index = strstr (buffer, header);
414 report (R_ERROR, "Can't parse subtests output of %s",
418 index += sizeof header;
421 test->subtests = xmalloc (allocated * sizeof(char*));
422 index = strtok (index, whitespace);
424 if (test->subtest_count == allocated) {
426 test->subtests = xrealloc (test->subtests,
427 allocated * sizeof(char*));
429 test->subtests[test->subtest_count++] = strdup (index);
430 index = strtok (NULL, whitespace);
432 test->subtests = xrealloc (test->subtests,
433 test->subtest_count * sizeof(char*));
436 if (remove (subname))
437 report (R_WARNING, "Can't delete file '%s': %d",
443 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
446 const char* file = get_test_source_file(test->name, subtest);
447 const char* rev = get_file_rev(file);
448 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
450 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
451 status = run_ex (cmd, NULL, tempdir, 120000);
453 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
457 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
458 LPTSTR lpszName, LONG_PTR lParam)
465 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
466 LPTSTR lpszName, LONG_PTR lParam)
468 const char *tempdir = (const char *)lParam;
469 char dllname[MAX_PATH];
472 /* Check if the main dll is present on this system */
473 CharLowerA(lpszName);
474 strcpy(dllname, lpszName);
475 *strstr(dllname, testexe) = 0;
477 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
479 xprintf (" %s=dll is missing\n", dllname);
484 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
486 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
487 nr_of_tests += wine_tests[nr_of_files].subtest_count;
493 run_tests (char *logname)
496 char *tempdir, *shorttempdir;
498 char *strres, *eol, *nextline;
501 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
504 logname = tempnam (0, "res");
505 if (!logname) report (R_FATAL, "Can't name logfile.");
507 report (R_OUT, logname);
509 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
513 report (R_FATAL, "File %s already exists.", logname);
514 else report (R_FATAL, "Could not open logfile: %d", errno);
516 if (-1 == dup2 (logfile, 1))
517 report (R_FATAL, "Can't redirect stdout: %d", errno);
520 tempdir = tempnam (0, "wct");
522 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
523 shorttempdir = strdup (tempdir);
524 if (shorttempdir) { /* try stable path for ZoneAlarm */
525 strstr (shorttempdir, "wct")[3] = 0;
526 if (CreateDirectoryA (shorttempdir, NULL)) {
528 tempdir = shorttempdir;
529 } else free (shorttempdir);
531 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
532 report (R_FATAL, "Could not create directory: %s", tempdir);
533 report (R_DIR, tempdir);
535 xprintf ("Version 4\n");
536 strres = extract_rcdata (MAKEINTRESOURCE(WINE_BUILD), STRINGRES, &strsize);
537 xprintf ("Tests from build ");
538 if (strres) xprintf ("%.*s", strsize, strres);
539 else xprintf ("-\n");
540 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
541 xprintf ("Archive: ");
542 if (strres) xprintf ("%.*s", strsize, strres);
543 else xprintf ("-\n");
544 xprintf ("Tag: %s\n", tag);
545 xprintf ("Build info:\n");
546 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
548 eol = memchr (strres, '\n', strsize);
551 eol = strres + strsize;
553 strsize -= eol - strres + 1;
554 nextline = strsize?eol+1:NULL;
555 if (eol > strres && *(eol-1) == '\r') eol--;
557 xprintf (" %.*s\n", eol-strres, strres);
560 xprintf ("Operating system version:\n");
562 xprintf ("Dll info:\n" );
564 report (R_STATUS, "Counting tests");
565 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
566 EnumTestFileProc, (LPARAM)&nr_of_files))
567 report (R_FATAL, "Can't enumerate test files: %d",
569 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
571 report (R_STATUS, "Extracting tests");
572 report (R_PROGRESS, 0, nr_of_files);
575 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
576 extract_test_proc, (LPARAM)tempdir))
577 report (R_FATAL, "Can't enumerate test files: %d",
580 xprintf ("Test output:\n" );
582 report (R_DELTA, 0, "Extracting: Done");
584 report (R_STATUS, "Running tests");
585 report (R_PROGRESS, 1, nr_of_tests);
586 for (i = 0; i < nr_of_files; i++) {
587 struct wine_test *test = wine_tests + i;
590 for (j = 0; j < test->subtest_count; j++) {
591 report (R_STEP, "Running: %s:%s", test->name,
593 run_test (test, test->subtests[j], tempdir);
596 report (R_DELTA, 0, "Running: Done");
598 report (R_STATUS, "Cleaning up");
600 remove_dir (tempdir);
611 "Usage: winetest [OPTION]...\n\n"
612 " -c console mode, no GUI\n"
613 " -e preserve the environment\n"
614 " -h print this message and exit\n"
615 " -p shutdown when the tests are done\n"
616 " -q quiet mode, no output at all\n"
617 " -o FILE put report into FILE, do not submit\n"
618 " -s FILE submit FILE, do not run tests\n"
619 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
622 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
623 LPSTR cmdLine, int cmdShow)
625 char *logname = NULL;
626 const char *cp, *submit = NULL;
631 /* initialize the revision information first */
634 cmdLine = strtok (cmdLine, whitespace);
636 if (cmdLine[0] != '-' || cmdLine[2]) {
637 report (R_ERROR, "Not a single letter option: %s", cmdLine);
641 switch (cmdLine[1]) {
661 submit = strtok (NULL, whitespace);
663 report (R_WARNING, "ignoring tag for submission");
667 logname = strtok (NULL, whitespace);
670 tag = strtok (NULL, whitespace);
671 if (strlen (tag) > MAXTAGLEN)
672 report (R_FATAL, "tag is too long (maximum %d characters)",
674 cp = findbadtagchar (tag);
676 report (R_ERROR, "invalid char in tag: %c", *cp);
682 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
686 cmdLine = strtok (NULL, whitespace);
689 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
690 platform_wine[] = "WINETEST_PLATFORM=wine",
691 debug_yes[] = "WINETEST_DEBUG=1",
692 interactive_no[] = "WINETEST_INTERACTIVE=0",
693 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
696 report (R_STATUS, "Starting up");
698 if (!running_on_visible_desktop ())
699 report (R_FATAL, "Tests must be run on a visible desktop");
701 platform = running_under_wine () ? platform_wine : platform_windows;
703 if (reset_env && (putenv (platform) ||
704 putenv (debug_yes) ||
705 putenv (interactive_no) ||
706 putenv (report_success_no)))
707 report (R_FATAL, "Could not reset environment: %d", errno);
711 report (R_FATAL, "Please specify a tag (-t option) if "
712 "running noninteractive!");
713 if (guiAskTag () == IDABORT) exit (1);
718 logname = run_tests (NULL);
719 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
720 "test results?") == IDYES)
721 if (!send_file (logname) && remove (logname))
722 report (R_WARNING, "Can't remove logfile: %d.", errno);
724 } else run_tests (logname);
725 report (R_STATUS, "Finished");
730 TOKEN_PRIVILEGES npr;
732 /* enable the shutdown privilege for the current process */
733 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
735 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
736 npr.PrivilegeCount = 1;
737 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
738 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
741 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);