[KMTESTS:FSRTL]
[reactos.git] / rostests / kmtests / ntos_fsrtl / FsRtlMcb.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite FsRtl Test
5 * PROGRAMMER: Pierre Schweitzer <pierre.schweitzer@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #define NDEBUG
11 #include <debug.h>
12
13 static VOID FsRtlMcbTest()
14 {
15 }
16
17 static VOID FsRtlLargeMcbTest()
18 {
19 LARGE_MCB LargeMcb;
20 ULONG NbRuns, Index;
21 LONGLONG Vbn, Lbn, SectorCount, StartingLbn, CountFromStartingLbn;
22
23 FsRtlInitializeLargeMcb(&LargeMcb, PagedPool);
24
25 ok(FsRtlLookupLastLargeMcbEntry(&LargeMcb, &Vbn, &Lbn) == FALSE, "expected FALSE, got TRUE\n");
26 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == FALSE, "expected FALSE, got TRUE\n");
27
28 ok(FsRtlAddLargeMcbEntry(&LargeMcb, 1, 1, 1024) == TRUE, "expected TRUE, got FALSE\n");
29 NbRuns = FsRtlNumberOfRunsInLargeMcb(&LargeMcb);
30 ok(NbRuns == 2, "Expected 2 runs, got: %lu\n", NbRuns);
31 ok(FsRtlLookupLastLargeMcbEntry(&LargeMcb, &Vbn, &Lbn) == TRUE, "expected FALSE, got TRUE\n");
32 ok(Vbn == 1024, "Expected Vbn 1024, got: %I64d\n", Vbn);
33 ok(Lbn == 1024, "Expected Lbn 1024, got: %I64d\n", Lbn);
34 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
35 ok(Vbn == 1024, "Expected Vbn 1024, got: %I64d\n", Vbn);
36 ok(Lbn == 1024, "Expected Lbn 1024, got: %I64d\n", Lbn);
37 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
38
39 ok(FsRtlAddLargeMcbEntry(&LargeMcb, 2048, 2, 1024) == TRUE, "expected TRUE, got FALSE\n");
40 NbRuns = FsRtlNumberOfRunsInLargeMcb(&LargeMcb);
41 ok(NbRuns == 4, "Expected 4 runs, got: %lu\n", NbRuns);
42 ok(FsRtlLookupLastLargeMcbEntry(&LargeMcb, &Vbn, &Lbn) == TRUE, "expected FALSE, got TRUE\n");
43 ok(Vbn == 3071, "Expected Vbn 3071, got: %I64d\n", Vbn);
44 ok(Lbn == 1025, "Expected Lbn 1025, got: %I64d\n", Lbn);
45 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
46 ok(Vbn == 3071, "Expected Vbn 3071, got: %I64d\n", Vbn);
47 ok(Lbn == 1025, "Expected Lbn 1025, got: %I64d\n", Lbn);
48 ok(Index == 3, "Expected Index 3, got: %lu\n", Index);
49
50 ok(FsRtlGetNextLargeMcbEntry(&LargeMcb, 0, &Vbn, &Lbn, &SectorCount) == TRUE, "expected TRUE, got FALSE\n");
51 ok(Vbn == 0, "Expected Vbn 0, got: %I64d\n", Vbn);
52 ok(Lbn == -1, "Expected Lbn -1, got: %I64d\n", Lbn);
53 ok(SectorCount == 1, "Expected SectorCount 1, got: %I64d\n", SectorCount);
54
55 ok(FsRtlGetNextLargeMcbEntry(&LargeMcb, 1, &Vbn, &Lbn, &SectorCount) == TRUE, "expected TRUE, got FALSE\n");
56 ok(Vbn == 1, "Expected Vbn 1, got: %I64d\n", Vbn);
57 ok(Lbn == 1, "Expected Lbn 1, got: %I64d\n", Lbn);
58 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
59
60 ok(FsRtlGetNextLargeMcbEntry(&LargeMcb, 2, &Vbn, &Lbn, &SectorCount) == TRUE, "expected TRUE, got FALSE\n");
61 ok(Vbn == 1025, "Expected Vbn 1025, got: %I64d\n", Vbn);
62 ok(Lbn == -1, "Expected Lbn -1, got: %I64d\n", Lbn);
63 ok(SectorCount == 1023, "Expected SectorCount 1023, got: %I64d\n", SectorCount);
64
65 ok(FsRtlGetNextLargeMcbEntry(&LargeMcb, 3, &Vbn, &Lbn, &SectorCount) == TRUE, "expected TRUE, got FALSE\n");
66 ok(Vbn == 2048, "Expected Vbn 2048, got: %I64d\n", Vbn);
67 ok(Lbn == 2, "Expected Lbn 2, got: %I64d\n", Lbn);
68 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
69
70 ok(FsRtlGetNextLargeMcbEntry(&LargeMcb, 4, &Vbn, &Lbn, &SectorCount) == FALSE, "expected FALSE, got TRUE\n");
71
72 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 1, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected TRUE, got FALSE\n");
73 ok(Lbn == 1, "Expected Lbn 1, got: %I64d\n", Lbn);
74 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
75 ok(StartingLbn == 1, "Expected StartingLbn 1, got: %I64d\n", StartingLbn);
76 ok(CountFromStartingLbn == 1024, "Expected CountFromStartingLbn 1024, got: %I64d\n", CountFromStartingLbn);
77 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
78
79 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 2048, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected TRUE, got FALSE\n");
80 ok(Lbn == 2, "Expected Lbn 2, got: %I64d\n", Lbn);
81 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
82 ok(StartingLbn == 2, "Expected StartingLbn 2, got: %I64d\n", StartingLbn);
83 ok(CountFromStartingLbn == 1024, "Expected CountFromStartingLbn 1024, got: %I64d\n", CountFromStartingLbn);
84 ok(Index == 3, "Expected Index 3, got: %lu\n", Index);
85
86 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 3073, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == FALSE, "expected FALSE, got TRUE\n");
87
88 FsRtlRemoveLargeMcbEntry(&LargeMcb, 1, 1024);
89 NbRuns = FsRtlNumberOfRunsInLargeMcb(&LargeMcb);
90 ok(NbRuns == 2, "Expected 2 runs, got: %lu\n", NbRuns);
91 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 512, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected TRUE, got FALSE\n");
92 ok(Lbn == -1, "Expected Lbn -1, got: %I64d\n", Lbn);
93 ok(SectorCount == 1536, "Expected SectorCount 1536, got: %I64d\n", SectorCount);
94 ok(StartingLbn == -1, "Expected StartingLbn -1, got: %I64d\n", StartingLbn);
95 ok(CountFromStartingLbn == 2048, "Expected CountFromStartingLbn 2048, got: %I64d\n", CountFromStartingLbn);
96 ok(Index == 0, "Expected Index 0, got: %lu\n", Index);
97 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
98 ok(Vbn == 3071, "Expected Vbn 3071, got: %I64d\n", Vbn);
99 ok(Lbn == 1025, "Expected Lbn 1025, got: %I64d\n", Lbn);
100 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
101
102 ok(FsRtlSplitLargeMcb(&LargeMcb, 2048, 1024) == TRUE, "expected FALSE, got TRUE\n");
103 NbRuns = FsRtlNumberOfRunsInLargeMcb(&LargeMcb);
104 ok(NbRuns == 2, "Expected 2 runs, got: %lu\n", NbRuns);
105 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
106 ok(Vbn == 4095, "Expected Vbn 4095, got: %I64d\n", Vbn);
107 ok(Lbn == 1025, "Expected Lbn 1025, got: %I64d\n", Lbn);
108 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
109 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 2048, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
110 ok(Lbn == -1, "Expected Lbn -1, got: %I64d\n", Lbn);
111 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
112 ok(StartingLbn == -1, "Expected StartingLbn -1, got: %I64d\n", StartingLbn);
113 ok(CountFromStartingLbn == 3072, "Expected CountFromStartingLbn 3072, got: %I64d\n", CountFromStartingLbn);
114 ok(Index == 0, "Expected Index 0, got: %lu\n", Index);
115 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 3072, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected TRUE, got FALSE\n");
116 ok(Lbn == 2, "Expected Lbn 2, got: %I64d\n", Lbn);
117 ok(SectorCount == 1024, "Expected SectorCount 1024, got: %I64d\n", SectorCount);
118 ok(StartingLbn == 2, "Expected StartingLbn 2, got: %I64d\n", StartingLbn);
119 ok(CountFromStartingLbn == 1024, "Expected CountFromStartingLbn 1024, got: %I64d\n", CountFromStartingLbn);
120 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
121
122 ok(FsRtlAddLargeMcbEntry(&LargeMcb, 3584, 3, 1024) == FALSE, "expected FALSE, got TRUE\n");
123
124 ok(FsRtlAddLargeMcbEntry(&LargeMcb, 4095, 1025, 1024) == TRUE, "expected TRUE, got FALSE\n");
125 NbRuns = FsRtlNumberOfRunsInLargeMcb(&LargeMcb);
126 ok(NbRuns == 2, "Expected 2 runs, got: %lu\n", NbRuns);
127 ok(FsRtlLookupLastLargeMcbEntry(&LargeMcb, &Vbn, &Lbn) == TRUE, "expected FALSE, got TRUE\n");
128 ok(Vbn == 5118, "Expected Vbn 5118, got: %I64d\n", Vbn);
129 ok(Lbn == 2048, "Expected Lbn 2048, got: %I64d\n", Lbn);
130 ok(FsRtlLookupLastLargeMcbEntryAndIndex(&LargeMcb, &Vbn, &Lbn, &Index) == TRUE, "expected FALSE, got TRUE\n");
131 ok(Vbn == 5118, "Expected Vbn 5118, got: %I64d\n", Vbn);
132 ok(Lbn == 2048, "Expected Lbn 2048, got: %I64d\n", Lbn);
133 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
134
135 FsRtlTruncateLargeMcb(&LargeMcb, 4607);
136 ok(FsRtlLookupLargeMcbEntry(&LargeMcb, 4095, &Lbn, &SectorCount, &StartingLbn, &CountFromStartingLbn, &Index) == TRUE, "expected TRUE, got FALSE\n");
137 ok(Lbn == 1025, "Expected Lbn 1025, got: %I64d\n", Lbn);
138 ok(SectorCount == 512, "Expected SectorCount 512, got: %I64d\n", SectorCount);
139 ok(StartingLbn == 2, "Expected StartingLbn 2, got: %I64d\n", StartingLbn);
140 ok(CountFromStartingLbn == 1535, "Expected CountFromStartingLbn 1535, got: %I64d\n", CountFromStartingLbn);
141 ok(Index == 1, "Expected Index 1, got: %lu\n", Index);
142
143 FsRtlUninitializeLargeMcb(&LargeMcb);
144 }
145
146 START_TEST(FsRtlMcb)
147 {
148 FsRtlMcbTest();
149 FsRtlLargeMcbTest();
150 }