From 8c52b0845d36317181ff19f9d4c0ee5aec7466ea Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 24 Oct 2023 10:04:09 +0800 Subject: [PATCH] feat(linux_target): enable hello world example for linux target --- components/spi_flash/CMakeLists.txt | 3 +- components/spi_flash/linux/spi_flash_linux.c | 13 +++++ examples/get-started/.build-test-rules.yml | 2 +- examples/get-started/hello_world/README.md | 4 +- .../hello_world/pytest_hello_world.py | 8 ++- tools/test_apps/.build-test-rules.yml | 4 -- .../CMakeLists.txt | 7 --- .../hello_world_linux_compatible/README.md | 45 ----------------- .../main/CMakeLists.txt | 2 - .../main/hello_world_main.c | 49 ------------------- .../pytest_hello_world_linux_compatible.py | 17 ------- .../sdkconfig.defaults | 0 12 files changed, 25 insertions(+), 129 deletions(-) create mode 100644 components/spi_flash/linux/spi_flash_linux.c delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/CMakeLists.txt delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/README.md delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/main/CMakeLists.txt delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/main/hello_world_main.c delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/pytest_hello_world_linux_compatible.py delete mode 100644 tools/test_apps/linux_compatible/hello_world_linux_compatible/sdkconfig.defaults diff --git a/components/spi_flash/CMakeLists.txt b/components/spi_flash/CMakeLists.txt index 013759a3db..2d686a2523 100644 --- a/components/spi_flash/CMakeLists.txt +++ b/components/spi_flash/CMakeLists.txt @@ -1,6 +1,7 @@ idf_build_get_property(target IDF_TARGET) if(${target} STREQUAL "linux") - idf_component_register(INCLUDE_DIRS include + idf_component_register(SRCS "linux/spi_flash_linux.c" + INCLUDE_DIRS include PRIV_INCLUDE_DIRS include/spi_flash) return() endif() diff --git a/components/spi_flash/linux/spi_flash_linux.c b/components/spi_flash/linux/spi_flash_linux.c new file mode 100644 index 0000000000..e408468034 --- /dev/null +++ b/components/spi_flash/linux/spi_flash_linux.c @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "esp_flash.h" + +esp_err_t esp_flash_get_size(esp_flash_t *chip, uint32_t *out_size) +{ + (void)chip; + *out_size = UINT32_MAX; + return ESP_OK; +} diff --git a/examples/get-started/.build-test-rules.yml b/examples/get-started/.build-test-rules.yml index 0e70fd65b4..0d1df0e98b 100644 --- a/examples/get-started/.build-test-rules.yml +++ b/examples/get-started/.build-test-rules.yml @@ -8,4 +8,4 @@ examples/get-started/blink: examples/get-started/hello_world: enable: - - if: INCLUDE_DEFAULT == 1 + - if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux" diff --git a/examples/get-started/hello_world/README.md b/examples/get-started/hello_world/README.md index 8bbda44cc6..29171c316c 100644 --- a/examples/get-started/hello_world/README.md +++ b/examples/get-started/hello_world/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ----- | # Hello World Example diff --git a/examples/get-started/hello_world/pytest_hello_world.py b/examples/get-started/hello_world/pytest_hello_world.py index e7380003dc..caeeff16b7 100644 --- a/examples/get-started/hello_world/pytest_hello_world.py +++ b/examples/get-started/hello_world/pytest_hello_world.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import hashlib @@ -21,6 +21,12 @@ def test_hello_world( log_minimum_free_heap_size() +@pytest.mark.linux +@pytest.mark.host_test +def test_hello_world_linux(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/test_apps/.build-test-rules.yml b/tools/test_apps/.build-test-rules.yml index f659a0a637..5cf3291d28 100644 --- a/tools/test_apps/.build-test-rules.yml +++ b/tools/test_apps/.build-test-rules.yml @@ -15,10 +15,6 @@ tools/test_apps/linux_compatible/driver_mock: enable: - if: IDF_TARGET == "linux" -tools/test_apps/linux_compatible/hello_world_linux_compatible: - enable: - - if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux" - tools/test_apps/linux_compatible/linux_freertos: enable: - if: IDF_TARGET == "linux" diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/CMakeLists.txt b/tools/test_apps/linux_compatible/hello_world_linux_compatible/CMakeLists.txt deleted file mode 100644 index 9e0d431d4c..0000000000 --- a/tools/test_apps/linux_compatible/hello_world_linux_compatible/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# The following lines of boilerplate have to be in your project's -# CMakeLists in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.16) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) - -project(hello_world) diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/README.md b/tools/test_apps/linux_compatible/hello_world_linux_compatible/README.md deleted file mode 100644 index c0152d0541..0000000000 --- a/tools/test_apps/linux_compatible/hello_world_linux_compatible/README.md +++ /dev/null @@ -1,45 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ----- | - -# Hello World Example Compatible with POSIX-port - -This is a version of the "Hello World" example compatible with the linux target. Just by using `idf.py (--preview) set-target `, it can be compiled for chip targets as well as for the [FreeRTOS POSIX/Linux simulator](https://www.freertos.org/FreeRTOS-simulator-for-Linux.html), i.e., for running it on Linux. The applications can then be run on the chosen target. - -## Requirements - -If you want to use this example on Linux, you need a Linux machine as host. The remaining requirements are the same requirements as for [Unit Testing on Linux (using cmock)](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/linux-host-testing.html#requirements), except you do not need Ruby. - -## How to use example - -### Configure the project - -No special configuration is required, we also do not recommend changing configuration when compiled for the POSIX/Linux simulator as this is still in preview. If you have to configure something, use the usual IDF menuconfig: -``` -idf.py menuconfig -``` - -### Build and Flash - -You can compile this example for chip targets, e.g. ESP32 and then run it by using: -``` -idf.py set-target esp32 -idf.py build -idf.py -p flash monitor -``` - -If you want to build this example for the linux target and run it, use the same commands except setting the linux target and omitting the flash command: -``` -idf.py --preview set-target linux -idf.by build -idf.py monitor -``` -The linux target is still in preview, hence the necessary `--preview` argument. Flashing can be omitted on Linux. - - -## Example folder contents - -The files in this project have the same structure as the files in the [original Hello World application](../../../../examples/get-started/hello_world/). - -## Example Output - -The output is similar to the output of the [original Hello World application](../../../../examples/get-started/hello_world/), except that no chip information is printed and there won't be any bootloader output on the linux target. diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/CMakeLists.txt b/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/CMakeLists.txt deleted file mode 100644 index 07686dc8e1..0000000000 --- a/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "hello_world_main.c" - INCLUDE_DIRS "") diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/hello_world_main.c b/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/hello_world_main.c deleted file mode 100644 index d8696bba6e..0000000000 --- a/tools/test_apps/linux_compatible/hello_world_linux_compatible/main/hello_world_main.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: CC0-1.0 - */ - -#include -#include -#include "sdkconfig.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_chip_info.h" -#include "esp_system.h" - -void app_main(void) -{ - printf("Hello world!\n"); - - /* Print chip information */ - esp_chip_info_t chip_info; - uint32_t flash_size; - esp_chip_info(&chip_info); - printf("This is %s chip with %d CPU core(s), WiFi%s%s%s, ", - CONFIG_IDF_TARGET, - chip_info.cores, - (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", - (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "", - (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : ""); - - unsigned major_rev = chip_info.revision / 100; - unsigned minor_rev = chip_info.revision % 100; - printf("silicon revision v%d.%d, ", major_rev, minor_rev); - - /* get_flash_size API not available on Linux*/ - flash_size = UINT32_MAX; - - printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), - (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); - - printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); - - for (int i = 10; i >= 0; i--) { - printf("Restarting in %d seconds...\n", i); - vTaskDelay(1000 / portTICK_PERIOD_MS); - } - printf("Restarting now.\n"); - fflush(stdout); - esp_restart(); -} diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/pytest_hello_world_linux_compatible.py b/tools/test_apps/linux_compatible/hello_world_linux_compatible/pytest_hello_world_linux_compatible.py deleted file mode 100644 index a73a140314..0000000000 --- a/tools/test_apps/linux_compatible/hello_world_linux_compatible/pytest_hello_world_linux_compatible.py +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: CC0-1.0 - -import pytest -from pytest_embedded_idf.dut import IdfDut - - -@pytest.mark.supported_targets -@pytest.mark.generic -def test_hello_world_linux_compatible(dut: IdfDut) -> None: - dut.expect('Hello world!') - - -@pytest.mark.linux -@pytest.mark.host_test -def test_hello_world_linux(dut: IdfDut) -> None: - dut.expect('Hello world!') diff --git a/tools/test_apps/linux_compatible/hello_world_linux_compatible/sdkconfig.defaults b/tools/test_apps/linux_compatible/hello_world_linux_compatible/sdkconfig.defaults deleted file mode 100644 index e69de29bb2..0000000000