push 5b66f3b36e7323272378316c923222b908f6e2d3
[wine/hacks.git] / programs / winetest / main.c
blob045845a355273ec6c02016b1c9b8972b0686133e
1 /*
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.
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdio.h>
32 #include <assert.h>
33 #include <windows.h>
35 #include "winetest.h"
36 #include "resource.h"
38 struct wine_test
40 char *name;
41 int resource;
42 int subtest_count;
43 char **subtests;
44 char *exename;
47 char *tag = NULL;
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];
57 DWORD size;
58 DWORD handle;
60 size = GetFileVersionInfoSizeA(file_name, &handle);
61 if (size) {
62 char * data = xmalloc(size);
63 if (data) {
64 if (GetFileVersionInfoA(file_name, handle, size, data)) {
65 static char backslash[] = "\\";
66 VS_FIXEDFILEINFO *pFixedVersionInfo;
67 UINT len;
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);
74 } else
75 sprintf(version, "version not available");
76 } else
77 sprintf(version, "unknown");
78 free(data);
79 } else
80 sprintf(version, "failed");
81 } else
82 sprintf(version, "version not available");
84 return version;
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)
97 HWND desktop;
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)
108 DWORD len;
109 HWINSTA wstation;
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)
121 OSVERSIONINFOEX ver;
122 BOOL ext;
123 int is_win2k3_r2;
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);
145 if(is_win2k3_r2)
146 xprintf(" R2 build number=%d\n", is_win2k3_r2);
148 if (!ext) return;
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)
163 HANDLE hFind;
164 WIN32_FIND_DATA wfd;
165 char path[MAX_PATH];
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;
174 do {
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)
181 remove_dir(path);
182 else if (!DeleteFile (path))
183 report (R_WARNING, "Can't delete file %s: error %d",
184 path, GetLastError ());
185 } while (FindNextFile (hFind, &wfd));
186 FindClose (hFind);
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] = {
195 { 0, 0 }
197 static char buffer[MAX_PATH];
198 int i;
200 for (i = 0; special_dirs[i][0]; i++) {
201 if (strcmp(test, special_dirs[i][0]) == 0) {
202 test = special_dirs[i][1];
203 break;
207 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
208 return buffer;
211 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
213 HRSRC rsrc;
214 HGLOBAL hdl;
215 LPVOID addr;
217 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
218 !(*size = SizeofResource (0, rsrc)) ||
219 !(hdl = LoadResource (0, rsrc)) ||
220 !(addr = LockResource (hdl)))
221 return NULL;
222 return addr;
225 /* Fills in the name and exename fields */
226 static void
227 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
229 BYTE* code;
230 DWORD size;
231 char *exepos;
232 HANDLE hfile;
233 DWORD written;
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);
242 *exepos = 0;
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);
254 CloseHandle(hfile);
257 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
258 stdout to there.
260 Return the exit status, -2 if can't create process or the return
261 value of WaitForSingleObject.
263 static int
264 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
266 STARTUPINFO si;
267 PROCESS_INFORMATION pi;
268 DWORD wait, status;
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)) {
278 status = -2;
279 } else {
280 CloseHandle (pi.hThread);
281 wait = WaitForSingleObject (pi.hProcess, ms);
282 if (wait == WAIT_OBJECT_0) {
283 GetExitCodeProcess (pi.hProcess, &status);
284 } else {
285 switch (wait) {
286 case WAIT_FAILED:
287 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
288 GetLastError ());
289 break;
290 case WAIT_TIMEOUT:
291 report (R_ERROR, "Process '%s' timed out.", cmd);
292 break;
293 default:
294 report (R_ERROR, "Wait returned %d", wait);
296 status = wait;
297 if (!TerminateProcess (pi.hProcess, 257))
298 report (R_ERROR, "TerminateProcess failed: %d",
299 GetLastError ());
300 wait = WaitForSingleObject (pi.hProcess, 5000);
301 switch (wait) {
302 case WAIT_FAILED:
303 report (R_ERROR,
304 "Wait for termination of '%s' failed: %d",
305 cmd, GetLastError ());
306 break;
307 case WAIT_OBJECT_0:
308 break;
309 case WAIT_TIMEOUT:
310 report (R_ERROR, "Can't kill process '%s'", cmd);
311 break;
312 default:
313 report (R_ERROR, "Waiting for termination: %d",
314 wait);
317 CloseHandle (pi.hProcess);
320 return status;
323 static void
324 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
326 char *cmd;
327 HANDLE subfile;
328 DWORD total;
329 char buffer[8192], *index;
330 static const char header[] = "Valid test names:";
331 int allocated;
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());
360 goto quit;
363 extract_test (test, tempdir, res_name);
364 cmd = strmake (NULL, "%s --list", test->exename);
365 run_ex (cmd, subfile, tempdir, 5000);
366 free (cmd);
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);
374 goto quit;
376 buffer[total] = 0;
378 index = strstr (buffer, header);
379 if (!index) {
380 report (R_ERROR, "Can't parse subtests output of %s",
381 test->name);
382 goto quit;
384 index += sizeof header;
386 allocated = 10;
387 test->subtests = xmalloc (allocated * sizeof(char*));
388 index = strtok (index, whitespace);
389 while (index) {
390 if (test->subtest_count == allocated) {
391 allocated *= 2;
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*));
401 quit:
402 if (!DeleteFileA (subname))
403 report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
406 static void
407 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
409 int status;
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);
415 free (cmd);
416 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
419 static BOOL CALLBACK
420 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
421 LPTSTR lpszName, LONG_PTR lParam)
423 (*(int*)lParam)++;
424 return TRUE;
427 static BOOL CALLBACK
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];
433 HMODULE dll;
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);
441 if (!dll) {
442 xprintf (" %s=dll is missing\n", dllname);
443 return TRUE;
445 FreeLibrary(dll);
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;
451 nr_of_files++;
452 return TRUE;
455 static char *
456 run_tests (char *logname)
458 int i;
459 char *strres, *eol, *nextline;
460 DWORD strsize;
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%%).");
469 if (!logname) {
470 static char tmpname[MAX_PATH];
471 if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
472 report (R_FATAL, "Can't name logfile.");
473 logname = tmpname;
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);
521 while (strres) {
522 eol = memchr (strres, '\n', strsize);
523 if (!eol) {
524 nextline = NULL;
525 eol = strres + strsize;
526 } else {
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);
532 strres = nextline;
534 xprintf ("Operating system version:\n");
535 print_version ();
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",
542 GetLastError ());
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);
547 nr_of_files = 0;
548 nr_of_tests = 0;
549 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
550 extract_test_proc, (LPARAM)tempdir))
551 report (R_FATAL, "Can't enumerate test files: %d",
552 GetLastError ());
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;
562 int j;
564 for (j = 0; j < test->subtest_count; j++) {
565 report (R_STEP, "Running: %s:%s", test->name,
566 test->subtests[j]);
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 );
574 logfile = 0;
575 remove_dir (tempdir);
576 free (wine_tests);
578 return logname;
581 static void
582 usage (void)
584 fprintf (stderr,
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;
601 int reset_env = 1;
602 int poweroff = 0;
603 int interactive = 1;
605 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
607 cmdLine = strtok (cmdLine, whitespace);
608 while (cmdLine) {
609 if (cmdLine[0] != '-' || cmdLine[2]) {
610 report (R_ERROR, "Not a single letter option: %s", cmdLine);
611 usage ();
612 exit (2);
614 switch (cmdLine[1]) {
615 case 'c':
616 report (R_TEXTMODE);
617 interactive = 0;
618 break;
619 case 'e':
620 reset_env = 0;
621 break;
622 case 'h':
623 case '?':
624 usage ();
625 exit (0);
626 case 'p':
627 poweroff = 1;
628 break;
629 case 'q':
630 report (R_QUIET);
631 interactive = 0;
632 break;
633 case 's':
634 submit = strtok (NULL, whitespace);
635 if (tag)
636 report (R_WARNING, "ignoring tag for submission");
637 send_file (submit);
638 break;
639 case 'o':
640 logname = strtok (NULL, whitespace);
641 break;
642 case 't':
643 tag = strtok (NULL, whitespace);
644 if (strlen (tag) > MAXTAGLEN)
645 report (R_FATAL, "tag is too long (maximum %d characters)",
646 MAXTAGLEN);
647 cp = findbadtagchar (tag);
648 if (cp) {
649 report (R_ERROR, "invalid char in tag: %c", *cp);
650 usage ();
651 exit (2);
653 break;
654 default:
655 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
656 usage ();
657 exit (2);
659 cmdLine = strtok (NULL, whitespace);
661 if (!submit) {
662 report (R_STATUS, "Starting up");
664 if (!running_on_visible_desktop ())
665 report (R_FATAL, "Tests must be run on a visible desktop");
667 if (reset_env)
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" );
675 if (!tag) {
676 if (!interactive)
677 report (R_FATAL, "Please specify a tag (-t option) if "
678 "running noninteractive!");
679 if (guiAskTag () == IDABORT) exit (1);
681 report (R_TAG);
683 if (!build_id[0])
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." );
687 if (!logname) {
688 logname = run_tests (NULL);
689 if (build_id[0] &&
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");
696 if (poweroff)
698 HANDLE hToken;
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);
708 CloseHandle(hToken);
710 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
712 exit (0);