]> granicus.if.org Git - esp-idf/blobdiff - components/fatfs/test/test_fatfs_sdmmc.c
Merge branch 'bugfix/parallel_multi_heap_test' into 'master'
[esp-idf] / components / fatfs / test / test_fatfs_sdmmc.c
index 5b6a2471ecb3cf4beb99b0985280a6cb64d9c611..c81302207122b8d3e350f594ee2484352601334c 100644 (file)
@@ -39,7 +39,8 @@ static void test_setup(void)
     sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
     esp_vfs_fat_sdmmc_mount_config_t mount_config = {
         .format_if_mount_failed = true,
-        .max_files = 5
+        .max_files = 5,
+        .allocation_unit_size = 16 * 1024
     };
     TEST_ESP_OK(esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, NULL));
 }
@@ -51,7 +52,7 @@ static void test_teardown(void)
 
 static const char* test_filename = "/sdcard/hello.txt";
 
-TEST_CASE("Mount fails cleanly without card inserted", "[fatfs][ignore]")
+TEST_CASE("Mount fails cleanly without card inserted", "[fatfs][sd][ignore]")
 {
     size_t heap_size;
     HEAP_SIZE_CAPTURE(heap_size);
@@ -63,22 +64,22 @@ TEST_CASE("Mount fails cleanly without card inserted", "[fatfs][ignore]")
     };
 
     for (int i = 0; i < 3; ++i) {
-        printf("Initializing card, attempt %d ", i);
+        printf("Initializing card, attempt %d\n", i);
         esp_err_t err = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, NULL);
-        printf(" err=%d\n", err);
-        TEST_ESP_ERR(ESP_FAIL, err);
+        printf("err=%d\n", err);
+        TEST_ESP_ERR(ESP_ERR_TIMEOUT, err);
     }
     HEAP_SIZE_CHECK(heap_size, 0);
 }
 
-TEST_CASE("(SD) can create and write file", "[fatfs][sdcard][ignore]")
+TEST_CASE("(SD) can create and write file", "[fatfs][sd][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_create_file_with_text(test_filename, fatfs_test_hello_str);
     test_teardown();
 }
 
-TEST_CASE("(SD) can read file", "[fatfs][ignore]")
+TEST_CASE("(SD) can read file", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_create_file_with_text(test_filename, fatfs_test_hello_str);
@@ -87,7 +88,7 @@ TEST_CASE("(SD) can read file", "[fatfs][ignore]")
 }
 
 
-TEST_CASE("(SD) overwrite and append file", "[fatfs][sdcard][ignore]")
+TEST_CASE("(SD) overwrite and append file", "[fatfs][sd][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_overwrite_append(test_filename);
@@ -95,56 +96,56 @@ TEST_CASE("(SD) overwrite and append file", "[fatfs][sdcard][ignore]")
 }
 
 
-TEST_CASE("(SD) can lseek", "[fatfs][sdcard][ignore]")
+TEST_CASE("(SD) can lseek", "[fatfs][sd][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_lseek("/sdcard/seek.txt");
     test_teardown();
 }
 
-TEST_CASE("(SD) stat returns correct values", "[fatfs][ignore]")
+TEST_CASE("(SD) stat returns correct values", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_stat("/sdcard/stat.txt", "/sdcard");
     test_teardown();
 }
 
-TEST_CASE("(SD) unlink removes a file", "[fatfs][ignore]")
+TEST_CASE("(SD) unlink removes a file", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_unlink("/sdcard/unlink.txt");
     test_teardown();
 }
 
-TEST_CASE("(SD) link copies a file, rename moves a file", "[fatfs][ignore]")
+TEST_CASE("(SD) link copies a file, rename moves a file", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_link_rename("/sdcard/link");
     test_teardown();
 }
 
-TEST_CASE("(SD) can create and remove directories", "[fatfs][ignore]")
+TEST_CASE("(SD) can create and remove directories", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_mkdir_rmdir("/sdcard/dir");
     test_teardown();
 }
 
-TEST_CASE("(SD) can opendir root directory of FS", "[fatfs][ignore]")
+TEST_CASE("(SD) can opendir root directory of FS", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_can_opendir("/sdcard");
     test_teardown();
 }
 
-TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs][ignore]")
+TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_opendir_readdir_rewinddir("/sdcard/dir");
     test_teardown();
 }
 
-TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][ignore]")
+TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][test_env=UT_T1_SDMODE]")
 {
     test_setup();
     test_fatfs_concurrent("/sdcard/f");
@@ -153,7 +154,7 @@ TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][ignore]")
 
 static void speed_test(void* buf, size_t buf_size, size_t file_size, bool write);
 
-TEST_CASE("(SD) write/read speed test", "[fatfs][sdcard][ignore]")
+TEST_CASE("(SD) write/read speed test", "[fatfs][sd][test_env=UT_T1_SDMODE][timeout=60]")
 {
     size_t heap_size;
     HEAP_SIZE_CAPTURE(heap_size);
@@ -163,7 +164,7 @@ TEST_CASE("(SD) write/read speed test", "[fatfs][sdcard][ignore]")
     for (size_t i = 0; i < buf_size / 4; ++i) {
         buf[i] = esp_random();
     }
-    const size_t file_size = 4 * 1024 * 1024;
+    const size_t file_size = 1 * 1024 * 1024;
 
     speed_test(buf, 4 * 1024, file_size, true);
     speed_test(buf, 8 * 1024, file_size, true);
@@ -195,7 +196,7 @@ static void speed_test(void* buf, size_t buf_size, size_t file_size, bool write)
     TEST_ESP_OK(esp_vfs_fat_sdmmc_unmount());
 }
 
-TEST_CASE("(SD) mount two FAT partitions, SDMMC and WL, at the same time", "[fatfs][sdcard][ignore]")
+TEST_CASE("(SD) mount two FAT partitions, SDMMC and WL, at the same time", "[fatfs][sd][test_env=UT_T1_SDMODE]")
 {
     esp_vfs_fat_sdmmc_mount_config_t mount_config = {
         .format_if_mount_failed = true,
@@ -239,3 +240,28 @@ TEST_CASE("(SD) mount two FAT partitions, SDMMC and WL, at the same time", "[fat
     fclose(f);
     TEST_ESP_OK(esp_vfs_fat_spiflash_unmount("/spiflash", wl_handle));
 }
+
+/*
+ * In FatFs menuconfig, set CONFIG_FATFS_API_ENCODING to UTF-8 and set the
+ * Codepage to CP936 (Simplified Chinese) in order to run the following tests.
+ * Ensure that the text editor is UTF-8 compatible when compiling these tests.
+ */
+#if defined(CONFIG_FATFS_API_ENCODING_UTF_8) && (CONFIG_FATFS_CODEPAGE == 936)
+
+static const char* test_filename_utf_8 = "/sdcard/测试文件.txt";
+
+TEST_CASE("(SD) can read file using UTF-8 encoded strings", "[fatfs][sd][test_env=UT_T1_SDMODE]")
+{
+    test_setup();
+    test_fatfs_create_file_with_text(test_filename_utf_8, fatfs_test_hello_str_utf);
+    test_fatfs_read_file_utf_8(test_filename_utf_8);
+    test_teardown();
+}
+
+TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected using UTF-8 encoded strings", "[fatfs][ignore]")
+{
+    test_setup();
+    test_fatfs_opendir_readdir_rewinddir_utf_8("/sdcard/目录");
+    test_teardown();
+}
+#endif // CONFIG_FATFS_API_ENCODING_UTF_8 && CONFIG_FATFS_CODEPAGE == 936