From 18af8677042c430ab1f1c416bfcf3a6652678911 Mon Sep 17 00:00:00 2001 From: Kyle Kearney Date: Tue, 21 Apr 2020 15:01:31 -0700 Subject: [PATCH] Filesystem test: Move lfs init in test startup tests-filesystem-general_filesystem declares BlockDevice and FileSystem pointers as globals. If these are initialized to their respective default_instance values in the declaration, the LFS init happens during OS startup when __libc_init_array() is invoked by mbed_toolchain_init(). If the filesystem blockdevice does not currently contain a valid filesystem (e.g. the chip has just been erased), then LFS will flag this as corruption and abort the mounting process. This cleanup process can take long enough (and is running pre-main) that greentea times out waiting for the device to respond to its sync packet, and resets the device. To resolve this, move the initialization into the first test case (bd_init_fs_reformat) right before it initializes and formats the blockdevice and filesystem. --- .../storage/TESTS/filesystem/general_filesystem/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/features/storage/TESTS/filesystem/general_filesystem/main.cpp b/features/storage/TESTS/filesystem/general_filesystem/main.cpp index 92095e65d3..cb686a77a2 100644 --- a/features/storage/TESTS/filesystem/general_filesystem/main.cpp +++ b/features/storage/TESTS/filesystem/general_filesystem/main.cpp @@ -44,8 +44,8 @@ static const size_t test_files = 2; FILE *fd[test_files]; -BlockDevice *bd = BlockDevice::get_default_instance(); -FileSystem *fs = FileSystem::get_default_instance(); +BlockDevice *bd; +FileSystem *fs; const char *bd_type; /*----------------help functions------------------*/ @@ -76,6 +76,9 @@ static void deinit() //init the blockdevice and reformat the filesystem static void bd_init_fs_reformat() { + bd = BlockDevice::get_default_instance(); + fs = FileSystem::get_default_instance(); + bd_type = bd->get_type(); init(); }