From f67bcc669a3eec57626a4eeadc86ca42a1fbcb31 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 14 Mar 2023 16:58:35 +0800 Subject: [PATCH 1/3] esp_partition: partition_linux.c and its test do not use hard-coded file anymore --- components/esp_partition/CMakeLists.txt | 4 ++++ .../host_test/partition_api_test/main/CMakeLists.txt | 3 +++ .../host_test/partition_api_test/main/partition_api_test.c | 4 ++-- components/esp_partition/partition_linux.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/components/esp_partition/CMakeLists.txt b/components/esp_partition/CMakeLists.txt index 5220e47671..371dae2c24 100644 --- a/components/esp_partition/CMakeLists.txt +++ b/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) diff --git a/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt b/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt index 5dee25b740..d0d6d1e909 100644 --- a/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt +++ b/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}\"") diff --git a/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c b/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c index f6ab19c432..a82952c26b 100644 --- a/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c +++ b/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; diff --git a/components/esp_partition/partition_linux.c b/components/esp_partition/partition_linux.c index 50ebe0103c..4c55e5e579 100644 --- a/components/esp_partition/partition_linux.c +++ b/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)); } From 5327fd89b55feb70c79c429daea4df329e4f61be Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Fri, 31 Mar 2023 15:04:54 +0800 Subject: [PATCH 2/3] spiffs: test is using configurable build dir --- components/spiffs/host_test/CMakeLists.txt | 4 ++-- components/spiffs/host_test/main/CMakeLists.txt | 3 +++ components/spiffs/host_test/main/host_test_spiffs.c | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/spiffs/host_test/CMakeLists.txt b/components/spiffs/host_test/CMakeLists.txt index 81a2485a61..521c80b60d 100644 --- a/components/spiffs/host_test/CMakeLists.txt +++ b/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) diff --git a/components/spiffs/host_test/main/CMakeLists.txt b/components/spiffs/host_test/main/CMakeLists.txt index 544f56e7fe..9e7cfedc75 100644 --- a/components/spiffs/host_test/main/CMakeLists.txt +++ b/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}\"") diff --git a/components/spiffs/host_test/main/host_test_spiffs.c b/components/spiffs/host_test/main/host_test_spiffs.c index 9b0cb018a4..5dbf0ab0d2 100644 --- a/components/spiffs/host_test/main/host_test_spiffs.c +++ b/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); } From 9295aef934fff9451703dc5c7a34679b1ca0bf96 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 21 Mar 2023 11:39:56 +0800 Subject: [PATCH 3/3] ci: remove linux build dir workaround --- conftest.py | 31 ++++++++----------------------- tools/ci/ci_build_apps.py | 4 ---- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/conftest.py b/conftest.py index cf924ec032..5469089cdd 100644 --- a/conftest.py +++ b/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: diff --git a/tools/ci/ci_build_apps.py b/tools/ci/ci_build_apps.py index f245cf8cd4..64e8beeb72 100644 --- a/tools/ci/ci_build_apps.py +++ b/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,