2121#include " HeapBlockDevice.h"
2222#include " FATFileSystem.h"
2323#include " MBRBlockDevice.h"
24+ #include " LittleFileSystem.h"
2425#include < stdlib.h>
2526#include " mbed_retarget.h"
2627
@@ -221,9 +222,66 @@ void test_single_mbr()
221222 TEST_ASSERT_EQUAL (0 , err);
222223
223224 delete bd;
224- bd = 0 ;
225225}
226226
227+ void test_with_other_fs ()
228+ {
229+ TEST_SKIP_UNLESS_MESSAGE (bd, " Not enough heap memory to run test. Test skipped." );
230+
231+ // Stage 0 - LittleFS
232+ // Stage 1 - FatFS with MBR
233+ // Stage 2 - LittleFS
234+ // Make sure that at no stage we are able to mount the current file system after using the
235+ // previous one
236+
237+ // start from scratch in this test
238+ bd = new (std::nothrow) HeapBlockDevice (BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE);
239+ TEST_SKIP_UNLESS_MESSAGE (bd, " Not enough heap memory to run test. Test skipped." );
240+
241+ int err;
242+
243+ for (int stage = 0 ; stage < 3 ; stage++) {
244+
245+ BlockDevice *part;
246+ FileSystem *fs;
247+
248+ if (stage == 1 ) {
249+ printf (" Stage %d: FAT FS\n " , stage + 1 );
250+ err = MBRBlockDevice::partition (bd, 1 , 0x83 , 0 , BLOCK_COUNT * BLOCK_SIZE);
251+ TEST_ASSERT_EQUAL (0 , err);
252+
253+ part = new (std::nothrow) MBRBlockDevice (bd, 1 );
254+ TEST_SKIP_UNLESS_MESSAGE (part, " Not enough heap memory to run test. Test skipped." );
255+
256+ err = part->init ();
257+ TEST_ASSERT_EQUAL (0 , err);
258+
259+ fs = new FATFileSystem (" fat" );
260+ } else {
261+ printf (" Stage %d: Little FS\n " , stage + 1 );
262+ part = bd;
263+ fs = new LittleFileSystem (" lfs" );
264+ }
265+ TEST_SKIP_UNLESS_MESSAGE (fs, " Not enough heap memory to run test. Test skipped." );
266+
267+ err = fs->mount (part);
268+ TEST_ASSERT_NOT_EQUAL (0 , err);
269+
270+ err = fs->reformat (part);
271+ TEST_ASSERT_EQUAL (0 , err);
272+
273+ err = fs->unmount ();
274+ TEST_ASSERT_EQUAL (0 , err);
275+
276+ delete fs;
277+ if (stage == 1 ) {
278+ delete part;
279+ }
280+ }
281+
282+ delete bd;
283+ bd = 0 ;
284+ }
227285
228286// Test setup
229287utest::v1::status_t test_setup (const size_t number_of_cases)
@@ -237,6 +295,7 @@ Case cases[] = {
237295 Case (" Testing read write < block" , test_read_write < BLOCK_SIZE / 2 >),
238296 Case (" Testing read write > block" , test_read_write<2 * BLOCK_SIZE>),
239297 Case (" Testing for no extra MBRs" , test_single_mbr),
298+ Case (" Testing with other file system" , test_with_other_fs),
240299};
241300
242301Specification specification (test_setup, cases);
0 commit comments