Procházet zdrojové kódy

Merge branch 'refactor/esp_partition_host_test_build_dir' into 'master'

esp_partition: partition_linux.c does not use hard-coded file anymore

Closes IDF-6644

See merge request espressif/esp-idf!22759
Zim Kalinowski před 2 roky
rodič
revize
ab5d8d0008

+ 4 - 0
components/esp_partition/CMakeLists.txt

@@ -3,6 +3,7 @@ set(priv_reqs esp_system bootloader_support spi_flash app_update partition_table
 set(reqs)
 set(include_dirs "include")
 
+idf_build_get_property(build_dir BUILD_DIR)
 idf_build_get_property(target IDF_TARGET)
 if(${target} STREQUAL "linux")
     list(APPEND srcs "partition_linux.c")
@@ -22,6 +23,9 @@ idf_component_register(SRCS "${srcs}"
     PRIV_REQUIRES ${priv_reqs})
 
 if(${target} STREQUAL "linux")
+    # set BUILD_DIR because partition_linux.c uses a file created in the build directory
+    target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"")
+
     # link bsd library for strlcpy
     find_library(LIB_BSD bsd)
     if(LIB_BSD)

+ 3 - 0
components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt

@@ -1,2 +1,5 @@
 idf_component_register(SRCS "partition_api_test.c"
                        REQUIRES esp_partition unity)
+
+# set BUILD_DIR because test uses a file created in the build directory
+target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"")

+ 2 - 2
components/esp_partition/host_test/partition_api_test/main/partition_api_test.c

@@ -171,7 +171,7 @@ TEST(partition_api, test_partition_mmap_diff_size)
 
     memset(p_file_mmap_ctrl, 0, sizeof(*p_file_mmap_ctrl));
     p_file_mmap_ctrl->flash_file_size = 0x800000;   // 8MB
-    strlcpy(p_file_mmap_ctrl->partition_file_name, "./build/partition_table/partition-table_8M.bin", sizeof(p_file_mmap_ctrl->partition_file_name));
+    strlcpy(p_file_mmap_ctrl->partition_file_name, BUILD_DIR "/partition_table/partition-table_8M.bin", sizeof(p_file_mmap_ctrl->partition_file_name));
 
     // esp_partition_find_first calls the esp_partition_file_mmap in the background
     const esp_partition_t *partition_data = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
@@ -483,7 +483,7 @@ TEST(partition_api, test_partition_mmap_size_too_small)
     memset(p_file_mmap_ctrl_input, 0, sizeof(*p_file_mmap_ctrl_input));
 
     // set valid partition table name and very small flash size
-    strlcpy(p_file_mmap_ctrl_input->partition_file_name, "./build/partition_table/partition-table.bin", sizeof(p_file_mmap_ctrl_input->partition_file_name));
+    strlcpy(p_file_mmap_ctrl_input->partition_file_name, BUILD_DIR "/partition_table/partition-table.bin", sizeof(p_file_mmap_ctrl_input->partition_file_name));
     p_file_mmap_ctrl_input->flash_file_size = 1;
 
     const uint8_t *p_mem_block = NULL;

+ 1 - 1
components/esp_partition/partition_linux.c

@@ -140,7 +140,7 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start)
 
         // check if partition file is present, if not, use default
         if (!has_partfile) {
-            strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, "build/partition_table/partition-table.bin", sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name));
+            strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, BUILD_DIR "/partition_table/partition-table.bin", sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name));
         } else {
             strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, s_esp_partition_file_mmap_ctrl_input.partition_file_name, sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name));
         }

+ 2 - 2
components/spiffs/host_test/CMakeLists.txt

@@ -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)

+ 3 - 0
components/spiffs/host_test/main/CMakeLists.txt

@@ -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}\"")

+ 4 - 3
components/spiffs/host_test/main/host_test_spiffs.c

@@ -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);
 }

+ 8 - 23
conftest.py

@@ -265,20 +265,14 @@ def build_dir(app_path: str, target: Optional[str], config: Optional[str]) -> st
     Returns:
         valid build directory
     """
-    if target == 'linux':
-        # IDF-6644
-        # hard-coded in components/esp_partition/partition_linux.c
-        # const char *partition_table_file_name = "build/partition_table/partition-table.bin";
-        check_dirs = ['build']
-    else:
-        check_dirs = []
-        if target is not None and config is not None:
-            check_dirs.append(f'build_{target}_{config}')
-        if target is not None:
-            check_dirs.append(f'build_{target}')
-        if config is not None:
-            check_dirs.append(f'build_{config}')
-        check_dirs.append('build')
+    check_dirs = []
+    if target is not None and config is not None:
+        check_dirs.append(f'build_{target}_{config}')
+    if target is not None:
+        check_dirs.append(f'build_{target}')
+    if config is not None:
+        check_dirs.append(f'build_{config}')
+    check_dirs.append('build')
 
     for check_dir in check_dirs:
         binary_path = os.path.join(app_path, check_dir)
@@ -294,15 +288,6 @@ def build_dir(app_path: str, target: Optional[str], config: Optional[str]) -> st
     )
 
 
-@pytest.fixture(autouse=True)
-def linux_cd_into_app_folder(app_path: str, target: Optional[str]) -> None:
-    # IDF-6644
-    # hard-coded in components/esp_partition/partition_linux.c
-    # const char *partition_table_file_name = "build/partition_table/partition-table.bin";
-    if target == 'linux':
-        os.chdir(app_path)
-
-
 @pytest.fixture(autouse=True)
 @multi_dut_fixture
 def junit_properties(test_case_name: str, record_xml_attribute: Callable[[str, object], None]) -> None:

+ 0 - 4
tools/ci/ci_build_apps.py

@@ -64,10 +64,6 @@ def get_pytest_apps(
     build_dir = 'build_@t_@w'
     if target == 'linux':  # no esp_idf_size for linux target
         default_size_json_path = None  # type: ignore
-        # IDF-6644
-        # hard-coded in components/esp_partition/partition_linux.c
-        # const char *partition_table_file_name = "build/partition_table/partition-table.bin";
-        build_dir = 'build'
 
     apps = find_apps(
         app_dirs,