Skip to content

Commit 3f74b4e

Browse files
feat(modem): host test support of the latest ESP-IDF release
1 parent 5b467cb commit 3f74b4e

File tree

9 files changed

+84
-24
lines changed

9 files changed

+84
-24
lines changed

.github/workflows/modem__build-host-tests.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,25 @@ jobs:
7676
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
7777
uses: "./.github/workflows/run-host-tests.yml"
7878
with:
79-
idf_version: "release-v4.3"
79+
idf_version: "latest"
8080
app_name: "host_modem_test"
8181
app_path: "esp-protocols/components/esp_modem/test/host_test"
8282
component_path: "esp-protocols/components/esp_modem"
8383
upload_artifacts: true
84+
run_executable: true
85+
run_coverage: true
8486
pre_run_script: "esp-protocols/components/esp_modem/test/host_test/env.sh"
8587
publish_unit_test_result: true
88+
89+
build_linux_example:
90+
if: contains(github.event.pull_request.labels.*.name, 'modem') || github.event_name == 'push'
91+
uses: "./.github/workflows/run-host-tests.yml"
92+
with:
93+
idf_version: "latest"
94+
app_name: "linux_modem"
95+
app_path: "esp-protocols/components/esp_modem/examples/linux_modem"
96+
component_path: "esp-protocols/components/esp_modem"
97+
upload_artifacts: true
98+
run_executable: false
99+
run_coverage: false
100+
pre_run_script: "esp-protocols/components/esp_modem/test/host_test/env.sh"

.github/workflows/run-host-tests.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ on:
1818
upload_artifacts:
1919
type: boolean
2020
required: true
21+
run_executable:
22+
type: boolean
23+
required: true
24+
run_coverage:
25+
type: boolean
26+
required: true
2127
pre_run_script:
2228
type: string
2329
required: false
@@ -51,14 +57,24 @@ jobs:
5157
# The sdkconfig.ci.linux specifies Linux as the build target with apropriate settings.
5258
cp sdkconfig.ci.linux sdkconfig.defaults
5359
idf.py build
54-
./build/${{inputs.app_name}}.elf -r junit -o junit.xml
60+
if [ "${{ inputs.run_executable}}" == "false" ]; then
61+
echo "Executeable wasn't run"
62+
exit 0
63+
fi
64+
65+
if [ "${{ inputs.publish_unit_test_result }}" == "true" ]; then
66+
./build/${{inputs.app_name}}.elf --reporter JUnit::out=result-junit.xml --reporter console::out=-::colour-mode=ansi
67+
else
68+
./build/${{inputs.app_name}}.elf
69+
fi
5570
- name: Publish Unit Test Result
5671
uses: EnricoMi/publish-unit-test-result-action@v2
5772
if: ${{ inputs.publish_unit_test_result }}
5873
with:
5974
files: ${{inputs.component_path}}/**/*junit.xml
6075
- name: Build with Coverage Enabled
6176
shell: bash
77+
if: ${{ inputs.run_coverage }}
6278
run: |
6379
component=$(basename ${{ inputs.component_path }})
6480
if [ -f "${{ inputs.pre_run_script }}" ]; then
@@ -74,6 +90,7 @@ jobs:
7490
./build/${{inputs.app_name}}.elf
7591
- name: Run Coverage
7692
shell: bash
93+
if: ${{ inputs.run_coverage }}
7794
run: |
7895
apt-get update && apt-get install -y python3-pip rsync
7996
python -m pip install gcovr
@@ -86,6 +103,7 @@ jobs:
86103
cp index.html ${{inputs.app_name}}_coverage_report
87104
cp -rf ${{inputs.app_name}}_coverage_report ${{inputs.app_name}}_coverage.xml $GITHUB_WORKSPACE
88105
- name: Code Coverage Summary Report
106+
if: ${{ inputs.run_coverage }}
89107
uses: irongut/[email protected]
90108
with:
91109
filename: esp-protocols/**/${{inputs.app_name}}_coverage.xml
@@ -99,9 +117,10 @@ jobs:
99117
thresholds: '60 80'
100118
- name: Write to Job Summary
101119
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
120+
if: ${{ inputs.run_coverage }}
102121
- name: Upload files to artifacts for run-target job
103122
uses: actions/upload-artifact@v3
104-
if: ${{inputs.upload_artifacts}}
123+
if: ${{ inputs.run_coverage }}
105124
with:
106125
name: ${{inputs.app_name}}_coverage_report
107126
path: |

.github/workflows/websocket__build-host-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ jobs:
1717
app_name: "websocket"
1818
app_path: "esp-protocols/components/esp_websocket_client/examples/linux"
1919
component_path: "esp-protocols/components/esp_websocket_client"
20+
run_executable: true
2021
upload_artifacts: true
22+
run_coverage: true

