From 3ce2674afa6f427d31e5740835da3e2b6e16475a Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Thu, 28 Mar 2024 15:51:56 -0700 Subject: [PATCH] Add sanitizer CI job --- .github/workflows/ci.yml | 12 ++++++++ CMakeLists.txt | 2 ++ devicedefender/CMakeLists.txt | 46 +++++++++++++++-------------- devicedefender/tests/CMakeLists.txt | 1 + iotdevicecommon/CMakeLists.txt | 45 ++++++++++++++-------------- 5 files changed, 62 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b0187019..fb70657fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d929a52a..24d8db064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ else() set(IN_SOURCE_BUILD OFF) endif() +include(AwsSanitizers) + aws_use_package(aws-crt-cpp) add_subdirectory(jobs) diff --git a/devicedefender/CMakeLists.txt b/devicedefender/CMakeLists.txt index 4040ca76f..ff04c3339 100644 --- a/devicedefender/CMakeLists.txt +++ b/devicedefender/CMakeLists.txt @@ -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 $<$:DEBUG_BUILD>) +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$: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 @@ -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 $ $) @@ -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) @@ -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) diff --git a/devicedefender/tests/CMakeLists.txt b/devicedefender/tests/CMakeLists.txt index 4ec1f7c32..59706fd98 100644 --- a/devicedefender/tests/CMakeLists.txt +++ b/devicedefender/tests/CMakeLists.txt @@ -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() diff --git a/iotdevicecommon/CMakeLists.txt b/iotdevicecommon/CMakeLists.txt index 05fbcb0c8..344c92003 100644 --- a/iotdevicecommon/CMakeLists.txt +++ b/iotdevicecommon/CMakeLists.txt @@ -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 $<$:DEBUG_BUILD>) +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$: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 @@ -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 $ $) @@ -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) @@ -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)