Leaked source code of windows server 2003
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.

2379 lines
65 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. tex.c
  5. Abstract:
  6. Test program for the EX subcomponent of the NTOS project
  7. Author:
  8. Steve Wood (stevewo) 31-Mar-1989
  9. Revision History:
  10. --*/
  11. #include "exp.h"
  12. //#include "zwapi.h"
  13. #include <version.h>
  14. #include <string.h>
  15. #define DumpPool(x, y)
  16. BOOLEAN
  17. ExTest (
  18. VOID
  19. );
  20. PTESTFCN TestFunction = ExTest;
  21. #ifndef MIPS
  22. USHORT TestEvent = 0;
  23. USHORT TestHandle = 0;
  24. USHORT TestInfo = 0;
  25. USHORT TestLuid = 0;
  26. USHORT TestMemory = 0;
  27. USHORT TestParty = 0;
  28. USHORT TestPool = 0;
  29. USHORT TestResource = 0;
  30. USHORT TestBitMap = 0;
  31. USHORT TestSemaphore = 0;
  32. USHORT TestTimer = 0;
  33. USHORT TestZone = 0;
  34. USHORT TestMutant = 0;
  35. USHORT TestException = 0;
  36. #else
  37. USHORT TestEvent = 1;
  38. USHORT TestHandle = 0;
  39. USHORT TestInfo = 0;
  40. USHORT TestLuid = 0;
  41. USHORT TestMemory = 0;
  42. USHORT TestParty = 0;
  43. USHORT TestPool = 0;
  44. USHORT TestResource = 0;
  45. USHORT TestBitMap = 0;
  46. USHORT TestSemaphore = 2;
  47. USHORT TestTimer = 3;
  48. USHORT TestZone = 0;
  49. USHORT TestMutant = 4;
  50. USHORT TestException = 0;
  51. #endif // MIPS
  52. BOOLEAN
  53. DoEventTest(
  54. )
  55. {
  56. ULONG DesiredAccess = EVENT_ALL_ACCESS;
  57. EVENT_BASIC_INFORMATION EventInformation;
  58. HANDLE Handle1;
  59. HANDLE Handle1c;
  60. HANDLE Handle2;
  61. HANDLE Handle2c;
  62. ULONG Length;
  63. UNICODE_STRING Name1;
  64. UNICODE_STRING Name2;
  65. OBJECT_ATTRIBUTES Object1Attributes;
  66. OBJECT_ATTRIBUTES Object2Attributes;
  67. LONG State;
  68. NTSTATUS Status;
  69. //
  70. // Announce start of event test.
  71. //
  72. DbgPrint(" ** Start of Event Test **\n");
  73. //
  74. // Initialize strings and fill in object attributes structures.
  75. //
  76. RtlInitUnicodeString(&Name1, L "\\Event1");
  77. RtlInitUnicodeString(&Name2, L "\\Event2");
  78. InitializeObjectAttributes(&Object1Attributes, &Name1, 0, NULL, NULL);
  79. InitializeObjectAttributes(&Object2Attributes, &Name2, 0, NULL, NULL);
  80. //
  81. // Create event 1.
  82. //
  83. Status = ZwCreateEvent(&Handle1c, DesiredAccess, &Object1Attributes,
  84. NotificationEvent, TRUE);
  85. if (Status < 0) {
  86. DbgPrint(" Event test - create event 1 failed, status = %lx\n", Status);
  87. }
  88. //
  89. // Open event 1.
  90. //
  91. Status = ZwOpenEvent(&Handle1, DesiredAccess, &Object1Attributes);
  92. if (Status < 0) {
  93. DbgPrint(" Event test - open event 1 failed, status = %lx\n", Status);
  94. }
  95. //
  96. // Query event 1.
  97. //
  98. EventInformation.EventState = 0;
  99. Length = 0;
  100. Status = ZwQueryEvent(Handle1, EventBasicInformation,
  101. (PVOID)&EventInformation, sizeof(EVENT_BASIC_INFORMATION),
  102. &Length);
  103. if (Status < 0) {
  104. DbgPrint(" Event test - query event 1 failed, status = %lx\n", Status);
  105. }
  106. if (EventInformation.EventType != NotificationEvent) {
  107. DbgPrint(" Event test - query event 1 wrong event type\n");
  108. }
  109. if (EventInformation.EventState == 0) {
  110. DbgPrint(" Event test - query event 1 current state wrong\n");
  111. }
  112. if (Length != sizeof(EVENT_BASIC_INFORMATION)) {
  113. DbgPrint(" Event test - query event 1 return length wrong\n");
  114. }
  115. //
  116. // Pulse event 1.
  117. //
  118. State = 0;
  119. Status = ZwPulseEvent(Handle1, &State);
  120. if (Status < 0) {
  121. DbgPrint(" Event test - pulse event 1 failed, status = %lx\n", Status);
  122. }
  123. if (State == 0) {
  124. DbgPrint(" Event test - pulse event 1 previous state wrong\n");
  125. }
  126. //
  127. // Set event 1.
  128. //
  129. State = 1;
  130. Status = ZwSetEvent(Handle1, &State);
  131. if (Status < 0) {
  132. DbgPrint(" Event test - set event 1 failed, status = %lx\n", Status);
  133. }
  134. if (State == 1) {
  135. DbgPrint(" Event test - set event 1 previous state wrong\n");
  136. }
  137. //
  138. // Wait on event 1.
  139. //
  140. Status = ZwWaitForSingleObject(Handle1, FALSE, NULL);
  141. if (Status < 0) {
  142. DbgPrint(" Event test - wait event 1 failed\n");
  143. }
  144. //
  145. // Reset event 1.
  146. //
  147. State = 0;
  148. Status = ZwResetEvent(Handle1, &State);
  149. if (Status < 0) {
  150. DbgPrint(" Event test - reset event 1 failed, status = %lx\n", Status);
  151. }
  152. if (State == 0) {
  153. DbgPrint(" Event test - reset event 1 previous state wrong\n");
  154. }
  155. //
  156. // Create event 2.
  157. //
  158. Status = ZwCreateEvent(&Handle2c, DesiredAccess, &Object2Attributes,
  159. NotificationEvent, FALSE);
  160. if (Status < 0) {
  161. DbgPrint(" Event test - create event 2 failed, status = %lx\n", Status);
  162. }
  163. //
  164. // Open event 2.
  165. //
  166. Status = ZwOpenEvent(&Handle2, DesiredAccess, &Object2Attributes);
  167. if (Status < 0) {
  168. DbgPrint(" Event test - open event 2 failed, status = %lx\n", Status);
  169. }
  170. //
  171. // Query event 2.
  172. //
  173. EventInformation.EventState = 1;
  174. Length = 0;
  175. Status = ZwQueryEvent(Handle2, EventBasicInformation,
  176. (PVOID)&EventInformation, sizeof(EVENT_BASIC_INFORMATION),
  177. &Length);
  178. if (Status < 0) {
  179. DbgPrint(" Event test - query event 2 failed, status = %lx\n", Status);
  180. }
  181. if (EventInformation.EventType != NotificationEvent) {
  182. DbgPrint(" Event test - query event 2 wrong event type\n");
  183. }
  184. if (EventInformation.EventState == 1) {
  185. DbgPrint(" Event test - query event 2 current state wrong\n");
  186. }
  187. if (Length != sizeof(EVENT_BASIC_INFORMATION)) {
  188. DbgPrint(" Event test - query event 2 return length wrong\n");
  189. }
  190. //
  191. // Pulse event 2.
  192. //
  193. State = 1;
  194. Status = ZwPulseEvent(Handle2, &State);
  195. if (Status < 0) {
  196. DbgPrint(" Event test - pulse event 2 failed, status = %lx\n", Status);
  197. }
  198. if (State == 1) {
  199. DbgPrint(" Event test - pulse event 2 previous state wrong\n");
  200. }
  201. //
  202. // Set event 2.
  203. //
  204. State = 1;
  205. Status = ZwSetEvent(Handle2, &State);
  206. if (Status < 0) {
  207. DbgPrint(" Event test - set event 2 failed, status = %lx\n", Status);
  208. }
  209. if (State == 1) {
  210. DbgPrint(" Event test - set event 2 previous state wrong\n");
  211. }
  212. //
  213. // Wait on event 2.
  214. //
  215. Status = ZwWaitForSingleObject(Handle2, FALSE, NULL);
  216. if (Status < 0) {
  217. DbgPrint(" Event test - wait event 2 failed\n");
  218. }
  219. //
  220. // Reset event 2.
  221. //
  222. State = 0;
  223. Status = ZwResetEvent(Handle2, &State);
  224. if (Status < 0) {
  225. DbgPrint(" Event test - reset event 2 failed, status = %lx\n", Status);
  226. }
  227. if (State == 0) {
  228. DbgPrint(" Event test - reset event 2 previous state wrong\n");
  229. }
  230. //
  231. // Close all handles.
  232. //
  233. Status = NtClose(Handle1);
  234. if (Status < 0) {
  235. DbgPrint(" Event test - event 1 close failed, status = %lx\n", Status);
  236. }
  237. Status = NtClose(Handle1c);
  238. if (Status < 0) {
  239. DbgPrint(" Event test - event 1c close failed, status = %lx\n", Status);
  240. }
  241. Status = NtClose(Handle2);
  242. if (Status < 0) {
  243. DbgPrint(" Event test - event 2 close failed, status = %lx\n", Status);
  244. }
  245. Status = NtClose(Handle2c);
  246. if (Status < 0) {
  247. DbgPrint(" Event test - event 2c close failed, status = %lx\n", Status);
  248. }
  249. //
  250. // Announce end of event test.
  251. //
  252. DbgPrint(" ** End of Event Test **\n");
  253. return TRUE;
  254. }
  255. BOOLEAN
  256. DoExceptionTest(
  257. )
  258. {
  259. #ifndef i386
  260. NTSTATUS Status;
  261. //
  262. // Announce start of system service exception test.
  263. //
  264. DbgPrint(" ** Start of System Service Exception Test **\n");
  265. //
  266. // Eventually this should have a test case for each system service that
  267. // has input of output arguments which are addressed by pointers. The
  268. // intent of this test is to make sure that each service correctly
  269. // handles access violations.
  270. //
  271. //
  272. // Query system time test.
  273. //
  274. Status = ZwQuerySystemTime((PLARGE_INTEGER)NULL);
  275. if (Status != STATUS_ACCESS_VIOLATION) {
  276. DbgPrint(" Exception test - NtQuerySystemTime failed, status = %lx\n", Status);
  277. }
  278. //
  279. // Set system time test.
  280. //
  281. Status = ZwSetSystemTime((PLARGE_INTEGER)NULL, (PLARGE_INTEGER)NULL);
  282. if (Status != STATUS_ACCESS_VIOLATION) {
  283. DbgPrint(" Exception test - NtSetSystemTime failed, status = %lx\n", Status);
  284. }
  285. //
  286. // Announce end of system service exception test.
  287. //
  288. DbgPrint(" ** End of System Service Exception Test **\n");
  289. #else
  290. DbgPrint(" ** Skip System Service Exception Test for 386 **\n");
  291. #endif // i386
  292. return TRUE;
  293. }
  294. BOOLEAN
  295. DoMutantTest(
  296. )
  297. {
  298. LONG Count;
  299. ULONG DesiredAccess = MUTANT_ALL_ACCESS;
  300. HANDLE Handle1;
  301. HANDLE Handle1c;
  302. HANDLE Handle2;
  303. HANDLE Handle2c;
  304. ULONG Length;
  305. STRING Name1;
  306. STRING Name2;
  307. OBJECT_ATTRIBUTES Object1Attributes;
  308. OBJECT_ATTRIBUTES Object2Attributes;
  309. MUTANT_BASIC_INFORMATION MutantInformation;
  310. NTSTATUS Status;
  311. //
  312. // Announce start of mutant test.
  313. //
  314. DbgPrint(" ** Start of Mutant Test **\n");
  315. //
  316. // Initialize strings and fill in object attributes structures.
  317. //
  318. RtlInitUnicodeString(&Name1, L"\\Mutant1");
  319. RtlInitUnicodeString(&Name2, L"\\Mutant2");
  320. InitializeObjectAttributes(&Object1Attributes,&Name1,0,NULL,NULL);
  321. InitializeObjectAttributes(&Object2Attributes,&Name2,0,NULL,NULL);
  322. //
  323. // Create mutant 1.
  324. //
  325. Status = ZwCreateMutant(&Handle1c, DesiredAccess, &Object1Attributes,
  326. FALSE);
  327. if (Status < 0) {
  328. DbgPrint(" Mutant test - create mutant 1 failed, status = %lx\n",
  329. Status);
  330. }
  331. //
  332. // Open mutant 1.
  333. //
  334. Status = ZwOpenMutant(&Handle1, DesiredAccess, &Object1Attributes);
  335. if (Status < 0) {
  336. DbgPrint(" Mutant test - open mutant 1 failed, status = %lx\n",
  337. Status);
  338. }
  339. //
  340. // Query mutant 1.
  341. //
  342. MutantInformation.CurrentCount = 10;
  343. MutantInformation.AbandonedState = TRUE;
  344. Length = 0;
  345. Status = ZwQueryMutant(Handle1, MutantBasicInformation,
  346. (PVOID)&MutantInformation,
  347. sizeof(MUTANT_BASIC_INFORMATION), &Length);
  348. if (Status < 0) {
  349. DbgPrint(" Mutant test - query mutant 1 failed, status = %lx\n",
  350. Status);
  351. }
  352. if (MutantInformation.CurrentCount != 1) {
  353. DbgPrint(" Mutant test - query mutant 1 current count wrong\n");
  354. }
  355. if (MutantInformation.AbandonedState != FALSE) {
  356. DbgPrint(" Mutant test - query mutant 1 abandoned state wrong\n");
  357. }
  358. if (Length != sizeof(MUTANT_BASIC_INFORMATION)) {
  359. DbgPrint(" Mutant test - query mutant 1 return length wrong\n");
  360. }
  361. //
  362. // Acquire mutant 1.
  363. //
  364. Status = ZwWaitForSingleObject(Handle1, FALSE, NULL);
  365. if (Status < 0) {
  366. DbgPrint(" Mutant test - wait mutant 1 failed, status = %lx\n",
  367. Status);
  368. }
  369. //
  370. // Release mutant 1.
  371. //
  372. Count = 100;
  373. Status = ZwReleaseMutant(Handle1, &Count);
  374. if (Status < 0) {
  375. DbgPrint(" Mutant test - release mutant 1 failed, status = %lx\n",
  376. Status);
  377. }
  378. if (Count != 0) {
  379. DbgPrint(" Mutant test - release mutant 1 previous count wrong\n");
  380. }
  381. //
  382. // Create mutant 2.
  383. //
  384. Status = ZwCreateMutant(&Handle2c, DesiredAccess, &Object2Attributes,
  385. FALSE);
  386. if (Status < 0) {
  387. DbgPrint(" Mutant test - create mutant 2 failed, status = %lx\n",
  388. Status);
  389. }
  390. //
  391. // Open mutant 2.
  392. //
  393. Status = ZwOpenMutant(&Handle2, DesiredAccess, &Object2Attributes);
  394. if (Status < 0) {
  395. DbgPrint(" Mutant test - open mutant 2 failed, status = %lx\n",
  396. Status);
  397. }
  398. //
  399. // Acquire mutant 2.
  400. //
  401. Status = ZwWaitForSingleObject(Handle2, FALSE, NULL);
  402. if (Status < 0) {
  403. DbgPrint(" Mutant test - wait mutant 2 failed, status = %lx\n",
  404. Status);
  405. }
  406. //
  407. // Query mutant 2.
  408. //
  409. MutantInformation.CurrentCount = 20;
  410. MutantInformation.AbandonedState = TRUE;
  411. Length = 0;
  412. Status = ZwQueryMutant(Handle2, MutantBasicInformation,
  413. (PVOID)&MutantInformation,
  414. sizeof(MUTANT_BASIC_INFORMATION), &Length);
  415. if (Status < 0) {
  416. DbgPrint(" Mutant test - query mutant 2 failed, status = %lx\n",
  417. Status);
  418. }
  419. if (MutantInformation.CurrentCount != 0) {
  420. DbgPrint(" Mutant test - query mutant 2 current count wrong\n");
  421. }
  422. if (MutantInformation.AbandonedState != FALSE) {
  423. DbgPrint(" Mutant test - query mutant 2 abandoned state wrong\n");
  424. }
  425. if (Length != sizeof(MUTANT_BASIC_INFORMATION)) {
  426. DbgPrint(" Mutant test - query mutant 2 return length wrong\n");
  427. }
  428. //
  429. // Acquire mutant 2.
  430. //
  431. Status = ZwWaitForSingleObject(Handle2, FALSE, NULL);
  432. if (Status < 0) {
  433. DbgPrint(" Mutant test - wait mutant 2 failed, status = %lx\n",
  434. Status);
  435. }
  436. //
  437. // Release mutant 2.
  438. //
  439. Count = 100;
  440. Status = ZwReleaseMutant(Handle2, &Count);
  441. if (Status < 0) {
  442. DbgPrint(" Mutant test - release mutant 2 failed, status = %lx\n",
  443. Status);
  444. }
  445. if (Count != - 1) {
  446. DbgPrint(" Mutant test - release mutant 2 previous count wrong\n");
  447. }
  448. //
  449. // Release mutant 2.
  450. //
  451. Count = 100;
  452. Status = ZwReleaseMutant(Handle2, &Count);
  453. if (Status < 0) {
  454. DbgPrint(" Mutant test - release mutant 2 failed, status = %lx\n",
  455. Status);
  456. }
  457. if (Count != 0) {
  458. DbgPrint(" Mutant test - release mutant 2 previous count wrong\n");
  459. }
  460. //
  461. // Close all handles.
  462. //
  463. Status = NtClose(Handle1);
  464. if (Status < 0) {
  465. DbgPrint(" Mutant test - mutant 1 close failed, status = %lx\n",
  466. Status);
  467. }
  468. Status = NtClose(Handle1c);
  469. if (Status < 0) {
  470. DbgPrint(" Mutant test - mutant 1c close failed, status = %lx\n",
  471. Status);
  472. }
  473. Status = NtClose(Handle2);
  474. if (Status < 0) {
  475. DbgPrint(" Mutant test - mutant 2 close failed, status = %lx\n",
  476. Status);
  477. }
  478. Status = NtClose(Handle2c);
  479. if (Status < 0) {
  480. DbgPrint(" Mutant test - mutant 2c close failed, status = %lx\n",
  481. Status);
  482. }
  483. //
  484. // Announce end of mutant test.
  485. //
  486. DbgPrint(" ** End of Mutant Test **\n");
  487. return TRUE;
  488. }
  489. BOOLEAN
  490. DoSemaphoreTest(
  491. )
  492. {
  493. LONG Count;
  494. ULONG DesiredAccess = SEMAPHORE_ALL_ACCESS;
  495. HANDLE Handle1;
  496. HANDLE Handle1c;
  497. HANDLE Handle2;
  498. HANDLE Handle2c;
  499. ULONG Length;
  500. STRING Name1;
  501. STRING Name2;
  502. OBJECT_ATTRIBUTES Object1Attributes;
  503. OBJECT_ATTRIBUTES Object2Attributes;
  504. SEMAPHORE_BASIC_INFORMATION SemaphoreInformation;
  505. NTSTATUS Status;
  506. //
  507. // Announce start of semaphore test.
  508. //
  509. DbgPrint(" ** Start of Semaphore Test **\n");
  510. //
  511. // Initialize strings and fill in object attributes structures.
  512. //
  513. RtlInitUnicodeString(&Name1, L"\\Semaphore1");
  514. RtlInitUnicodeString(&Name2, L"\\Semaphore2");
  515. InitializeObjectAttributes(&Object1Attributes,&Name1,0,NULL,NULL);
  516. InitializeObjectAttributes(&Object2Attributes,&Name2,0,NULL,NULL);
  517. //
  518. // Create semaphore 1.
  519. //
  520. Status = ZwCreateSemaphore(&Handle1c, DesiredAccess, &Object1Attributes,
  521. 0, 10);
  522. if (Status < 0) {
  523. DbgPrint(" Semaphore test - create semaphore 1 failed, status = %lx\n",
  524. Status);
  525. }
  526. //
  527. // Open semaphore 1.
  528. //
  529. Status = ZwOpenSemaphore(&Handle1, DesiredAccess, &Object1Attributes);
  530. if (Status < 0) {
  531. DbgPrint(" Semaphore test - open semaphore 1 failed, status = %lx\n",
  532. Status);
  533. }
  534. //
  535. // Query semaphore 1.
  536. //
  537. SemaphoreInformation.CurrentCount = 10;
  538. SemaphoreInformation.MaximumCount = 0;
  539. Length = 0;
  540. Status = ZwQuerySemaphore(Handle1, SemaphoreBasicInformation,
  541. (PVOID)&SemaphoreInformation,
  542. sizeof(SEMAPHORE_BASIC_INFORMATION), &Length);
  543. if (Status < 0) {
  544. DbgPrint(" Semaphore test - query semaphore 1 failed, status = %lx\n",
  545. Status);
  546. }
  547. if (SemaphoreInformation.CurrentCount != 0) {
  548. DbgPrint(" Semaphore test - query semaphore 1 current count wrong\n");
  549. }
  550. if (SemaphoreInformation.MaximumCount != 10) {
  551. DbgPrint(" Semaphore test - query semaphore 1 maximum count wrong\n");
  552. }
  553. if (Length != sizeof(SEMAPHORE_BASIC_INFORMATION)) {
  554. DbgPrint(" Semaphore test - query semaphore 1 return length wrong\n");
  555. }
  556. //
  557. // Release semaphore 1.
  558. //
  559. Count = 100;
  560. Status = ZwReleaseSemaphore(Handle1, 2, &Count);
  561. if (Status < 0) {
  562. DbgPrint(" Semaphore test - release semaphore 1 failed, status = %lx\n",
  563. Status);
  564. }
  565. if (Count != 0) {
  566. DbgPrint(" Semaphore test - release semaphore 1 previous count wrong\n");
  567. }
  568. //
  569. // Release semaphore 1.
  570. //
  571. Count = 100;
  572. Status = ZwReleaseSemaphore(Handle1, 5, &Count);
  573. if (Status < 0) {
  574. DbgPrint(" Semaphore test - release semaphore 1 failed, status = %lx\n",
  575. Status);
  576. }
  577. if (Count != 2) {
  578. DbgPrint(" Semaphore test - release semaphore 1 previous count wrong\n");
  579. }
  580. //
  581. // Create semaphore 2.
  582. //
  583. Status = ZwCreateSemaphore(&Handle2c, DesiredAccess, &Object2Attributes,
  584. 5, 20);
  585. if (Status < 0) {
  586. DbgPrint(" Semaphore test - create semaphore 2 failed, status = %lx\n",
  587. Status);
  588. }
  589. //
  590. // Open semaphore 2.
  591. //
  592. Status = ZwOpenSemaphore(&Handle2, DesiredAccess, &Object2Attributes);
  593. if (Status < 0) {
  594. DbgPrint(" Semaphore test - open semaphore 2 failed, status = %lx\n",
  595. Status);
  596. }
  597. //
  598. // Query semaphore 2.
  599. //
  600. SemaphoreInformation.CurrentCount = 20;
  601. SemaphoreInformation.MaximumCount = 5;
  602. Length = 0;
  603. Status = ZwQuerySemaphore(Handle2, SemaphoreBasicInformation,
  604. (PVOID)&SemaphoreInformation,
  605. sizeof(SEMAPHORE_BASIC_INFORMATION), &Length);
  606. if (Status < 0) {
  607. DbgPrint(" Semaphore test - query semaphore 2 failed, status = %lx\n",
  608. Status);
  609. }
  610. if (SemaphoreInformation.CurrentCount != 5) {
  611. DbgPrint(" Semaphore test - query semaphore 2 current count wrong\n");
  612. }
  613. if (SemaphoreInformation.MaximumCount != 20) {
  614. DbgPrint(" Semaphore test - query semaphore 2 maximum count wrong\n");
  615. }
  616. if (Length != sizeof(SEMAPHORE_BASIC_INFORMATION)) {
  617. DbgPrint(" Semaphore test - query semaphore 2 return length wrong\n");
  618. }
  619. //
  620. // Release semaphore 2.
  621. //
  622. Count = 100;
  623. Status = ZwReleaseSemaphore(Handle2, 3, &Count);
  624. if (Status < 0) {
  625. DbgPrint(" Semaphore test - release semaphore 2 failed, status = %lx\n",
  626. Status);
  627. }
  628. if (Count != 5) {
  629. DbgPrint(" Semaphore test - release semaphore 2 previous count wrong\n");
  630. }
  631. //
  632. // Release semaphore 2.
  633. //
  634. Count = 100;
  635. Status = ZwReleaseSemaphore(Handle2, 5, &Count);
  636. if (Status < 0) {
  637. DbgPrint(" Semaphore test - release semaphore 2 failed, status = %lx\n",
  638. Status);
  639. }
  640. if (Count != 8) {
  641. DbgPrint(" Semaphore test - release semaphore 2 previous count wrong\n");
  642. }
  643. //
  644. // Close all handles.
  645. //
  646. Status = NtClose(Handle1);
  647. if (Status < 0) {
  648. DbgPrint(" Semaphore test - semaphore 1 close failed, status = %lx\n",
  649. Status);
  650. }
  651. Status = NtClose(Handle1c);
  652. if (Status < 0) {
  653. DbgPrint(" Semaphore test - semaphore 1c close failed, status = %lx\n",
  654. Status);
  655. }
  656. Status = NtClose(Handle2);
  657. if (Status < 0) {
  658. DbgPrint(" Semaphore test - semaphore 2 close failed, status = %lx\n",
  659. Status);
  660. }
  661. Status = NtClose(Handle2c);
  662. if (Status < 0) {
  663. DbgPrint(" Semaphore test - semaphore 2c close failed, status = %lx\n",
  664. Status);
  665. }
  666. //
  667. // Announce end of semaphore test.
  668. //
  669. DbgPrint(" ** End of Semaphore Test **\n");
  670. return TRUE;
  671. }
  672. VOID
  673. TimerApcRoutine (
  674. IN PVOID TimerContext,
  675. IN ULONG TimerLowValue,
  676. IN LONG TimerHighValue
  677. )
  678. {
  679. *((PBOOLEAN)TimerContext) = TRUE;
  680. return;
  681. }
  682. BOOLEAN
  683. DoTimerTest (
  684. )
  685. {
  686. BOOLEAN ApcHappened;
  687. BOOLEAN CurrentState;
  688. ULONG DesiredAccess = TIMER_ALL_ACCESS;
  689. LARGE_INTEGER DueTime;
  690. HANDLE Handle1;
  691. HANDLE Handle1c;
  692. HANDLE Handle2;
  693. HANDLE Handle2c;
  694. ULONG Length;
  695. STRING Name1;
  696. STRING Name2;
  697. OBJECT_ATTRIBUTES Object1Attributes;
  698. OBJECT_ATTRIBUTES Object2Attributes;
  699. BOOLEAN PreviousState;
  700. TIMER_BASIC_INFORMATION TimerInformation;
  701. NTSTATUS Status;
  702. //
  703. // Announce start of timer test.
  704. //
  705. DbgPrint(" ** Start of Timer Test **\n");
  706. //
  707. // Initialize strings and fill in object attributes structures.
  708. //
  709. RtlInitUnicodeString(&Name1, L"\\Timer1");
  710. RtlInitUnicodeString(&Name2, L"\\Timer2");
  711. InitializeObjectAttributes(&Object1Attributes,&Name1,0,NULL,NULL);
  712. InitializeObjectAttributes(&Object2Attributes,&Name2,0,NULL,NULL);
  713. //
  714. // Create timer 1.
  715. //
  716. Status = ZwCreateTimer(&Handle1c, DesiredAccess, &Object1Attributes);
  717. if (!NT_SUCCESS(Status)) {
  718. DbgPrint(" Timer test - create timer 1 failed, status = %lx\n",
  719. Status);
  720. }
  721. //
  722. // Open timer 1.
  723. //
  724. Status = ZwOpenTimer(&Handle1, DesiredAccess, &Object1Attributes);
  725. if (Status < 0) {
  726. DbgPrint(" Timer test - open timer 1 failed, status = %lx\n",
  727. Status);
  728. }
  729. //
  730. // Query timer 1.
  731. //
  732. TimerInformation.TimerState = TRUE;
  733. Length = 0;
  734. Status = ZwQueryTimer(Handle1, TimerBasicInformation,
  735. (PVOID)&TimerInformation,
  736. sizeof(TIMER_BASIC_INFORMATION), &Length);
  737. if (Status < 0) {
  738. DbgPrint(" Timer test - query timer 1 failed, status = %lx\n",
  739. Status);
  740. }
  741. if (TimerInformation.TimerState) {
  742. DbgPrint(" Timer test - query timer 1 state wrong\n");
  743. }
  744. if (Length != sizeof(TIMER_BASIC_INFORMATION)) {
  745. DbgPrint(" Timer test - query timer 1 return length wrong\n");
  746. }
  747. //
  748. // Set timer 1 and then cancel timer 1.
  749. //
  750. DueTime.LowPart = -100000;
  751. DueTime.HighPart = -1;
  752. PreviousState = TRUE;
  753. Status = ZwSetTimer(Handle1, &DueTime, NULL, NULL, &PreviousState);
  754. if (!NT_SUCCESS(Status)) {
  755. DbgPrint(" Timer test - set timer 1 failed, status = %lx\n",
  756. Status);
  757. }
  758. if (PreviousState) {
  759. DbgPrint(" Timer test - set timer 1 previous state wrong\n");
  760. }
  761. CurrentState = TRUE;
  762. Status = ZwCancelTimer(Handle1, &CurrentState);
  763. if (!NT_SUCCESS(Status)) {
  764. DbgPrint(" Timer test - cancel timer 1 failed, status = %lx\n",
  765. Status);
  766. }
  767. if (CurrentState) {
  768. DbgPrint(" Timer test - cancel timer 1 current state wrong\n");
  769. }
  770. //
  771. // Set timer 1, wait for timer to expire, and then cancel timer 1.
  772. //
  773. DueTime.LowPart = -5;
  774. DueTime.HighPart = -1;
  775. PreviousState = TRUE;
  776. Status = ZwSetTimer(Handle1, &DueTime, NULL, NULL, &PreviousState);
  777. if (!NT_SUCCESS(Status)) {
  778. DbgPrint(" Timer test - set timer 1 failed, status = %lx\n",
  779. Status);
  780. }
  781. if (PreviousState) {
  782. DbgPrint(" Timer test - set timer 1 previous state wrong\n");
  783. }
  784. Status = ZwWaitForSingleObject(Handle1, FALSE, NULL);
  785. if (!NT_SUCCESS(Status)) {
  786. DbgPrint(" Timer test - wait timer 1 failed, status = %lx\n",
  787. Status);
  788. }
  789. CurrentState = FALSE;
  790. Status = ZwCancelTimer(Handle1, &CurrentState);
  791. if (!NT_SUCCESS(Status)) {
  792. DbgPrint(" Timer test - cancel timer 1 failed, status = %lx\n",
  793. Status);
  794. }
  795. if (!CurrentState) {
  796. DbgPrint(" Timer test - cancel timer 1 current state wrong\n");
  797. }
  798. //
  799. // Set timer 1 with APC, then cancel timer 1.
  800. //
  801. ApcHappened = FALSE;
  802. DueTime.LowPart = -100000;
  803. DueTime.HighPart = -1;
  804. PreviousState = FALSE;
  805. Status = ZwSetTimer(Handle1, &DueTime, TimerApcRoutine, &ApcHappened,
  806. &PreviousState);
  807. if (!NT_SUCCESS(Status)) {
  808. DbgPrint(" Timer test - set timer 1 failed, status = %lx\n",
  809. Status);
  810. }
  811. if (!PreviousState) {
  812. DbgPrint(" Timer test - set timer 1 previous state wrong\n");
  813. }
  814. CurrentState = TRUE;
  815. Status = ZwCancelTimer(Handle1, &CurrentState);
  816. if (!NT_SUCCESS(Status)) {
  817. DbgPrint(" Timer test - cancel timer 1 failed, status = %lx\n",
  818. Status);
  819. }
  820. if (CurrentState) {
  821. DbgPrint(" Timer test - cancel timer 1 current state wrong\n");
  822. }
  823. if (ApcHappened) {
  824. DbgPrint(" Timer test - cancel timer 1 APC happened state wrong\n");
  825. }
  826. //
  827. // Set timer 1 with APC, set timer again with APC, wait for timer, then
  828. // cancel timer 1.
  829. //
  830. ApcHappened = FALSE;
  831. DueTime.LowPart = -100000;
  832. DueTime.HighPart = -1;
  833. PreviousState = TRUE;
  834. Status = ZwSetTimer(Handle1, &DueTime, TimerApcRoutine, &ApcHappened,
  835. &PreviousState);
  836. if (!NT_SUCCESS(Status)) {
  837. DbgPrint(" Timer test - set timer 1 failed, status = %lx\n",
  838. Status);
  839. }
  840. if (PreviousState) {
  841. DbgPrint(" Timer test - set timer 1 previous state wrong\n");
  842. }
  843. DueTime.LowPart = -5;
  844. DueTime.HighPart = -1;
  845. PreviousState = TRUE;
  846. Status = ZwSetTimer(Handle1, &DueTime, TimerApcRoutine, &ApcHappened,
  847. &PreviousState);
  848. if (!NT_SUCCESS(Status)) {
  849. DbgPrint(" Timer test - set timer 1 failed, status = %lx\n",
  850. Status);
  851. }
  852. if (PreviousState) {
  853. DbgPrint(" Timer test - set timer 1 previous state wrong\n");
  854. }
  855. Status = ZwWaitForSingleObject(Handle1, FALSE, NULL);
  856. if (!NT_SUCCESS(Status)) {
  857. DbgPrint(" Timer test - wait timer 1 failed, status = %lx\n",
  858. Status);
  859. }
  860. CurrentState = FALSE;
  861. Status = ZwCancelTimer(Handle1, &CurrentState);
  862. if (!NT_SUCCESS(Status)) {
  863. DbgPrint(" Timer test - cancel timer 1 failed, status = %lx\n",
  864. Status);
  865. }
  866. if (!CurrentState) {
  867. DbgPrint(" Timer test - cancel timer 1 current state wrong\n");
  868. }
  869. if (!ApcHappened) {
  870. DbgPrint(" Timer test - cancel timer 1 APC happened state wrong\n");
  871. }
  872. //
  873. // Create timer 2.
  874. //
  875. Status = ZwCreateTimer(&Handle2c, DesiredAccess, &Object2Attributes);
  876. if (Status < 0) {
  877. DbgPrint(" Timer test - create timer 2 failed, status = %lx\n",
  878. Status);
  879. }
  880. //
  881. // Open timer 2.
  882. //
  883. Status = ZwOpenTimer(&Handle2, DesiredAccess, &Object2Attributes);
  884. if (Status < 0) {
  885. DbgPrint(" Timer test - open timer 2 failed, status = %lx\n",
  886. Status);
  887. }
  888. //
  889. // Query timer 2.
  890. //
  891. TimerInformation.TimerState = TRUE;
  892. Length = 0;
  893. Status = ZwQueryTimer(Handle2, TimerBasicInformation,
  894. (PVOID)&TimerInformation,
  895. sizeof(TIMER_BASIC_INFORMATION), &Length);
  896. if (Status < 0) {
  897. DbgPrint(" Timer test - query timer 2 failed, status = %lx\n",
  898. Status);
  899. }
  900. if (TimerInformation.TimerState) {
  901. DbgPrint(" Timer test - query timer 2 state wrong\n");
  902. }
  903. if (Length != sizeof(TIMER_BASIC_INFORMATION)) {
  904. DbgPrint(" Timer test - query timer 2 return length wrong\n");
  905. }
  906. //
  907. // Close all handles.
  908. //
  909. Status = NtClose(Handle1);
  910. if (Status < 0) {
  911. DbgPrint(" Timer test - timer 1 close failed, status = %lx\n",
  912. Status);
  913. }
  914. Status = NtClose(Handle1c);
  915. if (Status < 0) {
  916. DbgPrint(" Timer test - timer 1c close failed, status = %lx\n",
  917. Status);
  918. }
  919. Status = NtClose(Handle2);
  920. if (Status < 0) {
  921. DbgPrint(" Timer test - timer 2 close failed, status = %lx\n",
  922. Status);
  923. }
  924. Status = NtClose(Handle2c);
  925. if (Status < 0) {
  926. DbgPrint(" Timer test - timer 2c close failed, status = %lx\n",
  927. Status);
  928. }
  929. //
  930. // Announce end of timer test.
  931. //
  932. DbgPrint(" ** End of Timer Test **\n");
  933. return TRUE;
  934. }
  935. BOOLEAN
  936. TestDupHandle1(
  937. IN PVOID HandleTableEntry
  938. )
  939. {
  940. DbgPrint( "Dupping %lx\n", HandleTableEntry );
  941. return( TRUE );
  942. }
  943. BOOLEAN
  944. TestDupHandle4(
  945. IN PVOID HandleTableEntry
  946. )
  947. {
  948. PULONG p = (PULONG)HandleTableEntry;
  949. ULONG i;
  950. if (!((*p>>4) % 4)) {
  951. return( FALSE );
  952. }
  953. DbgPrint( "Dupping " );
  954. for (i=0; i<4; i++) {
  955. DbgPrint( " %lx", *p++ );
  956. }
  957. DbgPrint( "\n" );
  958. return( TRUE );
  959. }
  960. BOOLEAN
  961. TestEnumHandle1(
  962. IN PVOID HandleTableEntry,
  963. IN PVOID EnumParameter
  964. )
  965. {
  966. if (EnumParameter == HandleTableEntry) {
  967. return( TRUE );
  968. }
  969. else {
  970. return( FALSE );
  971. }
  972. }
  973. BOOLEAN
  974. TestEnumHandle4(
  975. IN PVOID HandleTableEntry,
  976. IN PVOID EnumParameter
  977. )
  978. {
  979. if (EnumParameter == (PVOID)*(PULONG)HandleTableEntry) {
  980. return( TRUE );
  981. }
  982. else {
  983. return( FALSE );
  984. }
  985. }
  986. #define HANDLE_TEST_SIZE 30
  987. BOOLEAN
  988. DoHandleTest( void )
  989. {
  990. PVOID HandleTable1;
  991. PVOID HandleTable4;
  992. PVOID HandleTable1a;
  993. PVOID HandleTable4a;
  994. HANDLE HandlesForTable1[ HANDLE_TEST_SIZE ];
  995. HANDLE HandlesForTable4[ HANDLE_TEST_SIZE ];
  996. HANDLE h;
  997. PULONG HandleValue;
  998. BOOLEAN LockFlag;
  999. ULONG i, v[4];
  1000. HandleTable1 = ExCreateHandleTable( (PEPROCESS)NULL, 0L, 0L, 0L, MUTEX_LEVEL_PS_CID_TABLE, FALSE );
  1001. HandleTable4 = ExCreateHandleTable( (PEPROCESS)NULL, 16L, 8L, 2L, MUTEX_LEVEL_OB_TABLE, TRUE );
  1002. ExDumpHandleTable( (PEPROCESS)NULL, HandleTable1, NULL );
  1003. ExDumpHandleTable( (PEPROCESS)NULL, HandleTable4, NULL );
  1004. for (i=0; i<HANDLE_TEST_SIZE; i++) {
  1005. v[0] = (i+1) << 4;
  1006. v[1] = (i+1) << 3;
  1007. v[2] = (i+1) << 2;
  1008. v[3] = (i+1) << 1;
  1009. HandlesForTable1[ i ] = ExCreateHandle( HandleTable1, (PVOID)(v[0]) );
  1010. DbgPrint( "HandleTable1: %lx => %lx\n", HandlesForTable1[ i ], v[0] );
  1011. HandlesForTable4[ i ] = ExCreateHandle( HandleTable4, (PVOID)(&v[0]) );
  1012. DbgPrint( "HandleTable4: %lx => %lx\n", HandlesForTable4[ i ], v[0] );
  1013. }
  1014. ExDumpHandleTable( HandleTable1, NULL, NULL );
  1015. ExDumpHandleTable( HandleTable4, NULL, NULL );
  1016. for (i=0; i<=HANDLE_TEST_SIZE; i++) {
  1017. v[0] = (i+1) << 4;
  1018. v[1] = (i+1) << 3;
  1019. v[2] = (i+1) << 2;
  1020. v[3] = (i+1) << 1;
  1021. if (ExEnumHandleTable( HandleTable1, TestEnumHandle1, (PVOID)(v[0]), &h )) {
  1022. DbgPrint( "HandleTable1: Found: %lx <= %lx\n", v[0], h );
  1023. }
  1024. else {
  1025. DbgPrint( "HandleTable1: %lx not found\n", v[0] );
  1026. }
  1027. if (ExEnumHandleTable( HandleTable4, TestEnumHandle4, (PVOID)(v[0]), &h )) {
  1028. DbgPrint( "HandleTable4: Found: %lx <= %lx\n", v[0], h );
  1029. }
  1030. else {
  1031. DbgPrint( "HandleTable4: %lx not found\n", v[0] );
  1032. }
  1033. }
  1034. for (i=0; i<HANDLE_TEST_SIZE; i++) {
  1035. LockFlag = ExMapHandleToPointer( HandleTable1,
  1036. HandlesForTable1[ i ],
  1037. (PVOID)&HandleValue
  1038. );
  1039. DbgPrint( "HandleTable1: %lx => %lx\n",
  1040. HandlesForTable1[ i ], HandleValue
  1041. );
  1042. ExUnlockHandleTable( HandleTable1, LockFlag );
  1043. LockFlag = ExMapHandleToPointer( HandleTable4,
  1044. HandlesForTable4[ i ],
  1045. (PVOID)&HandleValue
  1046. );
  1047. DbgPrint( "HandleTable4: %lx => %lx\n",
  1048. HandlesForTable4[ i ], *HandleValue
  1049. );
  1050. ExUnlockHandleTable( HandleTable4, LockFlag );
  1051. }
  1052. HandleTable1a = ExDupHandleTable( (PEPROCESS)NULL, HandleTable1, TestDupHandle1 );
  1053. HandleTable4a = ExDupHandleTable( (PEPROCESS)NULL, HandleTable4, TestDupHandle4 );
  1054. ExDumpHandleTable( HandleTable1a, NULL, NULL );
  1055. ExDumpHandleTable( HandleTable4a, NULL, NULL );
  1056. for (i=0; i<HANDLE_TEST_SIZE; i++) {
  1057. ExDestroyHandle( HandleTable1, HandlesForTable1[ i ] );
  1058. ExDestroyHandle( HandleTable4, HandlesForTable4[ i ] );
  1059. }
  1060. ExDumpHandleTable( HandleTable1, NULL, NULL );
  1061. ExDumpHandleTable( HandleTable4, NULL, NULL );
  1062. ExDestroyHandleTable( HandleTable1, NULL );
  1063. ExDestroyHandleTable( HandleTable4, NULL );
  1064. ExDestroyHandleTable( HandleTable1a, NULL );
  1065. ExDestroyHandleTable( HandleTable4a, NULL );
  1066. return( TRUE );
  1067. }
  1068. BOOLEAN
  1069. DoInfoTest( void )
  1070. {
  1071. BOOLEAN Result = FALSE;
  1072. NTSTATUS Status;
  1073. SYSTEM_BASIC_INFORMATION BasicInfo;
  1074. SYSTEM_PROCESSOR_INFORMATION ProcessorInfo;
  1075. ULONG ReturnedLength;
  1076. DbgPrint(" ** Start of System Information Test **\n");
  1077. Status = ZwQuerySystemInformation( SystemBasicInformation,
  1078. (PVOID)&BasicInfo,
  1079. sizeof( BasicInfo ),
  1080. &ReturnedLength
  1081. );
  1082. if (NT_SUCCESS( Status )) {
  1083. DbgPrint( "NtQuerySystemInformation returns:\n" );
  1084. DbgPrint( " Number of Processors: %ld\n",
  1085. BasicInfo.NumberOfProcessors
  1086. );
  1087. DbgPrint( " OEM Machine Id: %lx\n",
  1088. BasicInfo.OemMachineId
  1089. );
  1090. DbgPrint( " Timer Resolution: %ld microseconds\n",
  1091. BasicInfo.TimerResolutionInMicroSeconds
  1092. );
  1093. DbgPrint( " Page Size: %ld Allocation Granularity: %ld\n",
  1094. BasicInfo.PageSize,
  1095. BasicInfo.AllocationGranularity
  1096. );
  1097. DbgPrint( " User Mode Address Range: 0x%08lx <-> 0x%08lx\n",
  1098. BasicInfo.MinimumUserModeAddress,
  1099. BasicInfo.MaximumUserModeAddress
  1100. );
  1101. }
  1102. else {
  1103. DbgPrint( "NtQuerySystemInformation failed. Status == %X\n",
  1104. Status
  1105. );
  1106. }
  1107. DbgPrint(" ** End of System Information Test **\n");
  1108. return( Result );
  1109. }
  1110. BOOLEAN
  1111. DoLuidTest( void )
  1112. {
  1113. BOOLEAN Result = TRUE;
  1114. NTSTATUS Status;
  1115. LUID FirstLuid;
  1116. LUID SecondLuid;
  1117. FirstLuid.LowPart = 0;
  1118. FirstLuid.HighPart = 0;
  1119. SecondLuid.LowPart = 0;
  1120. SecondLuid.HighPart = 0;
  1121. DbgPrint(" ** Start of Locally Unique ID Test **\n");
  1122. Status = ZwAllocateLocallyUniqueId( &FirstLuid );
  1123. if (!NT_SUCCESS( Status )) {
  1124. DbgPrint( "First Luid Allocation Error.\n" );
  1125. Result = FALSE;
  1126. }
  1127. if (LiLeqZero( FirstLuid )) {
  1128. DbgPrint( "First Luid Allocation Failed - Bad Value.\n" );
  1129. Result = FALSE;
  1130. }
  1131. if (Result) {
  1132. Status = ZwAllocateLocallyUniqueId( &SecondLuid );
  1133. if (!NT_SUCCESS( Status )) {
  1134. DbgPrint( "Second Luid Allocation Error.\n" );
  1135. Result = FALSE;
  1136. }
  1137. if (LiLeqZero( SecondLuid )) {
  1138. DbgPrint( "Second Luid Allocation Failed - Bad Value.\n" );
  1139. Result = FALSE;
  1140. }
  1141. if (LiLeq( FirstLuid, SecondLuid )) {
  1142. DbgPrint( "Second Luid Allocation Failed - Not larger than first value.\n" );
  1143. Result = FALSE;
  1144. }
  1145. }
  1146. DbgPrint(" ** End of Locally Unique ID Test **\n");
  1147. return( Result );
  1148. }
  1149. char MemoryTestBuffer1[ 128 ];
  1150. char TestString1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  1151. char TestString2[] = "123456789012345678901234567890123456789012345678901234567890";
  1152. char MemoryTestBuffer2[ 128 ];
  1153. BOOLEAN
  1154. DoMemoryTest( void )
  1155. {
  1156. LONG i,j,k;
  1157. BOOLEAN Result;
  1158. DbgPrint(" ** Start of Memory Test **\n");
  1159. Result = TRUE;
  1160. strcpy( MemoryTestBuffer1, TestString1 );
  1161. for (i=15; i>=0; i--) {
  1162. MemoryTestBuffer1[16] = 0xFF;
  1163. RtlZeroMemory( &MemoryTestBuffer1[i], 16-i );
  1164. if (strncmp( MemoryTestBuffer1, TestString1, i ) || MemoryTestBuffer1[i] || !MemoryTestBuffer1[16]) {
  1165. DbgPrint( "*** failed *** - RtlZeroMemory( %s, %ld )\n",
  1166. MemoryTestBuffer1, 16-i );
  1167. Result = FALSE;
  1168. }
  1169. }
  1170. for (k = 0; k < 8; k++) {
  1171. DbgPrint("k = %d, j = ",k);
  1172. for (j = 0; j < 8; j++) {
  1173. DbgPrint(" %d ",j);
  1174. for (i=0; i<26; i++) {
  1175. RtlZeroMemory( MemoryTestBuffer1, (ULONG)sizeof( MemoryTestBuffer1 ) );
  1176. RtlMoveMemory( &MemoryTestBuffer1[j], &TestString2[k], i );
  1177. if (strncmp( &MemoryTestBuffer1[j], &TestString2[k], i ) || MemoryTestBuffer1[j+i]) {
  1178. DbgPrint( "*** failed *** - RtlMoveMemory( %s, %s, %ld )\n",
  1179. &MemoryTestBuffer1[j], TestString2, i );
  1180. Result = FALSE;
  1181. }
  1182. }
  1183. }
  1184. DbgPrint("\n");
  1185. }
  1186. for (k = 0; k < 8; k++) {
  1187. DbgPrint("k = %d, j = ",k);
  1188. for (j = 0; j < 8; j++) {
  1189. DbgPrint(" %d ",j);
  1190. for (i=0; i<26; i++) {
  1191. RtlZeroMemory( MemoryTestBuffer2, (ULONG)sizeof( MemoryTestBuffer2 ) );
  1192. RtlMoveMemory( &MemoryTestBuffer2[j], &TestString2[k], i );
  1193. if (strncmp( &MemoryTestBuffer2[j], &TestString2[k], i ) || MemoryTestBuffer2[j+i]) {
  1194. DbgPrint( "*** failed *** - RtlMoveMemory( %s, %s, %ld )\n",
  1195. &MemoryTestBuffer2[j], TestString2, i );
  1196. Result = FALSE;
  1197. }
  1198. }
  1199. }
  1200. DbgPrint("\n");
  1201. }
  1202. for (k = 0; k < 8; k++) {
  1203. DbgPrint("k = %d, j = ",k);
  1204. for (j = 0; j < 8; j++) {
  1205. DbgPrint(" %d ",j);
  1206. for (i=0; i<26; i++) {
  1207. strcpy( MemoryTestBuffer1, TestString1 );
  1208. RtlMoveMemory( &MemoryTestBuffer1[j], &MemoryTestBuffer1[k], i );
  1209. if (strncmp( &MemoryTestBuffer1[j], &TestString1[k], i )) {
  1210. DbgPrint( "*** failed *** - RtlMoveMemory( %s, %s, %ld )\n",
  1211. &MemoryTestBuffer2[j], TestString2, i );
  1212. Result = FALSE;
  1213. }
  1214. }
  1215. }
  1216. DbgPrint("\n");
  1217. }
  1218. DbgPrint(" ** End of Memory Test **\n");
  1219. return( Result );
  1220. }
  1221. BOOLEAN
  1222. DoPartyTest( void )
  1223. {
  1224. BOOLEAN Result = TRUE;
  1225. NTSTATUS Status;
  1226. OBJECT_ATTRIBUTES ObjectAttributes;
  1227. HANDLE Handle;
  1228. DbgPrint(" ** Start of Party By Number Test **\n");
  1229. NtPartyByNumber( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 );
  1230. InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
  1231. Status = ZwCreateEvent( &Handle,
  1232. EVENT_ALL_ACCESS,
  1233. &ObjectAttributes, NotificationEvent ,TRUE);
  1234. NtPartyByNumber( PARTY_DUMP_OBJECT_BY_HANDLE, Handle, NULL );
  1235. ZwClose( Handle );
  1236. NtPartyByNumber( PARTY_DUMP_OBJECT_BY_HANDLE, Handle, NULL );
  1237. DbgPrint(" ** End of Party By Number Test **\n");
  1238. return( Result );
  1239. }
  1240. BOOLEAN
  1241. DoPoolTest( void )
  1242. {
  1243. PVOID p,p0,p1,p2,p3;
  1244. p = ExAllocatePool(NonPagedPool,4000L);
  1245. DumpPool("After 4000 byte Allocation",NonPagedPool);
  1246. p = ExAllocatePool(NonPagedPool,2000L);
  1247. DumpPool("After 2000 byte Allocation",NonPagedPool);
  1248. p = ExAllocatePool(NonPagedPool,2000L);
  1249. DumpPool("After 2000 byte Allocation",NonPagedPool);
  1250. p0 = ExAllocatePool(NonPagedPool,24L);
  1251. DumpPool("After 24 byte Allocation p0",NonPagedPool);
  1252. p1 = ExAllocatePool(NonPagedPool,24L);
  1253. DumpPool("After 24 byte Allocation p1",NonPagedPool);
  1254. p2 = ExAllocatePool(NonPagedPool,24L);
  1255. DumpPool("After 24 byte Allocation p2",NonPagedPool);
  1256. p3 = ExAllocatePool(NonPagedPool,24L);
  1257. DumpPool("After 24 byte Allocation p3",NonPagedPool);
  1258. ExFreePool(p1);
  1259. DumpPool("After 24 byte Deallocation p1",NonPagedPool);
  1260. ExFreePool(p3);
  1261. DumpPool("After 24 byte Deallocation p3",NonPagedPool);
  1262. ExFreePool(p2);
  1263. DumpPool("After 24 byte Deallocation p2",NonPagedPool);
  1264. ExFreePool(p0);
  1265. DumpPool("After 24 byte Deallocation p0",NonPagedPool);
  1266. p0 = ExAllocatePool(NonPagedPool,120L);
  1267. DumpPool("After 120 byte Allocation p0",NonPagedPool);
  1268. p1 = ExAllocatePool(NonPagedPool,24L);
  1269. DumpPool("After 24 byte Allocation p1",NonPagedPool);
  1270. ExFreePool(p1);
  1271. DumpPool("After 24 byte Deallocation p1",NonPagedPool);
  1272. ExFreePool(p0);
  1273. DumpPool("After 120 byte Deallocation p0",NonPagedPool);
  1274. return( TRUE );
  1275. }
  1276. BOOLEAN
  1277. DoZoneTest( void )
  1278. {
  1279. PULONG p1,p2;
  1280. PZONE_HEADER z;
  1281. NTSTATUS st;
  1282. PVOID b1, b2, b3, b4, b5;
  1283. z = ExAllocatePool(NonPagedPool,(ULONG)sizeof(ZONE_HEADER));
  1284. p1 = ExAllocatePool(NonPagedPool,2048L);
  1285. p2 = ExAllocatePool(NonPagedPool,1024L);
  1286. st = ExInitializeZone(z,512L,p1,2048L);
  1287. ExDumpZone(z);
  1288. b1 = ExAllocateFromZone(z);
  1289. DbgPrint("b1 = 0x%lx\n",b1);
  1290. ExDumpZone(z);
  1291. b2 = ExAllocateFromZone(z);
  1292. DbgPrint("b2 = 0x%lx\n",b2);
  1293. ExDumpZone(z);
  1294. b3 = ExAllocateFromZone(z);
  1295. DbgPrint("b3 = 0x%lx\n",b3);
  1296. ExDumpZone(z);
  1297. b4 = ExAllocateFromZone(z);
  1298. DbgPrint("b4 = 0x%lx\n",b4);
  1299. ExDumpZone(z);
  1300. b5 = ExAllocateFromZone(z);
  1301. DbgPrint("b5 = 0x%lx\n",b5);
  1302. ExDumpZone(z);
  1303. ExFreeToZone(z,b4);
  1304. ExDumpZone(z);
  1305. ExFreeToZone(z,b3);
  1306. ExDumpZone(z);
  1307. ExFreeToZone(z,b2);
  1308. ExDumpZone(z);
  1309. ExFreeToZone(z,b1);
  1310. ExDumpZone(z);
  1311. st = ExExtendZone(z,p2,1024L);
  1312. ExDumpZone(z);
  1313. return( TRUE );
  1314. }
  1315. ERESOURCE Resource;
  1316. ULONG ResourceCount;
  1317. KSEMAPHORE ResourceSemaphore;
  1318. PVOID ExDumpResource( IN PERESOURCE Resource );
  1319. VOID
  1320. Reader (
  1321. IN PVOID StartContext
  1322. )
  1323. {
  1324. LARGE_INTEGER Time;
  1325. //KeSetPriorityThread( &PsGetCurrentThread()->Tcb, 2 );
  1326. DbgPrint("Starting Reader %lx...\n", StartContext);
  1327. Time.LowPart = -(1+(ULONG)StartContext);
  1328. Time.HighPart = -1;
  1329. while (TRUE) {
  1330. (VOID)ExAcquireResourceShared(&Resource,TRUE);
  1331. DbgPrint("%lx with shared access\n", StartContext);
  1332. if (ResourceCount >= 10) {
  1333. ExReleaseResourceLite(&Resource);
  1334. break;
  1335. }
  1336. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1337. ExReleaseResourceLite(&Resource);
  1338. DbgPrint("%lx released shared access\n", StartContext);
  1339. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1340. }
  1341. DbgPrint("Reader %lx exiting\n", StartContext);
  1342. KeReleaseSemaphore(&ResourceSemaphore, 0, 1, FALSE);
  1343. }
  1344. VOID
  1345. Writer (
  1346. IN PVOID StartContext
  1347. )
  1348. {
  1349. LARGE_INTEGER Time;
  1350. //KeSetPriorityThread( &PsGetCurrentThread()->Tcb, 3 );
  1351. DbgPrint("Starting Writer %lx...\n", StartContext);
  1352. Time.LowPart = -(1+(ULONG)StartContext);
  1353. Time.HighPart = -1;
  1354. while (TRUE) {
  1355. (VOID)ExAcquireResourceExclusive(&Resource,TRUE);
  1356. DbgPrint("%lx with Exclusive access\n", StartContext);
  1357. ResourceCount += 1;
  1358. if (ResourceCount >= 10) {
  1359. ExReleaseResourceLite(&Resource);
  1360. break;
  1361. }
  1362. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1363. ExReleaseResourceLite(&Resource);
  1364. DbgPrint("%lx released Exclusive access\n", StartContext);
  1365. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1366. }
  1367. DbgPrint("Writer %lx exiting\n", StartContext);
  1368. KeReleaseSemaphore(&ResourceSemaphore, 0, 1, FALSE);
  1369. }
  1370. VOID
  1371. ReaderTurnedWriter (
  1372. IN PVOID StartContext
  1373. )
  1374. {
  1375. LARGE_INTEGER Time;
  1376. //KeSetPriorityThread( &PsGetCurrentThread()->Tcb, 4 );
  1377. DbgPrint("Starting Reader turned Writer %lx\n", StartContext);
  1378. Time.LowPart = -(1+(ULONG)StartContext);
  1379. Time.HighPart = -1;
  1380. while (TRUE) {
  1381. (VOID)ExAcquireResourceShared(&Resource,TRUE);
  1382. DbgPrint("%lx with shared access\n", StartContext);
  1383. if (ResourceCount >= 10) {
  1384. ExReleaseResourceLite(&Resource);
  1385. break;
  1386. }
  1387. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1388. ExConvertSharedToExclusive(&Resource);
  1389. DbgPrint("%lx Shared turned Exclusive access\n", StartContext);
  1390. ResourceCount += 1;
  1391. if (ResourceCount >= 10) {
  1392. ExReleaseResourceLite(&Resource);
  1393. break;
  1394. }
  1395. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1396. ExConvertExclusiveToShared(&Resource);
  1397. DbgPrint("%lx Exclusive turned Shared access\n", StartContext);
  1398. if (ResourceCount >= 10) {
  1399. ExReleaseResourceLite(&Resource);
  1400. break;
  1401. }
  1402. ExReleaseResourceLite(&Resource);
  1403. DbgPrint("%lx release Shared access\n", StartContext);
  1404. KeDelayExecutionThread ( KernelMode, FALSE, &Time);
  1405. }
  1406. DbgPrint("Reader turned Writer %lx exiting\n", StartContext);
  1407. KeReleaseSemaphore(&ResourceSemaphore, 0, 1, FALSE);
  1408. }
  1409. BOOLEAN
  1410. DoResourceTest( void )
  1411. {
  1412. HANDLE Handles[32];
  1413. ULONG i;
  1414. DbgPrint("Start DoResourceTest...\n");
  1415. ExInitializeResource(&Resource);
  1416. ResourceCount = 0;
  1417. KeInitializeSemaphore(&ResourceSemaphore, 0, MAXLONG);
  1418. for (i = 0; i < 4; i += 1) {
  1419. if (!NT_SUCCESS(PsCreateSystemThread(&Handles[i],
  1420. 0,
  1421. NULL,
  1422. 0,
  1423. NULL,
  1424. Reader,
  1425. (PVOID)i))) {
  1426. DbgPrint("Create system thread error %8lx\n", i);
  1427. }
  1428. }
  1429. for (i = 4; i < 6; i += 1) {
  1430. if (!NT_SUCCESS(PsCreateSystemThread(&Handles[i],
  1431. 0,
  1432. NULL,
  1433. 0,
  1434. NULL,
  1435. Writer,
  1436. (PVOID)i))) {
  1437. DbgPrint("Create system thread error %8lx\n", i);
  1438. }
  1439. }
  1440. for (i = 6; i < 8; i += 1) {
  1441. if (!NT_SUCCESS(PsCreateSystemThread(&Handles[i],
  1442. 0,
  1443. NULL,
  1444. 0,
  1445. NULL,
  1446. ReaderTurnedWriter,
  1447. (PVOID)i))) {
  1448. DbgPrint("Create system thread error %8lx\n", i);
  1449. }
  1450. }
  1451. DbgPrint("DoResourceTest wait for everyone to complete...\n");
  1452. for (i = 0; i < 8; i += 1) {
  1453. KeWaitForSingleObject( &ResourceSemaphore,
  1454. Executive,
  1455. KernelMode,
  1456. FALSE,
  1457. NULL);
  1458. }
  1459. DbgPrint("DoResourceTest Done\n");
  1460. return( TRUE );
  1461. }
  1462. BOOLEAN
  1463. DoBitMapTest( void )
  1464. {
  1465. ULONG Size;
  1466. PRTL_BITMAP BitMap;
  1467. DbgPrint("Start DoBitMapTest...\n");
  1468. //
  1469. // First create a new bitmap
  1470. //
  1471. Size = sizeof(RTL_BITMAP) + (((2048*8 + 31) / 32) * 4);
  1472. BitMap = (PRTL_BITMAP)(ExAllocatePool( NonPagedPool, Size ));
  1473. RtlInitializeBitMap( BitMap, (PULONG)(BitMap+1), 2048*8 );
  1474. //
  1475. // >>>> Test setting bits
  1476. //
  1477. //
  1478. // Now clear all bits
  1479. //
  1480. RtlClearAllBits( BitMap );
  1481. //
  1482. // Now set some bit patterns, and test them
  1483. //
  1484. RtlSetBits( BitMap, 0, 1 );
  1485. RtlSetBits( BitMap, 63, 1 );
  1486. RtlSetBits( BitMap, 65, 30 );
  1487. RtlSetBits( BitMap, 127, 2 );
  1488. RtlSetBits( BitMap, 191, 34 );
  1489. if ((BitMap->Buffer[0] != 0x00000001) ||
  1490. (BitMap->Buffer[1] != 0x80000000) ||
  1491. (BitMap->Buffer[2] != 0x7ffffffe) ||
  1492. (BitMap->Buffer[3] != 0x80000000) ||
  1493. (BitMap->Buffer[4] != 0x00000001) ||
  1494. (BitMap->Buffer[5] != 0x80000000) ||
  1495. (BitMap->Buffer[6] != 0xffffffff) ||
  1496. (BitMap->Buffer[7] != 0x00000001)) {
  1497. DbgPrint("RtlSetBits Error\n");
  1498. return FALSE;
  1499. }
  1500. //
  1501. // Now test some RtlFindClearBitsAndSet
  1502. //
  1503. RtlSetAllBits( BitMap );
  1504. RtlClearBits( BitMap, 0 + 10*32, 1 );
  1505. RtlClearBits( BitMap, 5 + 11*32, 1 );
  1506. RtlClearBits( BitMap, 7 + 12*32, 1 );
  1507. RtlClearBits( BitMap, 0 + 13*32, 9 );
  1508. RtlClearBits( BitMap, 4 + 14*32, 9 );
  1509. RtlClearBits( BitMap, 7 + 15*32, 9 );
  1510. RtlClearBits( BitMap, 0 + 16*32, 10 );
  1511. RtlClearBits( BitMap, 4 + 17*32, 10 );
  1512. RtlClearBits( BitMap, 6 + 18*32, 10 );
  1513. RtlClearBits( BitMap, 7 + 19*32, 10 );
  1514. RtlClearBits( BitMap, 0 + 110*32, 14 );
  1515. RtlClearBits( BitMap, 1 + 111*32, 14 );
  1516. RtlClearBits( BitMap, 2 + 112*32, 14 );
  1517. RtlClearBits( BitMap, 0 + 113*32, 15 );
  1518. RtlClearBits( BitMap, 1 + 114*32, 15 );
  1519. RtlClearBits( BitMap, 2 + 115*32, 15 );
  1520. // {
  1521. // ULONG i;
  1522. // for (i = 0; i < 16; i++) {
  1523. // DbgPrint("%2d: %08lx\n", i, BitMap->Buffer[i]);
  1524. // }
  1525. // }
  1526. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 0 + 113*32) {
  1527. DbgPrint("RtlFindClearBitsAndSet Error 0 + 113*32\n");
  1528. return FALSE;
  1529. }
  1530. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 1 + 114*32) {
  1531. DbgPrint("RtlFindClearBitsAndSet Error 1 + 114*32\n");
  1532. return FALSE;
  1533. }
  1534. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 2 + 115*32) {
  1535. DbgPrint("RtlFindClearBitsAndSet Error 2 + 115*32\n");
  1536. return FALSE;
  1537. }
  1538. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 0 + 110*32) {
  1539. DbgPrint("RtlFindClearBitsAndSet Error 0 + 110*32\n");
  1540. return FALSE;
  1541. }
  1542. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 1 + 111*32) {
  1543. DbgPrint("RtlFindClearBitsAndSet Error 1 + 111*32\n");
  1544. return FALSE;
  1545. }
  1546. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 2 + 112*32) {
  1547. DbgPrint("RtlFindClearBitsAndSet Error 2 + 112*32\n");
  1548. return FALSE;
  1549. }
  1550. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 0 + 16*32) {
  1551. DbgPrint("RtlFindClearBitsAndSet Error 0 + 16*32\n");
  1552. return FALSE;
  1553. }
  1554. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 4 + 17*32) {
  1555. DbgPrint("RtlFindClearBitsAndSet Error 4 + 17*32\n");
  1556. return FALSE;
  1557. }
  1558. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 6 + 18*32) {
  1559. DbgPrint("RtlFindClearBitsAndSet Error 6 + 18*32\n");
  1560. return FALSE;
  1561. }
  1562. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 7 + 19*32) {
  1563. DbgPrint("RtlFindClearBitsAndSet Error 7 + 19*32\n");
  1564. return FALSE;
  1565. }
  1566. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 0 + 13*32) {
  1567. DbgPrint("RtlFindClearBitsAndSet Error 0 + 13*32\n");
  1568. return FALSE;
  1569. }
  1570. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 4 + 14*32) {
  1571. DbgPrint("RtlFindClearBitsAndSet Error 4 + 14*32\n");
  1572. return FALSE;
  1573. }
  1574. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 7 + 15*32) {
  1575. DbgPrint("RtlFindClearBitsAndSet Error 7 + 15*32\n");
  1576. return FALSE;
  1577. }
  1578. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 0 + 10*32) {
  1579. DbgPrint("RtlFindClearBitsAndSet Error 0 + 10*32\n");
  1580. return FALSE;
  1581. }
  1582. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 5 + 11*32) {
  1583. DbgPrint("RtlFindClearBitsAndSet Error 5 + 11*32\n");
  1584. return FALSE;
  1585. }
  1586. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 7 + 12*32) {
  1587. DbgPrint("RtlFindClearBitsAndSet Error 7 + 12*32\n");
  1588. return FALSE;
  1589. }
  1590. //
  1591. // Now test some RtlFindClearBitsAndSet
  1592. //
  1593. RtlSetAllBits( BitMap );
  1594. RtlClearBits( BitMap, 0 + 0*32, 1 );
  1595. RtlClearBits( BitMap, 5 + 1*32, 1 );
  1596. RtlClearBits( BitMap, 7 + 2*32, 1 );
  1597. RtlClearBits( BitMap, 0 + 3*32, 9 );
  1598. RtlClearBits( BitMap, 4 + 4*32, 9 );
  1599. RtlClearBits( BitMap, 7 + 5*32, 9 );
  1600. RtlClearBits( BitMap, 0 + 6*32, 10 );
  1601. RtlClearBits( BitMap, 4 + 7*32, 10 );
  1602. RtlClearBits( BitMap, 6 + 8*32, 10 );
  1603. RtlClearBits( BitMap, 7 + 9*32, 10 );
  1604. RtlClearBits( BitMap, 0 + 10*32, 14 );
  1605. RtlClearBits( BitMap, 1 + 11*32, 14 );
  1606. RtlClearBits( BitMap, 2 + 12*32, 14 );
  1607. RtlClearBits( BitMap, 0 + 13*32, 15 );
  1608. RtlClearBits( BitMap, 1 + 14*32, 15 );
  1609. RtlClearBits( BitMap, 2 + 15*32, 15 );
  1610. // {
  1611. // ULONG i;
  1612. // for (i = 0; i < 16; i++) {
  1613. // DbgPrint("%2d: %08lx\n", i, BitMap->Buffer[i]);
  1614. // }
  1615. // }
  1616. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 0 + 13*32) {
  1617. DbgPrint("RtlFindClearBitsAndSet Error 0 + 13*32\n");
  1618. return FALSE;
  1619. }
  1620. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 1 + 14*32) {
  1621. DbgPrint("RtlFindClearBitsAndSet Error 1 + 14*32\n");
  1622. return FALSE;
  1623. }
  1624. if (RtlFindClearBitsAndSet( BitMap, 15, 0) != 2 + 15*32) {
  1625. DbgPrint("RtlFindClearBitsAndSet Error 2 + 15*32\n");
  1626. return FALSE;
  1627. }
  1628. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 0 + 10*32) {
  1629. DbgPrint("RtlFindClearBitsAndSet Error 0 + 10*32\n");
  1630. return FALSE;
  1631. }
  1632. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 1 + 11*32) {
  1633. DbgPrint("RtlFindClearBitsAndSet Error 1 + 11*32\n");
  1634. return FALSE;
  1635. }
  1636. if (RtlFindClearBitsAndSet( BitMap, 14, 0) != 2 + 12*32) {
  1637. DbgPrint("RtlFindClearBitsAndSet Error 2 + 12*32\n");
  1638. return FALSE;
  1639. }
  1640. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 0 + 6*32) {
  1641. DbgPrint("RtlFindClearBitsAndSet Error 0 + 6*32\n");
  1642. return FALSE;
  1643. }
  1644. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 4 + 7*32) {
  1645. DbgPrint("RtlFindClearBitsAndSet Error 4 + 7*32\n");
  1646. return FALSE;
  1647. }
  1648. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 6 + 8*32) {
  1649. DbgPrint("RtlFindClearBitsAndSet Error 6 + 8*32\n");
  1650. return FALSE;
  1651. }
  1652. if (RtlFindClearBitsAndSet( BitMap, 10, 0) != 7 + 9*32) {
  1653. DbgPrint("RtlFindClearBitsAndSet Error 7 + 9*32\n");
  1654. return FALSE;
  1655. }
  1656. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 0 + 3*32) {
  1657. DbgPrint("RtlFindClearBitsAndSet Error 0 + 3*32\n");
  1658. return FALSE;
  1659. }
  1660. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 4 + 4*32) {
  1661. DbgPrint("RtlFindClearBitsAndSet Error 4 + 4*32\n");
  1662. return FALSE;
  1663. }
  1664. if (RtlFindClearBitsAndSet( BitMap, 9, 0) != 7 + 5*32) {
  1665. DbgPrint("RtlFindClearBitsAndSet Error 7 + 5*32\n");
  1666. return FALSE;
  1667. }
  1668. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 0 + 0*32) {
  1669. DbgPrint("RtlFindClearBitsAndSet Error 0 + 0*32\n");
  1670. return FALSE;
  1671. }
  1672. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 5 + 1*32) {
  1673. DbgPrint("RtlFindClearBitsAndSet Error 5 + 1*32\n");
  1674. return FALSE;
  1675. }
  1676. if (RtlFindClearBitsAndSet( BitMap, 1, 0) != 7 + 2*32) {
  1677. DbgPrint("RtlFindClearBitsAndSet Error 7 + 2*32\n");
  1678. return FALSE;
  1679. }
  1680. //
  1681. // >>>> Test clearing bits
  1682. //
  1683. //
  1684. // Now clear all bits
  1685. //
  1686. RtlSetAllBits( BitMap );
  1687. //
  1688. // Now set some bit patterns, and test them
  1689. //
  1690. RtlClearBits( BitMap, 0, 1 );
  1691. RtlClearBits( BitMap, 63, 1 );
  1692. RtlClearBits( BitMap, 65, 30 );
  1693. RtlClearBits( BitMap, 127, 2 );
  1694. RtlClearBits( BitMap, 191, 34 );
  1695. if ((BitMap->Buffer[0] != ~0x00000001) ||
  1696. (BitMap->Buffer[1] != ~0x80000000) ||
  1697. (BitMap->Buffer[2] != ~0x7ffffffe) ||
  1698. (BitMap->Buffer[3] != ~0x80000000) ||
  1699. (BitMap->Buffer[4] != ~0x00000001) ||
  1700. (BitMap->Buffer[5] != ~0x80000000) ||
  1701. (BitMap->Buffer[6] != ~0xffffffff) ||
  1702. (BitMap->Buffer[7] != ~0x00000001)) {
  1703. DbgPrint("RtlClearBits Error\n");
  1704. return FALSE;
  1705. }
  1706. //
  1707. // Now test some RtlFindSetBitsAndClear
  1708. //
  1709. RtlClearAllBits( BitMap );
  1710. RtlSetBits( BitMap, 0 + 0*32, 1 );
  1711. RtlSetBits( BitMap, 5 + 1*32, 1 );
  1712. RtlSetBits( BitMap, 7 + 2*32, 1 );
  1713. RtlSetBits( BitMap, 0 + 3*32, 9 );
  1714. RtlSetBits( BitMap, 4 + 4*32, 9 );
  1715. RtlSetBits( BitMap, 7 + 5*32, 9 );
  1716. RtlSetBits( BitMap, 0 + 6*32, 10 );
  1717. RtlSetBits( BitMap, 4 + 7*32, 10 );
  1718. RtlSetBits( BitMap, 6 + 8*32, 10 );
  1719. RtlSetBits( BitMap, 7 + 9*32, 10 );
  1720. RtlSetBits( BitMap, 0 + 10*32, 14 );
  1721. RtlSetBits( BitMap, 1 + 11*32, 14 );
  1722. RtlSetBits( BitMap, 2 + 12*32, 14 );
  1723. RtlSetBits( BitMap, 0 + 13*32, 15 );
  1724. RtlSetBits( BitMap, 1 + 14*32, 15 );
  1725. RtlSetBits( BitMap, 2 + 15*32, 15 );
  1726. {
  1727. ULONG i;
  1728. for (i = 0; i < 16; i++) {
  1729. DbgPrint("%2d: %08lx\n", i, BitMap->Buffer[i]);
  1730. }
  1731. }
  1732. if (RtlFindSetBitsAndClear( BitMap, 15, 0) != 0 + 13*32) {
  1733. DbgPrint("RtlFindSetBitsAndClear Error 0 + 13*32\n");
  1734. return FALSE;
  1735. }
  1736. if (RtlFindSetBitsAndClear( BitMap, 15, 0) != 1 + 14*32) {
  1737. DbgPrint("RtlFindSetBitsAndClear Error 1 + 14*32\n");
  1738. return FALSE;
  1739. }
  1740. if (RtlFindSetBitsAndClear( BitMap, 15, 0) != 2 + 15*32) {
  1741. DbgPrint("RtlFindSetBitsAndClear Error 2 + 15*32\n");
  1742. return FALSE;
  1743. }
  1744. if (RtlFindSetBitsAndClear( BitMap, 14, 0) != 0 + 10*32) {
  1745. DbgPrint("RtlFindSetBitsAndClear Error 0 + 10*32\n");
  1746. return FALSE;
  1747. }
  1748. if (RtlFindSetBitsAndClear( BitMap, 14, 0) != 1 + 11*32) {
  1749. DbgPrint("RtlFindSetBitsAndClear Error 1 + 11*32\n");
  1750. return FALSE;
  1751. }
  1752. if (RtlFindSetBitsAndClear( BitMap, 14, 0) != 2 + 12*32) {
  1753. DbgPrint("RtlFindSetBitsAndClear Error 2 + 12*32\n");
  1754. return FALSE;
  1755. }
  1756. if (RtlFindSetBitsAndClear( BitMap, 10, 0) != 0 + 6*32) {
  1757. DbgPrint("RtlFindSetBitsAndClear Error 0 + 6*32\n");
  1758. return FALSE;
  1759. }
  1760. if (RtlFindSetBitsAndClear( BitMap, 10, 0) != 4 + 7*32) {
  1761. DbgPrint("RtlFindSetBitsAndClear Error 4 + 7*32\n");
  1762. return FALSE;
  1763. }
  1764. if (RtlFindSetBitsAndClear( BitMap, 10, 0) != 6 + 8*32) {
  1765. DbgPrint("RtlFindSetBitsAndClear Error 6 + 8*32\n");
  1766. return FALSE;
  1767. }
  1768. if (RtlFindSetBitsAndClear( BitMap, 10, 0) != 7 + 9*32) {
  1769. DbgPrint("RtlFindSetBitsAndClear Error 7 + 9*32\n");
  1770. return FALSE;
  1771. }
  1772. if (RtlFindSetBitsAndClear( BitMap, 9, 0) != 0 + 3*32) {
  1773. DbgPrint("RtlFindSetBitsAndClear Error 0 + 3*32\n");
  1774. return FALSE;
  1775. }
  1776. if (RtlFindSetBitsAndClear( BitMap, 9, 0) != 4 + 4*32) {
  1777. DbgPrint("RtlFindSetBitsAndClear Error 4 + 4*32\n");
  1778. return FALSE;
  1779. }
  1780. if (RtlFindSetBitsAndClear( BitMap, 9, 0) != 7 + 5*32) {
  1781. DbgPrint("RtlFindSetBitsAndClear Error 7 + 5*32\n");
  1782. return FALSE;
  1783. }
  1784. if (RtlFindSetBitsAndClear( BitMap, 1, 0) != 0 + 0*32) {
  1785. DbgPrint("RtlFindSetBitsAndClear Error 0 + 0*32\n");
  1786. return FALSE;
  1787. }
  1788. if (RtlFindSetBitsAndClear( BitMap, 1, 0) != 5 + 1*32) {
  1789. DbgPrint("RtlFindSetBitsAndClear Error 5 + 1*32\n");
  1790. return FALSE;
  1791. }
  1792. if (RtlFindSetBitsAndClear( BitMap, 1, 0) != 7 + 2*32) {
  1793. DbgPrint("RtlFindSetBitsAndClear Error 7 + 2*32\n");
  1794. return FALSE;
  1795. }
  1796. DbgPrint("DoBitMapTest Done.\n");
  1797. return TRUE;
  1798. }
  1799. BOOLEAN
  1800. ExTest (
  1801. VOID
  1802. )
  1803. {
  1804. USHORT i;
  1805. DbgPrint( "In extest\n" );
  1806. for (i=1; i<16; i++) {
  1807. if (i == TestEvent)
  1808. DoEventTest();
  1809. else
  1810. if (i == TestHandle)
  1811. DoHandleTest();
  1812. else
  1813. if (i == TestInfo)
  1814. DoInfoTest();
  1815. else
  1816. if (i == TestLuid) {
  1817. DoLuidTest();
  1818. }
  1819. else
  1820. if (i == TestMemory) {
  1821. DoMemoryTest();
  1822. }
  1823. else
  1824. if (i == TestParty)
  1825. DoPartyTest();
  1826. else
  1827. if (i == TestPool)
  1828. DoPoolTest();
  1829. else
  1830. if (i == TestResource)
  1831. DoResourceTest();
  1832. else
  1833. if (i == TestBitMap)
  1834. DoBitMapTest();
  1835. else
  1836. if (i == TestSemaphore)
  1837. DoSemaphoreTest();
  1838. else
  1839. if (i == TestTimer)
  1840. DoTimerTest();
  1841. else
  1842. if (i == TestZone)
  1843. DoZoneTest();
  1844. else
  1845. if (i == TestMutant)
  1846. DoMutantTest();
  1847. else
  1848. if (i == TestException)
  1849. DoExceptionTest();
  1850. }
  1851. TestFunction = NULL; // Invoke the CLI
  1852. return TRUE;
  1853. }
  1854. #ifndef MIPS
  1855. int
  1856. _CDECL
  1857. main(
  1858. int argc,
  1859. char *argv[]
  1860. )
  1861. {
  1862. #ifdef SIMULATOR
  1863. char c, *s;
  1864. USHORT i;
  1865. i = 1;
  1866. if (argc > 1 ) {
  1867. while (--argc) {
  1868. s = *++argv;
  1869. while ((c = *s++) != '\0') {
  1870. switch (c) {
  1871. case 'B':
  1872. case 'b':
  1873. TestBitMap = i++;
  1874. break;
  1875. case 'C':
  1876. case 'c':
  1877. TestException = i++;
  1878. break;
  1879. case 'E':
  1880. case 'e':
  1881. TestEvent = i++;
  1882. break;
  1883. case 'H':
  1884. case 'h':
  1885. TestHandle = i++;
  1886. break;
  1887. case 'I':
  1888. case 'i':
  1889. TestInfo = i++;
  1890. break;
  1891. case 'L':
  1892. case 'l':
  1893. TestLuid = i++;
  1894. break;
  1895. case 'M':
  1896. case 'm':
  1897. TestMemory = i++;
  1898. break;
  1899. case 'P':
  1900. case 'p':
  1901. TestPool = i++;
  1902. break;
  1903. case 'R':
  1904. case 'r':
  1905. TestResource = i++;
  1906. break;
  1907. case 'S':
  1908. case 's':
  1909. TestSemaphore = i++;
  1910. break;
  1911. case 'T':
  1912. case 't':
  1913. TestTimer = i++;
  1914. break;
  1915. case 'X':
  1916. case 'x':
  1917. TestMutant = i++;
  1918. break;
  1919. case 'Z':
  1920. case 'z':
  1921. TestZone = i++;
  1922. break;
  1923. default:
  1924. DbgPrint( "tex: invalid test code - '%s'", *argv );
  1925. break;
  1926. }
  1927. }
  1928. }
  1929. } else {
  1930. if (!strcmp( "DAVEC", szVerUser )) {
  1931. TestEvent = 1;
  1932. TestSemaphore = 2;
  1933. TestTimer = 3;
  1934. TestMutant = 4;
  1935. TestException = 5;
  1936. }
  1937. else
  1938. if (!strcmp( "MARKL", szVerUser )) {
  1939. TestPool = 1;
  1940. TestZone = 2;
  1941. }
  1942. else
  1943. if (!strcmp( "STEVEWO", szVerUser )) {
  1944. TestInfo = 1;
  1945. TestParty = 2;
  1946. TestMemory = 3;
  1947. TestHandle = 4;
  1948. }
  1949. else
  1950. if (!strcmp( "GARYKI", szVerUser )) {
  1951. TestResource = 1;
  1952. TestMemory = 2;
  1953. TestBitMap = 3;
  1954. }
  1955. else
  1956. if (!strcmp( "JIMK", szVerUser )) {
  1957. TestLuid = 1;
  1958. }
  1959. else {
  1960. DbgPrint( "*** Warning *** - %s is an unauthorized user of tex\n",
  1961. szVerUser
  1962. );
  1963. }
  1964. }
  1965. #else
  1966. TestEvent = 1;
  1967. TestSemaphore = 2;
  1968. TestTimer = 3;
  1969. TestMutant = 4;
  1970. TestException = 5;
  1971. #endif // SIMULATOR
  1972. TestFunction = extest;
  1973. KiSystemStartup();
  1974. return 0;
  1975. }
  1976. #endif // MIPS
  1977. void
  1978. oops()
  1979. {
  1980. ExTimerRundown();
  1981. }