From ac64aa0c60c5c1431d274099aea2b05416a0a56e Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Thu, 23 May 2024 11:32:56 +0200 Subject: [PATCH 1/5] fix(linux): Miscellaneous fixes for linux build on MacOS This commit fixes some compilation errors for the linux build on MacOS. --- components/efuse/linux/esp_efuse_utility.c | 2 +- components/log/src/linux/log_timestamp.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/efuse/linux/esp_efuse_utility.c b/components/efuse/linux/esp_efuse_utility.c index de622922424f..25c69d0cadf0 100644 --- a/components/efuse/linux/esp_efuse_utility.c +++ b/components/efuse/linux/esp_efuse_utility.c @@ -89,7 +89,7 @@ esp_err_t esp_efuse_utility_burn_chip_opt(bool ignore_coding_errors, bool verify // This function reads EFUSE_BLKx_WDATAx_REG registers, and checks possible to write these data with RS coding scheme. // The RS coding scheme does not require data changes for the encoded data. esp32s2 has special registers for this. // They will be filled during the burn operation. -esp_err_t esp_efuse_utility_apply_new_coding_scheme() +esp_err_t esp_efuse_utility_apply_new_coding_scheme(void) { // start with EFUSE_BLK1. EFUSE_BLK0 - always uses EFUSE_CODING_SCHEME_NONE. for (int num_block = EFUSE_BLK1; num_block < EFUSE_BLK_MAX; num_block++) { diff --git a/components/log/src/linux/log_timestamp.c b/components/log/src/linux/log_timestamp.c index 04fc51d43368..f341c0e5a228 100644 --- a/components/log/src/linux/log_timestamp.c +++ b/components/log/src/linux/log_timestamp.c @@ -17,4 +17,8 @@ uint32_t esp_log_early_timestamp(void) return milliseconds; } -uint32_t esp_log_timestamp(void) __attribute__((alias("esp_log_early_timestamp"))); +// Avoid using __attribute(alias) here since linux target builds on MacOS fail to compile. +uint32_t esp_log_timestamp(void) +{ + return esp_log_early_timestamp(); +} From 50460d348310d7532f99d808fce2b591a8459b3e Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 13 May 2024 10:57:47 +0200 Subject: [PATCH 2/5] feat(ci): Added CI host test for the linux target on MacOS runners This commit adds a CI host test for the linux target to build and run MacOS runners. Additionally, it adds a MacOS test for the hellow_world app. --- .gitlab/ci/host-test.yml | 30 +++++++++++++++++++ .../hello_world/pytest_hello_world.py | 10 +++++-- tools/ci/idf_pytest/constants.py | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index 741d47ea70c2..968dcec1bfdd 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -352,6 +352,36 @@ test_pytest_linux: --ignore-result-files ${KNOWN_FAILURE_CASES_FILE_NAME} --app-info-filepattern \"list_job_*.txt\" +test_pytest_macos: + extends: + - .host_test_template + - .before_script:build:macos + tags: + - macos_shell + artifacts: + paths: + - XUNIT_RESULT.xml + - pytest-embedded/ + - "**/build*/build_log.txt" + reports: + junit: XUNIT_RESULT.xml + script: + - run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -vv + --target linux + --pytest-apps + -m \"host_test and macos_shell\" + --collect-app-info "list_job_${CI_JOB_NAME_SLUG}.txt" + --modified-components ${MR_MODIFIED_COMPONENTS} + --modified-files ${MR_MODIFIED_FILES} + - python tools/ci/get_known_failure_cases_file.py + - run_cmd pytest + --target linux + -m \"host_test and macos_shell\" + --junitxml=XUNIT_RESULT.xml + --ignore-result-files ${KNOWN_FAILURE_CASES_FILE_NAME} + --app-info-filepattern \"list_job_*.txt\" + + test_idf_pytest_plugin: extends: - .host_test_template diff --git a/examples/get-started/hello_world/pytest_hello_world.py b/examples/get-started/hello_world/pytest_hello_world.py index caeeff16b792..3524fd94957a 100644 --- a/examples/get-started/hello_world/pytest_hello_world.py +++ b/examples/get-started/hello_world/pytest_hello_world.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import hashlib import logging from typing import Callable @@ -27,6 +26,13 @@ def test_hello_world_linux(dut: IdfDut) -> None: dut.expect('Hello world!') +@pytest.mark.linux +@pytest.mark.host_test +@pytest.mark.macos_shell +def test_hello_world_macos(dut: IdfDut) -> None: + dut.expect('Hello world!') + + def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None: sha256 = hashlib.sha256() with open(app.elf_file, 'rb') as f: diff --git a/tools/ci/idf_pytest/constants.py b/tools/ci/idf_pytest/constants.py index 89f3bbe1c1eb..2886b3ac0ac1 100644 --- a/tools/ci/idf_pytest/constants.py +++ b/tools/ci/idf_pytest/constants.py @@ -46,6 +46,7 @@ ENV_MARKERS = { # special markers 'qemu': 'build and test using qemu, not real target', + 'macos_shell': 'tests should be run on macos hosts', # single-dut markers 'generic': 'tests should be run on generic runners', 'flash_suspend': 'support flash suspend feature', From 61559dc3e4f8eb5f06779f8ae429dc9abc1c32d5 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Thu, 23 May 2024 13:51:31 +0200 Subject: [PATCH 3/5] ci: ignore collect import error on CI with env var --- .gitlab/ci/host-test.yml | 2 ++ tools/ci/idf_pytest/plugin.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index 968dcec1bfdd..f2ab6b89d232 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -365,6 +365,8 @@ test_pytest_macos: - "**/build*/build_log.txt" reports: junit: XUNIT_RESULT.xml + variables: + PYTEST_IGNORE_COLLECT_IMPORT_ERROR: "1" script: - run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -vv --target linux diff --git a/tools/ci/idf_pytest/plugin.py b/tools/ci/idf_pytest/plugin.py index b2e04402c423..d88370792b77 100644 --- a/tools/ci/idf_pytest/plugin.py +++ b/tools/ci/idf_pytest/plugin.py @@ -141,7 +141,7 @@ def item_to_pytest_case(self, item: Function) -> t.Optional[PytestCase]: def pytest_collectstart(self) -> None: # mock the optional packages while collecting locally - if not os.getenv('CI_JOB_ID'): + if not os.getenv('CI_JOB_ID') or os.getenv('PYTEST_IGNORE_COLLECT_IMPORT_ERROR') == '1': # optional packages required by test scripts for p in [ 'scapy', From e5fb198adc124ec850f3d345892650996aeccdd6 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 24 May 2024 07:45:31 +0200 Subject: [PATCH 4/5] fix(linux): Fixed linux target build failure in esp_app_format for MacOS This commit fixes a build failure in the esp_app_format component for the linux target when built on a MacOS machine. --- components/esp_app_format/CMakeLists.txt | 8 +++++++- components/esp_app_format/esp_app_desc.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/esp_app_format/CMakeLists.txt b/components/esp_app_format/CMakeLists.txt index 95e20d034110..27a3d2ffd661 100644 --- a/components/esp_app_format/CMakeLists.txt +++ b/components/esp_app_format/CMakeLists.txt @@ -11,7 +11,13 @@ idf_component_register(SRCS ${src} if(NOT BOOTLOADER_BUILD) # esp_app_desc structure is added as an undefined symbol because otherwise the # linker will ignore this structure as it has no other files depending on it. - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_app_desc") + if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + # On MacOS, the linker expects the exact mangled symbol name (with leading underscore) + # to be present in the object file. + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u _esp_app_desc") + else() + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_app_desc") + endif() if(CONFIG_APP_PROJECT_VER_FROM_CONFIG) # Ignore current PROJECT_VER (which was set in project.cmake) diff --git a/components/esp_app_format/esp_app_desc.c b/components/esp_app_format/esp_app_desc.c index 60d5bbd823a8..e40c9fd5a7f6 100644 --- a/components/esp_app_format/esp_app_desc.c +++ b/components/esp_app_format/esp_app_desc.c @@ -20,7 +20,11 @@ static const char *TAG = "app_init"; #endif // Application version info +#if defined(__APPLE__) && CONFIG_IDF_TARGET_LINUX +const __attribute__((weak)) __attribute__((section("__RODATA_DESC,.rodata_desc"))) esp_app_desc_t esp_app_desc = { +#else const __attribute__((weak)) __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { +#endif /* #if defined(__APPLE__) && CONFIG_IDF_TARGET_LINUX */ .magic_word = ESP_APP_DESC_MAGIC_WORD, #ifdef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR .version = "", From 00efba056512a18f4c853ce84c8f77daae47022f Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 24 May 2024 11:55:26 +0200 Subject: [PATCH 5/5] fix(linux): Added instructions to ignore build warnings in CI for MacOS This commit updates the host-test.yml to add instructions to ignore certain build warnings when the linux target is built on MacOS. This way the test doesn't get flagged as failed in CI for the warnings and can run. --- tools/ci/ignore_build_warnings.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ci/ignore_build_warnings.txt b/tools/ci/ignore_build_warnings.txt index 5c208435de2e..ca30cdaf9b01 100644 --- a/tools/ci/ignore_build_warnings.txt +++ b/tools/ci/ignore_build_warnings.txt @@ -39,3 +39,5 @@ warning: unknown kconfig symbol 'SPIRAM' assigned to 'y' in .*/examples/protocol warning: unknown kconfig symbol 'SPIRAM' assigned to 'y' in .*/examples/protocols/https_request/sdkconfig.ci.ssldyn warning: unknown kconfig symbol 'UNITY_FREERTOS_STACK_SIZE' assigned to '12288' in .*/components/bt/test_apps/sdkconfig.defaults warning: unknown kconfig symbol 'WPA3_SAE' assigned to 'y' in .*/components/wpa_supplicant/test_apps/sdkconfig.defaults +ld: warning: ignoring duplicate libraries +archive library: .+ the table of contents is empty