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.

506 lines
14 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. TMcbSup.c
  5. Abstract:
  6. This module tests the Pinball Map Control Block support routines
  7. Author:
  8. Gary Kimura [GaryKi] 5-Feb-1990
  9. Revision History:
  10. --*/
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "PbProcs.h"
  14. VOID
  15. PbDumpMcb (
  16. IN PMCB Mcb
  17. );
  18. #ifndef SIMULATOR
  19. ULONG IoInitIncludeDevices;
  20. #endif // SIMULATOR
  21. BOOLEAN McbTest();
  22. int
  23. main(
  24. int argc,
  25. char *argv[]
  26. )
  27. {
  28. extern ULONG IoInitIncludeDevices;
  29. VOID KiSystemStartup();
  30. DbgPrint("sizeof(MCB) = %d\n", sizeof(MCB));
  31. IoInitIncludeDevices = 0; // IOINIT_FATFS |
  32. // IOINIT_PINBALLFS |
  33. // IOINIT_DDFS;
  34. TestFunction = McbTest;
  35. KiSystemStartup();
  36. return( 0 );
  37. }
  38. BOOLEAN
  39. McbTest()
  40. {
  41. BOOLEAN TestAddEntry();
  42. BOOLEAN TestRemoveEntry();
  43. BOOLEAN TestLookupEntry();
  44. BOOLEAN TestGetEntry();
  45. BOOLEAN TestLookupLastEntry();
  46. if (!TestAddEntry()) {
  47. return FALSE;
  48. }
  49. if (!TestRemoveEntry()) {
  50. return FALSE;
  51. }
  52. if (!TestLookupEntry()) {
  53. return FALSE;
  54. }
  55. if (!TestGetEntry()) {
  56. return FALSE;
  57. }
  58. if (!TestLookupLastEntry()) {
  59. return FALSE;
  60. }
  61. return TRUE;
  62. }
  63. BOOLEAN
  64. TestAddEntry()
  65. {
  66. MCB Mcb;
  67. ULONG i;
  68. ULONG Vbn,Lbn,Length;
  69. DbgPrint("\n\n\n>>>> Test PbAddMcbEntry <<<<\n");
  70. //
  71. // Build the following runs
  72. //
  73. // [0-9|10-19][20-29] [40-49]
  74. //
  75. PbInitializeMcb(Mcb, NonPagedPool);
  76. DbgPrint("\nTest 0:|--NewRun--|\n");
  77. if (!PbAddMcbEntry(Mcb, 0, 1000, 10)) {DbgPrint("Error\n");return FALSE;}
  78. PbDumpMcb( Mcb );
  79. DbgPrint("\nTest --LastRun--|--NewRun--|\n");
  80. if (!PbAddMcbEntry(Mcb, 10, 1010, 10)) {DbgPrint("Error\n");return FALSE;}
  81. PbDumpMcb( Mcb );
  82. DbgPrint("\nTest --LastRun--||--NewRun--|\n");
  83. if (!PbAddMcbEntry(Mcb, 20, 2020, 10)) {DbgPrint("Error\n");return FALSE;}
  84. PbDumpMcb( Mcb );
  85. DbgPrint("\nTest --LastRun--| hole |--NewRun--|\n");
  86. if (!PbAddMcbEntry(Mcb, 40, 1040, 10)) {DbgPrint("Error\n");return FALSE;}
  87. PbDumpMcb( Mcb );
  88. DbgPrint("\nTest over writing an existing run\n");
  89. if (PbAddMcbEntry(Mcb, 40, 1190, 5)) {DbgPrint("Error\n");return FALSE;}
  90. if (PbAddMcbEntry(Mcb, 25, 1190, 10)) {DbgPrint("Error\n");return FALSE;}
  91. if (PbAddMcbEntry(Mcb, 15, 1190, 10)) {DbgPrint("Error\n");return FALSE;}
  92. PbUninitializeMcb(Mcb);
  93. //
  94. // Build the following runs
  95. //
  96. // [0-9] [30-39][40-49|50-59|60-64] [70-79][80-84] [90-99]
  97. //
  98. PbInitializeMcb(Mcb, NonPagedPool);
  99. DbgPrint("\nTest 0: hole |--NewRun--|\n");
  100. if (!PbAddMcbEntry(Mcb, 90, 1090, 10)) {DbgPrint("Error\n");return FALSE;}
  101. PbDumpMcb( Mcb );
  102. DbgPrint("\nTest 0: hole |--NewRun--| hole |--FollowingRun--\n");
  103. if (!PbAddMcbEntry(Mcb, 50, 1050, 10)) {DbgPrint("Error\n");return FALSE;}
  104. PbDumpMcb( Mcb );
  105. DbgPrint("\nTest --PreviousRun--| hole |--NewRun--| hole |--FollowingRun--\n");
  106. if (!PbAddMcbEntry(Mcb, 70, 1070, 10)) {DbgPrint("Error\n");return FALSE;}
  107. PbDumpMcb( Mcb );
  108. DbgPrint("\nTest --PreviousRun--|--NewRun--| hole |--FollowingRun--\n");
  109. if (!PbAddMcbEntry(Mcb, 60, 1060, 5)) {DbgPrint("Error\n");return FALSE;}
  110. PbDumpMcb( Mcb );
  111. DbgPrint("\nTest --PreviousRun--||--NewRun--| hole |--FollowingRun--\n");
  112. if (!PbAddMcbEntry(Mcb, 80, 1180, 5)) {DbgPrint("Error\n");return FALSE;}
  113. PbDumpMcb( Mcb );
  114. DbgPrint("\nTest 0:|--NewRun--| hole |--FollowingRun--\n");
  115. if (!PbAddMcbEntry(Mcb, 0, 1000, 10)) {DbgPrint("Error\n");return FALSE;}
  116. PbDumpMcb( Mcb );
  117. DbgPrint("\nTest --PreviousRun--| hole |--NewRun--|--FollowingRun--\n");
  118. if (!PbAddMcbEntry(Mcb, 40, 1040, 10)) {DbgPrint("Error\n");return FALSE;}
  119. PbDumpMcb( Mcb );
  120. DbgPrint("\nTest --PreviousRun--| hole |--NewRun--||--FollowingRun--\n");
  121. if (!PbAddMcbEntry(Mcb, 30, 1130, 10)) {DbgPrint("Error\n");return FALSE;}
  122. PbDumpMcb( Mcb );
  123. PbUninitializeMcb(Mcb);
  124. //
  125. // Build the following runs
  126. //
  127. // [0-9|10-19|20-29][30-39][40-49|50-59|60-69|70-79][80-89|90-99]
  128. //
  129. PbInitializeMcb(Mcb, NonPagedPool);
  130. if (!PbAddMcbEntry(Mcb, 90, 1090, 10)) {DbgPrint("Error\n");return FALSE;}
  131. DbgPrint("\nTest 0: hole |--NewRun--|--FollowingRun--\n");
  132. if (!PbAddMcbEntry(Mcb, 80, 1080, 10)) {DbgPrint("Error\n");return FALSE;}
  133. PbDumpMcb( Mcb );
  134. DbgPrint("\nTest 0: hole |--NewRun--||--FollowingRun--\n");
  135. if (!PbAddMcbEntry(Mcb, 70, 1170, 10)) {DbgPrint("Error\n");return FALSE;}
  136. PbDumpMcb( Mcb );
  137. if (!PbAddMcbEntry(Mcb, 50, 1150, 10)) {DbgPrint("Error\n");return FALSE;}
  138. DbgPrint("\nTest --PreviousRun--|--NewRun--|--FollowingRun--\n");
  139. if (!PbAddMcbEntry(Mcb, 60, 1160, 10)) {DbgPrint("Error\n");return FALSE;}
  140. PbDumpMcb( Mcb );
  141. if (!PbAddMcbEntry(Mcb, 30, 1030, 10)) {DbgPrint("Error\n");return FALSE;}
  142. DbgPrint("\nTest --PreviousRun--||--NewRun--|--FollowingRun--\n");
  143. if (!PbAddMcbEntry(Mcb, 40, 1140, 10)) {DbgPrint("Error\n");return FALSE;}
  144. PbDumpMcb( Mcb );
  145. if (!PbAddMcbEntry(Mcb, 10, 1110, 10)) {DbgPrint("Error\n");return FALSE;}
  146. DbgPrint("\nTest --PreviousRun--|--NewRun--||--FollowingRun--\n");
  147. if (!PbAddMcbEntry(Mcb, 20, 1120, 10)) {DbgPrint("Error\n");return FALSE;}
  148. PbDumpMcb( Mcb );
  149. DbgPrint("\nTest 0:|--NewRun--|--FollowingRun--\n");
  150. if (!PbAddMcbEntry(Mcb, 0, 1100, 10)) {DbgPrint("Error\n");return FALSE;}
  151. PbDumpMcb( Mcb );
  152. PbUninitializeMcb(Mcb);
  153. //
  154. // Build the following runs
  155. //
  156. // [0-69][80-79|80-89|90-99]
  157. //
  158. PbInitializeMcb(Mcb, NonPagedPool);
  159. if (!PbAddMcbEntry(Mcb, 90, 1090, 10)) {DbgPrint("Error\n");return FALSE;}
  160. if (!PbAddMcbEntry(Mcb, 70, 1070, 10)) {DbgPrint("Error\n");return FALSE;}
  161. DbgPrint("\nTest --PreviousRun--||--NewRun--||--FollowingRun--\n");
  162. if (!PbAddMcbEntry(Mcb, 80, 1010, 10)) {DbgPrint("Error\n");return FALSE;}
  163. PbDumpMcb( Mcb );
  164. DbgPrint("\nTest 0:|--NewRun--||--FollowingRun--\n");
  165. if (!PbAddMcbEntry(Mcb, 0, 1100, 70)) {DbgPrint("Error\n");return FALSE;}
  166. PbDumpMcb( Mcb );
  167. PbUninitializeMcb(Mcb);
  168. return TRUE;
  169. }
  170. BOOLEAN
  171. TestRemoveEntry()
  172. {
  173. MCB Mcb;
  174. ULONG i;
  175. ULONG Vbn,Lbn,Length;
  176. DbgPrint("\n\n\n>>>> Test PbRemoveMcbEntry <<<<\n");
  177. PbInitializeMcb(Mcb, NonPagedPool);
  178. if (!PbAddMcbEntry(Mcb, 0, 1000, 100)) {DbgPrint("Error\n");return FALSE;}
  179. DbgPrint("\nTest --Previous--| Hole\n");
  180. PbRemoveMcbEntry(Mcb, 90, 10);
  181. PbDumpMcb( Mcb );
  182. DbgPrint("\nTest --Previous--| Hole |--Following--\n");
  183. PbRemoveMcbEntry(Mcb, 50, 10);
  184. PbDumpMcb( Mcb );
  185. DbgPrint("\nTest --Previous--| Hole |--Hole--\n");
  186. PbRemoveMcbEntry(Mcb, 40, 10);
  187. PbDumpMcb( Mcb );
  188. DbgPrint("\nTest --hole--| Hole |--Following--\n");
  189. PbRemoveMcbEntry(Mcb, 60, 10);
  190. PbDumpMcb( Mcb );
  191. DbgPrint("\nTest --hole--| Hole\n");
  192. PbRemoveMcbEntry(Mcb, 70, 20);
  193. PbDumpMcb( Mcb );
  194. DbgPrint("\nTest 0: Hole |--Following--\n");
  195. PbRemoveMcbEntry(Mcb, 0, 10);
  196. PbDumpMcb( Mcb );
  197. DbgPrint("\nTest over remove\n");
  198. PbRemoveMcbEntry(Mcb, 0, 100);
  199. PbDumpMcb( Mcb );
  200. PbUninitializeMcb(Mcb);
  201. PbInitializeMcb(Mcb, NonPagedPool);
  202. if (!PbAddMcbEntry(Mcb, 0, 1000, 100)) {DbgPrint("Error\n");return FALSE;}
  203. PbRemoveMcbEntry(Mcb, 10, 10);
  204. DbgPrint("\nTest 0: Hole |--Hole--\n");
  205. PbRemoveMcbEntry(Mcb, 0, 10);
  206. PbDumpMcb( Mcb );
  207. PbRemoveMcbEntry(Mcb, 30, 10);
  208. DbgPrint("\nTest --Hole--| Hole |--Hole--\n");
  209. PbRemoveMcbEntry(Mcb, 20, 10);
  210. PbDumpMcb( Mcb );
  211. DbgPrint("\nTest over remove\n");
  212. PbRemoveMcbEntry(Mcb, 0, 100);
  213. PbDumpMcb( Mcb );
  214. PbUninitializeMcb(Mcb);
  215. PbInitializeMcb(Mcb, NonPagedPool);
  216. if (!PbAddMcbEntry(Mcb, 0, 1000, 100)){DbgPrint("Error\n");return FALSE;}
  217. DbgPrint("\nTest 0: Hole\n");
  218. PbRemoveMcbEntry(Mcb, 0, 100);
  219. PbDumpMcb( Mcb );
  220. if (!PbAddMcbEntry(Mcb, 0, 1000, 30)) {DbgPrint("Error\n");return FALSE;}
  221. if (!PbAddMcbEntry(Mcb, 30, 1130, 30)) {DbgPrint("Error\n");return FALSE;}
  222. if (!PbAddMcbEntry(Mcb, 60, 1060, 30)) {DbgPrint("Error\n");return FALSE;}
  223. if (!PbAddMcbEntry(Mcb, 90, 1190, 10)) {DbgPrint("Error\n");return FALSE;}
  224. DbgPrint("\nTest --Previous--| Hole |--Index--||--Following--\n");
  225. PbRemoveMcbEntry(Mcb, 30, 10);
  226. PbDumpMcb( Mcb );
  227. DbgPrint("\nTest --Hole--| Hole |--Index--||--Following--\n");
  228. PbRemoveMcbEntry(Mcb, 40, 10);
  229. PbDumpMcb( Mcb );
  230. DbgPrint("\nTest --Previous--||--Index--| Hole |--Following--\n");
  231. PbRemoveMcbEntry(Mcb, 80, 10);
  232. PbDumpMcb( Mcb );
  233. DbgPrint("\nTest --Previous--||--Index--| Hole |--Hole--\n");
  234. PbRemoveMcbEntry(Mcb, 70, 10);
  235. PbDumpMcb( Mcb );
  236. DbgPrint("\nTest 0:|--Index--| Hole |--Index--||--Following--\n");
  237. PbRemoveMcbEntry(Mcb, 10, 10);
  238. PbDumpMcb( Mcb );
  239. DbgPrint("\nTest over remove\n");
  240. PbRemoveMcbEntry(Mcb, 0, 100);
  241. PbDumpMcb( Mcb );
  242. if (!PbAddMcbEntry(Mcb, 0, 1000, 30)) {DbgPrint("Error\n");return FALSE;}
  243. if (!PbAddMcbEntry(Mcb, 30, 1130, 30)) {DbgPrint("Error\n");return FALSE;}
  244. if (!PbAddMcbEntry(Mcb, 60, 1060, 30)) {DbgPrint("Error\n");return FALSE;}
  245. if (!PbAddMcbEntry(Mcb, 90, 1190, 10)) {DbgPrint("Error\n");return FALSE;}
  246. DbgPrint("\nTest --Previous--||--Index--| Hole |--Index--||--Following--\n");
  247. PbRemoveMcbEntry(Mcb, 40, 10);
  248. PbDumpMcb( Mcb );
  249. DbgPrint("\nTest 0:|--Index--| Hole |--Following--\n");
  250. PbRemoveMcbEntry(Mcb, 20, 10);
  251. PbDumpMcb( Mcb );
  252. DbgPrint("\nTest --Previous--||--Index--| Hole\n");
  253. PbRemoveMcbEntry(Mcb, 80, 20);
  254. PbDumpMcb( Mcb );
  255. DbgPrint("\nTest over remove\n");
  256. PbRemoveMcbEntry(Mcb, 0, 100);
  257. PbDumpMcb( Mcb );
  258. if (!PbAddMcbEntry(Mcb, 0, 1000, 100)){DbgPrint("Error\n");return FALSE;}
  259. DbgPrint("\nTest 0:--Index--| Hole\n");
  260. PbRemoveMcbEntry(Mcb, 50, 50);
  261. PbDumpMcb( Mcb );
  262. DbgPrint("\nTest over remove\n");
  263. PbRemoveMcbEntry(Mcb, 0, 100);
  264. PbDumpMcb( Mcb );
  265. if (!PbAddMcbEntry(Mcb, 0, 1000, 50)) {DbgPrint("Error\n");return FALSE;}
  266. if (!PbAddMcbEntry(Mcb, 50, 1150, 50)) {DbgPrint("Error\n");return FALSE;}
  267. DbgPrint("\nTest 0: hole |--Index--||--Following--\n");
  268. PbRemoveMcbEntry(Mcb, 0, 20);
  269. PbDumpMcb( Mcb );
  270. PbUninitializeMcb(Mcb);
  271. return TRUE;
  272. }
  273. BOOLEAN
  274. TestLookupEntry()
  275. {
  276. MCB Mcb;
  277. ULONG i;
  278. ULONG Vbn,Lbn,Length;
  279. DbgPrint("\n\n\n>>>> Test PbLookupMcbEntry <<<<\n");
  280. PbInitializeMcb(Mcb, NonPagedPool);
  281. for (i = 0; i < 100; i += 30) {
  282. if (!PbAddMcbEntry(Mcb, i, 1000+i, 10))
  283. {DbgPrint("Add1Error\n");return FALSE;}
  284. }
  285. for (i = 10; i < 100; i += 30) {
  286. if (!PbAddMcbEntry(Mcb, i, 1100+i, 10))
  287. {DbgPrint("Add2Error\n");return FALSE;}
  288. }
  289. PbDumpMcb( Mcb );
  290. for (i = 0; i < 100; i += 30) {
  291. if (!PbLookupMcbEntry(Mcb,i,&Lbn,&Length))
  292. {DbgPrint("Lookup1Error %d\n", i);return FALSE;}
  293. if ((Lbn != 1000+i) || (Length != 10))
  294. {DbgPrint("Result1Error %d, %d, %d\n", i, Lbn, Length);return FALSE;}
  295. if (!PbLookupMcbEntry(Mcb,i+5,&Lbn,&Length))
  296. {DbgPrint("Lookup2Error %d\n", i);return FALSE;}
  297. if ((Lbn != 1000+i+5) || (Length != 5))
  298. {DbgPrint("Result2Error %d, %d, %d\n", i, Lbn, Length);return FALSE;}
  299. }
  300. for (i = 20; i < 100; i += 30) {
  301. if (!PbLookupMcbEntry(Mcb,i,&Lbn,&Length))
  302. {DbgPrint("Lookup3Error %d\n", i);return FALSE;}
  303. if ((Lbn != 0) || (Length != 10))
  304. {DbgPrint("Result3Error %d, %d, %d\n", i, Lbn, Length);return FALSE;}
  305. if (!PbLookupMcbEntry(Mcb,i+5,&Lbn,&Length))
  306. {DbgPrint("Lookup4Error %d\n", i);return FALSE;}
  307. if ((Lbn != 0) || (Length != 5)) {
  308. DbgPrint("Result4Error %d", i+5);
  309. DbgPrint(", %08lx", Lbn);
  310. DbgPrint(", %08lx\n", Length);
  311. return FALSE;
  312. }
  313. }
  314. PbUninitializeMcb(Mcb);
  315. return TRUE;
  316. }
  317. BOOLEAN
  318. TestGetEntry()
  319. {
  320. MCB Mcb;
  321. ULONG i;
  322. ULONG Vbn,Lbn,Length;
  323. DbgPrint("\n\n\n>>>> TestPbNumberOfRunsInMcb <<<<\n");
  324. PbInitializeMcb(Mcb, NonPagedPool);
  325. for (i = 0; i < 100; i += 30) {
  326. if (!PbAddMcbEntry(Mcb, i, 1000+i, 10))
  327. {DbgPrint("Add1Error\n");return FALSE;}
  328. }
  329. for (i = 10; i < 100; i += 30) {
  330. if (!PbAddMcbEntry(Mcb, i, 1100+i, 10))
  331. {DbgPrint("Add2Error\n");return FALSE;}
  332. }
  333. PbDumpMcb( Mcb );
  334. i = PbNumberOfRunsInMcb(Mcb);
  335. if (i != 10) {DbgPrint("Error\n");return FALSE;}
  336. for (i = 0; i < 10; i += 1) {
  337. if (!PbGetNextMcbEntry(Mcb,i,&Vbn,&Lbn,&Length))
  338. {DbgPrint("Error\n");return FALSE;}
  339. DbgPrint("%d", i);
  340. DbgPrint(", %ld", Vbn);
  341. DbgPrint(", %ld", Lbn);
  342. DbgPrint(", %ld\n", Length);
  343. }
  344. PbUninitializeMcb(Mcb);
  345. return TRUE;
  346. }
  347. BOOLEAN
  348. TestLookupLastEntry()
  349. {
  350. MCB Mcb;
  351. ULONG i;
  352. ULONG Vbn,Lbn,Length;
  353. DbgPrint("\n\n\n>>>> Test PbLookupLastMcbEntry <<<<\n");
  354. PbInitializeMcb(Mcb, NonPagedPool);
  355. if (!PbAddMcbEntry(Mcb, 0, 1000, 100)) {DbgPrint("Error\n");return FALSE;}
  356. if (!PbLookupLastMcbEntry(Mcb, &Vbn, &Lbn)) {DbgPrint("Error\n");return FALSE;}
  357. if ((Vbn != 99) && (Lbn != 1099)) {DbgPrint("Lookup Error\n");return FALSE;}
  358. PbUninitializeMcb(Mcb);
  359. return TRUE;
  360. }