Skip to content

Commit 989f37f

Browse files
Merge 87217ba into 46ffb60
2 parents 46ffb60 + 87217ba commit 989f37f

File tree

6 files changed

+62
-21
lines changed

6 files changed

+62
-21
lines changed

.github/actions/build-native-binary/action.yaml

+30-9
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ runs:
4343
sudo apt-get -y update
4444
sudo apt-get -y upgrade
4545
sudo apt-get -y install autoconf binutils cmake file \
46-
gcc g++ git libtool make \
47-
build-essential libcurl4-openssl-dev \
48-
binutils-aarch64-linux-gnu gcc-9-aarch64-linux-gnu g++-9-aarch64-linux-gnu \
49-
python3 python3-pip python3-setuptools python3-wheel ninja-build python3-pip \
50-
libselinux1-dev libmount-dev libmount1 libblkid-dev
51-
pip3 install meson
46+
gcc g++ git libtool make gcovr \
47+
build-essential libcurl4-openssl-dev \
48+
binutils-aarch64-linux-gnu gcc-9-aarch64-linux-gnu g++-9-aarch64-linux-gnu \
49+
python3 python3-pip python3-setuptools python3-wheel ninja-build python3-pip \
50+
libselinux1-dev libmount-dev libmount1 libblkid-dev
51+
pip3 install meson
5252
shell: bash
5353

5454
- name: Build for ${{ inputs.arch }}
@@ -62,16 +62,37 @@ runs:
6262
-DCMAKE_TOOLCHAIN_FILE=../cmake/linux/${{ matrix.arch }}/toolchain.cmake \
6363
-DOPENSSL_ROOT_DIR=../build_${{ matrix.arch }} \
6464
-DOPENSSL_CRYPTO_LIBRARY=../build_${{ matrix.arch }}/lib/libcrypto.so \
65-
-DSUA_BUILD_NUMBER=${{ inputs.run_number }} ..
65+
-DSUA_BUILD_NUMBER=${{ inputs.run_number }} \
66+
-DSUA_BUILD_TESTS=NO \
67+
..
68+
make
69+
make install
70+
shell: bash
71+
72+
- name: Build for ${{ inputs.arch }} (with code-coverage enabled)
73+
if: ${{ inputs.arch=='amd64' }}
74+
run: |
75+
cd build_${{ inputs.arch }}
76+
cmake \
77+
-DCMAKE_INSTALL_PREFIX=../dist_${{ inputs.arch }}_testing \
78+
-DCMAKE_TOOLCHAIN_FILE=../cmake/linux/${{ matrix.arch }}/toolchain.cmake \
79+
-DOPENSSL_ROOT_DIR=../build_${{ matrix.arch }} \
80+
-DOPENSSL_CRYPTO_LIBRARY=../build_${{ matrix.arch }}/lib/libcrypto.so \
81+
-DSUA_BUILD_NUMBER=${{ inputs.run_number }} \
82+
-DSUA_BUILD_TESTS=YES \
83+
..
6684
make
6785
make install
6886
shell: bash
6987

7088
- name: Run unit tests
7189
if: ${{ inputs.arch=='amd64' }}
7290
run: |
73-
cd dist_${{ inputs.arch }}/utest
74-
./TestSDVSelfUpdateAgent
91+
cd dist_${{ inputs.arch }}_testing/utest
92+
./TestSelfUpdateAgent
93+
mkdir report
94+
gcovr --root ../.. --html --html-details --output report/coverage.html -e ../../3rdparty -e ../../utest -e ../../src/main.cpp
95+
tar -czvf ../../code-coverage.tar.gz report
7596
shell: bash
7697

7798
- name: Compress artifacts

.github/workflows/main.yaml

+11-4
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ jobs:
9090
arch: ${{ matrix.arch }}
9191
run_number: ${{ github.run_number }}
9292

