]> granicus.if.org Git - esp-idf/commitdiff
fatfs: reduce rawflash tests run time
authorIvan Grokhotkov <ivan@espressif.com>
Tue, 25 Jun 2019 11:54:07 +0000 (19:54 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Tue, 25 Jun 2019 15:07:07 +0000 (23:07 +0800)
Don't flash fatfs.img on every test run. Comparing the content is
faster than flashing.

components/fatfs/test/test_fatfs_rawflash.c

index 5e60bb2965b3e42b88a48dc5e5b6c4c3bd8f7ec8..66412451a369d7cce34cd5041cb7f73e47da613e 100644 (file)
@@ -43,9 +43,18 @@ static void test_setup(size_t max_files)
 
     TEST_ASSERT(part->size == (fatfs_end - fatfs_start - 1));
 
-    esp_partition_erase_range(part, 0, part->size);
-    for (int i = 0; i < part->size; i+= SPI_FLASH_SEC_SIZE) {
-        ESP_ERROR_CHECK( esp_partition_write(part, i, fatfs_start + i, SPI_FLASH_SEC_SIZE) );
+    spi_flash_mmap_handle_t mmap_handle;
+    const void* mmap_ptr;
+    TEST_ESP_OK(esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, &mmap_ptr, &mmap_handle));
+    bool content_valid = memcmp(fatfs_start, mmap_ptr, part->size) == 0;
+    spi_flash_munmap(mmap_handle);
+
+    if (!content_valid) {
+        printf("Copying fatfs.img into test partition...\n");
+        esp_partition_erase_range(part, 0, part->size);
+        for (int i = 0; i < part->size; i+= SPI_FLASH_SEC_SIZE) {
+            ESP_ERROR_CHECK( esp_partition_write(part, i, fatfs_start + i, SPI_FLASH_SEC_SIZE) );
+        }
     }
 
     TEST_ESP_OK(esp_vfs_fat_rawflash_mount("/spiflash", "flash_test", &mount_config));
@@ -319,12 +328,8 @@ TEST_CASE("(raw) multiple tasks can use same volume", "[fatfs]")
     test_teardown();
 }
 
-TEST_CASE("(raw) write/read speed test", "[fatfs][timeout=60]")
+TEST_CASE("(raw) read speed test", "[fatfs][timeout=60]")
 {
-    /* Erase partition before running the test to get consistent results */
-    const esp_partition_t* part = get_test_data_partition();
-    esp_partition_erase_range(part, 0, part->size);
-
     test_setup(5);
 
     const size_t buf_size = 16 * 1024;