Skip to content

Commit fd9e4c1

Browse files
committed
Added test to catch multiple nested MBRs
1 parent 70cfef8 commit fd9e4c1

File tree

1 file changed

+41
-0
lines changed
  • features/TESTS/filesystem/multipart_fat_filesystem

1 file changed

+41
-0
lines changed

features/TESTS/filesystem/multipart_fat_filesystem/main.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,46 @@ void test_read_write() {
163163
TEST_ASSERT_EQUAL(0, err);
164164
}
165165

166+
void test_single_mbr() {
167+
int err = bd.init();
168+
TEST_ASSERT_EQUAL(0, err);
169+
170+
const bd_addr_t MBR_OFFSET = 0;
171+
const bd_addr_t FAT1_OFFSET = 1;
172+
const bd_addr_t FAT2_OFFSET = BLOCK_COUNT/2;
173+
174+
uint8_t *buffer = (uint8_t *)malloc(BLOCK_SIZE);
175+
TEST_ASSERT(buffer);
176+
177+
// Check that all three header blocks have the 0x55aa signature
178+
err = bd.read(buffer, MBR_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
179+
TEST_ASSERT_EQUAL(0, err);
180+
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
181+
182+
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
183+
TEST_ASSERT_EQUAL(0, err);
184+
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
185+
186+
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
187+
TEST_ASSERT_EQUAL(0, err);
188+
TEST_ASSERT(memcmp(&buffer[BLOCK_SIZE-2], "\x55\xaa", 2) == 0);
189+
190+
// Check that the headers for both filesystems contain a jump code
191+
// indicating they are actual FAT superblocks and not an extra MBR
192+
err = bd.read(buffer, FAT1_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
193+
TEST_ASSERT_EQUAL(0, err);
194+
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
195+
196+
err = bd.read(buffer, FAT2_OFFSET*BLOCK_SIZE, BLOCK_SIZE);
197+
TEST_ASSERT_EQUAL(0, err);
198+
TEST_ASSERT(buffer[0] == 0xe9 || buffer[0] == 0xeb || buffer[0] == 0xe8);
199+
200+
free(buffer);
201+
202+
bd.deinit();
203+
TEST_ASSERT_EQUAL(0, err);
204+
}
205+
166206

167207
// Test setup
168208
utest::v1::status_t test_setup(const size_t number_of_cases) {
@@ -174,6 +214,7 @@ Case cases[] = {
174214
Case("Testing formating", test_format),
175215
Case("Testing read write < block", test_read_write<BLOCK_SIZE/2>),
176216
Case("Testing read write > block", test_read_write<2*BLOCK_SIZE>),
217+
Case("Testing for no extra MBRs", test_single_mbr),
177218
};
178219

179220
Specification specification(test_setup, cases);

0 commit comments

Comments
 (0)