Skip to content

Commit a22391a

Browse files
feat(websocket): Added linux port for websocket
1 parent ecc465d commit a22391a

20 files changed

+362
-17
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ jobs:
109109
- name: Build and Test
110110
shell: bash
111111
run: |
112-
apt-get update
113112
apt-get update && apt-get install -y gcc-8 g++-8 python3-pip
114113
apt-get install -y rsync
115114
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
@@ -129,9 +128,9 @@ jobs:
129128
cd $GITHUB_WORKSPACE/${{ env.COMP_DIR }}
130129
gcov-8 `find . -name "esp_modem*gcda" -printf '%h\n' | head -n 1`/*
131130
gcovr --gcov-ignore-parse-errors -g -k -r . --html index.html -x esp_modem_coverage.xml
132-
mkdir docs_gcovr
133-
cp $GITHUB_WORKSPACE/${{ env.COMP_DIR }}/index.html docs_gcovr
134-
cp -rf docs_gcovr $GITHUB_WORKSPACE
131+
mkdir modem_coverage_report
132+
cp $GITHUB_WORKSPACE/${{ env.COMP_DIR }}/index.html modem_coverage_report
133+
cp -rf modem_coverage_report $GITHUB_WORKSPACE
135134
- name: Code Coverage Summary Report
136135
uses: irongut/[email protected]
137136
with:
@@ -151,13 +150,7 @@ jobs:
151150
uses: actions/upload-artifact@v3
152151
if: always()
153152
with:
154-
name: docs_gcovr
153+
name: modem_coverage_report
155154
path: |
156-
${{ env.COMP_DIR }}/docs_gcovr
155+
${{ env.COMP_DIR }}/modem_coverage_report
157156
if-no-files-found: error
158-
- name: Deploy code coverage results
159-
if: github.ref == 'refs/heads/master'
160-
uses: peaceiris/actions-gh-pages@v3
161-
with:
162-
github_token: ${{ secrets.GITHUB_TOKEN }}
163-
publish_dir: ./docs_gcovr
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish coverage report to Github Pages
2+
3+
on:
4+
workflow_run:
5+
workflows: ["websocket: build/host-tests", "esp-modem: build/host-tests"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
publish_github_pages:
11+
runs-on: ubuntu-latest
12+
if: github.repository == 'espressif/esp-protocols'
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
- name: Download Websocket Artifact
17+
uses: dawidd6/action-download-artifact@v2
18+
with:
19+
workflow: websocket__build-host-tests.yml
20+
workflow_conclusion: success
21+
name: websocket_coverage_report
22+
path: websocket_coverage_report_artifact
23+
- name: Download Modem Artifact
24+
uses: dawidd6/action-download-artifact@v2
25+
with:
26+
workflow: modem__build-host-tests.yml
27+
workflow_conclusion: success
28+
name: modem_coverage_report
29+
path: modem_coverage_report_artifact
30+
- name: Merge HTML files
31+
run: |
32+
echo "<html><body>" > index.html
33+
cat modem_coverage_report_artifact/index.html >> index.html
34+
cat websocket_coverage_report_artifact/index.html >> index.html
35+
echo "</body></html>" >> index.html
36+
mkdir coverage_report
37+
mv index.html coverage_report
38+
39+
- name: Deploy generated docs
40+
uses: JamesIves/[email protected]
41+
with:
42+
branch: gh-pages
43+
folder: coverage_report

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Run on host
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
idf_version:
7+
required: true
8+
type: string
9+
app_name:
10+
type: string
11+
required: true
12+
app_path:
13+
type: string
14+
required: true
15+
component_path:
16+
type: string
17+
required: true
18+
upload_artifacts:
19+
type: boolean
20+
required: true
21+
22+
jobs:
23+
build:
24+
name: Build App
25+
runs-on: ubuntu-20.04
26+
permissions:
27+
contents: write
28+
container: espressif/idf:${{inputs.idf_version}}
29+
steps:
30+
- name: Checkout esp-protocols
31+
uses: actions/checkout@v3
32+
with:
33+
path: esp-protocols
34+
- name: Build ${{ inputs.app_name }} with IDF-${{ inputs.idf_version }}
35+
shell: bash
36+
run: |
37+
. ${IDF_PATH}/export.sh
38+
cd $GITHUB_WORKSPACE/${{inputs.app_path}}
39+
rm -rf sdkconfig sdkconfig.defaults build
40+
cp sdkconfig.ci.linux sdkconfig.defaults
41+
idf.py build
42+
./build/${{inputs.app_name}}.elf
43+
- name: Build with Coverage Enabled
44+
shell: bash
45+
run: |
46+
. ${IDF_PATH}/export.sh
47+
cd $GITHUB_WORKSPACE/${{inputs.app_path}}
48+
rm -rf build sdkconfig sdkconfig.defaults
49+
cp sdkconfig.ci.coverage sdkconfig.defaults
50+
idf.py fullclean
51+
idf.py build
52+
./build/${{inputs.app_name}}.elf
53+
- name: Run Coverage
54+
shell: bash
55+
run: |
56+
apt-get update && apt-get install -y gcc-8 g++-8 python3-pip rsync
57+
python -m pip install gcovr
58+
cd $GITHUB_WORKSPACE/${{inputs.component_path}}
59+
gcov `find . -name "*gcda"`
60+
gcovr --gcov-ignore-parse-errors -g -k -r . --html index.html -x ${{inputs.app_name}}_coverage.xml
61+
mkdir ${{inputs.app_name}}_coverage_report
62+
touch ${{inputs.app_name}}_coverage_report/.nojekyll
63+
cp index.html ${{inputs.app_name}}_coverage_report
64+
cp -rf ${{inputs.app_name}}_coverage_report ${{inputs.app_name}}_coverage.xml $GITHUB_WORKSPACE
65+
- name: Code Coverage Summary Report
66+
uses: irongut/[email protected]
67+
with:
68+
filename: esp-protocols/**/${{inputs.app_name}}_coverage.xml
69+
badge: true
70+
fail_below_min: false
71+
format: markdown
72+
hide_branch_rate: false
73+
hide_complexity: false
74+
indicators: true
75+
output: both
76+
thresholds: '60 80'
77+
- name: Write to Job Summary
78+
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
79+
- name: Upload files to artifacts for run-target job
80+
uses: actions/upload-artifact@v3
81+
if: ${{inputs.upload_artifacts}}
82+
with:
83+
name: ${{inputs.app_name}}_coverage_report
84+
path: |
85+
${{inputs.component_path}}/${{inputs.app_name}}_coverage_report
86+
if-no-files-found: error
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "websocket: build/host-tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types: [opened, synchronize, reopened, labeled]
9+
10+
11+
jobs:
12+
host_test_websocket:
13+
if: contains(github.event.pull_request.labels.*.name, 'websocket') || github.event_name == 'push'
14+
uses: "./.github/workflows/run-host-tests.yml"
15+
with:
16+
idf_version: "latest"
17+
app_name: "websocket"
18+
app_path: "esp-protocols/components/esp_websocket_client/examples/linux"
19+
component_path: "esp-protocols/components/esp_websocket_client"
20+
upload_artifacts: true

