Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
7.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. senstest.cxx
  5. Abstract:
  6. BVT for the SENS Connectivity APIs.
  7. Author:
  8. Gopal Parupudi <GopalP>
  9. [Notes:]
  10. optional-notes
  11. Revision History:
  12. GopalP 10/13/1997 Start.
  13. --*/
  14. #include <common.hxx>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <windows.h>
  19. #include <sensapi.h>
  20. #include <conio.h>
  21. //
  22. // Globals
  23. //
  24. DWORD gdwThreads;
  25. DWORD gdwInterval;
  26. //
  27. // Forwards
  28. //
  29. void
  30. MultiThreadedTest(
  31. void
  32. );
  33. inline void
  34. Usage(
  35. void
  36. )
  37. {
  38. printf("\nUsage: senstest [Destination] \n");
  39. printf(" senstest [-m [Threads] [Interval]] \n\n");
  40. printf("Options:\n\n");
  41. printf(" Destination Name of the destination whose\n"
  42. " reachability is of interest.\n");
  43. printf(" -m Perform Mulithreaded SensAPI test.\n");
  44. printf(" Threads Number of threads [Default = 5]\n");
  45. printf(" Interval Wait between calls [Default = 10 sec]\n");
  46. printf("\n");
  47. }
  48. int __cdecl
  49. main(
  50. int argc,
  51. const char * argv[]
  52. )
  53. {
  54. DWORD dwFlags = 0;
  55. BOOL bAlive = FALSE;
  56. BOOL bReachable = FALSE;
  57. if (argc > 4)
  58. {
  59. Usage();
  60. return -1;
  61. }
  62. if ( (argc == 2)
  63. && ( (strcmp(argv[1], "-?") == 0)
  64. || (strcmp(argv[1], "/?") == 0)
  65. || (strcmp(argv[1], "-help") == 0)
  66. || (strcmp(argv[1], "/help") == 0)))
  67. {
  68. Usage();
  69. return -1;
  70. }
  71. //
  72. // Start the MultiThreadedTest, if required.
  73. //
  74. if (argc > 1)
  75. {
  76. if (strcmp(argv[1], "-m") == 0)
  77. {
  78. gdwThreads = 5;
  79. gdwInterval = 10;
  80. if (argc > 2)
  81. {
  82. gdwThreads = atoi(argv[2]);
  83. }
  84. if (argc > 3)
  85. {
  86. gdwInterval = atoi(argv[3]);
  87. }
  88. MultiThreadedTest();
  89. return 0;
  90. }
  91. }
  92. //
  93. // Call IsNetworkAlive()
  94. //
  95. printf("------------------------------------------------------------------"
  96. "----\n");
  97. bAlive = IsNetworkAlive(&dwFlags);
  98. printf(" IsNetworkAlive() returned %s\n", bAlive ? "TRUE" : "FALSE");
  99. if (bAlive)
  100. {
  101. printf(" Type of connection -%s%s%s\n",
  102. (dwFlags & NETWORK_ALIVE_WAN) ? " WAN" : "",
  103. (dwFlags & NETWORK_ALIVE_AOL) ? " AOL" : "",
  104. (dwFlags & NETWORK_ALIVE_LAN) ? " LAN" : "");
  105. }
  106. printf(" The GetLastError() was %d\n", GetLastError());
  107. printf("------------------------------------------------------------------"
  108. "----\n");
  109. if (argc == 1)
  110. {
  111. return 0;
  112. }
  113. //
  114. // Test the other API.
  115. //
  116. bReachable = IsDestinationReachableA((LPCSTR) argv[1], NULL);
  117. printf(" IsDestinationReachableA(%s, NULL) returned %s\n",
  118. argv[1], bReachable ? "TRUE" : "FALSE");
  119. if (bReachable)
  120. {
  121. printf(" QOC is NULL.\n");
  122. }
  123. printf(" The GetLastError() was %d\n", GetLastError());
  124. //
  125. // Now, call with QOC Info.
  126. //
  127. printf("------------------------------------------------------------------"
  128. "----\n");
  129. QOCINFO QOCInfo;
  130. NTSTATUS NtStatus;
  131. QOCInfo.dwSize = sizeof(QOCINFO);
  132. #if !defined(SENS_CHICAGO)
  133. ANSI_STRING AnsiString;
  134. UNICODE_STRING UnicodeString;
  135. RtlInitAnsiString(&AnsiString, (PSZ)argv[1]);
  136. NtStatus = RtlAnsiStringToUnicodeString(
  137. &UnicodeString,
  138. &AnsiString,
  139. TRUE
  140. );
  141. if (!NT_SUCCESS(NtStatus))
  142. {
  143. printf("RtlAnsiStringToUnicodeString() returned 0x%x\n", NtStatus);
  144. return -1;
  145. }
  146. bReachable = IsDestinationReachableW(UnicodeString.Buffer, &QOCInfo);
  147. wprintf(L" IsDestinationReachableW(%s, QOC) returned %s\n",
  148. UnicodeString.Buffer, bReachable ? L"TRUE" : L"FALSE");
  149. RtlFreeUnicodeString(&UnicodeString);
  150. #else // !SENS_CHICAGO
  151. bReachable = IsDestinationReachableA(argv[1], &QOCInfo);
  152. printf(" IsDestinationReachableA(%s, QOC) returned %s\n",
  153. argv[1], bReachable ? "TRUE" : "FALSE");
  154. #endif // SENS_CHICAGO
  155. if (bReachable)
  156. {
  157. printf(" QOCInfo\n");
  158. printf(" o dwSize = 0x%x \n", QOCInfo.dwSize);
  159. printf(" o dwFlags = 0x%x \n", QOCInfo.dwFlags);
  160. printf(" o dwInSpeed = %d bits/sec.\n", QOCInfo.dwInSpeed);
  161. printf(" o dwOutSpeed = %d bits/sec.\n", QOCInfo.dwOutSpeed);
  162. }
  163. printf(" The GetLastError() was %d\n", GetLastError());
  164. printf("------------------------------------------------------------------"
  165. "----\n");
  166. return 0;
  167. }
  168. #if _MSC_FULL_VER >= 13008827
  169. #pragma warning(push)
  170. #pragma warning(disable:4715) // Not all control paths return (due to infinite loop)
  171. #endif
  172. DWORD WINAPI
  173. ThreadProc(
  174. LPVOID lpvThreadNum
  175. )
  176. {
  177. DWORD dwFlags = 0;
  178. BOOL bAlive = FALSE;
  179. int iThreadNum;
  180. int iWait;
  181. iThreadNum = PtrToLong(lpvThreadNum);
  182. for (;;)
  183. {
  184. printf("[%2d]-----------------------------------------------------------"
  185. "----\n", iThreadNum);
  186. bAlive = IsNetworkAlive(&dwFlags);
  187. printf("[%2d] IsNetworkAlive() returned %s\n", iThreadNum,
  188. bAlive ? "TRUE" : "FALSE");
  189. if (bAlive)
  190. {
  191. printf("[%2d] Type of connection -%s%s%s\n",
  192. iThreadNum,
  193. (dwFlags & NETWORK_ALIVE_WAN) ? " WAN" : "",
  194. (dwFlags & NETWORK_ALIVE_AOL) ? " AOL" : "",
  195. (dwFlags & NETWORK_ALIVE_LAN) ? " LAN" : "");
  196. }
  197. printf("[%2d] The GetLastError() was %d\n", iThreadNum, GetLastError());
  198. iWait = rand() % gdwInterval;
  199. printf("[%2d] Sleeping for %d seconds\n", iThreadNum, iWait);
  200. printf("[%2d]-----------------------------------------------------------"
  201. "----\n\n", iThreadNum);
  202. Sleep(iWait * 1000);
  203. }
  204. return 0;
  205. }
  206. #if _MSC_FULL_VER >= 13008827
  207. #pragma warning(pop)
  208. #endif
  209. void
  210. MultiThreadedTest(
  211. void
  212. )
  213. {
  214. DWORD i;
  215. DWORD dwThreadId;
  216. DWORD dwResult;
  217. HANDLE hThread;
  218. srand(GetTickCount());
  219. printf("\nSENSTEST: Starting Multithreaded IsNetworkAlive Test\n"
  220. "\tNumber of threads = %d\n"
  221. "\tMax Wait interval = %d seconds\n\n",
  222. gdwThreads, gdwInterval);
  223. for (i = 0; i < gdwThreads; i++)
  224. {
  225. hThread = CreateThread(
  226. NULL,
  227. 0,
  228. ThreadProc,
  229. ULongToPtr(i),
  230. 0,
  231. &dwThreadId
  232. );
  233. if (NULL != hThread)
  234. {
  235. // Don't close the last handle.
  236. if ((i+1) != gdwThreads)
  237. {
  238. CloseHandle(hThread);
  239. }
  240. }
  241. else
  242. {
  243. printf("CreateThread(%d) failed with a GLE of %d\n", i,
  244. GetLastError());
  245. }
  246. }
  247. dwResult = WaitForSingleObject(hThread, INFINITE);
  248. printf("WaitForSingleObject() returned %d, GLE = %d\n",
  249. dwResult, GetLastError());
  250. CloseHandle(hThread);
  251. }