93-
- name: Upload ${{ matrix.arch }} artifact to workspace
93+
- name: Upload ${{ matrix.arch }} artifacts to workspace
9494
uses: actions/upload-artifact@v3
9595
with:
96-
name: self-update-agent-${{ matrix.arch }}-build-${{ github.run_number }}.tar.gz
9796
path: self-update-agent-${{ matrix.arch }}-build-${{ github.run_number }}.tar.gz
9897

98+
- name: Upload code coverage results to workspace
99+
if: ${{ matrix.arch == 'amd64' }}
100+
uses: actions/upload-artifact@v3
101+
with:
102+
path: code-coverage.tar.gz
103+
99104
upload-native-binary:
100105
runs-on: ubuntu-latest
101106
needs: build-native-binary
@@ -115,5 +120,7 @@ jobs:
115120
prerelease: true
116121
automatic_release_tag: build_${{ github.run_number }}
117122
title: "Build ${{ github.run_number }}"
118-
files: "**/self-update-agent-*-build-${{ github.run_number }}.tar.gz"
119-
123+
files: |
124+
./artifact/code-coverage.tar.gz
125+
./artifact/self-update-agent-amd64-build-${{ github.run_number }}.tar.gz
126+
./artifact/self-update-agent-arm64-build-${{ github.run_number }}.tar.gz

3rdparty/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ set(BUILD_SHARED_LIBS ON)
2222
set(BUILD_CURL_EXE OFF)
2323
add_subdirectory(curl)
2424

25-
if(SDV_SUA_BUILD_TESTS)
25+
if(SUA_BUILD_TESTS)
2626
add_subdirectory(googletest)
27-
endif()
27+
endif()

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ set(CMAKE_SKIP_BUILD_RPATH TRUE)
77
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
88
set(CMAKE_INSTALL_RPATH ../lib)
99

10-
set(SDV_SUA_BUILD_TESTS TRUE)
10+
option(SUA_BUILD_TESTS "Build unit tests with code-coverage report enabled" OFF)
1111

1212
include(cmake/dependencies.cmake)
1313

1414
add_subdirectory(3rdparty)
1515
add_subdirectory(src)
1616

17-
if(SDV_SUA_BUILD_TESTS)
17+
if(SUA_BUILD_TESTS)
1818
add_subdirectory(utest)
1919
endif()
20+
21+
unset(SUA_BUILD_TESTS CACHE)

src/CMakeLists.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ if(NOT DEFINED SUA_BUILD_NUMBER)
1010
set(SUA_BUILD_NUMBER "local")
1111
endif()
1212

13+
if(SUA_BUILD_TESTS)
14+
add_compile_options(
15+
-fprofile-arcs
16+
-ftest-coverage
17+
-fPIC
18+
)
19+
endif()
20+
1321
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/version.h @ONLY)
1422

1523
include_directories(
@@ -56,6 +64,10 @@ target_link_libraries(${PROJECT_NAME}
5664
sua
5765
)
5866

67+
if(SUA_BUILD_TESTS)
68+
target_link_libraries(sua gcov)
69+
endif()
70+
5971
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
6072
install(TARGETS sua LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
6173

@@ -65,4 +77,3 @@ install(
6577
${CMAKE_BINARY_DIR}/lib/libcrypto.so.3
6678
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
6779
)
68-

utest/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_executable(TestSDVSelfUpdateAgent
1+
add_executable(TestSelfUpdateAgent
22
TestDispatcher.cpp
33
TestFSM.cpp
44
TestMqttMessagingProtocolYAML.cpp
@@ -12,7 +12,7 @@ include_directories(
1212
)
1313

1414
target_link_libraries(
15-
TestSDVSelfUpdateAgent
15+
TestSelfUpdateAgent
1616
sua
1717
curl_lib
1818
paho-mqttpp3
@@ -31,4 +31,4 @@ target_link_libraries(
3131
gmock
3232
)
3333

34-
install(TARGETS TestSDVSelfUpdateAgent RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/utest)
34+
install(TARGETS TestSelfUpdateAgent RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/utest)

0 commit comments

Comments
 (0)