Skip to content

Commit

Permalink
Run unit tests on the CI server on check-in
Browse files Browse the repository at this point in the history
Also, enable running unit tests at build time for desktop builds.
To enable: cmake -DRUN_UNIT_TESTS=ON path/to/CMakeLists.txt
  • Loading branch information
DanielMcInnes committed Jul 29, 2024
1 parent 568c6a3 commit 709236d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: run unit tests on the desktop build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
QT_VERSION: 6.6.1

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout repository and submodules
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update -yq &&
sudo apt-get install -y g++ build-essential mesa-common-dev libssl-dev \
wget lsb libgl1-mesa-dev libxkbcommon-x11-0 libpulse-dev p7zip-full \
ninja-build dos2unix libegl1 libxcb-cursor0
sudo snap install yq
- name: Install Qt ${{env.QT_VERSION}} linux desktop
if: steps.cached_qt_emscripten.outputs.cache-hit != 'true'
uses: jurplel/install-qt-action@v3
with:
aqtversion: '==3.1.*'
version: "${{env.QT_VERSION}}"
host: 'linux'
target: 'desktop'
arch: 'gcc_64'
modules: 'qtwebsockets qt5compat qtshadertools'
dir: '/opt/hostedtoolcache'

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
export QTDIR=/opt/hostedtoolcache/Qt/$QT_VERSION/gcc_64
mkdir build && cd build
${QTDIR}/bin/qt-cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ../tests
- name: Build unit tests
run: |
cd build
cmake --build . --config ${{env.BUILD_TYPE}}
- name: Run unit test
run: |
cd build
# The following line needs 'QT_QPA_PLATFORM=offscreen' in order to run on the headless CI server
QT_DEBUG_PLUGINS=1 QT_QPA_PLATFORM=offscreen ctest --rerun-failed --output-on-failure
28 changes: 20 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ else()
include(GNUInstallDirs)
endif()

option(LOAD_QML_FROM_FILESYSTEM "disable filesystem loading via cmake -DLOAD_QML_FROM_FILESYSTEM=OFF" ON) # Enabled by default
option(RUN_UNIT_TESTS "only affects desktop builds. Enable via cmake -DRUN_UNIT_TESTS=ON" OFF) # Disabled by default

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(VENUS_DESKTOP_BUILD ON)
endif()
if (${VENUS_DESKTOP_BUILD})
add_compile_definitions(VENUS_DESKTOP_BUILD)
enable_testing()
endif()
add_subdirectory(tests)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -70,11 +80,6 @@ message("Building VenusOS for ${CMAKE_SYSTEM_NAME}")
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")

option(VENUS_DESKTOP_BUILD "enable desktop build via cmake -DVENUS_DESKTOP_BUILD=ON" OFF) # Disabled by default
option(VENUS_WEBASSEMBLY_BUILD "enable webassembly build via cmake -DVENUS_WEBASSEMBLY_BUILD=ON" OFF) # Disabled by default
option(MQTT_WEBSOCKETS_ENABLED "enable websockets build via cmake -DMQTT_WEBSOCKETS_ENABLED=ON" OFF) # Disabled by default
option(LOAD_QML_FROM_FILESYSTEM "disable filesystem loading via cmake -DLOAD_QML_FROM_FILESYSTEM=OFF" ON) # Enabled by default

# If we want a release build, remove the '-g' debug compiler flag set by the environment setup script.
# Otherwise, our executable size ballons from ~10MB to ~220MB.
if(("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel"))
Expand Down Expand Up @@ -1001,18 +1006,15 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
list(APPEND venusCompileFlags ${UNIX_COMPILE_FLAGS})
add_compile_definitions(VENUS_DESKTOP_BUILD)
qt_add_executable(${PROJECT_NAME}
MACOSX_BUNDLE
${SOURCES}
)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
add_compile_definitions(VENUS_DESKTOP_BUILD)
qt_add_executable(${PROJECT_NAME}
${SOURCES}
)
elseif(VENUS_DESKTOP_BUILD)
add_compile_definitions(VENUS_DESKTOP_BUILD)
qt_add_executable(${PROJECT_NAME}
${SOURCES}
)
Expand All @@ -1023,6 +1025,16 @@ else()
)
endif()

if (("${RUN_UNIT_TESTS}" STREQUAL "ON") AND ("${VENUS_DESKTOP_BUILD}" STREQUAL "ON")) # Don't run unit tests when building wasm or cerbo
add_custom_command(
TARGET ${PROJECT_NAME}
COMMENT "Run tests"
POST_BUILD
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> --output-on-failures
)
endif()

qt_add_qml_module( ${PROJECT_NAME}
URI ${PROJECT_NAME}
VERSION 1.0
Expand Down
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0048 NEW)
project(tests LANGUAGES CXX)

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
set(VENUS_DESKTOP_BUILD ON)
endif()
if (${VENUS_DESKTOP_BUILD})
add_compile_definitions(VENUS_DESKTOP_BUILD)
enable_testing()
endif()


add_subdirectory(firmwareversion)
add_subdirectory(units)
add_subdirectory(screenblanker)
Expand Down
1 change: 1 addition & 0 deletions tests/firmwareversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ target_link_libraries(tst_firmwareversion PRIVATE
Qt6::Quick
)

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
1 change: 1 addition & 0 deletions tests/screenblanker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ target_link_libraries(tst_screenblanker PRIVATE
Qt6::Quick
)

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
1 change: 1 addition & 0 deletions tests/units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ target_link_libraries(tst_units PRIVATE
Qt6::Quick
)

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

0 comments on commit 709236d

Please sign in to comment.