From eb84eed8d3346940bc0938d75708b7f38b501b9e Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 5 Apr 2024 12:41:41 +0200 Subject: [PATCH] ci(common): Add clang tidy check to esp-protocols --- .github/workflows/clang-tidy.yml | 59 ++++++++++++++++++++++++++++++++ test_app/CMakeLists.txt | 30 ++++++++++++++++ test_app/main/CMakeLists.txt | 3 ++ test_app/main/test_app_main.c | 14 ++++++++ test_app/partitions.csv | 5 +++ test_app/pytest_test_app.py | 4 +++ test_app/sdkconfig.defaults | 15 ++++++++ 7 files changed, 130 insertions(+) create mode 100644 .github/workflows/clang-tidy.yml create mode 100644 test_app/CMakeLists.txt create mode 100644 test_app/main/CMakeLists.txt create mode 100644 test_app/main/test_app_main.c create mode 100644 test_app/partitions.csv create mode 100644 test_app/pytest_test_app.py create mode 100644 test_app/sdkconfig.defaults diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml new file mode 100644 index 0000000000..1f7a01a329 --- /dev/null +++ b/.github/workflows/clang-tidy.yml @@ -0,0 +1,59 @@ +name: Run clang-tidy + +on: + pull_request: + push: + branches: + - master + +jobs: + build: + name: Run clang-tidy + runs-on: ubuntu-20.04 + container: espressif/idf:latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'true' + - name: Install libtinfo (esp-clang dependency) + run: | + export DEBIAN_FRONTEND=noninteractive + apt update && apt-get install -y libtinfo5 + - name: Install esp-clang + run: | + ${IDF_PATH}/tools/idf_tools.py --non-interactive install esp-clang + - name: Install clang-tidy-sarif + run: | + curl -sSL https://github.com/psastras/sarif-rs/releases/download/clang-tidy-sarif-v0.3.3/clang-tidy-sarif-x86_64-unknown-linux-gnu -o clang-tidy-sarif + chmod +x clang-tidy-sarif + curl -sSL https://raw.githubusercontent.com/espressif/idf-extra-components/master/.github/filter_sarif.py -o filter_sarif.py + - name: Install pyclang + run: | + . ${IDF_PATH}/export.sh + pip install pyclang~=0.2.0 + - name: Run code analysis + shell: bash + env: + IDF_TOOLCHAIN: clang + IDF_TARGET: esp32 + working-directory: test_app + run: | + . ${IDF_PATH}/export.sh + idf.py clang-check --include-paths $GITHUB_WORKSPACE --exclude-paths $PWD --run-clang-tidy-py run-clang-tidy + cp warnings.txt ../ + - name: Convert clang-tidy results into SARIF output + run: | + export PATH=$PWD:$PATH + ./clang-tidy-sarif -o results.sarif.raw warnings.txt + python3 filter_sarif.py -o results.sarif --include-prefix ${GITHUB_WORKSPACE}/ results.sarif.raw + - uses: actions/upload-artifact@v2 + with: + path: | + warnings.txt + results.sarif + results.sarif.raw + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: results.sarif + category: clang-tidy diff --git a/test_app/CMakeLists.txt b/test_app/CMakeLists.txt new file mode 100644 index 0000000000..3743c581f6 --- /dev/null +++ b/test_app/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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.5) +include($ENV{IDF_PATH}/tools/cmake/version.cmake) + +# Add newly added components to one of these lines: +set(EXTRA_COMPONENT_DIRS + ../components/eppp_link + ../components/esp_modem + ../components/esp_mqtt_cxx + ../components/esp_websocket_client + ../components/console_cmd_ifconfig + ../components/console_cmd_ping + ../components/console_cmd_wifi + ../components/console_simple_init + ../components/mbedtls_cxx + ../components/mdns) + + +# !This section should NOT be touched when adding new component! +# Take all components in EXTRA_COMPONENT_DIRS, strip leading '../' and add it to TEST_COMPONENTS +# The build system will build and link unit tests, if the component contains 'test' subdirectory +set(TEST_COMPONENTS "" CACHE STRING "List of components to test") +foreach (CMP_DIR ${EXTRA_COMPONENT_DIRS}) + string(SUBSTRING ${CMP_DIR} 3 100 STRIPPED_CMP) # There should be no component name longer than 100 bytes... + list(APPEND TEST_COMPONENTS ${STRIPPED_CMP}) +endforeach() + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_protocols_test_app) diff --git a/test_app/main/CMakeLists.txt b/test_app/main/CMakeLists.txt new file mode 100644 index 0000000000..55e6764a08 --- /dev/null +++ b/test_app/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "test_app_main.c" + INCLUDE_DIRS "" + REQUIRES unity) diff --git a/test_app/main/test_app_main.c b/test_app/main/test_app_main.c new file mode 100644 index 0000000000..bf9add7772 --- /dev/null +++ b/test_app/main/test_app_main.c @@ -0,0 +1,14 @@ +/* + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" + +void app_main(void) +{ + UNITY_BEGIN(); + unity_run_all_tests(); + UNITY_END(); +} diff --git a/test_app/partitions.csv b/test_app/partitions.csv new file mode 100644 index 0000000000..75c7787df4 --- /dev/null +++ b/test_app/partitions.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap +nvs, data, nvs, , 0x6000, +phy_init, data, phy, , 0x1000, +factory, app, factory, , 2M, diff --git a/test_app/pytest_test_app.py b/test_app/pytest_test_app.py new file mode 100644 index 0000000000..e2e563051d --- /dev/null +++ b/test_app/pytest_test_app.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +def test_app(dut): + dut.expect_unity_test_output(timeout=240) diff --git a/test_app/sdkconfig.defaults b/test_app/sdkconfig.defaults new file mode 100644 index 0000000000..e2e441af97 --- /dev/null +++ b/test_app/sdkconfig.defaults @@ -0,0 +1,15 @@ +CONFIG_ESP_INT_WDT=n +CONFIG_ESP_TASK_WDT=n +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" + +# Run-time checks of Heap and Stack +CONFIG_HEAP_POISONING_COMPREHENSIVE=y +CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y +CONFIG_COMPILER_STACK_CHECK=y +CONFIG_ESP_MAIN_TASK_STACK_SIZE=16000 +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y + +CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y