.github/workflows/websocket__build-target-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
17-
test: [ { app: example, path: "examples" }, { app: unit_test, path: "test" } ]
17+
test: [ { app: example, path: "examples/target" }, { app: unit_test, path: "test" } ]
1818
runs-on: ubuntu-20.04
1919
container: espressif/idf:${{ matrix.idf_ver }}
2020
env:
@@ -53,7 +53,7 @@ jobs:
5353
matrix:
5454
idf_ver: ["release-v5.0", "release-v5.1", "latest"]
5555
idf_target: ["esp32"]
56-
test: [ { app: example, path: "examples" }, { app: unit_test, path: "test" } ]
56+
test: [ { app: example, path: "examples/target" }, { app: unit_test, path: "test" } ]
5757
runs-on:
5858
- self-hosted
5959
- ESP32-ETHERNET-KIT
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
13
if(NOT CONFIG_WS_TRANSPORT AND NOT CMAKE_BUILD_EARLY_EXPANSION)
24
message(STATUS "Websocket transport is disabled so the esp_websocket_client component will not be built")
35
# note: the component is still included in the build so it can become visible again in config
@@ -6,7 +8,14 @@ if(NOT CONFIG_WS_TRANSPORT AND NOT CMAKE_BUILD_EARLY_EXPANSION)
68
return()
79
endif()
810

9-
idf_component_register(SRCS "esp_websocket_client.c"
11+
if(${IDF_TARGET} STREQUAL "linux")
12+
idf_component_register(SRCS "esp_websocket_client.c"
13+
INCLUDE_DIRS "include"
14+
REQUIRES esp-tls tcp_transport http_parser esp_event nvs_flash esp_stubs json
15+
PRIV_REQUIRES esp_timer)
16+
else()
17+
idf_component_register(SRCS "esp_websocket_client.c"
1018
INCLUDE_DIRS "include"
1119
REQUIRES lwip esp-tls tcp_transport http_parser
1220
PRIV_REQUIRES esp_timer esp_event)
21+
endif()

components/esp_websocket_client/esp_websocket_client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include "esp_log.h"
2020
#include "esp_timer.h"
2121
#include "esp_tls_crypto.h"
22+
#include "esp_system.h"
23+
#include <errno.h>
24+
#include <arpa/inet.h>
2225

2326
static const char *TAG = "websocket_client";
2427

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
set(COMPONENTS esp_websocket_client main)
4+
set(common_component_dir ../../../../common_components)
5+
set(EXTRA_COMPONENT_DIRS
6+
../../..
7+
"${common_component_dir}/linux_compat/esp_timer"
8+
"${common_component_dir}/linux_compat"
9+
"${common_component_dir}/linux_compat/freertos")
10+
11+
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
12+
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs)
13+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
14+
15+
project(websocket)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
idf_component_register(SRCS "main.c"
2+
INCLUDE_DIRS
3+
"."
4+
REQUIRES esp_websocket_client protocol_examples_common)
5+
6+
if(CONFIG_GCOV_ENABLED)
7+
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
8+
target_link_options(${COMPONENT_LIB} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
9+
10+
idf_component_get_property(esp_websocket_client esp_websocket_client COMPONENT_LIB)
11+
12+
target_compile_options(${esp_websocket_client} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
13+
target_link_options(${esp_websocket_client} PUBLIC --coverage -fprofile-arcs -ftest-coverage)
14+
endif()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
config WEBSOCKET_URI
10+
string "Websocket endpoint URI"
11+
default "ws://echo.websocket.events"
12+
help
13+
URL of websocket endpoint this example connects to and sends echo
14+
15+
endmenu

0 commit comments

Comments
 (0)