Skip to content

Commit f49e319

Browse files
chore: CPP CI Unit Test Coverage Report (#345)
* chore: CI to test CPP SDK * fixup! chore: CI to test CPP SDK --------- Co-authored-by: kschrief <[email protected]>
1 parent 94b7bca commit f49e319

File tree

5 files changed

+212
-26
lines changed

5 files changed

+212
-26
lines changed

.github/workflows/cxx-build.yml

Lines changed: 123 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,31 @@ on:
1111
- opened
1212
- synchronize
1313

14+
defaults:
15+
run:
16+
shell: bash
17+
1418
env:
1519
HUSKY: 0
1620
jobs:
1721
thunder:
1822
name: Build Thunder Libraries
1923
runs-on: ubuntu-latest
2024
container:
21-
image: kevinshahfws/node-c:3.0
25+
image: node:23.3.0
2226
steps:
23-
- name: Checkout
27+
- name: Checkout firebolt-apis
2428
uses: actions/checkout@v2
2529

2630
- name: Clone and Install Thunder
27-
id: install_thunder
2831
run: |
32+
apt update
33+
apt install -y cmake ninja-build python3-pip python3.11-venv
34+
python3 -m venv firebolt-env
35+
source firebolt-env/bin/activate
36+
pip install jsonref
2937
.github/workflows/utils.sh cloneAndInstallThunder
30-
38+
3139
- name: Upload the library artifact
3240
uses: actions/upload-artifact@v3
3341
with:
@@ -36,9 +44,12 @@ jobs:
3644

3745
openrpc:
3846
name: Build Openrpc Artifacts
47+
needs: thunder
3948
runs-on: ubuntu-latest
4049
container:
41-
image: kevinshahfws/node-c:3.0
50+
image: node:23.3.0
51+
permissions:
52+
pull-requests: write
4253
steps:
4354
- name: Checkout
4455
uses: actions/checkout@v2
@@ -62,7 +73,7 @@ jobs:
6273
key: deps-node-modules-${{ hashFiles('package-lock.json') }}
6374

6475
- name: Install dependencies
65-
run: npm ci
76+
run: npm install
6677

6778
- name: Set file permissions
6879
run: |
@@ -84,19 +95,19 @@ jobs:
8495
with:
8596
name: manage
8697
path: src/sdks/manage
87-
98+
8899
- name: Upload Discovery SDK
89100
uses: actions/upload-artifact@v3
90101
with:
91102
name: discovery
92-
path: src/sdks/discovery
103+
path: src/sdks/discovery
93104

94105
core_sdk:
95106
name: Build Core SDK
96107
needs: [thunder, openrpc]
97108
runs-on: ubuntu-latest
98109
container:
99-
image: kevinshahfws/node-c:3.0
110+
image: node:23.3.0
100111
steps:
101112
- name: Checkout
102113
uses: actions/checkout@v2
@@ -107,7 +118,6 @@ jobs:
107118
name: core
108119
path: /__w/firebolt-apis/firebolt-apis/src/sdks/core
109120

110-
111121
- name: Download Thunder
112122
uses: actions/download-artifact@v3
113123
with:
@@ -121,27 +131,58 @@ jobs:
121131
key: deps-node-modules-${{ hashFiles('package-lock.json') }}
122132

123133
- name: Install npm dependencies
124-
run: npm ci
134+
run: |
135+
apt update
136+
apt install -y cmake
137+
npm install
125138
126139
- name: Generate core SDK source code
127140
run: |
128141
.github/workflows/utils.sh generate_cpp_core_sdk_source_code
129142
130-
- name: Build CXX Core SDK
143+
- name: Build CXX Core SDK
131144
run: |
145+
apt install -y python3-pip python3.11-venv
146+
python3 -m venv firebolt-env
147+
source firebolt-env/bin/activate
148+
pip install gcovr
149+
132150
.github/workflows/utils.sh build_core_cpp_sdk
133151
152+
- name: Test and Generate coverage report
153+
run: .github/workflows/utils.sh generate_core_sdk_coverage_report
154+
155+
- name: Display coverage report
156+
uses: irongut/[email protected]
157+
with:
158+
filename: coverage/coverage.cobertura.xml
159+
badge: true
160+
fail_below_min: false
161+
format: markdown
162+
hide_branch_rate: false
163+
hide_complexity: true
164+
indicators: true
165+
output: both
166+
thresholds: '80 40'
167+
168+
- name: Add coverage PR comment
169+
uses: marocchino/sticky-pull-request-comment@v2
170+
with:
171+
recreate: true
172+
path: code-coverage-results.md
173+
174+
134175
manage_sdk:
135176
name: Build Manage SDK
136177
needs: [thunder, openrpc]
137178
runs-on: ubuntu-latest
138179
container:
139-
image: kevinshahfws/node-c:3.0
180+
image: node:23.3.0
140181
steps:
141182
- name: Checkout
142183
uses: actions/checkout@v2
143184

144-
- name: Download Manage SDK
185+
- name: Download Manage SDK
145186
uses: actions/download-artifact@v3
146187
with:
147188
name: manage
@@ -160,22 +201,52 @@ jobs:
160201
key: deps-node-modules-${{ hashFiles('package-lock.json') }}
161202

162203
- name: Install npm dependencies
163-
run: npm ci
204+
run: |
205+
apt update
206+
apt install -y cmake
207+
npm install
164208
165209
- name: Generate manage SDK source code
166210
run: |
167211
.github/workflows/utils.sh generate_cpp_manage_sdk_source_code
168212
169-
- name: Build CXX manage SDK
213+
- name: Build CXX Manage SDK
170214
run: |
215+
apt install -y python3-pip python3.11-venv
216+
python3 -m venv firebolt-env
217+
source firebolt-env/bin/activate
218+
pip install gcovr
219+
171220
.github/workflows/utils.sh build_manage_cpp_sdk
172221
173-
dicovery_sdk:
222+
- name: Test and Generate coverage report
223+
run: .github/workflows/utils.sh generate_manage_sdk_coverage_report
224+
225+
- name: Display coverage report
226+
uses: irongut/[email protected]
227+
with:
228+
filename: coverage/coverage.cobertura.xml
229+
badge: true
230+
fail_below_min: false
231+
format: markdown
232+
hide_branch_rate: false
233+
hide_complexity: true
234+
indicators: true
235+
output: both
236+
thresholds: '80 40'
237+
238+
- name: Add coverage PR comment
239+
uses: marocchino/sticky-pull-request-comment@v2
240+
with:
241+
recreate: true
242+
path: code-coverage-results.md
243+
244+
discovery_sdk:
174245
name: Build Discovery SDK
175246
needs: [thunder, openrpc]
176247
runs-on: ubuntu-latest
177248
container:
178-
image: kevinshahfws/node-c:3.0
249+
image: node:23.3.0
179250
steps:
180251
- name: Checkout
181252
uses: actions/checkout@v2
@@ -199,12 +270,43 @@ jobs:
199270
key: deps-node-modules-${{ hashFiles('package-lock.json') }}
200271

201272
- name: Install npm dependencies
202-
run: npm ci
273+
run: |
274+
apt update
275+
apt install -y cmake
276+
npm install
203277
204278
- name: Generate discovery SDK source code
205279
run: |
206280
.github/workflows/utils.sh generate_cpp_discovery_sdk_source_code
207281
208-
- name: Build CXX Discovery SDK
282+
- name: Build CXX Discovery SDK
209283
run: |
210-
.github/workflows/utils.sh build_discovery_cpp_sdk
284+
apt install -y python3-pip python3.11-venv
285+
python3 -m venv firebolt-env
286+
source firebolt-env/bin/activate
287+
pip install gcovr
288+
289+
.github/workflows/utils.sh build_discovery_cpp_sdk
290+
291+
- name: Test and Generate coverage report
292+
run: .github/workflows/utils.sh generate_discovery_sdk_coverage_report
293+
294+
- name: Display coverage report
295+
uses: irongut/[email protected]
296+
with:
297+
filename: coverage/coverage.cobertura.xml
298+
badge: true
299+
fail_below_min: false
300+
format: markdown
301+
hide_branch_rate: false
302+
hide_complexity: true
303+
indicators: true
304+
output: both
305+
thresholds: '80 40'
306+
307+
- name: Add coverage PR comment
308+
uses: marocchino/sticky-pull-request-comment@v2
309+
with:
310+
recreate: true
311+
path: code-coverage-results.md
312+

.github/workflows/utils.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ function unzipArtifact(){
182182
}
183183

184184
function cloneAndInstallThunder() {
185+
printenv
186+
185187
cd ..
186188

187189
git clone https://github.com/rdkcentral/Thunder.git
@@ -269,12 +271,27 @@ function build_cpp_sdk() {
269271

270272
echo " ************ Build ${sdk_name^} CPP SDK ************"
271273

272-
cd /__w/firebolt-apis/firebolt-apis/src/sdks/${sdk_name}/build/cpp/src/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}/
274+
tar -xvf /__w/firebolt-apis/firebolt-apis/src/sdks/${sdk_name}/build/cpp/src/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}.tgz -C /__w/firebolt-apis/firebolt-apis/
275+
cd /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}
273276
chmod +x ./build.sh
274277

