main.c 47 KB

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