main.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  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. #define COBJMACROS
  28. #include <stdio.h>
  29. #include <assert.h>
  30. #include <windows.h>
  31. #include <commctrl.h>
  32. #include <winternl.h>
  33. #include <mshtml.h>
  34. #include "winetest.h"
  35. #include "resource.h"
  36. /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
  37. #define SKIP_LIMIT 10
  38. /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
  39. #define FAILURES_LIMIT 50
  40. /* Maximum output size for individual test */
  41. #define MAX_OUTPUT_SIZE (32 * 1024)
  42. struct wine_test
  43. {
  44. char *name;
  45. int subtest_count;
  46. char **subtests;
  47. char *exename;
  48. char *maindllpath;
  49. };
  50. char *tag = NULL;
  51. char *description = NULL;
  52. char *url = NULL;
  53. char *email = NULL;
  54. BOOL aborting = FALSE;
  55. static struct wine_test *wine_tests;
  56. static int nr_of_files, nr_of_tests, nr_of_skips;
  57. static int nr_native_dlls;
  58. static const char whitespace[] = " \t\r\n";
  59. static const char testexe[] = "_test.exe";
  60. static char build_id[64];
  61. static BOOL is_wow64;
  62. static int failures;
  63. static int quiet_mode;
  64. static HANDLE logfile;
  65. static HANDLE junit;
  66. /* filters for running only specific tests */
  67. static char **filters;
  68. static unsigned int nb_filters;
  69. static unsigned int alloc_filters;
  70. static BOOL exclude_tests = FALSE;
  71. /* Needed to check for .NET dlls */
  72. static HMODULE hmscoree;
  73. static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
  74. /* For SxS DLLs e.g. msvcr90 */
  75. static HANDLE (WINAPI *pCreateActCtxA)(PACTCTXA);
  76. static BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR *);
  77. static BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
  78. static void (WINAPI *pReleaseActCtx)(HANDLE);
  79. /* To store the current PATH setting (related to .NET only provided dlls) */
  80. static char *curpath;
  81. /* check if test is being filtered out */
  82. static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
  83. {
  84. char *p, dllname[MAX_PATH];
  85. unsigned int i, len;
  86. strcpy( dllname, module );
  87. CharLowerA( dllname );
  88. p = strstr( dllname, testexe );
  89. if (p) *p = 0;
  90. len = strlen(dllname);
  91. if (!nb_filters) return exclude_tests;
  92. for (i = 0; i < nb_filters; i++)
  93. {
  94. if (!strncmp( dllname, filters[i], len ))
  95. {
  96. if (!filters[i][len]) return exclude_tests;
  97. if (filters[i][len] != ':') continue;
  98. if (testname && !strcmp( testname, &filters[i][len+1] )) return exclude_tests;
  99. if (!testname && !exclude_tests) return FALSE;
  100. }
  101. }
  102. return !exclude_tests;
  103. }
  104. static void add_filter( const char *name )
  105. {
  106. if (name[0] == '@')
  107. {
  108. char *p, *str, buffer[256];
  109. FILE *f = fopen( name + 1, "rt" );
  110. if (!f) return;
  111. while (fgets( buffer, sizeof(buffer), f ))
  112. {
  113. p = buffer;
  114. while (*p == ' ' || *p == '\t') p++;
  115. if (*p == '#') continue;
  116. str = p;
  117. while (*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n') p++;
  118. *p = 0;
  119. add_filter( str );
  120. }
  121. fclose( f );
  122. return;
  123. }
  124. if (nb_filters >= alloc_filters)
  125. {
  126. alloc_filters = max( alloc_filters * 2, 64 );
  127. filters = xrealloc( filters, alloc_filters * sizeof(*filters) );
  128. }
  129. filters[nb_filters++] = xstrdup(name);
  130. }
  131. static HANDLE create_output_file( const char *name )
  132. {
  133. SECURITY_ATTRIBUTES sa;
  134. HANDLE file;
  135. /* make handle inheritable */
  136. sa.nLength = sizeof(sa);
  137. sa.lpSecurityDescriptor = NULL;
  138. sa.bInheritHandle = TRUE;
  139. file = CreateFileA( name, GENERIC_READ|GENERIC_WRITE,
  140. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  141. &sa, CREATE_ALWAYS, 0, NULL );
  142. if (file == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_PARAMETER)
  143. {
  144. /* FILE_SHARE_DELETE not supported on win9x */
  145. file = CreateFileA( name, GENERIC_READ|GENERIC_WRITE,
  146. FILE_SHARE_READ | FILE_SHARE_WRITE,
  147. &sa, CREATE_ALWAYS, 0, NULL );
  148. }
  149. return file;
  150. }
  151. static HANDLE create_temp_file( char name[MAX_PATH] )
  152. {
  153. char tmpdir[MAX_PATH];
  154. if (!GetTempPathA( MAX_PATH, tmpdir ) ||
  155. !GetTempFileNameA( tmpdir, "out", 0, name ))
  156. report (R_FATAL, "Can't name temp file.");
  157. return create_output_file( name );
  158. }
  159. static void close_temp_file( const char *name, HANDLE file )
  160. {
  161. CloseHandle( file );
  162. DeleteFileA( name );
  163. }
  164. static char *flush_temp_file( const char *name, HANDLE file, DWORD *retsize )
  165. {
  166. DWORD size = SetFilePointer( file, 0, NULL, FILE_CURRENT );
  167. char *buffer = xalloc( size + 1 );
  168. SetFilePointer( file, 0, NULL, FILE_BEGIN );
  169. if (!ReadFile( file, buffer, size, retsize, NULL )) *retsize = 0;
  170. close_temp_file( name, file );
  171. buffer[*retsize] = 0;
  172. return buffer;
  173. }
  174. static char * get_file_version(char * file_name)
  175. {
  176. static char version[32];
  177. DWORD size;
  178. DWORD handle;
  179. size = GetFileVersionInfoSizeA(file_name, &handle);
  180. if (size) {
  181. char * data = xalloc(size);
  182. if (GetFileVersionInfoA(file_name, handle, size, data)) {
  183. static const char backslash[] = "\\";
  184. VS_FIXEDFILEINFO *pFixedVersionInfo;
  185. UINT len;
  186. if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
  187. sprintf(version, "%ld.%ld.%ld.%ld",
  188. pFixedVersionInfo->dwFileVersionMS >> 16,
  189. pFixedVersionInfo->dwFileVersionMS & 0xffff,
  190. pFixedVersionInfo->dwFileVersionLS >> 16,
  191. pFixedVersionInfo->dwFileVersionLS & 0xffff);
  192. } else
  193. sprintf(version, "version not found");
  194. } else
  195. sprintf(version, "version error %lu", GetLastError());
  196. free(data);
  197. } else if (GetLastError() == ERROR_FILE_NOT_FOUND)
  198. sprintf(version, "dll is missing");
  199. else
  200. sprintf(version, "version not present %lu", GetLastError());
  201. return version;
  202. }
  203. static BOOL running_under_wine (void)
  204. {
  205. HMODULE module = GetModuleHandleA("ntdll.dll");
  206. if (!module) return FALSE;
  207. return (GetProcAddress(module, "wine_server_call") != NULL);
  208. }
  209. static BOOL check_mount_mgr(void)
  210. {
  211. HANDLE handle = CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ,
  212. FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
  213. if (handle == INVALID_HANDLE_VALUE) return FALSE;
  214. CloseHandle( handle );
  215. return TRUE;
  216. }
  217. static BOOL check_wow64_registry(void)
  218. {
  219. char buffer[MAX_PATH];
  220. DWORD type, size = MAX_PATH;
  221. HKEY hkey;
  222. BOOL ret;
  223. if (!is_wow64) return TRUE;
  224. if (RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey ))
  225. return FALSE;
  226. ret = !RegQueryValueExA( hkey, "ProgramFilesDir (x86)", NULL, &type, (BYTE *)buffer, &size );
  227. RegCloseKey( hkey );
  228. return ret;
  229. }
  230. static BOOL check_display_driver(void)
  231. {
  232. HWND hwnd = CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  233. 0, 0, GetModuleHandleA(0), 0 );
  234. if (!hwnd) return FALSE;
  235. DestroyWindow( hwnd );
  236. return TRUE;
  237. }
  238. static BOOL running_on_visible_desktop (void)
  239. {
  240. HWND desktop;
  241. HMODULE huser32 = GetModuleHandleA("user32.dll");
  242. HWINSTA (WINAPI *pGetProcessWindowStation)(void);
  243. BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
  244. pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
  245. pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
  246. desktop = GetDesktopWindow();
  247. if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
  248. return IsWindowVisible(desktop);
  249. if (pGetProcessWindowStation && pGetUserObjectInformationA)
  250. {
  251. DWORD len;
  252. HWINSTA wstation;
  253. USEROBJECTFLAGS uoflags;
  254. wstation = pGetProcessWindowStation();
  255. assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
  256. return (uoflags.dwFlags & WSF_VISIBLE) != 0;
  257. }
  258. return IsWindowVisible(desktop);
  259. }
  260. static int running_as_admin (void)
  261. {
  262. PSID administrators = NULL;
  263. SID_IDENTIFIER_AUTHORITY nt_authority = { SECURITY_NT_AUTHORITY };
  264. HANDLE token;
  265. DWORD groups_size;
  266. PTOKEN_GROUPS groups;
  267. DWORD group_index;
  268. /* Create a well-known SID for the Administrators group. */
  269. if (! AllocateAndInitializeSid(&nt_authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
  270. DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
  271. &administrators))
  272. return -1;
  273. /* Get the process token */
  274. if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
  275. {
  276. FreeSid(administrators);
  277. return -1;
  278. }
  279. /* Get the group info from the token */
  280. groups_size = 0;
  281. GetTokenInformation(token, TokenGroups, NULL, 0, &groups_size);
  282. groups = xalloc(groups_size);
  283. if (! GetTokenInformation(token, TokenGroups, groups, groups_size, &groups_size))
  284. {
  285. free(groups);
  286. CloseHandle(token);
  287. FreeSid(administrators);
  288. return -1;
  289. }
  290. CloseHandle(token);
  291. /* Now check if the token groups include the Administrators group */
  292. for (group_index = 0; group_index < groups->GroupCount; group_index++)
  293. {
  294. if (EqualSid(groups->Groups[group_index].Sid, administrators))
  295. {
  296. free(groups);
  297. FreeSid(administrators);
  298. return 1;
  299. }
  300. }
  301. /* If we end up here we didn't find the Administrators group */
  302. free(groups);
  303. FreeSid(administrators);
  304. return 0;
  305. }
  306. static int running_elevated (void)
  307. {
  308. HANDLE token;
  309. TOKEN_ELEVATION elevation_info;
  310. DWORD size;
  311. /* Get the process token */
  312. if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
  313. return -1;
  314. /* Get the elevation info from the token */
  315. if (! GetTokenInformation(token, TokenElevation, &elevation_info,
  316. sizeof(TOKEN_ELEVATION), &size))
  317. {
  318. CloseHandle(token);
  319. return -1;
  320. }
  321. CloseHandle(token);
  322. return elevation_info.TokenIsElevated;
  323. }
  324. /* check for native dll when running under wine */
  325. static BOOL is_native_dll( HMODULE module )
  326. {
  327. static const char builtin_signature[] = "Wine builtin DLL";
  328. static const char fakedll_signature[] = "Wine placeholder DLL";
  329. const IMAGE_DOS_HEADER *dos;
  330. if (!running_under_wine()) return FALSE;
  331. if (!((ULONG_PTR)module & 1)) return FALSE; /* not loaded as datafile */
  332. /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
  333. dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
  334. if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
  335. if (dos->e_lfanew >= sizeof(*dos) + 32)
  336. {
  337. if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) )) return FALSE;
  338. if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
  339. }
  340. return TRUE;
  341. }
  342. /*
  343. * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
  344. * to install that component. To bypass this check we need to look at the version resource.
  345. */
  346. static BOOL is_stub_dll(const char *filename)
  347. {
  348. UINT size;
  349. DWORD ver;
  350. BOOL isstub = FALSE;
  351. char *p, *data;
  352. size = GetFileVersionInfoSizeA(filename, &ver);
  353. if (!size) return FALSE;
  354. data = xalloc(size);
  355. if (GetFileVersionInfoA(filename, ver, size, data))
  356. {
  357. char buf[256];
  358. sprintf(buf, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 1200);
  359. if (VerQueryValueA(data, buf, (void**)&p, &size))
  360. isstub = !lstrcmpiA("wcodstub.dll", p);
  361. }
  362. free(data);
  363. return isstub;
  364. }
  365. static int disable_crash_dialog(void)
  366. {
  367. HKEY key;
  368. DWORD type, data, size;
  369. int ret = 0;
  370. if (RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &key )) return 0;
  371. size = sizeof(data);
  372. if (RegQueryValueExA( key, "ShowCrashDialog", NULL, &type, (BYTE *)&data, &size )) ret = 1;
  373. else if (type != REG_DWORD || data) ret = 2;
  374. data = 0;
  375. RegSetValueExA( key, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&data, sizeof(data) );
  376. RegCloseKey( key );
  377. return ret;
  378. }
  379. static void restore_crash_dialog( int prev )
  380. {
  381. HKEY key;
  382. DWORD data = 1;
  383. if (!prev) return;
  384. if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\WineDbg", &key )) return;
  385. if (prev == 1) RegDeleteKeyValueA( key, NULL, "ShowCrashDialog" );
  386. else RegSetValueExA( key, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&data, sizeof(data) );
  387. RegCloseKey( key );
  388. }
  389. static void print_version (void)
  390. {
  391. #ifdef __i386__
  392. static const char platform[] = "i386";
  393. #elif defined(__x86_64__)
  394. static const char platform[] = "x86_64";
  395. #elif defined(__arm__)
  396. static const char platform[] = "arm";
  397. #elif defined(__aarch64__)
  398. static const char platform[] = "arm64";
  399. #else
  400. # error CPU unknown
  401. #endif
  402. OSVERSIONINFOEXA ver;
  403. RTL_OSVERSIONINFOEXW rtlver;
  404. BOOL ext;
  405. int is_win2k3_r2, is_admin, is_elevated;
  406. const char *(CDECL *wine_get_build_id)(void);
  407. HMODULE hntdll = GetModuleHandleA("ntdll.dll");
  408. void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
  409. BOOL (WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
  410. NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
  411. ver.dwOSVersionInfoSize = sizeof(ver);
  412. if (!(ext = GetVersionExA ((OSVERSIONINFOA *) &ver)))
  413. {
  414. ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
  415. if (!GetVersionExA ((OSVERSIONINFOA *) &ver))
  416. report (R_FATAL, "Can't get OS version.");
  417. }
  418. /* try to get non-faked values */
  419. if (ver.dwMajorVersion == 6 && ver.dwMinorVersion == 2)
  420. {
  421. rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
  422. pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
  423. pRtlGetVersion(&rtlver);
  424. ver.dwMajorVersion = rtlver.dwMajorVersion;
  425. ver.dwMinorVersion = rtlver.dwMinorVersion;
  426. ver.dwBuildNumber = rtlver.dwBuildNumber;
  427. ver.dwPlatformId = rtlver.dwPlatformId;
  428. ver.wServicePackMajor = rtlver.wServicePackMajor;
  429. ver.wServicePackMinor = rtlver.wServicePackMinor;
  430. ver.wSuiteMask = rtlver.wSuiteMask;
  431. ver.wProductType = rtlver.wProductType;
  432. WideCharToMultiByte(CP_ACP, 0, rtlver.szCSDVersion, -1, ver.szCSDVersion, sizeof(ver.szCSDVersion), NULL, NULL);
  433. }
  434. xprintf (" Platform=%s%s\n", platform, is_wow64 ? " (WOW64)" : "");
  435. xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
  436. xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
  437. is_admin = running_as_admin ();
  438. if (0 <= is_admin)
  439. {
  440. xprintf (" Account=%s", is_admin ? "admin" : "non-admin");
  441. is_elevated = running_elevated ();
  442. if (0 <= is_elevated)
  443. xprintf(", %s", is_elevated ? "elevated" : "not elevated");
  444. xprintf ("\n");
  445. }
  446. if (email)
  447. xprintf (" Submitter=%s\n", email );
  448. if (description)
  449. xprintf (" Description=%s\n", description );
  450. if (url)
  451. xprintf (" URL=%s\n", url );
  452. xprintf (" dwMajorVersion=%lu\n dwMinorVersion=%lu\n"
  453. " dwBuildNumber=%lu\n PlatformId=%lu\n szCSDVersion=%s\n",
  454. ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
  455. ver.dwPlatformId, ver.szCSDVersion);
  456. wine_get_build_id = (void *)GetProcAddress(hntdll, "wine_get_build_id");
  457. wine_get_host_version = (void *)GetProcAddress(hntdll, "wine_get_host_version");
  458. if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
  459. if (wine_get_host_version)
  460. {
  461. const char *sysname, *release;
  462. wine_get_host_version( &sysname, &release );
  463. xprintf( " Host system=%s\n Host version=%s\n", sysname, release );
  464. }
  465. is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
  466. if(is_win2k3_r2)
  467. xprintf(" R2 build number=%d\n", is_win2k3_r2);
  468. if (!ext) return;
  469. xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
  470. " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
  471. ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
  472. ver.wProductType, ver.wReserved);
  473. pGetProductInfo = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
  474. if (pGetProductInfo && !running_under_wine())
  475. {
  476. DWORD prodtype = 0;
  477. pGetProductInfo(ver.dwMajorVersion, ver.dwMinorVersion, ver.wServicePackMajor, ver.wServicePackMinor, &prodtype);
  478. xprintf(" dwProductInfo=%lu\n", prodtype);
  479. }
  480. }
  481. static void print_language(void)
  482. {
  483. HMODULE hkernel32;
  484. BOOL (WINAPI *pGetSystemPreferredUILanguages)(DWORD, PULONG, PZZWSTR, PULONG);
  485. LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
  486. LANGID (WINAPI *pGetThreadUILanguage)(void);
  487. xprintf (" SystemDefaultLCID=%04lx\n", GetSystemDefaultLCID());
  488. xprintf (" UserDefaultLCID=%04lx\n", GetUserDefaultLCID());
  489. xprintf (" ThreadLocale=%04lx\n", GetThreadLocale());
  490. hkernel32 = GetModuleHandleA("kernel32.dll");
  491. pGetSystemPreferredUILanguages = (void*)GetProcAddress(hkernel32, "GetSystemPreferredUILanguages");
  492. pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
  493. pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
  494. if (pGetSystemPreferredUILanguages && !running_under_wine())
  495. {
  496. WCHAR langW[32];
  497. ULONG num, size = ARRAY_SIZE(langW);
  498. if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID, &num, langW, &size))
  499. {
  500. char lang[32], *p = lang;
  501. WideCharToMultiByte(CP_ACP, 0, langW, size, lang, sizeof(lang), NULL, NULL);
  502. for (p += strlen(p) + 1; *p != '\0'; p += strlen(p) + 1) *(p - 1) = ',';
  503. xprintf (" SystemPreferredUILanguages=%s\n", lang);
  504. }
  505. }
  506. if (pGetUserDefaultUILanguage)
  507. xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
  508. if (pGetThreadUILanguage)
  509. xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
  510. xprintf (" KeyboardLayout=%p\n", GetKeyboardLayout(0));
  511. xprintf (" Country=%ld\n", GetUserGeoID(GEOCLASS_NATION));
  512. xprintf (" ACP=%d\n", GetACP());
  513. }
  514. static inline BOOL is_dot_dir(const char* x)
  515. {
  516. return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
  517. }
  518. static void remove_dir (const char *dir)
  519. {
  520. HANDLE hFind;
  521. WIN32_FIND_DATAA wfd;
  522. char path[MAX_PATH];
  523. size_t dirlen = strlen (dir);
  524. /* Make sure the directory exists before going further */
  525. memcpy (path, dir, dirlen);
  526. strcpy (path + dirlen++, "\\*");
  527. hFind = FindFirstFileA (path, &wfd);
  528. if (hFind == INVALID_HANDLE_VALUE) return;
  529. do {
  530. char *lp = wfd.cFileName;
  531. if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
  532. if (is_dot_dir (lp)) continue;
  533. strcpy (path + dirlen, lp);
  534. if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
  535. remove_dir(path);
  536. else if (!DeleteFileA(path))
  537. report (R_WARNING, "Can't delete file %s: error %d",
  538. path, GetLastError ());
  539. } while (FindNextFileA(hFind, &wfd));
  540. FindClose (hFind);
  541. if (!RemoveDirectoryA(dir))
  542. report (R_WARNING, "Can't remove directory %s: error %d",
  543. dir, GetLastError ());
  544. }
  545. static const char* get_test_source_file(const char* test, const char* subtest)
  546. {
  547. static char buffer[MAX_PATH];
  548. int len = strlen(test);
  549. if (len > 4 && !strcmp( test + len - 4, ".exe" ) &&
  550. strcmp( test, "ntoskrnl.exe" )) /* the one exception! */
  551. {
  552. len = sprintf(buffer, "programs/%s", test) - 4;
  553. buffer[len] = 0;
  554. }
  555. else len = sprintf(buffer, "dlls/%s", test);
  556. sprintf(buffer + len, "/tests/%s.c", subtest);
  557. return buffer;
  558. }
  559. static void* extract_rcdata (LPCSTR name, LPCSTR type, DWORD* size)
  560. {
  561. HRSRC rsrc;
  562. HGLOBAL hdl;
  563. LPVOID addr;
  564. if (!(rsrc = FindResourceA(NULL, name, type)) ||
  565. !(*size = SizeofResource (0, rsrc)) ||
  566. !(hdl = LoadResource (0, rsrc)) ||
  567. !(addr = LockResource (hdl)))
  568. return NULL;
  569. return addr;
  570. }
  571. /* Fills in the name and exename fields */
  572. static void
  573. extract_test (struct wine_test *test, const char *dir, LPSTR res_name)
  574. {
  575. BYTE* code;
  576. DWORD size;
  577. char *exepos;
  578. HANDLE hfile;
  579. DWORD written;
  580. code = extract_rcdata (res_name, "TESTRES", &size);
  581. if (!code) report (R_FATAL, "Can't find test resource %s: %d",
  582. res_name, GetLastError ());
  583. test->name = xstrdup( res_name );
  584. test->exename = strmake("%s\\%s", dir, test->name);
  585. exepos = strstr (test->name, testexe);
  586. if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
  587. *exepos = 0;
  588. test->name = xrealloc(test->name, exepos - test->name + 1);
  589. report (R_STEP, "Extracting: %s", test->name);
  590. hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
  591. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  592. if (hfile == INVALID_HANDLE_VALUE)
  593. report (R_FATAL, "Failed to open file %s.", test->exename);
  594. if (!WriteFile(hfile, code, size, &written, NULL))
  595. report (R_FATAL, "Failed to write file %s.", test->exename);
  596. CloseHandle(hfile);
  597. }
  598. static HANDLE get_admin_token(void)
  599. {
  600. TOKEN_ELEVATION_TYPE type;
  601. TOKEN_LINKED_TOKEN linked;
  602. DWORD size;
  603. if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenElevationType, &type, sizeof(type), &size)
  604. || type == TokenElevationTypeFull)
  605. return NULL;
  606. if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenLinkedToken, &linked, sizeof(linked), &size))
  607. return NULL;
  608. return linked.LinkedToken;
  609. }
  610. static DWORD wait_process( HANDLE process, DWORD timeout )
  611. {
  612. DWORD wait, diff = 0, start = GetTickCount();
  613. MSG msg;
  614. while (diff < timeout)
  615. {
  616. wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
  617. if (wait != WAIT_OBJECT_0 + 1) return wait;
  618. while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
  619. diff = GetTickCount() - start;
  620. }
  621. return WAIT_TIMEOUT;
  622. }
  623. static void append_path( const char *path)
  624. {
  625. char *newpath = strmake( "%s;%s", curpath, path );
  626. SetEnvironmentVariableA("PATH", newpath);
  627. free(newpath);
  628. }
  629. /* Run a command for MS milliseconds. If OUT != NULL, also redirect
  630. stdout to there.
  631. Return the exit status, -2 if can't create process or the return
  632. value of WaitForSingleObject.
  633. */
  634. static int
  635. run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms, BOOL nocritical, DWORD* pid)
  636. {
  637. STARTUPINFOA si;
  638. PROCESS_INFORMATION pi;
  639. DWORD wait, status, flags;
  640. UINT old_errmode;
  641. HANDLE token = NULL;
  642. GetStartupInfoA (&si);
  643. si.dwFlags = STARTF_USESTDHANDLES;
  644. si.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
  645. si.hStdOutput = out_file;
  646. si.hStdError = out_file;
  647. if (nocritical)
  648. {
  649. old_errmode = SetErrorMode(0);
  650. SetErrorMode(old_errmode | SEM_FAILCRITICALERRORS);
  651. flags = 0;
  652. }
  653. else
  654. flags = CREATE_DEFAULT_ERROR_MODE;
  655. /* Some tests cause a UAC prompt on Windows if the user is not elevated,
  656. * so to allow them to run unattended the relevant test units need to skip
  657. * the tests if so.
  658. *
  659. * However, we still want Wine to run as many tests as possible, so always
  660. * elevate ourselves. On Wine elevation isn't interactive. */
  661. if (running_under_wine())
  662. token = get_admin_token();
  663. if (!CreateProcessAsUserA(token, NULL, cmd, NULL, NULL, TRUE, flags, NULL, tempdir, &si, &pi))
  664. {
  665. if (nocritical) SetErrorMode(old_errmode);
  666. if (pid) *pid = 0;
  667. return -2;
  668. }
  669. if (nocritical) SetErrorMode(old_errmode);
  670. CloseHandle (pi.hThread);
  671. if (pid) *pid = pi.dwProcessId;
  672. status = wait_process( pi.hProcess, ms );
  673. switch (status)
  674. {
  675. case WAIT_OBJECT_0:
  676. GetExitCodeProcess (pi.hProcess, &status);
  677. CloseHandle (pi.hProcess);
  678. return status;
  679. case WAIT_FAILED:
  680. report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
  681. break;
  682. case WAIT_TIMEOUT:
  683. break;
  684. default:
  685. report (R_ERROR, "Wait returned %d", status);
  686. break;
  687. }
  688. if (!TerminateProcess (pi.hProcess, 257))
  689. report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
  690. wait = wait_process( pi.hProcess, 5000 );
  691. switch (wait)
  692. {
  693. case WAIT_OBJECT_0:
  694. break;
  695. case WAIT_FAILED:
  696. report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
  697. break;
  698. case WAIT_TIMEOUT:
  699. report (R_ERROR, "Can't kill process '%s'", cmd);
  700. break;
  701. default:
  702. report (R_ERROR, "Waiting for termination: %d", wait);
  703. break;
  704. }
  705. CloseHandle (pi.hProcess);
  706. return status;
  707. }
  708. static DWORD
  709. get_subtests (const char *tempdir, struct wine_test *test, LPSTR res_name)
  710. {
  711. char *cmd;
  712. HANDLE subfile;
  713. DWORD err, total;
  714. char *buffer, *index;
  715. static const char header[] = "Valid test names:";
  716. int status, allocated;
  717. char subname[MAX_PATH];
  718. test->subtest_count = 0;
  719. subfile = create_temp_file( subname );
  720. if (subfile == INVALID_HANDLE_VALUE) return GetLastError();
  721. cmd = strmake("%s --list", test->exename);
  722. if (test->maindllpath) {
  723. /* We need to add the path (to the main dll) to PATH */
  724. append_path(test->maindllpath);
  725. }
  726. status = run_ex (cmd, subfile, tempdir, 5000, TRUE, NULL);
  727. err = GetLastError();
  728. if (test->maindllpath) {
  729. /* Restore PATH again */
  730. SetEnvironmentVariableA("PATH", curpath);
  731. }
  732. free(cmd);
  733. if (status)
  734. {
  735. close_temp_file( subname, subfile );
  736. return status == -2 ? err : status;
  737. }
  738. buffer = flush_temp_file( subname, subfile, &total );
  739. index = strstr (buffer, header);
  740. if (!index) {
  741. report (R_ERROR, "Can't parse subtests output of %s",
  742. test->name);
  743. return ERROR_INTERNAL_ERROR;
  744. }
  745. index += sizeof header;
  746. allocated = 10;
  747. test->subtests = xalloc(allocated * sizeof(char*));
  748. index = strtok (index, whitespace);
  749. while (index) {
  750. if (test->subtest_count == allocated) {
  751. allocated *= 2;
  752. test->subtests = xrealloc(test->subtests, allocated * sizeof(char*));
  753. }
  754. test->subtests[test->subtest_count++] = xstrdup(index);
  755. index = strtok (NULL, whitespace);
  756. }
  757. test->subtests = xrealloc(test->subtests, test->subtest_count * sizeof(char*));
  758. free( buffer );
  759. return 0;
  760. }
  761. static char *xmlescape( const char *src, const char *end, int comment )
  762. {
  763. char *dst = calloc( 1, (end - src) * 6 + 1 ), *tmp;
  764. while (end > src && (end[-1] == '\r' || end[-1] == '\n')) end--;
  765. for (tmp = dst; tmp && src < end; src++)
  766. {
  767. if (comment && *src == '-') tmp += sprintf( tmp, "&#45;" );
  768. else if (comment) *tmp++ = *src;
  769. else if (*src == '&') tmp += sprintf( tmp, "&amp;" );
  770. else if (*src == '"') tmp += sprintf( tmp, "&quot;" );
  771. else if (*src == '<') tmp += sprintf( tmp, "&lt;" );
  772. else if (*src == '>') tmp += sprintf( tmp, "&gt;" );
  773. else if (*src < ' ' && *src != '\t' && *src != '\r' && *src != '\n')
  774. {
  775. char *esc = strmake( "\\x%02x", *src );
  776. tmp += sprintf( tmp, "%s", esc );
  777. free( esc );
  778. }
  779. else *tmp++ = *src;
  780. }
  781. return dst;
  782. }
  783. static void report_test_start( struct wine_test *test, const char *subtest, const char *file )
  784. {
  785. report( R_STEP, "Running: %s:%s", test->name, subtest );
  786. xprintf( "%s:%s start %s\n", test->name, subtest, file );
  787. }
  788. static void report_test_done( struct wine_test *test, const char *subtest, const char *file, DWORD pid, DWORD ticks,
  789. HANDLE out_file, UINT status, const char *data, DWORD size )
  790. {
  791. if (quiet_mode <= 1 || status || size > MAX_OUTPUT_SIZE) WriteFile( out_file, data, size, &size, NULL );
  792. xprintf( "%s:%s:%04lx done (%d) in %lds %luB\n", test->name, subtest, pid, status, ticks / 1000, size );
  793. if (size > MAX_OUTPUT_SIZE) xprintf( "%s:%s:%04lx The test prints too much data (%lu bytes)\n", test->name, subtest, pid, size );
  794. if (junit)
  795. {
  796. int total = 0, fail_total = 0, skip_total = 0, failures = 0;
  797. const char *next, *line, *ptr, *dir = strrchr( file, '/' );
  798. float time, last_time = 0;
  799. for (line = next = data; *line; line = next)
  800. {
  801. int count, todo_count, flaky_count, fail_count, skip_count;
  802. if ((next = strchr( next, '\n' ))) next += 1;
  803. else next = line + strlen( line );
  804. if (!(ptr = strchr( line, ' ' ))) continue;
  805. if (sscanf( ptr, " %d tests executed (%d marked as todo, %d as flaky, %d failur%*[^)]), %d skipped.",
  806. &count, &todo_count, &flaky_count, &fail_count, &skip_count ) == 5)
  807. {
  808. total += count;
  809. fail_total += fail_count;
  810. skip_total += skip_count;
  811. }
  812. }
  813. output( junit, " <testsuite name=\"%s:%s\" file=\"%s\" time=\"%f\" tests=\"%d\" failures=\"%d\" skipped=\"%d\">\n",
  814. test->name, subtest, file, ticks / 1000.0, total, fail_total, skip_total );
  815. for (line = next = data; *line; line = next)
  816. {
  817. struct { const char *pattern; int length; int error; } patterns[] =
  818. {
  819. #define X(x, y) {.pattern = x, .length = strlen(x), .error = y}
  820. X("Tests skipped: ", -1),
  821. X("Test failed: ", 1),
  822. X("Test succeeded inside todo block: ", 1),
  823. X("Test succeeded inside flaky todo block: ", 1),
  824. #undef X
  825. };
  826. char src[256], *name, *message;
  827. int i, n, len;
  828. if ((next = strchr( next, '\n' ))) next += 1;
  829. else next = line + strlen( line );
  830. if ((len = sscanf( line, "%255[^:\n]:%d:%f", src, &n, &time )) != 2 && len != 3) continue;
  831. if (len == 2) time = last_time;
  832. if (!(ptr = strchr( line, ' ' ))) continue;
  833. ptr++;
  834. message = xmlescape( ptr, next, 0 );
  835. name = strmake( "%s:%d %s", src, n, message );
  836. for (i = 0; i < ARRAY_SIZE(patterns); i++)
  837. {
  838. if (!strncmp( ptr, patterns[i].pattern, patterns[i].length ))
  839. {
  840. output( junit, " <testcase classname=\"%s:%s\" name=\"%s:%s %s\" file=\"%.*s%s#L%d\" assertions=\"1\" time=\"%f\">",
  841. test->name, subtest, test->name, subtest, name, (int)(dir - file + 1), file, src, n, time - last_time );
  842. if (patterns[i].error == -1) output( junit, "<system-out>%s</system-out><skipped/>", message );
  843. else if (patterns[i].error == 1) output( junit, "<system-out>%s</system-out><failure/>", message );
  844. output( junit, "</testcase>\n" );
  845. if (patterns[i].error == 1) failures++;
  846. last_time = time;
  847. break;
  848. }
  849. }
  850. free( name );
  851. free( message );
  852. }
  853. if (total > fail_total + skip_total)
  854. {
  855. output( junit, " <testcase classname=\"%s:%s\" name=\"%d succeeding tests\" file=\"%s\" assertions=\"%d\" time=\"%f\"/>\n",
  856. test->name, subtest, total - fail_total - skip_total, file, total - fail_total - skip_total, ticks / 1000.0 - last_time );
  857. }
  858. if (status == WAIT_TIMEOUT)
  859. {
  860. output( junit, " <testcase classname=\"%s:%s\" name=\"%s:%s timeout\" file=\"%s\" assertions=\"%d\" time=\"%f\">",
  861. test->name, subtest, test->name, subtest, file, total, ticks / 1000.0 );
  862. output( junit, "<system-out>Test timeout after %f seconds</system-out><failure/>", ticks / 1000.0 );
  863. output( junit, "</testcase>\n" );
  864. }
  865. else if (status != failures)
  866. {
  867. output( junit, " <testcase classname=\"%s:%s\" name=\"%s:%s status %d\" file=\"%s\" assertions=\"%d\" time=\"%f\">",
  868. test->name, subtest, test->name, subtest, status, file, total, ticks / 1000.0 );
  869. output( junit, "<system-out>Test exited with status %d</system-out><failure/>", status );
  870. output( junit, "</testcase>\n" );
  871. }
  872. if (size > MAX_OUTPUT_SIZE)
  873. {
  874. output( junit, " <testcase classname=\"%s:%s\" name=\"%s:%s output overflow\" file=\"%s\" assertions=\"%d\" time=\"%f\">",
  875. test->name, subtest, test->name, subtest, file, total, ticks / 1000.0 );
  876. output( junit, "<system-out>Test prints too much data (%lukB > %ukB)</system-out><failure/>",
  877. size / 1024, MAX_OUTPUT_SIZE / 1024 );
  878. output( junit, "</testcase>\n" );
  879. }
  880. output( junit, " </testsuite>\n" );
  881. }
  882. }
  883. static void report_test_skip( struct wine_test *test, const char *subtest, const char *file )
  884. {
  885. report( R_STEP, "Skipping: %s:%s", test->name, subtest );
  886. xprintf( "%s:%s skipped %s\n", test->name, subtest, file );
  887. }
  888. static void
  889. run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
  890. {
  891. /* Build the source filename so analysis tools can link to it */
  892. const char* file = get_test_source_file(test->name, subtest);
  893. if (test_filtered_out( test->name, subtest ))
  894. {
  895. report_test_skip( test, subtest, file );
  896. nr_of_skips++;
  897. }
  898. else
  899. {
  900. char *data, tmpname[MAX_PATH];
  901. HANDLE tmpfile = create_temp_file( tmpname );
  902. int status;
  903. DWORD pid, size, start = GetTickCount();
  904. char *cmd = strmake("%s %s", test->exename, subtest);
  905. report_test_start( test, subtest, file );
  906. /* Flush to disk so we know which test caused Windows to crash if it does */
  907. FlushFileBuffers(out_file);
  908. status = run_ex( cmd, tmpfile, tempdir, 120000, FALSE, &pid );
  909. if (status == -2 && GetLastError()) status = -GetLastError();
  910. free(cmd);
  911. data = flush_temp_file( tmpname, tmpfile, &size );
  912. report_test_done( test, subtest, file, pid, GetTickCount() - start, out_file, status, data, size );
  913. free( data );
  914. if (status || size > MAX_OUTPUT_SIZE) failures++;
  915. }
  916. if (failures) report (R_STATUS, "Running tests - %u failures", failures);
  917. }
  918. static BOOL CALLBACK
  919. EnumTestFileProc (HMODULE hModule, LPCSTR lpszType,
  920. LPSTR lpszName, LONG_PTR lParam)
  921. {
  922. if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
  923. return TRUE;
  924. }
  925. static const struct clsid_mapping
  926. {
  927. const char *name;
  928. CLSID clsid;
  929. } clsid_list[] =
  930. {
  931. {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
  932. {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
  933. };
  934. static BOOL get_main_clsid(const char *name, CLSID *clsid)
  935. {
  936. const struct clsid_mapping *mapping;
  937. for(mapping = clsid_list; mapping->name; mapping++)
  938. {
  939. if(!strcasecmp(name, mapping->name))
  940. {
  941. *clsid = mapping->clsid;
  942. return TRUE;
  943. }
  944. }
  945. return FALSE;
  946. }
  947. static HMODULE load_com_dll(const char *name, char **path, char *filename)
  948. {
  949. HMODULE dll = NULL;
  950. HKEY hkey;
  951. char keyname[100];
  952. char dllname[MAX_PATH];
  953. char *p;
  954. CLSID clsid;
  955. if(!get_main_clsid(name, &clsid)) return NULL;
  956. sprintf(keyname, "CLSID\\{%08lx-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
  957. clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
  958. clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
  959. clsid.Data4[6], clsid.Data4[7]);
  960. if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
  961. {
  962. LONG size = sizeof(dllname);
  963. if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
  964. {
  965. if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
  966. {
  967. strcpy( filename, dllname );
  968. p = strrchr(dllname, '\\');
  969. if (p) *p = 0;
  970. *path = xstrdup( dllname );
  971. }
  972. }
  973. RegCloseKey(hkey);
  974. }
  975. return dll;
  976. }
  977. static void get_dll_path(HMODULE dll, char **path, char *filename)
  978. {
  979. char dllpath[MAX_PATH];
  980. GetModuleFileNameA(dll, dllpath, MAX_PATH);
  981. strcpy(filename, dllpath);
  982. *strrchr(dllpath, '\\') = '\0';
  983. *path = xstrdup( dllpath );
  984. }
  985. static BOOL CALLBACK
  986. extract_test_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
  987. {
  988. const char *tempdir = (const char *)lParam;
  989. char dllname[MAX_PATH];
  990. char filename[MAX_PATH];
  991. WCHAR dllnameW[MAX_PATH];
  992. HMODULE dll;
  993. DWORD err;
  994. HANDLE actctx;
  995. ULONG_PTR cookie;
  996. BOOL run;
  997. if (aborting) return TRUE;
  998. /* Check if the main dll is present on this system */
  999. CharLowerA(lpszName);
  1000. strcpy(dllname, lpszName);
  1001. *strstr(dllname, testexe) = 0;
  1002. if (test_filtered_out( lpszName, NULL ))
  1003. {
  1004. nr_of_skips++;
  1005. if (exclude_tests) xprintf (" %s=skipped\n", dllname);
  1006. return TRUE;
  1007. }
  1008. extract_test (&wine_tests[nr_of_files], tempdir, lpszName);
  1009. if (pCreateActCtxA != NULL && pActivateActCtx != NULL &&
  1010. pDeactivateActCtx != NULL && pReleaseActCtx != NULL)
  1011. {
  1012. ACTCTXA actctxinfo;
  1013. memset(&actctxinfo, 0, sizeof(ACTCTXA));
  1014. actctxinfo.cbSize = sizeof(ACTCTXA);
  1015. actctxinfo.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
  1016. actctxinfo.lpSource = wine_tests[nr_of_files].exename;
  1017. actctxinfo.lpResourceName = (LPSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
  1018. actctx = pCreateActCtxA(&actctxinfo);
  1019. if (actctx != INVALID_HANDLE_VALUE &&
  1020. ! pActivateActCtx(actctx, &cookie))
  1021. {
  1022. pReleaseActCtx(actctx);
  1023. actctx = INVALID_HANDLE_VALUE;
  1024. }
  1025. } else actctx = INVALID_HANDLE_VALUE;
  1026. wine_tests[nr_of_files].maindllpath = NULL;
  1027. strcpy(filename, dllname);
  1028. dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
  1029. if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
  1030. if (!dll && pLoadLibraryShim)
  1031. {
  1032. MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
  1033. if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
  1034. {
  1035. get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
  1036. FreeLibrary(dll);
  1037. dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
  1038. }
  1039. else dll = 0;
  1040. }
  1041. run = TRUE;
  1042. if (dll)
  1043. {
  1044. if (is_stub_dll(dllname))
  1045. {
  1046. xprintf (" %s=dll is a stub\n", dllname);
  1047. run = FALSE;
  1048. }
  1049. else if (is_native_dll(dll))
  1050. {
  1051. xprintf (" %s=dll is native\n", dllname);
  1052. nr_native_dlls++;
  1053. run = FALSE;
  1054. }
  1055. FreeLibrary(dll);
  1056. }
  1057. if (run)
  1058. {
  1059. err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
  1060. switch (err)
  1061. {
  1062. case 0:
  1063. xprintf (" %s=%s\n", dllname, get_file_version(filename));
  1064. nr_of_tests += wine_tests[nr_of_files].subtest_count;
  1065. nr_of_files++;
  1066. break;
  1067. case STATUS_DLL_NOT_FOUND:
  1068. xprintf (" %s=dll is missing\n", dllname);
  1069. /* or it is a side-by-side dll but the test has no manifest */
  1070. break;
  1071. case STATUS_ORDINAL_NOT_FOUND:
  1072. xprintf (" %s=dll is missing an ordinal (%s)\n", dllname, get_file_version(filename));
  1073. break;
  1074. case STATUS_ENTRYPOINT_NOT_FOUND:
  1075. xprintf (" %s=dll is missing an entrypoint (%s)\n", dllname, get_file_version(filename));
  1076. break;
  1077. case ERROR_SXS_CANT_GEN_ACTCTX:
  1078. xprintf (" %s=dll is missing the requested side-by-side version\n", dllname);
  1079. break;
  1080. default:
  1081. xprintf (" %s=load error %lu\n", dllname, err);
  1082. break;
  1083. }
  1084. }
  1085. if (actctx != INVALID_HANDLE_VALUE)
  1086. {
  1087. pDeactivateActCtx(0, cookie);
  1088. pReleaseActCtx(actctx);
  1089. }
  1090. return TRUE;
  1091. }
  1092. static char *
  1093. run_tests (char *logname, char *outdir)
  1094. {
  1095. int i;
  1096. char *strres, *eol, *nextline;
  1097. DWORD strsize;
  1098. char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
  1099. BOOL newdir;
  1100. DWORD needed;
  1101. HMODULE kernel32;
  1102. /* Get the current PATH only once */
  1103. needed = GetEnvironmentVariableA("PATH", NULL, 0);
  1104. curpath = xalloc(needed);
  1105. GetEnvironmentVariableA("PATH", curpath, needed);
  1106. SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  1107. if (!GetTempPathA( MAX_PATH, tmppath ))
  1108. report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
  1109. if (logname)
  1110. {
  1111. if (!strcmp(logname, "-")) logfile = GetStdHandle( STD_OUTPUT_HANDLE );
  1112. else logfile = create_output_file( logname );
  1113. }
  1114. else
  1115. {
  1116. static char tmpname[MAX_PATH];
  1117. logfile = create_temp_file( tmpname );
  1118. logname = tmpname;
  1119. }
  1120. report (R_OUT, "%s", logname);
  1121. if (logfile == INVALID_HANDLE_VALUE)
  1122. report (R_FATAL, "Could not open logfile: %u", GetLastError());
  1123. if (outdir)
  1124. {
  1125. /* Get a full path so it is still valid after a chdir */
  1126. GetFullPathNameA( outdir, ARRAY_SIZE(tempdir), tempdir, NULL );
  1127. }
  1128. else
  1129. {
  1130. strcpy( tempdir, tmppath );
  1131. strcat( tempdir, "wct" ); /* try stable path for ZoneAlarm */
  1132. }
  1133. newdir = CreateDirectoryA( tempdir, NULL );
  1134. if (!newdir && !outdir)
  1135. {
  1136. if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
  1137. report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
  1138. DeleteFileA( tempdir );
  1139. newdir = CreateDirectoryA( tempdir, NULL );
  1140. }
  1141. if (!newdir && (!outdir || GetLastError() != ERROR_ALREADY_EXISTS))
  1142. report (R_FATAL, "Could not create directory %s (%d)", tempdir, GetLastError());
  1143. report (R_DIR, "%s", tempdir);
  1144. if (junit)
  1145. {
  1146. output( junit, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
  1147. output( junit, "<testsuites>\n" );
  1148. }
  1149. xprintf ("Version 4\n");
  1150. xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
  1151. xprintf ("Archive: -\n"); /* no longer used */
  1152. xprintf ("Tag: %s\n", tag);
  1153. xprintf ("Build info:\n");
  1154. strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
  1155. while (strres) {
  1156. eol = memchr (strres, '\n', strsize);
  1157. if (!eol) {
  1158. nextline = NULL;
  1159. eol = strres + strsize;
  1160. } else {
  1161. strsize -= eol - strres + 1;
  1162. nextline = strsize?eol+1:NULL;
  1163. if (eol > strres && *(eol-1) == '\r') eol--;
  1164. }
  1165. xprintf (" %.*s\n", (int)(eol-strres), strres);
  1166. strres = nextline;
  1167. }
  1168. xprintf ("Operating system version:\n");
  1169. print_version ();
  1170. print_language ();
  1171. xprintf ("Dll info:\n" );
  1172. report (R_STATUS, "Counting tests");
  1173. if (!EnumResourceNamesA (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
  1174. report (R_FATAL, "Can't enumerate test files: %d",
  1175. GetLastError ());
  1176. wine_tests = xalloc(nr_of_files * sizeof wine_tests[0]);
  1177. /* Do this only once during extraction (and version checking) */
  1178. hmscoree = LoadLibraryA("mscoree.dll");
  1179. pLoadLibraryShim = NULL;
  1180. if (hmscoree)
  1181. pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
  1182. kernel32 = GetModuleHandleA("kernel32.dll");
  1183. pCreateActCtxA = (void *)GetProcAddress(kernel32, "CreateActCtxA");
  1184. pActivateActCtx = (void *)GetProcAddress(kernel32, "ActivateActCtx");
  1185. pDeactivateActCtx = (void *)GetProcAddress(kernel32, "DeactivateActCtx");
  1186. pReleaseActCtx = (void *)GetProcAddress(kernel32, "ReleaseActCtx");
  1187. report (R_STATUS, "Extracting tests");
  1188. report (R_PROGRESS, 0, nr_of_files);
  1189. nr_of_files = 0;
  1190. nr_of_tests = 0;
  1191. nr_of_skips = 0;
  1192. if (!EnumResourceNamesA (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
  1193. report (R_FATAL, "Can't enumerate test files: %d",
  1194. GetLastError ());
  1195. FreeLibrary(hmscoree);
  1196. if (aborting) return logname;
  1197. xprintf ("Test output:\n" );
  1198. report (R_DELTA, 0, "Extracting: Done");
  1199. if (nr_native_dlls)
  1200. report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
  1201. report (R_STATUS, "Running tests");
  1202. report (R_PROGRESS, 1, nr_of_tests);
  1203. for (i = 0; i < nr_of_files; i++) {
  1204. struct wine_test *test = wine_tests + i;
  1205. int j;
  1206. if (aborting) break;
  1207. if (test->maindllpath) {
  1208. /* We need to add the path (to the main dll) to PATH */
  1209. append_path(test->maindllpath);
  1210. }
  1211. for (j = 0; j < test->subtest_count; j++) {
  1212. if (aborting) break;
  1213. run_test (test, test->subtests[j], logfile, tempdir);
  1214. }
  1215. if (test->maindllpath) {
  1216. /* Restore PATH again */
  1217. SetEnvironmentVariableA("PATH", curpath);
  1218. }
  1219. }
  1220. report (R_DELTA, 0, "Running: Done");
  1221. if (junit)
  1222. {
  1223. output( junit, "</testsuites>\n" );
  1224. CloseHandle( junit );
  1225. }
  1226. report (R_STATUS, "Cleaning up - %u failures", failures);
  1227. if (strcmp(logname, "-") != 0) CloseHandle( logfile );
  1228. logfile = 0;
  1229. if (newdir)
  1230. remove_dir (tempdir);
  1231. free(wine_tests);
  1232. free(curpath);
  1233. return logname;
  1234. }
  1235. static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
  1236. {
  1237. if (ctrl_type == CTRL_C_EVENT) {
  1238. printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
  1239. return TRUE;
  1240. }
  1241. return FALSE;
  1242. }
  1243. static BOOL CALLBACK
  1244. extract_only_proc (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
  1245. {
  1246. const char *target_dir = (const char *)lParam;
  1247. char filename[MAX_PATH];
  1248. if (test_filtered_out( lpszName, NULL )) return TRUE;
  1249. strcpy(filename, lpszName);
  1250. CharLowerA(filename);
  1251. extract_test( &wine_tests[nr_of_files], target_dir, filename );
  1252. nr_of_files++;
  1253. return TRUE;
  1254. }
  1255. static void extract_only (const char *target_dir)
  1256. {
  1257. BOOL res;
  1258. report (R_DIR, target_dir);
  1259. res = CreateDirectoryA( target_dir, NULL );
  1260. if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
  1261. report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
  1262. nr_of_files = 0;
  1263. report (R_STATUS, "Counting tests");
  1264. if (!EnumResourceNamesA(NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
  1265. report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
  1266. wine_tests = xalloc(nr_of_files * sizeof wine_tests[0] );
  1267. report (R_STATUS, "Extracting tests");
  1268. report (R_PROGRESS, 0, nr_of_files);
  1269. nr_of_files = 0;
  1270. if (!EnumResourceNamesA(NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
  1271. report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
  1272. report (R_DELTA, 0, "Extracting: Done");
  1273. }
  1274. static void
  1275. usage (void)
  1276. {
  1277. fprintf (stderr,
  1278. "Usage: winetest [OPTION]... [TESTS]\n\n"
  1279. " --help print this message and exit\n"
  1280. " --version print the build version and exit\n"
  1281. " -c console mode, no GUI\n"
  1282. " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
  1283. " -e preserve the environment\n"
  1284. " -h print this message and exit\n"
  1285. " -i INFO an optional description of the test platform\n"
  1286. " -m MAIL an email address to enable developers to contact you\n"
  1287. " -n exclude the specified tests\n"
  1288. " -p shutdown when the tests are done\n"
  1289. " -q quiet mode, no output at all\n"
  1290. " -J FILE output junit XML report into FILE\n"
  1291. " -o FILE put report into FILE, do not submit\n"
  1292. " -s FILE submit FILE, do not run tests\n"
  1293. " -S URL URL to submit the results to\n"
  1294. " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
  1295. " -u URL include TestBot URL in the report\n"
  1296. " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
  1297. }
  1298. int __cdecl main( int argc, char *argv[] )
  1299. {
  1300. BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
  1301. char *logname = NULL, *outdir = NULL, *path = NULL;
  1302. const char *extract = NULL;
  1303. const char *cp, *submit = NULL, *submiturl = NULL, *job_name;
  1304. int reset_env = 1;
  1305. int poweroff = 0;
  1306. int interactive = 1;
  1307. int prev_crash_dialog = 0;
  1308. int i;
  1309. InitCommonControls();
  1310. if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
  1311. pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
  1312. if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
  1313. if ((job_name = getenv( "CI_JOB_NAME" )))
  1314. {
  1315. tag = strmake( "gitlab-%s", job_name );
  1316. url = getenv( "CI_JOB_URL" );
  1317. }
  1318. for (i = 1; i < argc && argv[i]; i++)
  1319. {
  1320. if (!strcmp(argv[i], "--help")) {
  1321. usage ();
  1322. exit (0);
  1323. }
  1324. else if (!strcmp(argv[i], "--version")) {
  1325. printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
  1326. exit (0);
  1327. }
  1328. else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
  1329. add_filter( argv[i] );
  1330. }
  1331. else switch (argv[i][1]) {
  1332. case 'c':
  1333. report (R_TEXTMODE);
  1334. interactive = 0;
  1335. break;
  1336. case 'e':
  1337. reset_env = 0;
  1338. break;
  1339. case 'h':
  1340. case '?':
  1341. usage ();
  1342. exit (0);
  1343. case 'i':
  1344. if (!(description = argv[++i]))
  1345. {
  1346. usage();
  1347. exit( 2 );
  1348. }
  1349. break;
  1350. case 'J':
  1351. if (!(path = argv[++i]))
  1352. {
  1353. usage();
  1354. exit( 2 );
  1355. }
  1356. junit = create_output_file( path );
  1357. break;
  1358. case 'm':
  1359. if (!(email = argv[++i]))
  1360. {
  1361. usage();
  1362. exit( 2 );
  1363. }
  1364. break;
  1365. case 'n':
  1366. exclude_tests = TRUE;
  1367. break;
  1368. case 'p':
  1369. poweroff = 1;
  1370. break;
  1371. case 'q':
  1372. report (R_QUIET);
  1373. interactive = 0;
  1374. quiet_mode++;
  1375. break;
  1376. case 's':
  1377. if (!(submit = argv[++i]))
  1378. {
  1379. usage();
  1380. exit( 2 );
  1381. }
  1382. break;
  1383. case 'S':
  1384. if (!(submiturl = argv[++i]))
  1385. {
  1386. usage();
  1387. exit( 2 );
  1388. }
  1389. break;
  1390. case 'o':
  1391. if (!(logname = argv[++i]))
  1392. {
  1393. usage();
  1394. exit( 2 );
  1395. }
  1396. break;
  1397. case 't':
  1398. if (!(tag = argv[++i]))
  1399. {
  1400. usage();
  1401. exit( 2 );
  1402. }
  1403. if (strlen (tag) > MAXTAGLEN)
  1404. report (R_FATAL, "tag is too long (maximum %d characters)",
  1405. MAXTAGLEN);
  1406. break;
  1407. case 'u':
  1408. if (!(url = argv[++i]))
  1409. {
  1410. usage();
  1411. exit( 2 );
  1412. }
  1413. break;
  1414. case 'x':
  1415. report (R_TEXTMODE);
  1416. if (!(extract = argv[++i]))
  1417. extract = ".\\wct";
  1418. extract_only (extract);
  1419. break;
  1420. case 'd':
  1421. outdir = argv[++i];
  1422. break;
  1423. default:
  1424. report (R_ERROR, "invalid option: -%c", argv[i][1]);
  1425. usage ();
  1426. exit (2);
  1427. }
  1428. }
  1429. if (submit) {
  1430. if (tag)
  1431. report (R_WARNING, "ignoring tag for submission");
  1432. send_file (submiturl, submit);
  1433. } else if (!extract) {
  1434. int is_win9x = (GetVersion() & 0x80000000) != 0;
  1435. report (R_STATUS, "Starting up");
  1436. if (is_win9x)
  1437. report (R_WARNING, "Running on win9x is not supported. You won't be able to submit results.");
  1438. if (!running_on_visible_desktop ())
  1439. report (R_FATAL, "Tests must be run on a visible desktop");
  1440. if (running_under_wine())
  1441. {
  1442. if (!check_mount_mgr())
  1443. report (R_FATAL, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
  1444. if (!check_wow64_registry())
  1445. report (R_FATAL, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
  1446. if (!check_display_driver())
  1447. report (R_FATAL, "Unable to create a window, the display driver is not working.");
  1448. if (!interactive) prev_crash_dialog = disable_crash_dialog();
  1449. }
  1450. SetConsoleCtrlHandler(ctrl_handler, TRUE);
  1451. if (reset_env)
  1452. {
  1453. SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
  1454. SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
  1455. SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
  1456. SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
  1457. }
  1458. if (junit)
  1459. {
  1460. SetEnvironmentVariableA( "WINETEST_COLOR", "0" );
  1461. SetEnvironmentVariableA( "WINETEST_TIME", "1" );
  1462. }
  1463. if (nb_filters && !exclude_tests)
  1464. {
  1465. run_tests( logname, outdir );
  1466. exit( failures ? 3 : 0 );
  1467. }
  1468. if (tag && (cp = findbadtagchar(tag)))
  1469. {
  1470. report (R_ERROR, "invalid char in tag: %c", *cp);
  1471. usage ();
  1472. exit (2);
  1473. }
  1474. while (!tag) {
  1475. if (!interactive)
  1476. report (R_FATAL, "Please specify a tag (-t option) if "
  1477. "running noninteractive!");
  1478. if (guiAskTag () == IDABORT) exit (1);
  1479. }
  1480. report (R_TAG);
  1481. while (!email) {
  1482. if (!interactive)
  1483. {
  1484. if (url) break;
  1485. report (R_FATAL, "Please specify an email address (-m option) to enable developers\n"
  1486. " to contact you about your report if necessary.");
  1487. }
  1488. if (guiAskEmail () == IDABORT) exit (1);
  1489. }
  1490. if (!build_id[0])
  1491. report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
  1492. "To submit results, winetest needs to be built from a git checkout." );
  1493. if (!logname) {
  1494. logname = run_tests (NULL, outdir);
  1495. if (aborting) {
  1496. DeleteFileA(logname);
  1497. exit (0);
  1498. }
  1499. if (failures > FAILURES_LIMIT)
  1500. report( R_WARNING,
  1501. "%d tests failed. There is probably something broken with your setup.\n"
  1502. "You need to address this before submitting results.", failures );
  1503. if (build_id[0] && nr_of_skips <= SKIP_LIMIT && failures <= FAILURES_LIMIT &&
  1504. !nr_native_dlls && !is_win9x &&
  1505. report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
  1506. {
  1507. if (!send_file (submiturl, logname) && !DeleteFileA(logname))
  1508. report (R_WARNING, "Can't remove logfile: %u", GetLastError());
  1509. else
  1510. failures = 0; /* return success */
  1511. }
  1512. }
  1513. else
  1514. {
  1515. run_tests (logname, outdir);
  1516. report (R_STATUS, "Finished - %u failures", failures);
  1517. }
  1518. if (prev_crash_dialog) restore_crash_dialog( prev_crash_dialog );
  1519. }
  1520. if (poweroff)
  1521. {
  1522. HANDLE hToken;
  1523. TOKEN_PRIVILEGES npr;
  1524. /* enable the shutdown privilege for the current process */
  1525. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
  1526. {
  1527. LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr.Privileges[0].Luid);
  1528. npr.PrivilegeCount = 1;
  1529. npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  1530. AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
  1531. CloseHandle(hToken);
  1532. }
  1533. ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
  1534. }
  1535. exit( failures ? 3 : 0 );
  1536. }