275278
./build.sh -s "/__w/thunder/install/" || exit 9999
276279
}
277280

281+
282+
function generate_coverage_report(){
283+
FIREBOLT_VERSION=$(node -p "require('./package.json').version")
284+
echo "The version from package.json is $FIREBOLT_VERSION"
285+
local sdk_name=$1
286+
287+
echo " ************ Generate coverage report for ${sdk_name^} CPP SDK ************"
288+
289+
cd /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}
290+
cmake --build build --target coverage
291+
292+
mv /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}/build/test/coverage /__w/firebolt-apis/firebolt-apis/
293+
}
294+
278295
# Check argument and call corresponding function
279296
case "$1" in
280297
runTests) runTests ;;
@@ -288,6 +305,9 @@ case "$1" in
288305
build_core_cpp_sdk) build_cpp_sdk "core" ;;
289306
build_manage_cpp_sdk) build_cpp_sdk "manage" ;;
290307
build_discovery_cpp_sdk) build_cpp_sdk "discovery" ;;
308+
generate_core_sdk_coverage_report) generate_coverage_report "core" ;;
309+
generate_manage_sdk_coverage_report) generate_coverage_report "manage" ;;
310+
generate_discovery_sdk_coverage_report) generate_coverage_report "discovery" ;;
291311
*)
292312
echo "Invalid function specified."
293313
exit 1

