Skip to content

Commit

Permalink
Enable sanitizers
Browse files Browse the repository at this point in the history
  • Loading branch information
higaski committed Mar 13, 2024
1 parent 996534c commit c1c6b66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
CC: gcc-13
CXX: g++-13
- run: cmake --build build --parallel --target DCCEXProtocolTests
- run: ctest --test-dir build --schedule-random
- run: ./build/tests/DCCEXProtocolTests --gtest_shuffle
15 changes: 9 additions & 6 deletions cmake/sanitize.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
macro(sanitize SANITIZERS)
# Set in current scope
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZERS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZERS}")
set(LDFLAGS "${LDFLAGS} -fsanitize=${SANITIZERS}")

# Set in PARENT_SCOPE
get_directory_property(HAS_PARENT_SCOPE PARENT_DIRECTORY)
if(HAS_PARENT_SCOPE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fsanitize=${SANITIZERS}"
${CMAKE_C_FLAGS}
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZERS}"
${CMAKE_CXX_FLAGS}
PARENT_SCOPE)
set(LDFLAGS
"${LDFLAGS} -fsanitize=${SANITIZERS}"
${LDFLAGS}
PARENT_SCOPE)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${SANITIZERS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${SANITIZERS}")
set(LDFLAGS "${LDFLAGS} -fsanitize=${SANITIZERS}")
endmacro()
6 changes: 1 addition & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
include(GoogleTest)
include(${CMAKE_SOURCE_DIR}/cmake/sanitize.cmake)

option(SANITIZE "Enable sanitizers")

file(GLOB_RECURSE SRC *.cpp)
add_executable(DCCEXProtocolTests ${SRC})

Expand All @@ -15,9 +13,7 @@ target_sources(
target_include_directories(DCCEXProtocolTests
PUBLIC ${arduinocore-api_SOURCE_DIR}/test/include)

if(SANITIZE)
sanitize(address,undefined)
endif()
sanitize(address,leak,undefined)

target_compile_options(DCCEXProtocolTests PUBLIC -Wall -Wextra -Wconversion
-Wsign-conversion)
Expand Down
6 changes: 5 additions & 1 deletion tests/Version.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "DCCEXProtocolTest.hpp"

/*
TEST_F(DCCEXProtocolTest, version) {
_stream << "<iDCCEX V-1.2.3 / MEGA / STANDARD_MOTOR_SHIELD / 7>";
EXPECT_CALL(_delegate, receivedServerVersion(1, 2, 3)).Times(Exactly(1));
_dccexProtocol.check();
}
}
*/

0 comments on commit c1c6b66

Please sign in to comment.