Skip to content

Commit 0bf0718

Browse files
author
offirko
committed
Start test by formatting SD Card, otherwise FATFS mount might fail
Fix Jira: IOTSTOR-752
1 parent a6509cf commit 0bf0718

File tree

1 file changed

+23
-1
lines changed
  • components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/fopen

1 file changed

+23
-1
lines changed

components/storage/blockdevice/COMPONENT_SD/TESTS/filesystem/fopen/fopen.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static const char *sd_testfile_path = "/sd/test.txt";
8080
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
8181
FATFileSystem fs("sd", &sd);
8282

83+
#define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_00
8384
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_01
8485
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_02
8586
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_03
@@ -276,6 +277,26 @@ static int32_t fsfat_filepath_make_dirs(char *filepath, bool do_asserts)
276277
return ret;
277278
}
278279

280+
/** @brief
281+
* First and last test must format the SD card to FAT FS format:
282+
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
283+
*/
284+
control_t fsfat_fopen_test_00(const size_t call_count)
285+
{
286+
FSFAT_FENTRYLOG("%s:entered\n", __func__);
287+
(void) call_count;
288+
int32_t ret = -1;
289+
290+
fs.unmount();
291+
ret = fs.format(&sd);
292+
FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE,
293+
"%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret);
294+
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
295+
fs.mount(&sd);
296+
297+
return CaseNext;
298+
}
299+
279300

280301
/* FIX ME: errno not set correctly when error occurs. This indicates a problem with the implementation. */
281302

@@ -1535,7 +1556,7 @@ control_t fsfat_fopen_test_16(const size_t call_count)
15351556

15361557
#else
15371558

1538-
1559+
#define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_dummy
15391560
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_dummy
15401561
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_dummy
15411562
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_dummy
@@ -1590,6 +1611,7 @@ utest::v1::status_t greentea_setup(const size_t number_of_cases)
15901611
Case cases[] = {
15911612
/* 1 2 3 4 5 6 7 */
15921613
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
1614+
Case("FSFAT_FOPEN_TEST_00: format sd card to FAT FS.", FSFAT_FOPEN_TEST_00),
15931615
Case("FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath.", FSFAT_FOPEN_TEST_01),
15941616
Case("FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it.", FSFAT_FOPEN_TEST_02),
15951617
Case("FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it.", FSFAT_FOPEN_TEST_03),

0 commit comments

Comments
 (0)