spiffs: test is using configurable build dir

This commit is contained in:
Jakob Hasse 2023-03-31 15:04:54 +08:00
parent f67bcc669a
commit 5327fd89b5
3 changed files with 9 additions and 5 deletions

View File

@ -15,12 +15,12 @@ add_custom_target(image.bin)
add_custom_command(
TARGET image.bin
POST_BUILD
COMMAND python ../../spiffsgen.py 2097152 ../../spiffs ../image.bin
COMMAND python ../../spiffsgen.py 2097152 ../../spiffs ${build_dir}/image.bin
)
set_property(
DIRECTORY
APPEND PROPERTY ADDITIONAL_CLEAN_FILES "../image.bin")
APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${build_dir}/image.bin")
add_dependencies(host_test_spiffs.elf image.bin)

View File

@ -1,3 +1,6 @@
idf_component_register(SRCS "host_test_spiffs.c"
PRIV_INCLUDE_DIRS "../.." "../../spiffs/src"
REQUIRES spiffs unity)
# set BUILD_DIR because test uses a file created in the build directory
target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"")

View File

@ -236,9 +236,10 @@ TEST(spiffs, can_read_spiffs_image)
s32_t spiffs_res;
const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "storage");
TEST_ASSERT_NOT_NULL(partition);
// Write the contents of the image file to partition
FILE *img_file = fopen("image.bin", "r");
FILE *img_file = fopen(BUILD_DIR "/image.bin", "r");
TEST_ASSERT_NOT_NULL(img_file);
fseek(img_file, 0, SEEK_END);
@ -248,7 +249,7 @@ TEST(spiffs, can_read_spiffs_image)
char *img = (char *) malloc(img_size);
TEST_ASSERT(fread(img, 1, img_size, img_file) == img_size);
fclose(img_file);
TEST_ASSERT_TRUE(partition->size == img_size);
TEST_ASSERT_EQUAL(partition->size, img_size);
esp_partition_erase_range(partition, 0, partition->size);
esp_partition_write(partition, 0, img, img_size);
@ -267,7 +268,7 @@ TEST(spiffs, can_read_spiffs_image)
// The image is created from the spiffs source directory. Compare the files in that
// directory to the files read from the SPIFFS image.
check_spiffs_files(&fs, "../spiffs", path_buf);
check_spiffs_files(&fs, BUILD_DIR "/../../spiffs", path_buf);
deinit_spiffs(&fs);
}