Skip to content

Commit

Permalink
Add sanitizer CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Mar 28, 2024
1 parent 25ddf5e commit 3ce2674
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 44 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,15 @@ jobs:
- name: Check for edits to code-generated files
run: |
./utils/check_codegen_edits.py
clang-sanitizers:
runs-on: ubuntu-22.04 # latest
strategy:
matrix:
sanitizers: ["thread", "address,undefined"]
steps:
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ env.LINUX_BASE_IMAGE }} build -p ${{ env.PACKAGE_NAME }} --compiler=clang-12 --cmake-extra=-DENABLE_SANITIZERS=ON --cmake-extra=-DSANITIZERS="${{ matrix.sanitizers }}"
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ else()
set(IN_SOURCE_BUILD OFF)
endif()

include(AwsSanitizers)

aws_use_package(aws-crt-cpp)

add_subdirectory(jobs)
Expand Down
46 changes: 24 additions & 22 deletions devicedefender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ if (WIN32)
endif ()
endif()

add_library(IotDeviceDefender-cpp ${AWS_IOTDEVICEDEFENDER_CPP_SRC})
add_library(${PROJECT_NAME} ${AWS_IOTDEVICEDEFENDER_CPP_SRC})

set_target_properties(IotDeviceDefender-cpp PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

set(CMAKE_C_FLAGS_DEBUGOPT "")

#set warnings
if (MSVC)
target_compile_options(IotDeviceDefender-cpp PRIVATE /W4 /WX)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
else ()
target_compile_options(IotDeviceDefender-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

target_compile_definitions(IotDeviceDefender-cpp PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)

if (BUILD_SHARED_LIBS)
target_compile_definitions(IotDeviceDefender-cpp PUBLIC "-DAWS_IOTDEVICEDEFENDER_USE_IMPORT_EXPORT")
target_compile_definitions(IotDeviceDefender-cpp PRIVATE "-DAWS_IOTDEVICEDEFENDER_EXPORTS")
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_IOTDEVICEDEFENDER_USE_IMPORT_EXPORT")
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DAWS_IOTDEVICEDEFENDER_EXPORTS")

install(TARGETS IotDeviceDefender-cpp
EXPORT IotDeviceDefender-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development
Expand All @@ -77,20 +77,20 @@ if (BUILD_SHARED_LIBS)
DESTINATION ${RUNTIME_DIRECTORY}
COMPONENT Runtime)

install(TARGETS IotDeviceDefender-cpp
EXPORT IotDeviceDefender-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development)
else()
install(TARGETS IotDeviceDefender-cpp
EXPORT IotDeviceDefender-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development)
endif()

target_include_directories(IotDeviceDefender-cpp PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand All @@ -101,7 +101,9 @@ if (BUILD_DEPS)
endif()
endif()

target_link_libraries(IotDeviceDefender-cpp IotDeviceCommon-cpp)
aws_add_sanitizers(${PROJECT_NAME})

target_link_libraries(${PROJECT_NAME} IotDeviceCommon-cpp)

install(FILES ${AWS_IOTDEVICEDEFENDER_HEADERS} DESTINATION "include/aws/iotdevicedefender/" COMPONENT Development)

Expand All @@ -114,22 +116,22 @@ endif()
include(CMakePackageConfigHelpers)
if (DEFINED SIMPLE_VERSION)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/iotdevicedefender-cpp-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
endif()

install(EXPORT "IotDeviceDefender-cpp-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/IotDeviceDefender-cpp/cmake/${TARGET_DIR}"
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)

configure_file("cmake/iotdevicedefender-cpp-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/iotdevicedefender-cpp-config.cmake"
configure_file("cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iotdevicedefender-cpp-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/IotDeviceDefender-cpp/cmake/"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
COMPONENT Development)

if (BUILD_TESTING)
Expand Down
1 change: 1 addition & 0 deletions devicedefender/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ if (UNIX AND NOT APPLE)
add_net_test_case(Mqtt5DeviceDefenderCustomMetricSuccess)
add_net_test_case(Mqtt5DeviceDefenderCustomMetricFail)
generate_cpp_test_driver(${TEST_BINARY_NAME})
aws_add_sanitizers(${TEST_BINARY_NAME})
endif()
45 changes: 23 additions & 22 deletions iotdevicecommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ endif()

aws_use_package(aws-c-iot)

add_library(IotDeviceCommon-cpp ${AWS_IOTDEVICECOMMON_CPP_SRC})
add_library(${PROJECT_NAME} ${AWS_IOTDEVICECOMMON_CPP_SRC})

set_target_properties(IotDeviceCommon-cpp PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

set(CMAKE_C_FLAGS_DEBUGOPT "")

#set warnings
if (MSVC)
target_compile_options(IotDeviceCommon-cpp PRIVATE /W4 /WX)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
else ()
target_compile_options(IotDeviceCommon-cpp PRIVATE -Wall -Wno-long-long -pedantic -Werror)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

target_compile_definitions(IotDeviceCommon-cpp PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG_BUILD>)

if (BUILD_SHARED_LIBS)
target_compile_definitions(IotDeviceCommon-cpp PUBLIC "-DAWS_IOTDEVICECOMMON_USE_IMPORT_EXPORT")
target_compile_definitions(IotDeviceCommon-cpp PRIVATE "-DAWS_IOTDEVICECOMMON_EXPORTS")
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_IOTDEVICECOMMON_USE_IMPORT_EXPORT")
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DAWS_IOTDEVICECOMMON_EXPORTS")

install(TARGETS IotDeviceCommon-cpp
EXPORT IotDeviceCommon-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development
Expand All @@ -78,20 +78,20 @@ if (BUILD_SHARED_LIBS)
DESTINATION ${RUNTIME_DIRECTORY}
COMPONENT Runtime)

install(TARGETS IotDeviceCommon-cpp
EXPORT IotDeviceCommon-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development)
else()
install(TARGETS IotDeviceCommon-cpp
EXPORT IotDeviceCommon-cpp-targets
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development)
endif()

target_include_directories(IotDeviceCommon-cpp PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand All @@ -102,7 +102,8 @@ if (BUILD_DEPS)
aws_use_package(aws-c-iot)
endif()

target_link_libraries(IotDeviceCommon-cpp ${DEP_AWS_LIBS})
aws_add_sanitizers(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} ${DEP_AWS_LIBS})

install(FILES ${AWS_IOTDEVICECOMMON_HEADERS} DESTINATION "include/aws/iotdevicecommon/" COMPONENT Development)

Expand All @@ -115,20 +116,20 @@ endif()
include(CMakePackageConfigHelpers)
if (DEFINED SIMPLE_VERSION)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/iotdevicecommon-cpp-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
endif()

install(EXPORT "IotDeviceCommon-cpp-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/IotDeviceCommon-cpp/cmake/${TARGET_DIR}"
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)

configure_file("cmake/iotdevicecommon-cpp-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/iotdevicecommon-cpp-config.cmake"
configure_file("cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/iotdevicecommon-cpp-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/IotDeviceCommon-cpp/cmake/"
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/"
COMPONENT Development)

0 comments on commit 3ce2674

Please sign in to comment.