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.

471 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\test.c
  5. Abstract:
  6. The file contains test utilities.
  7. --*/
  8. #include "pchsample.h"
  9. #pragma hdrstop
  10. #ifdef TEST
  11. #define TEST_NUM_IE 230
  12. #define TEST_NUM_INTERFACE 2
  13. #define TEST_SLEEP_TIME 3*PERIODIC_INTERVAL
  14. #define TEST_NUM_START_STOP 2
  15. VOID
  16. ErrorCodes()
  17. {
  18. TRACE1(DEBUG, "ERROR_CAN_NOT_COMPLETE: %u",
  19. ERROR_CAN_NOT_COMPLETE);
  20. TRACE1(DEBUG, "ERROR_INSUFFICIENT_BUFFER: %u",
  21. ERROR_INSUFFICIENT_BUFFER);
  22. TRACE1(DEBUG, "ERROR_NO_MORE_ITEMS: %u",
  23. ERROR_NO_MORE_ITEMS);
  24. TRACE1(DEBUG, "ERROR_INVALID_PARAMETER: %u",
  25. ERROR_INVALID_PARAMETER);
  26. }
  27. VOID
  28. HT_Test()
  29. {
  30. ULONG i, ulNumDeleted = 0, ulNumGotten = 0;
  31. DWORD dwErr;
  32. PNETWORK_ENTRY pneNetworkEntry;
  33. PINTERFACE_ENTRY pieInterfaceEntry;
  34. INTERFACE_ENTRY ieKey;
  35. PLIST_ENTRY plePtr;
  36. WCHAR pwszIfName[20];
  37. do // breakout loop
  38. {
  39. dwErr = NE_Create(&pneNetworkEntry);
  40. if (dwErr != NO_ERROR)
  41. {
  42. TRACE0(DEBUG, "HT_Test: Could not create NetworkEntry");
  43. break;
  44. }
  45. for (i = 0; i < TEST_NUM_IE; i++)
  46. {
  47. swprintf(pwszIfName, L"if%u", i);
  48. dwErr = IE_Create(pwszIfName,
  49. i,
  50. IEFLAG_MULTIACCESS,
  51. &pieInterfaceEntry);
  52. if (dwErr != NO_ERROR)
  53. {
  54. TRACE1(DEBUG, "HT_Test: Could not Create %u", i);
  55. break;
  56. }
  57. dwErr = HT_InsertEntry(pneNetworkEntry->phtInterfaceTable,
  58. &(pieInterfaceEntry->leInterfaceTableLink));
  59. if (dwErr != NO_ERROR)
  60. {
  61. TRACE1(DEBUG, "HT_Test: Could not Insert %u", i);
  62. break;
  63. }
  64. }
  65. TRACE1(DEBUG, "Hash Table Size %u",
  66. HT_Size(pneNetworkEntry->phtInterfaceTable));
  67. for (i = 0; i < TEST_NUM_IE; i += 2)
  68. {
  69. ieKey.dwIfIndex = i;
  70. dwErr = HT_DeleteEntry(pneNetworkEntry->phtInterfaceTable,
  71. &(ieKey.leInterfaceTableLink),
  72. &plePtr);
  73. if (dwErr != NO_ERROR)
  74. {
  75. TRACE1(DEBUG, "HT_Test: Could not Delete %u", i);
  76. break;
  77. }
  78. // indicate deletion
  79. InitializeListHead(plePtr);
  80. IE_Destroy(CONTAINING_RECORD(plePtr,
  81. INTERFACE_ENTRY,
  82. leInterfaceTableLink));
  83. ulNumDeleted++;
  84. }
  85. TRACE2(DEBUG, "NumDeleted %u Hash Table Size %u",
  86. ulNumDeleted, HT_Size(pneNetworkEntry->phtInterfaceTable));
  87. for (i = 0; i < TEST_NUM_IE; i++)
  88. {
  89. ieKey.dwIfIndex = i;
  90. if (HT_IsPresentEntry(pneNetworkEntry->phtInterfaceTable,
  91. &(ieKey.leInterfaceTableLink)))
  92. {
  93. dwErr = HT_GetEntry(pneNetworkEntry->phtInterfaceTable,
  94. &(ieKey.leInterfaceTableLink),
  95. &plePtr);
  96. if (dwErr != NO_ERROR)
  97. {
  98. TRACE1(DEBUG, "HT_Test: Could not Get %u", i);
  99. break;
  100. }
  101. ulNumGotten++;
  102. }
  103. }
  104. TRACE1(DEBUG, "NumGotten %u", ulNumGotten);
  105. } while (FALSE);
  106. NE_Destroy(pneNetworkEntry);
  107. }
  108. VOID
  109. MM_Test(HANDLE hEvent)
  110. {
  111. ROUTING_PROTOCOL_EVENTS rpeEvent;
  112. MESSAGE mMessage;
  113. ULONG ulSize;
  114. BYTE byBuffer[100];
  115. PIPSAMPLE_GLOBAL_CONFIG pigc;
  116. PIPSAMPLE_IP_ADDRESS piia;
  117. PIPSAMPLE_IF_BINDING piib;
  118. PIPSAMPLE_IF_CONFIG piic;
  119. IPSAMPLE_MIB_GET_INPUT_DATA imgid;
  120. PIPSAMPLE_MIB_SET_INPUT_DATA pimsid =
  121. (PIPSAMPLE_MIB_SET_INPUT_DATA) byBuffer;
  122. PIPSAMPLE_MIB_GET_OUTPUT_DATA pimgod =
  123. (PIPSAMPLE_MIB_GET_OUTPUT_DATA) byBuffer;
  124. // mib set global configuration
  125. pimsid->IMSID_TypeID = IPSAMPLE_GLOBAL_CONFIG_ID;
  126. pimsid->IMSID_BufferSize = sizeof(IPSAMPLE_GLOBAL_CONFIG);
  127. pigc = (PIPSAMPLE_GLOBAL_CONFIG) pimsid->IMSID_Buffer;
  128. pigc->dwLoggingLevel = IPSAMPLE_LOGGING_ERROR;
  129. MM_MibSet(pimsid);
  130. TRACE2(MIB, "MIB SET: %u %u", pimsid->IMSID_TypeID, pigc->dwLoggingLevel);
  131. WaitForSingleObject(hEvent, INFINITE);
  132. CM_GetEventMessage(&rpeEvent, &mMessage);
  133. TRACE1(DEBUG, "SetMib %u", rpeEvent);
  134. // mib get global configuration
  135. ulSize = 0;
  136. imgid.IMGID_TypeID = IPSAMPLE_GLOBAL_CONFIG_ID;
  137. pigc = (PIPSAMPLE_GLOBAL_CONFIG) pimgod->IMGOD_Buffer;
  138. MM_MibGet(&imgid, pimgod, &ulSize, GET_EXACT);
  139. TRACE3(MIB, "MIB GET: %u %u %u",
  140. ulSize, pimgod->IMGOD_TypeID, pigc->dwLoggingLevel);
  141. MM_MibGet(&imgid, pimgod, &ulSize, GET_EXACT);
  142. TRACE3(MIB, "MIB GET: %u %u %u",
  143. ulSize, pimgod->IMGOD_TypeID, pigc->dwLoggingLevel);
  144. // mib get first interface binding
  145. ulSize = 0;
  146. imgid.IMGID_TypeID = IPSAMPLE_IF_BINDING_ID;
  147. imgid.IMGID_IfIndex = 0;
  148. piib = (PIPSAMPLE_IF_BINDING) pimgod->IMGOD_Buffer;
  149. piia = IPSAMPLE_IF_ADDRESS_TABLE(piib);
  150. MM_MibGet(&imgid, pimgod, &ulSize, GET_FIRST);
  151. TRACE4(MIB, "MIB GET: %u %u %u %u",
  152. ulSize, pimgod->IMGOD_TypeID, piib->dwState, piib->ulCount);
  153. MM_MibGet(&imgid, pimgod, &ulSize, GET_FIRST);
  154. TRACE5(MIB, "MIB GET: %u %u %u %u %u",
  155. ulSize, pimgod->IMGOD_TypeID, piib->dwState, piib->ulCount,
  156. piia->dwAddress);
  157. // mib get next interface binding
  158. ulSize = 0;
  159. MM_MibGet(&imgid, pimgod, &ulSize, GET_NEXT);
  160. TRACE4(MIB, "MIB GET: %u %u %u %u",
  161. ulSize, pimgod->IMGOD_TypeID, piib->dwState, piib->ulCount);
  162. MM_MibGet(&imgid, pimgod, &ulSize, GET_NEXT);
  163. TRACE5(MIB, "MIB GET: %u %u %u %u %u",
  164. ulSize, pimgod->IMGOD_TypeID, piib->dwState, piib->ulCount,
  165. piia->dwAddress);
  166. // mib set interface configuration
  167. pimsid->IMSID_TypeID = IPSAMPLE_IF_CONFIG_ID;
  168. pimsid->IMSID_IfIndex = 0;
  169. pimsid->IMSID_BufferSize = sizeof(IPSAMPLE_IF_CONFIG);
  170. piic = (PIPSAMPLE_IF_CONFIG) pimsid->IMSID_Buffer;
  171. piic->ulMetric = 0;
  172. MM_MibSet(pimsid);
  173. TRACE1(MIB, "MIB SET: %u", pimsid->IMSID_TypeID);
  174. WaitForSingleObject(hEvent, INFINITE);
  175. CM_GetEventMessage(&rpeEvent, &mMessage);
  176. TRACE1(DEBUG, "SetMib %u", rpeEvent);
  177. // mib get interface configuration
  178. ulSize = 0;
  179. imgid.IMGID_TypeID = IPSAMPLE_IF_CONFIG_ID;
  180. imgid.IMGID_IfIndex = 0;
  181. piic = (PIPSAMPLE_IF_CONFIG) pimgod->IMGOD_Buffer;
  182. MM_MibGet(&imgid, pimgod, &ulSize, GET_EXACT);
  183. TRACE3(MIB, "MIB GET: %u %u %u",
  184. ulSize, pimgod->IMGOD_TypeID, piic->ulMetric);
  185. MM_MibGet(&imgid, pimgod, &ulSize, GET_EXACT);
  186. TRACE3(MIB, "MIB GET: %u %u %u",
  187. ulSize, pimgod->IMGOD_TypeID, piic->ulMetric);
  188. }
  189. VOID
  190. NM_Test(HANDLE hEvent)
  191. {
  192. DWORD dwErr = NO_ERROR;
  193. ULONG i;
  194. WCHAR pwszIfName[20];
  195. ROUTING_PROTOCOL_EVENTS rpeEvent;
  196. MESSAGE mMessage;
  197. IPSAMPLE_IF_CONFIG iic = { 1 };
  198. PIP_ADAPTER_BINDING_INFO pBinding;
  199. MALLOC(&pBinding,
  200. (sizeof(IP_ADAPTER_BINDING_INFO) + 3 * sizeof(IP_LOCAL_BINDING)),
  201. &dwErr);
  202. pBinding->AddressCount = 3;
  203. pBinding->Address[0].Address = 0xfffffffd;
  204. pBinding->Address[0].Mask = 0xffffffff;
  205. pBinding->Address[1].Address = INADDR_ANY;
  206. pBinding->Address[1].Mask = 0xffffffff;
  207. pBinding->Address[2].Address = 0xfffffffe;
  208. pBinding->Address[2].Mask = 0xffffffff;
  209. // add interfaces
  210. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  211. {
  212. swprintf(pwszIfName, L"if%u", i);
  213. dwErr = NM_AddInterface(pwszIfName,
  214. i,
  215. PERMANENT,
  216. &iic);
  217. if (dwErr != NO_ERROR)
  218. {
  219. TRACE1(DEBUG, "NM_Test: Could not Add Interface %u", i);
  220. break;
  221. }
  222. }
  223. TRACE1(DEBUG, "...AddInterface %u", dwErr);
  224. CE_Display(&g_ce);
  225. // bind interfaces
  226. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  227. {
  228. pBinding->Address[0].Address = i;
  229. dwErr = NM_InterfaceStatus(i,
  230. FALSE,
  231. RIS_INTERFACE_ADDRESS_CHANGE,
  232. (PVOID) pBinding);
  233. if (dwErr != NO_ERROR)
  234. {
  235. TRACE1(DEBUG, "NM_Test: Could not Bind Interface %u", i);
  236. break;
  237. }
  238. }
  239. TRACE1(DEBUG, "...BindInterface %u", dwErr);
  240. CE_Display(&g_ce);
  241. // activate interfaces
  242. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  243. {
  244. dwErr = NM_InterfaceStatus(i,
  245. TRUE,
  246. RIS_INTERFACE_ENABLED,
  247. NULL);
  248. if (dwErr != NO_ERROR)
  249. {
  250. TRACE1(DEBUG, "NM_Test: Could not Activate Interface %u", i);
  251. break;
  252. }
  253. }
  254. TRACE1(DEBUG, "...ActivateInterface %u", dwErr);
  255. CE_Display(&g_ce);
  256. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  257. {
  258. dwErr = NM_DoUpdateRoutes(i);
  259. if (dwErr != NO_ERROR)
  260. {
  261. TRACE1(DEBUG, "NM_Test: Couldn't UpdateRoutes on Interface %u", i);
  262. break;
  263. }
  264. dwErr = WaitForSingleObject(hEvent, INFINITE);
  265. dwErr = CM_GetEventMessage(&rpeEvent, &mMessage);
  266. TRACE2(DEBUG, "DidUpdateRoutes %u %u", rpeEvent, dwErr);
  267. }
  268. TRACE1(DEBUG, "...DoUpdateRoutes %u", dwErr);
  269. CE_Display(&g_ce);
  270. // interface is active (enabled and bound)
  271. TRACE1(DEBUG, "Sleeping...", dwErr);
  272. Sleep(SECTOMILLISEC(TEST_SLEEP_TIME));
  273. TRACE1(DEBUG, "...Awake", dwErr);
  274. // mib manager test
  275. MM_Test(hEvent);
  276. TRACE0(DEBUG, "...MM_Test");
  277. // deactivate interfaces
  278. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  279. {
  280. dwErr = NM_InterfaceStatus(i,
  281. FALSE,
  282. RIS_INTERFACE_DISABLED,
  283. NULL);
  284. if (dwErr != NO_ERROR)
  285. {
  286. TRACE1(DEBUG, "NM_Test: Could not Deactivate Interface %u", i);
  287. break;
  288. }
  289. }
  290. TRACE1(DEBUG, "...DeactivateInterface %u", dwErr);
  291. CE_Display(&g_ce);
  292. // unbind interfaces
  293. pBinding->AddressCount = 0;
  294. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  295. {
  296. dwErr = NM_InterfaceStatus(i,
  297. FALSE,
  298. RIS_INTERFACE_ADDRESS_CHANGE,
  299. (PVOID) pBinding);
  300. if (dwErr != NO_ERROR)
  301. {
  302. TRACE1(DEBUG, "NM_Test: Could not Unbind Interface %u", i);
  303. break;
  304. }
  305. }
  306. TRACE1(DEBUG, "...UnbindInterface %u", dwErr);
  307. CE_Display(&g_ce);
  308. // delete interfaces
  309. for (i = 0; i < TEST_NUM_INTERFACE; i++)
  310. {
  311. dwErr = NM_DeleteInterface(i);
  312. if (dwErr != NO_ERROR)
  313. {
  314. TRACE1(DEBUG, "CM_Test: Could not Delete Interface %u", i);
  315. break;
  316. }
  317. }
  318. TRACE1(DEBUG, "...DeleteInterface %u", dwErr);
  319. CE_Display(&g_ce);
  320. }
  321. VOID
  322. CM_Test()
  323. {
  324. DWORD dwErr = NO_ERROR;
  325. IPSAMPLE_GLOBAL_CONFIG igc = { IPSAMPLE_LOGGING_INFO };
  326. ROUTING_PROTOCOL_EVENTS rpeEvent;
  327. MESSAGE mMessage;
  328. HANDLE hEvent;
  329. hEvent = CreateEvent(NULL, FALSE, FALSE, "RouterManagerEvent");
  330. // start protocol
  331. dwErr = CM_StartProtocol(hEvent, NULL, (PVOID) (&igc));
  332. TRACE1(DEBUG, "StartProtocol %u", dwErr);
  333. CE_Display(&g_ce);
  334. // network manager test
  335. NM_Test(hEvent);
  336. TRACE0(DEBUG, "...NM_Test");
  337. // stop protocol
  338. dwErr = CM_StopProtocol();
  339. TRACE1(DEBUG, "StopProtocol %u", dwErr);
  340. CE_Display(&g_ce);
  341. // wait for stop event
  342. dwErr = WaitForSingleObject(hEvent, INFINITE);
  343. dwErr = CM_GetEventMessage(&rpeEvent, &mMessage);
  344. TRACE2(DEBUG, "Stopped %u %u", rpeEvent, dwErr);
  345. CE_Display(&g_ce);
  346. CloseHandle(hEvent);
  347. }
  348. VOID
  349. WINAPI
  350. TestProtocol(VOID)
  351. {
  352. ULONG i;
  353. TRACE0(DEBUG, "Hello World!!!");
  354. for (i = 0; i < TEST_NUM_START_STOP; i++)
  355. {
  356. CM_Test();
  357. TRACE1(DEBUG, "...CM_Test (%u)", i);
  358. }
  359. HT_Test();
  360. TRACE0(DEBUG, "...HT_Test");
  361. ErrorCodes();
  362. TRACE0(DEBUG, "...ErrorCodes");
  363. }
  364. #else // TEST
  365. VOID
  366. WINAPI
  367. TestProtocol(VOID)
  368. {
  369. TRACE0(ANY, "Hello World!");
  370. }
  371. #endif // TEST