src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ if(ENABLE_UNIT_TESTS)
105105
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
106106
)
107107

108+
set_target_properties(${UNIT_TESTS_APP} PROPERTIES
109+
CXX_STANDARD 17
110+
CXX_STANDARD_REQUIRED YES
111+
)
112+
108113
include(GoogleTest)
109114
gtest_discover_tests(${UNIT_TESTS_APP})
110115
endif()
116+
117+
if(ENABLE_COVERAGE)
118+
include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake)
119+
120+
set(COVERAGE_MAIN "coverage")
121+
set(COVERAGE_EXCLUDES
122+
"${CMAKE_SOURCE_DIR}/build/*"
123+
"${CMAKE_SOURCE_DIR}/cmake/*"
124+
"${CMAKE_SOURCE_DIR}/include/*"
125+
"${CMAKE_SOURCE_DIR}/test/*"
126+
"/usr/include/*")
127+
128+
set(COVERAGE_EXTRA_FLAGS)
129+
set(COVERAGE_DEPENDENCIES ${UNIT_TESTS_APP})
130+
131+
setup_target_for_coverage_gcovr_html(
132+
NAME ${COVERAGE_MAIN}
133+
BASE_DIRECTORY ${CMAKE_SOURCE_DIR}
134+
EXECUTABLE ctest
135+
EXECUTABLE_ARGS "--test-dir ../build/ --output-on-failure"
136+
DEPENDENCIES ${COVERAGE_DEPENDENCIES}
137+
)
138+
139+
endif()

src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ target_link_libraries(${TESTAPP}
5252
PRIVATE
5353
${NAMESPACE}Core::${NAMESPACE}Core
5454
${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK
55+
nlohmann_json_schema_validator
56+
gtest_main
5557
)
5658

5759
target_include_directories(${TESTAPP}
5860
PRIVATE
59-
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/${FIREBOLT_NAMESPACE}SDK>
60-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/>
61-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
61+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
6262
)
6363

64+
if (POLYMORPHICS_REDUCER_METHODS)
65+
target_compile_definitions(${TESTAPP}
66+
PUBLIC
67+
POLYMORPHICS_REDUCER_METHODS=1)
68+
endif()
69+
6470
set_target_properties(${TESTAPP} PROPERTIES
6571
CXX_STANDARD 17
6672
CXX_STANDARD_REQUIRED YES

0 commit comments

Comments
 (0)