components/esp_modem/examples/linux_modem/main/modem_main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ using namespace esp_modem;
2222

2323
[[maybe_unused]] constexpr auto TAG = "linux_modem_main";
2424

25-
26-
int main()
25+
extern "C" void app_main(void)
2726
{
2827
// init the DTE
2928
esp_modem_dte_config_t dte_config = {

components/esp_modem/test/host_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(EXTRA_COMPONENT_DIRS # Add esp_modem component and linux port components
66
../..
77
../../port/linux)
88

9-
set(COMPONENTS main)
9+
set(COMPONENTS esp_modem main)
1010
project(host_modem_test)
1111

1212
idf_component_get_property(esp_modem esp_modem COMPONENT_LIB)

components/esp_modem/test/host_test/env.sh

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
idf_version=$1
44
component=$2
55

6-
if [[ "$idf_version" == "release-v4.3" ]] && [[ "$component" == "esp_modem" ]]; then
7-
lwip=lwip-2.1.2
8-
lwip_uri=http://download.savannah.nongnu.org/releases/lwip
9-
lwip_contrib=contrib-2.1.0
6+
lwip=lwip-2.1.2
7+
lwip_uri=http://download.savannah.nongnu.org/releases/lwip
8+
lwip_contrib=contrib-2.1.0
109

11-
wget --no-verbose ${lwip_uri}/${lwip}.zip
12-
unzip -oq ${lwip}.zip
13-
wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip
14-
unzip -oq ${lwip_contrib}.zip
10+
wget --no-verbose ${lwip_uri}/${lwip}.zip
11+
unzip -oq ${lwip}.zip
12+
wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip
13+
unzip -oq ${lwip_contrib}.zip
1514

16-
apt-get update && apt-get install -y gcc-8 g++-8
17-
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
18-
rm /usr/bin/gcov && ln -s /usr/bin/gcov-8 /usr/bin/gcov
19-
export LWIP_PATH=`pwd`/$lwip
20-
export LWIP_CONTRIB_PATH=`pwd`/$lwip_contrib
21-
fi
15+
export LWIP_PATH=`pwd`/$lwip
16+
export LWIP_CONTRIB_PATH=`pwd`/$lwip_contrib

components/esp_modem/test/host_test/main/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
idf_component_register(SRCS "test_modem.cpp" "LoopbackTerm.cpp"
2-
INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch"
3-
REQUIRES esp_modem)
2+
REQUIRES esp_modem WHOLE_ARCHIVE)
43

54
set(THREADS_PREFER_PTHREAD_FLAG ON)
65
find_package(Threads REQUIRED)
76
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
87

8+
target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain)
9+
910
set_target_properties(${COMPONENT_LIB} PROPERTIES
1011
CXX_STANDARD 17
1112
CXX_STANDARD_REQUIRED ON
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dependencies:
2+
espressif/catch2:
3+
version: '*'
4+
idf:
5+
version: ">=5.0"

components/esp_modem/test/host_test/main/test_modem.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
66
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
77
#include <memory>
88
#include <future>
9-
#include "catch.hpp"
9+
#include <catch2/catch_test_macros.hpp>
10+
#include <catch2/catch_session.hpp>
1011
#include "cxx_include/esp_modem_api.hpp"
1112
#include "LoopbackTerm.h"
13+
#include <iostream>
1214

1315
using namespace esp_modem;
1416

@@ -346,3 +348,25 @@ TEST_CASE("CMUX manual mode transitions", "[esp_modem][transitions]")
346348
CHECK(dce->set_mode(esp_modem::modem_mode::UNDEF) == true); // Succeeds from any state
347349

348350
}
351+
352+
#define CATCH_CONFIG_RUNNER
353+
extern "C" int app_main(void)
354+
{
355+
// Define the argument count and arguments for Catch2, including JUnit reporting
356+
int argc = 5;
357+
const char *argv[] = {"esp_modem", "-r", "junit", "-o", "junit.xml", nullptr};
358+
359+
// Run the Catch2 session and store the result
360+
int result = Catch::Session().run(argc, argv);
361+
362+
// Use more descriptive error handling
363+
if (result != 0) {
364+
printf("Test failed with result %d. Refer to the Catch2 documentation for error details.\n", result);
365+
} else {
366+
printf("All tests passed successfully.\n");
367+
}
368+
369+
// Check for the junit.xml file in the current working directory
370+
// Exit the application with the test result as the status code
371+
std::exit(result);
372+
}

0 commit comments

Comments
 (0)