winetest: Put dll version information in the report.
[wine] / programs / winetest / main.c
1 /*
2  * Wine Conformance Test EXE
3  *
4  * Copyright 2003, 2004 Jakob Eriksson   (for Solid Form Sweden AB)
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2003 Ferenc Wagner
7  *
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.
12  *
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.
17  *
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
21  *
22  * This program is dedicated to Anna Lindh,
23  * Swedish Minister of Foreign Affairs.
24  * Anna was murdered September 11, 2003.
25  *
26  */
27
28 #include "config.h"
29 #include "wine/port.h"
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <errno.h>
35 #ifdef HAVE_UNISTD_H
36 #  include <unistd.h>
37 #endif
38 #include <windows.h>
39
40 #include "winetest.h"
41 #include "resource.h"
42
43 struct wine_test
44 {
45     char *name;
46     int resource;
47     int subtest_count;
48     char **subtests;
49     char *exename;
50 };
51
52 struct rev_info
53 {
54     const char* file;
55     const char* rev;
56 };
57
58 char *tag = NULL;
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";
64
65 static char * get_file_version(char * file_name)
66 {
67     static char version[32];
68     DWORD size;
69     DWORD handle;
70
71     size = GetFileVersionInfoSizeA(file_name, &handle);
72     if (size) {
73         char * data = xmalloc(size);
74         if (data) {
75             if (GetFileVersionInfoA(file_name, handle, size, data)) {
76                 static char backslash[] = "\\";
77                 VS_FIXEDFILEINFO *pFixedVersionInfo;
78                 UINT len;
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);
85                 } else
86                     sprintf(version, "version not available");
87             } else
88                 sprintf(version, "unknown");
89             free(data);
90         } else
91             sprintf(version, "failed");
92     } else
93         sprintf(version, "version not available");
94
95     return version;
96 }
97
98 static int running_under_wine (void)
99 {
100     HMODULE module = GetModuleHandleA("ntdll.dll");
101
102     if (!module) return 0;
103     return (GetProcAddress(module, "wine_server_call") != NULL);
104 }
105
106 static int running_on_visible_desktop (void)
107 {
108     HWND desktop;
109     HMODULE huser32 = GetModuleHandle("user32.dll");
110     FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
111     FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
112
113     desktop = GetDesktopWindow();
114     if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
115         return IsWindowVisible(desktop);
116
117     if (pGetProcessWindowStation && pGetUserObjectInformationA)
118     {
119         DWORD len;
120         HWINSTA wstation;
121         USEROBJECTFLAGS uoflags;
122
123         wstation = (HWINSTA)pGetProcessWindowStation();
124         assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
125         return (uoflags.dwFlags & WSF_VISIBLE) != 0;
126     }
127     return IsWindowVisible(desktop);
128 }
129
130 static void print_version (void)
131 {
132     OSVERSIONINFOEX ver;
133     BOOL ext;
134     int is_win2k3_r2;
135
136     ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
137     if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
138     {
139         ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
140         if (!GetVersionEx ((OSVERSIONINFO *) &ver))
141             report (R_FATAL, "Can't get OS version.");
142     }
143
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);
150
151     is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
152     if(is_win2k3_r2)
153         xprintf("    R2 build number=%d\n", is_win2k3_r2);
154
155     if (!ext) return;
156
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);
161 }
162
163 static inline int is_dot_dir(const char* x)
164 {
165     return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
166 }
167
168 static void remove_dir (const char *dir)
169 {
170     HANDLE  hFind;
171     WIN32_FIND_DATA wfd;
172     char path[MAX_PATH];
173     size_t dirlen = strlen (dir);
174
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;
180
181     do {
182         char *lp = wfd.cFileName;
183
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)
188             remove_dir(path);
189         else if (!DeleteFile (path))
190             report (R_WARNING, "Can't delete file %s: error %d",
191                     path, GetLastError ());
192     } while (FindNextFile (hFind, &wfd));
193     FindClose (hFind);
194     if (!RemoveDirectory (dir))
195         report (R_WARNING, "Can't remove directory %s: error %d",
196                 dir, GetLastError ());
197 }
198
199 static const char* get_test_source_file(const char* test, const char* subtest)
200 {
201     static const char* special_dirs[][2] = {
202         { 0, 0 }
203     };
204     static char buffer[MAX_PATH];
205     int i;
206
207     for (i = 0; special_dirs[i][0]; i++) {
208         if (strcmp(test, special_dirs[i][0]) == 0) {
209             test = special_dirs[i][1];
210             break;
211         }
212     }
213
214     snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
215     return buffer;
216 }
217
218 static const char* get_file_rev(const char* file)
219 {
220     const struct rev_info* rev;
221  
222     for(rev = rev_infos; rev->file; rev++) {
223         if (strcmp(rev->file, file) == 0) return rev->rev;
224     }
225
226     return "-";
227 }
228
229 static void extract_rev_infos (void)
230 {
231     char revinfo[256], *p;
232     int size = 0, i;
233     unsigned int len;
234     HMODULE module = GetModuleHandle (NULL);
235
236     for (i = 0; TRUE; i++) {
237         if (i >= size) {
238             size += 100;
239             rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
240         }
241         memset(rev_infos + i, 0, sizeof(rev_infos[i]));
242
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);
249         *p = 0;
250         rev_infos[i].file = strdup(revinfo);
251         rev_infos[i].rev = strdup(p + 1);
252     }
253 }
254
255 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
256 {
257     HRSRC rsrc;
258     HGLOBAL hdl;
259     LPVOID addr;
260     
261     if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
262         !(*size = SizeofResource (0, rsrc)) ||
263         !(hdl = LoadResource (0, rsrc)) ||
264         !(addr = LockResource (hdl)))
265         return NULL;
266     return addr;
267 }
268
269 /* Fills in the name and exename fields */
270 static void
271 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
272 {
273     BYTE* code;
274     DWORD size;
275     FILE* fout;
276     char *exepos;
277
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);
285     *exepos = 0;
286     test->name = xrealloc (test->name, exepos - test->name + 1);
287     report (R_STEP, "Extracting: %s", test->name);
288
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.",
292                                test->exename);
293 }
294
295 /* Run a command for MS milliseconds.  If OUT != NULL, also redirect
296    stdout to there.
297
298    Return the exit status, -2 if can't create process or the return
299    value of WaitForSingleObject.
300  */
301 static int
302 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
303 {
304     STARTUPINFO si;
305     PROCESS_INFORMATION pi;
306     int fd, oldstdout = -1;
307     DWORD wait, status;
308
309     GetStartupInfo (&si);
310     si.dwFlags = 0;
311
312     if (out) {
313         fd = open (out, O_WRONLY | O_CREAT, 0666);
314         if (-1 == fd)
315             report (R_FATAL, "Can't open '%s': %d", out, errno);
316         oldstdout = dup (1);
317         if (-1 == oldstdout)
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);
321         close (fd);
322     }
323
324     if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
325                          NULL, tempdir, &si, &pi)) {
326         status = -2;
327     } else {
328         CloseHandle (pi.hThread);
329         wait = WaitForSingleObject (pi.hProcess, ms);
330         if (wait == WAIT_OBJECT_0) {
331             GetExitCodeProcess (pi.hProcess, &status);
332         } else {
333             switch (wait) {
334             case WAIT_FAILED:
335                 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
336                         GetLastError ());
337                 break;
338             case WAIT_TIMEOUT:
339                 report (R_ERROR, "Process '%s' timed out.", cmd);
340                 break;
341             default:
342                 report (R_ERROR, "Wait returned %d", wait);
343             }
344             status = wait;
345             if (!TerminateProcess (pi.hProcess, 257))
346                 report (R_ERROR, "TerminateProcess failed: %d",
347                         GetLastError ());
348             wait = WaitForSingleObject (pi.hProcess, 5000);
349             switch (wait) {
350             case WAIT_FAILED:
351                 report (R_ERROR,
352                         "Wait for termination of '%s' failed: %d",
353                         cmd, GetLastError ());
354                 break;
355             case WAIT_OBJECT_0:
356                 break;
357             case WAIT_TIMEOUT:
358                 report (R_ERROR, "Can't kill process '%s'", cmd);
359                 break;
360             default:
361                 report (R_ERROR, "Waiting for termination: %d",
362                         wait);
363             }
364         }
365         CloseHandle (pi.hProcess);
366     }
367
368     if (out) {
369         close (1);
370         if (-1 == dup2 (oldstdout, 1))
371             report (R_FATAL, "Can't recover stdout: %d", errno);
372         close (oldstdout);
373     }
374     return status;
375 }
376
377 static void
378 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
379 {
380     char *subname, *cmd;
381     FILE *subfile;
382     size_t total;
383     char buffer[8192], *index;
384     static const char header[] = "Valid test names:";
385     int allocated;
386
387     test->subtest_count = 0;
388
389     subname = tempnam (0, "sub");
390     if (!subname) report (R_FATAL, "Can't name subtests file.");
391
392     extract_test (test, tempdir, res_name);
393     cmd = strmake (NULL, "%s --list", test->exename);
394     run_ex (cmd, subname, tempdir, 5000);
395     free (cmd);
396
397     subfile = fopen (subname, "r");
398     if (!subfile) {
399         report (R_ERROR, "Can't open subtests output of %s: %d",
400                 test->name, errno);
401         goto quit;
402     }
403     total = fread (buffer, 1, sizeof buffer, subfile);
404     fclose (subfile);
405     if (sizeof buffer == total) {
406         report (R_ERROR, "Subtest list of %s too big.",
407                 test->name, sizeof buffer);
408         goto quit;
409     }
410     buffer[total] = 0;
411
412     index = strstr (buffer, header);
413     if (!index) {
414         report (R_ERROR, "Can't parse subtests output of %s",
415                 test->name);
416         goto quit;
417     }
418     index += sizeof header;
419
420     allocated = 10;
421     test->subtests = xmalloc (allocated * sizeof(char*));
422     index = strtok (index, whitespace);
423     while (index) {
424         if (test->subtest_count == allocated) {
425             allocated *= 2;
426             test->subtests = xrealloc (test->subtests,
427                                        allocated * sizeof(char*));
428         }
429         test->subtests[test->subtest_count++] = strdup (index);
430         index = strtok (NULL, whitespace);
431     }
432     test->subtests = xrealloc (test->subtests,
433                                test->subtest_count * sizeof(char*));
434
435  quit:
436     if (remove (subname))
437         report (R_WARNING, "Can't delete file '%s': %d",
438                 subname, errno);
439     free (subname);
440 }
441
442 static void
443 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
444 {
445     int status;
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);
449
450     xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
451     status = run_ex (cmd, NULL, tempdir, 120000);
452     free (cmd);
453     xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
454 }
455
456 static BOOL CALLBACK
457 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
458                   LPTSTR lpszName, LONG_PTR lParam)
459 {
460     (*(int*)lParam)++;
461     return TRUE;
462 }
463
464 static BOOL CALLBACK
465 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
466                    LPTSTR lpszName, LONG_PTR lParam)
467 {
468     const char *tempdir = (const char *)lParam;
469     char dllname[MAX_PATH];
470     HMODULE dll;
471
472     /* Check if the main dll is present on this system */
473     CharLowerA(lpszName);
474     strcpy(dllname, lpszName);
475     *strstr(dllname, testexe) = 0;
476
477     dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
478     if (!dll) {
479         xprintf ("    %s=dll is missing\n", dllname);
480         return TRUE;
481     }
482     FreeLibrary(dll);
483
484     xprintf ("    %s=%s\n", dllname, get_file_version(dllname));
485
486     get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
487     nr_of_tests += wine_tests[nr_of_files].subtest_count;
488     nr_of_files++;
489     return TRUE;
490 }
491
492 static char *
493 run_tests (char *logname)
494 {
495     int i;
496     char *tempdir, *shorttempdir;
497     int logfile;
498     char *strres, *eol, *nextline;
499     DWORD strsize;
500
501     SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
502
503     if (!logname) {
504         logname = tempnam (0, "res");
505         if (!logname) report (R_FATAL, "Can't name logfile.");
506     }
507     report (R_OUT, logname);
508
509     logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
510                     0666);
511     if (-1 == logfile) {
512         if (EEXIST == errno)
513             report (R_FATAL, "File %s already exists.", logname);
514         else report (R_FATAL, "Could not open logfile: %d", errno);
515     }
516     if (-1 == dup2 (logfile, 1))
517         report (R_FATAL, "Can't redirect stdout: %d", errno);
518     close (logfile);
519
520     tempdir = tempnam (0, "wct");
521     if (!tempdir)
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)) {
527             free (tempdir);
528             tempdir = shorttempdir;
529         } else free (shorttempdir);
530     }
531     if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
532         report (R_FATAL, "Could not create directory: %s", tempdir);
533     report (R_DIR, tempdir);
534
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);
547     while (strres) {
548         eol = memchr (strres, '\n', strsize);
549         if (!eol) {
550             nextline = NULL;
551             eol = strres + strsize;
552         } else {
553             strsize -= eol - strres + 1;
554             nextline = strsize?eol+1:NULL;
555             if (eol > strres && *(eol-1) == '\r') eol--;
556         }
557         xprintf ("    %.*s\n", eol-strres, strres);
558         strres = nextline;
559     }
560     xprintf ("Operating system version:\n");
561     print_version ();
562     xprintf ("Dll info:\n" );
563
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",
568                 GetLastError ());
569     wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
570
571     report (R_STATUS, "Extracting tests");
572     report (R_PROGRESS, 0, nr_of_files);
573     nr_of_files = 0;
574     nr_of_tests = 0;
575     if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
576                             extract_test_proc, (LPARAM)tempdir))
577         report (R_FATAL, "Can't enumerate test files: %d",
578                 GetLastError ());
579
580     xprintf ("Test output:\n" );
581
582     report (R_DELTA, 0, "Extracting: Done");
583
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;
588         int j;
589
590         for (j = 0; j < test->subtest_count; j++) {
591             report (R_STEP, "Running: %s:%s", test->name,
592                     test->subtests[j]);
593             run_test (test, test->subtests[j], tempdir);
594         }
595     }
596     report (R_DELTA, 0, "Running: Done");
597
598     report (R_STATUS, "Cleaning up");
599     close (1);
600     remove_dir (tempdir);
601     free (tempdir);
602     free (wine_tests);
603
604     return logname;
605 }
606
607 static void
608 usage (void)
609 {
610     fprintf (stderr,
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 "  -q       quiet mode, no output at all\n"
616 "  -o FILE  put report into FILE, do not submit\n"
617 "  -s FILE  submit FILE, do not run tests\n"
618 "  -t TAG   include TAG of characters [-.0-9a-zA-Z] in the report\n");
619 }
620
621 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
622                     LPSTR cmdLine, int cmdShow)
623 {
624     char *logname = NULL;
625     const char *cp, *submit = NULL;
626     int reset_env = 1;
627     int interactive = 1;
628
629     /* initialize the revision information first */
630     extract_rev_infos();
631
632     cmdLine = strtok (cmdLine, whitespace);
633     while (cmdLine) {
634         if (cmdLine[0] != '-' || cmdLine[2]) {
635             report (R_ERROR, "Not a single letter option: %s", cmdLine);
636             usage ();
637             exit (2);
638         }
639         switch (cmdLine[1]) {
640         case 'c':
641             report (R_TEXTMODE);
642             interactive = 0;
643             break;
644         case 'e':
645             reset_env = 0;
646             break;
647         case 'h':
648             usage ();
649             exit (0);
650         case 'q':
651             report (R_QUIET);
652             interactive = 0;
653             break;
654         case 's':
655             submit = strtok (NULL, whitespace);
656             if (tag)
657                 report (R_WARNING, "ignoring tag for submission");
658             send_file (submit);
659             break;
660         case 'o':
661             logname = strtok (NULL, whitespace);
662             break;
663         case 't':
664             tag = strtok (NULL, whitespace);
665             if (strlen (tag) > MAXTAGLEN)
666                 report (R_FATAL, "tag is too long (maximum %d characters)",
667                         MAXTAGLEN);
668             cp = findbadtagchar (tag);
669             if (cp) {
670                 report (R_ERROR, "invalid char in tag: %c", *cp);
671                 usage ();
672                 exit (2);
673             }
674             break;
675         default:
676             report (R_ERROR, "invalid option: -%c", cmdLine[1]);
677             usage ();
678             exit (2);
679         }
680         cmdLine = strtok (NULL, whitespace);
681     }
682     if (!submit) {
683         static CHAR platform_windows[]  = "WINETEST_PLATFORM=windows",
684                     platform_wine[]     = "WINETEST_PLATFORM=wine",
685                     debug_yes[]         = "WINETEST_DEBUG=1",
686                     interactive_no[]    = "WINETEST_INTERACTIVE=0",
687                     report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
688         CHAR *platform;
689
690         report (R_STATUS, "Starting up");
691
692         if (!running_on_visible_desktop ())
693             report (R_FATAL, "Tests must be run on a visible desktop");
694
695         platform = running_under_wine () ? platform_wine : platform_windows;
696
697         if (reset_env && (putenv (platform) ||
698                           putenv (debug_yes)        ||
699                           putenv (interactive_no)   ||
700                           putenv (report_success_no)))
701             report (R_FATAL, "Could not reset environment: %d", errno);
702
703         if (!tag) {
704             if (!interactive)
705                 report (R_FATAL, "Please specify a tag (-t option) if "
706                         "running noninteractive!");
707             if (guiAskTag () == IDABORT) exit (1);
708         }
709         report (R_TAG);
710
711         if (!logname) {
712             logname = run_tests (NULL);
713             if (report (R_ASK, MB_YESNO, "Do you want to submit the "
714                         "test results?") == IDYES)
715                 if (!send_file (logname) && remove (logname))
716                     report (R_WARNING, "Can't remove logfile: %d.", errno);
717             free (logname);
718         } else run_tests (logname);
719         report (R_STATUS, "Finished");
720     }
721     exit (0);
722 }