Skip to content

Commit

Permalink
Fixed issues with CanId reporting incorrect CAN IDs. (#17)
Browse files Browse the repository at this point in the history
* Refactored CanId type to be constexpr and utilise templates.
Removed unnecessary checks from constructor.
Switched to bitmasks instead of std::bitset.

Changed type `uint32_t`to `canid_t` where applicable.
Added more operator overloads.

* Restructured test directory

* Updated gitignore

* Added GTest unit tests for CanId type.

* Bumped up version

* Re-added ability to generate static library.

* Sources and headers are now added to test libraries if required.

* Added runner for tests

* Added CMakeLists for test directory.

* Updated test generators.

* Updated runners.

* Added missing gtest dependency

* Trying to fix dependencies

* Trying to get GTest to install...

* Disabled compiler warning because of unknown pragmas

* Disabled same compiler warning in unit tests
  • Loading branch information
SimonCahill authored Jun 10, 2024
1 parent f2463f9 commit 9d642e2
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 173 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake
name: Build Debug

on:
push:
Expand All @@ -8,7 +8,7 @@ on:

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

jobs:
build:
Expand Down Expand Up @@ -40,9 +40,3 @@ jobs:
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

2 changes: 1 addition & 1 deletion .github/workflows/cpack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake
name: Build and Pack

on:
push:
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/gtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Test

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

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

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

steps:
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt -y install can-utils libsocketcan-dev googletest
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- uses: actions/checkout@v3
- uses: MarkusJx/[email protected]

- 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: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

30 changes: 25 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
cmake_minimum_required(VERSION 3.23)

project(sockcanpp LANGUAGES CXX VERSION 1.0)
project(sockcanpp LANGUAGES CXX VERSION 1.1.0)

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
option(BUILD_TESTS "Build the tests" OFF)

set(CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)

add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
if (BUILD_SHARED_LIBS STREQUAL "ON")
add_library(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
else()
add_library(${PROJECT_NAME} STATIC)
endif()

###
# If BUILD_TESTS is set to ON, a static test library with the name of the project suffixed with "_test" will be created
###
if(BUILD_TESTS STREQUAL "ON")
add_library(${PROJECT_NAME}_test STATIC)
endif()

add_subdirectory(include)
add_subdirectory(src)
Expand Down Expand Up @@ -57,4 +69,12 @@ add_custom_command(
COMMENT "Generate Doxygen documentation for publication or reading"
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
)

###
# If the CMAKE_BUILD_TYPE is set to Debug, enable the tests
###
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND BUILD_TESTS STREQUAL "ON")
enable_testing()
add_subdirectory(test)
endif()
13 changes: 12 additions & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ target_sources(${PROJECT_NAME}
CanDriver.hpp
CanId.hpp
CanMessage.hpp
)
)

if (TARGET sockcanpp_test)
target_sources(sockcanpp_test
PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}
FILES
CanDriver.hpp
CanId.hpp
CanMessage.hpp
)
endif()
Loading

0 comments on commit 9d642e2

Please sign in to comment.