Skip to content

Commit 6b684ce

Browse files
CI: Added coverage analyzer for esp_modem host tests
1 parent c7f20ee commit 6b684ce

File tree

7 files changed

+137
-4
lines changed

7 files changed

+137
-4
lines changed

.github/workflows/gcov_analyzer.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Code Coverage Analyzer
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
gcovr_analyzer_esp_modem:
7+
name: Run gcovr on esp modem host test
8+
runs-on: ubuntu-22.04
9+
container: espressif/idf:release-v4.3
10+
env:
11+
lwip: lwip-2.1.2
12+
lwip_contrib: contrib-2.1.0
13+
lwip_uri: http://download.savannah.nongnu.org/releases/lwip
14+
COMP_DIR: esp-protocols/components/esp_modem
15+
steps:
16+
- name: Checkout esp-protocols
17+
uses: actions/checkout@v3
18+
with:
19+
path: esp-protocols
20+
persist-credentials: false
21+
- name: Build and Test
22+
shell: bash
23+
run: |
24+
apt-get update
25+
apt-get update && apt-get install -y gcc-8 g++-8 python3-pip
26+
apt-get install -y rsync
27+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
28+
export DEBIAN_FRONTEND=noninteractive
29+
export LWIP_PATH=`pwd`/${{ env.lwip }}
30+
export LWIP_CONTRIB_PATH=`pwd`/${{ env.lwip_contrib }}
31+
. ${IDF_PATH}/export.sh
32+
${{ env.COMP_DIR }}/test/host_test/env.sh $lwip $lwip_uri $lwip_contrib
33+
cd $GITHUB_WORKSPACE/${{ env.COMP_DIR }}/test/host_test
34+
cat sdkconfig.ci.coverage >> sdkconfig.defaults
35+
idf.py build
36+
./build/host_modem_test.elf
37+
- name: Run gcovr
38+
shell: bash
39+
run: |
40+
python -m pip install gcovr
41+
cd $GITHUB_WORKSPACE/${{ env.COMP_DIR }}
42+
gcov-8 `find . -name "esp_modem*gcda" -printf '%h\n' | head -n 1`/*
43+
gcovr --gcov-ignore-parse-errors -g -k -r . --html index.html -x esp_modem_coverage.xml
44+
mkdir docs_gcovr
45+
cp $GITHUB_WORKSPACE/${{ env.COMP_DIR }}/index.html docs_gcovr
46+
touch docs_gcovr/.nojekyll
47+
48+
- name: Code Coverage Summary Report
49+
uses: irongut/CodeCoverageSummary@v1.3.0
50+
with:
51+
filename: esp-protocols/**/esp_modem_coverage.xml
52+
badge: true
53+
fail_below_min: false
54+
format: markdown
55+
hide_branch_rate: false
56+
hide_complexity: false
57+
indicators: true
58+
output: both
59+
thresholds: '60 80'
60+
61+
- name: Write to Job Summary
62+
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
63+
64+
- name: Upload artifacts
65+
uses: actions/upload-artifact@v3
66+
if: always()
67+
with:
68+
name: docs_gcovr
69+
path: |
70+
${{ env.COMP_DIR }}/docs_gcovr
71+
if-no-files-found: error
72+
73+
show_report_data:
74+
name: Publish-Results
75+
if: github.ref == 'refs/heads/master' || github.repository != 'espressif/esp-protocols'
76+
runs-on: ubuntu-22.04
77+
needs: gcovr_analyzer_esp_modem
78+
steps:
79+
- name: Checkout 🛎️
80+
uses: actions/checkout@v3
81+
with:
82+
persist-credentials: false
83+
- name: Download Artifacts
84+
uses: actions/download-artifact@v1
85+
with:
86+
name: docs_gcovr
87+
88+
- name: Deploy generated docs
89+
uses: JamesIves/github-pages-deploy-action@v4
90+
with:
91+
branch: gh-pages
92+
folder: 'docs_gcovr'

.github/workflows/host-test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ jobs:
2626
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
2727
export LWIP_PATH=`pwd`/${{ env.lwip }}
2828
export LWIP_CONTRIB_PATH=`pwd`/${{ env.lwip_contrib }}
29-
wget --no-verbose ${lwip_uri}/${lwip}.zip
30-
unzip -oq ${lwip}.zip
31-
wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip
32-
unzip -oq ${lwip_contrib}.zip
3329
. ${IDF_PATH}/export.sh
30+
${{ GITHUB_WORKSPACE }}/${{ env.COMP_DIR }}/test/host_test/env.sh $lwip $lwip_uri $lwip_contrib
3431
cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/examples/linux_modem
3532
idf.py build
3633
cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/test/host_test

components/esp_modem/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ if(${target} STREQUAL "linux")
4747
# This is needed for ESP_LOGx() macros, as integer formats differ on ESP32(..) and x64
4848
set_target_properties(${COMPONENT_LIB} PROPERTIES COMPILE_FLAGS -Wno-format)
4949
endif()
50+
51+
if(CONFIG_GCOV_ENABLED)
52+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
54+
55+
56+
MARK_AS_ADVANCED(
57+
CMAKE_CXX_FLAGS_COVERAGE
58+
CMAKE_C_FLAGS_COVERAGE
59+
CMAKE_EXE_LINKER_FLAGS_COVERAGE
60+
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
61+
endif()

components/esp_modem/test/host_test/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ idf_component_get_property(esp_modem esp_modem COMPONENT_LIB)
1313
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_COMPILER_CXX_EXCEPTIONS")
1414
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
1515
target_link_options(${esp_modem} INTERFACE -fsanitize=address -fsanitize=undefined)
16+
17+
if(CONFIG_GCOV_ENABLED)
18+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
20+
21+
22+
MARK_AS_ADVANCED(
23+
CMAKE_CXX_FLAGS_COVERAGE
24+
CMAKE_C_FLAGS_COVERAGE
25+
CMAKE_EXE_LINKER_FLAGS_COVERAGE
26+
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
27+
endif()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
lwip=$1
4+
lwip_uri=$2
5+
lwip_contrib=$3
6+
7+
wget --no-verbose ${lwip_uri}/${lwip}.zip
8+
unzip -oq ${lwip}.zip
9+
wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip
10+
unzip -oq ${lwip_contrib}.zip
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menu "Host-test config"
2+
3+
config GCOV_ENABLED
4+
bool "Coverage analyzer"
5+
default n
6+
help
7+
Enables coverage analyzing for host tests.
8+
9+
endmenu
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_GCOV_ENABLED=y

0 commit comments

Comments
 (0)