Skip to content

Commit 5ac9ca7

Browse files
author
Aliaksandr Adziareika
committed
<TBBAS-2530> Add CI script installing prebuilt openDAQ, building module, running tests, and uploading reports
1 parent ab04b2b commit 5ac9ca7

File tree

8 files changed

+76
-25
lines changed

8 files changed

+76
-25
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Test example module
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- jira/*
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4
15+
16+
- name: Install dependencies
17+
run: |
18+
sudo apt-get update && sudo apt-get install -y git wget cmake ninja-build mono-complete g++ libgmock-dev
19+
wget -v https://docs.opendaq.com/download/SDK/opendaq-3.20.4-ubuntu22.04-x86_64.deb -O /tmp/opendaq.deb
20+
sudo dpkg -i /tmp/opendaq.deb || sudo apt-get install -f -y
21+
22+
- name: Configure CMake
23+
run: cmake -B build/output -S . -G Ninja -DOPENDAQ_ENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release
24+
25+
- name: Build
26+
run: cmake --build build/output --target all
27+
28+
- name: Run tests with GTest report
29+
run: |
30+
mkdir -p build/reports
31+
export GTEST_OUTPUT=xml:$(pwd)/build/reports/gtest-report.xml
32+
ctest --test-dir build/output --output-on-failure -V
33+
34+
- name: Upload test report artifact
35+
if: always()
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: gtest-report
39+
path: build/reports/gtest-report.xml

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_SERVER_APP)
3030
set(OPENDAQ_ENABLE_NATIVE_STREAMING ON CACHE BOOL "" FORCE)
3131
endif()
3232

33+
if (OPENDAQ_ENABLE_TESTS)
34+
message(STATUS "Unit tests are ENABLED")
35+
enable_testing()
36+
endif()
37+
3338
add_subdirectory(external)
3439
add_subdirectory(example_module)
3540

example_module/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if (MSVC)
3737
target_compile_options(${LIB_NAME} PRIVATE /bigobj)
3838
endif()
3939

40+
find_package(openDAQ 3.20.4 REQUIRED)
4041
target_link_libraries(${LIB_NAME} PUBLIC daq::opendaq
4142
)
4243

example_module/tests/CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,37 @@ set(TEST_SOURCES test_example_module.cpp
88
add_executable(${TEST_APP} ${TEST_SOURCES}
99
)
1010

11-
target_link_libraries(${TEST_APP} PRIVATE daq::test_utils
11+
find_package(openDAQ 3.20.4 REQUIRED)
12+
target_link_libraries(${TEST_APP} PRIVATE daq::opendaq
1213
${SDK_TARGET_NAMESPACE}::${MODULE_NAME}
1314
)
1415

16+
find_package(GTest QUIET)
17+
if (NOT GTest_FOUND)
18+
message(STATUS "GTest not found, fetching googletest with gmock...")
19+
20+
include(FetchContent)
21+
FetchContent_Declare(
22+
googletest
23+
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
24+
)
25+
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
26+
FetchContent_MakeAvailable(googletest)
27+
else()
28+
message(STATUS "GTest found, setting up googletest with gtest, gmock...")
29+
endif()
30+
31+
# Link module + gtest/gmock
32+
target_link_libraries(${TEST_APP}
33+
PRIVATE
34+
GTest::gtest
35+
GTest::gtest_main
36+
GTest::gmock
37+
GTest::gmock_main
38+
)
39+
include(GoogleTest)
40+
gtest_discover_tests(${TEST_APP})
41+
1542
add_test(NAME ${TEST_APP}
1643
COMMAND $<TARGET_FILE_NAME:${TEST_APP}>
1744
WORKING_DIRECTORY bin

example_module/tests/test_app.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
#include <testutils/testutils.h>
2-
#include <testutils/bb_memcheck_listener.h>
1+
#include <gtest/gtest.h>
32
#include <coreobjects/util.h>
4-
#include <opendaq/module_manager_init.h>
5-
#include <coretypes/stringobject_factory.h>
6-
73

84
int main(int argc, char** args)
95
{
10-
daq::daqInitializeCoreObjectsTesting();
11-
daqInitModuleManagerLibrary();
12-
136
testing::InitGoogleTest(&argc, args);
147

15-
testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners();
16-
listeners.Append(new DaqMemCheckListener());
17-
188
auto res = RUN_ALL_TESTS();
199

2010
return res;

example_module/tests/test_example_module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <example_module/version.h>
66
#include <gmock/gmock.h>
77
#include <opendaq/opendaq.h>
8-
#include <testutils/testutils.h>
8+
// #include <testutils/testutils.h>
99

1010
#include <chrono>
1111
#include <thread>

external/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
55
message(FATAL_ERROR "In-source build is not supported!")
66
endif()
77

8-
include(FetchContent)
9-
108
add_subdirectory(openDAQ)

external/openDAQ/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
set(OPENDAQ_ENABLE_TESTS false)
22

3-
FetchContent_Declare(
4-
openDAQ
5-
GIT_REPOSITORY https://github.com/openDAQ/openDAQ.git
6-
GIT_TAG v3.20.1
7-
GIT_PROGRESS ON
8-
SYSTEM
9-
FIND_PACKAGE_ARGS 3.20.1 GLOBAL
10-
)
11-
12-
FetchContent_MakeAvailable(openDAQ)
3+
find_package(openDAQ 3.20.4 REQUIRED)

0 commit comments

Comments
 (0)