Skip to content

Commit eb84eed

Browse files
committed
ci(common): Add clang tidy check to esp-protocols
1 parent 06d013b commit eb84eed

File tree

7 files changed

+130
-0
lines changed

7 files changed

+130
-0
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Run clang-tidy
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
name: Run clang-tidy
12+
runs-on: ubuntu-20.04
13+
container: espressif/idf:latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
submodules: 'true'
18+
- name: Install libtinfo (esp-clang dependency)
19+
run: |
20+
export DEBIAN_FRONTEND=noninteractive
21+
apt update && apt-get install -y libtinfo5
22+
- name: Install esp-clang
23+
run: |
24+
${IDF_PATH}/tools/idf_tools.py --non-interactive install esp-clang
25+
- name: Install clang-tidy-sarif
26+
run: |
27+
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
28+
chmod +x clang-tidy-sarif
29+
curl -sSL https://raw.githubusercontent.com/espressif/idf-extra-components/master/.github/filter_sarif.py -o filter_sarif.py
30+
- name: Install pyclang
31+
run: |
32+
. ${IDF_PATH}/export.sh
33+
pip install pyclang~=0.2.0
34+
- name: Run code analysis
35+
shell: bash
36+
env:
37+
IDF_TOOLCHAIN: clang
38+
IDF_TARGET: esp32
39+
working-directory: test_app
40+
run: |
41+
. ${IDF_PATH}/export.sh
42+
idf.py clang-check --include-paths $GITHUB_WORKSPACE --exclude-paths $PWD --run-clang-tidy-py run-clang-tidy
43+
cp warnings.txt ../
44+
- name: Convert clang-tidy results into SARIF output
45+
run: |
46+
export PATH=$PWD:$PATH
47+
./clang-tidy-sarif -o results.sarif.raw warnings.txt
48+
python3 filter_sarif.py -o results.sarif --include-prefix ${GITHUB_WORKSPACE}/ results.sarif.raw
49+
- uses: actions/upload-artifact@v2
50+
with:
51+
path: |
52+
warnings.txt
53+
results.sarif
54+
results.sarif.raw
55+
- name: Upload SARIF file
56+
uses: github/codeql-action/upload-sarif@v2
57+
with:
58+
sarif_file: results.sarif
59+
category: clang-tidy

test_app/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
include($ENV{IDF_PATH}/tools/cmake/version.cmake)
5+
6+
# Add newly added components to one of these lines:
7+
set(EXTRA_COMPONENT_DIRS
8+
../components/eppp_link
9+
../components/esp_modem
10+
../components/esp_mqtt_cxx
11+
../components/esp_websocket_client
12+
../components/console_cmd_ifconfig
13+
../components/console_cmd_ping
14+
../components/console_cmd_wifi
15+
../components/console_simple_init
16+
../components/mbedtls_cxx
17+
../components/mdns)
18+
19+
20+
# !This section should NOT be touched when adding new component!
21+
# Take all components in EXTRA_COMPONENT_DIRS, strip leading '../' and add it to TEST_COMPONENTS
22+
# The build system will build and link unit tests, if the component contains 'test' subdirectory
23+
set(TEST_COMPONENTS "" CACHE STRING "List of components to test")
24+
foreach (CMP_DIR ${EXTRA_COMPONENT_DIRS})
25+
string(SUBSTRING ${CMP_DIR} 3 100 STRIPPED_CMP) # There should be no component name longer than 100 bytes...
26+
list(APPEND TEST_COMPONENTS ${STRIPPED_CMP})
27+
endforeach()
28+
29+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
30+
project(esp_protocols_test_app)

test_app/main/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "test_app_main.c"
2+
INCLUDE_DIRS ""
3+
REQUIRES unity)

test_app/main/test_app_main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "unity.h"
8+
9+
void app_main(void)
10+
{
11+
UNITY_BEGIN();
12+
unity_run_all_tests();
13+
UNITY_END();
14+
}

test_app/partitions.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3+
nvs, data, nvs, , 0x6000,
4+
phy_init, data, phy, , 0x1000,
5+
factory, app, factory, , 2M,

test_app/pytest_test_app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
def test_app(dut):
4+
dut.expect_unity_test_output(timeout=240)

test_app/sdkconfig.defaults

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONFIG_ESP_INT_WDT=n
2+
CONFIG_ESP_TASK_WDT=n
3+
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
4+
CONFIG_PARTITION_TABLE_CUSTOM=y
5+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
6+
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
7+
8+
# Run-time checks of Heap and Stack
9+
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
10+
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
11+
CONFIG_COMPILER_STACK_CHECK=y
12+
CONFIG_ESP_MAIN_TASK_STACK_SIZE=16000
13+
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
14+
15+
CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y

0 commit comments

Comments
 (0)