From 4d9bda0cc2b3b016a854c831985232ac4389a8c1 Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Thu, 13 Oct 2022 19:17:14 +0200 Subject: [PATCH 01/14] CMake code to run ASAN Address Sanitizer --- CMakeLists.txt | 4 +++- windows/CMakeLists.txt | 5 +++++ windows/test/CMakeLists.txt | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c72b315a7..9186a5298 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,10 @@ endif() if(WIN32) # so far only Windows has tests + set(EnableAsanDump ${IS_DEBUG_BUILD}) option(HIDAPI_WITH_TESTS "Build HIDAPI (unit-)tests" ${IS_DEBUG_BUILD}) -else() +else() + set(EnableAsanDump OFF) set(HIDAPI_WITH_TESTS OFF) endif() diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 52d164e73..356f11ff8 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -10,6 +10,11 @@ set(SOURCES hidapi_hidsdi.h ) +if(EnableAsanDump) + # Option /MTd needed to embedd ASAN library + add_compile_options(-fsanitize=address /MTd) +endif() + if(BUILD_SHARED_LIBS) list(APPEND SOURCES hidapi.rc) endif() diff --git a/windows/test/CMakeLists.txt b/windows/test/CMakeLists.txt index 4c9da4543..49b59edda 100644 --- a/windows/test/CMakeLists.txt +++ b/windows/test/CMakeLists.txt @@ -55,4 +55,7 @@ foreach(TEST_CASE ${HID_DESCRIPTOR_RECONSTRUCT_TEST_CASES}) COMMAND hid_report_reconstructor_test "${TEST_PP_DATA}" "${TEST_EXPECTED_DESCRIPTOR}" WORKING_DIRECTORY "$" ) + if(EnableAsanDump) + set_property(TEST "WinHidReportReconstructTest_${TEST_CASE}" PROPERTY ENVIRONMENT "ASAN_SAVE_DUMPS=AsanDump_${TEST_CASE}.dmp") + endif() endforeach() From c244e55c253582a862bf33a637e03bd5b1cf4894 Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Thu, 13 Oct 2022 20:11:56 +0200 Subject: [PATCH 02/14] Renamed option to HIDAPI_ENABLE_ASAN and made it a real option HIDAPI_ENABLE_ASAN is no set platform independent --- CMakeLists.txt | 10 +++++++--- windows/CMakeLists.txt | 4 ++-- windows/test/CMakeLists.txt | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9186a5298..b5003de7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,12 +54,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(IS_DEBUG_BUILD ON) endif() +option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" ON) + +if(HIDAPI_ENABLE_ASAN) + add_compile_options(-fsanitize=address) +endif() + if(WIN32) # so far only Windows has tests - set(EnableAsanDump ${IS_DEBUG_BUILD}) option(HIDAPI_WITH_TESTS "Build HIDAPI (unit-)tests" ${IS_DEBUG_BUILD}) -else() - set(EnableAsanDump OFF) +else() set(HIDAPI_WITH_TESTS OFF) endif() diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 356f11ff8..7fa9434a7 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -10,9 +10,9 @@ set(SOURCES hidapi_hidsdi.h ) -if(EnableAsanDump) +if(HIDAPI_ENABLE_ASAN) # Option /MTd needed to embedd ASAN library - add_compile_options(-fsanitize=address /MTd) + add_compile_options(/MTd) endif() if(BUILD_SHARED_LIBS) diff --git a/windows/test/CMakeLists.txt b/windows/test/CMakeLists.txt index 49b59edda..28f772b0f 100644 --- a/windows/test/CMakeLists.txt +++ b/windows/test/CMakeLists.txt @@ -55,7 +55,7 @@ foreach(TEST_CASE ${HID_DESCRIPTOR_RECONSTRUCT_TEST_CASES}) COMMAND hid_report_reconstructor_test "${TEST_PP_DATA}" "${TEST_EXPECTED_DESCRIPTOR}" WORKING_DIRECTORY "$" ) - if(EnableAsanDump) + if(HIDAPI_ENABLE_ASAN) set_property(TEST "WinHidReportReconstructTest_${TEST_CASE}" PROPERTY ENVIRONMENT "ASAN_SAVE_DUMPS=AsanDump_${TEST_CASE}.dmp") endif() endforeach() From ff59f58b83fb03fd99c453d0ba2d0593d5c457e8 Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Fri, 14 Oct 2022 21:26:57 +0200 Subject: [PATCH 03/14] Enable only for Windows CI builds --- .github/workflows/builds.yml | 6 +++--- CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 0ee78bd91..f3445ba9f 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -124,7 +124,7 @@ jobs: - name: Configure CMake MSVC shell: cmd run: | - cmake -B build\msvc -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" + cmake -B build\msvc -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake MSVC working-directory: build/msvc run: cmake --build . --config RelWithDebInfo --target install @@ -144,7 +144,7 @@ jobs: shell: cmd run: | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" + cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake NMake working-directory: build\nmake shell: cmd @@ -166,7 +166,7 @@ jobs: - name: Configure CMake MinGW shell: cmd run: | - cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" + cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" - name: Build CMake MinGW working-directory: build\mingw run: cmake --build . --target install diff --git a/CMakeLists.txt b/CMakeLists.txt index b5003de7b..95ef6eb37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(IS_DEBUG_BUILD ON) endif() -option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" ON) +option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" OFF) if(HIDAPI_ENABLE_ASAN) add_compile_options(-fsanitize=address) From 6cde962d75bf83a8e69c376980561887c6ab87d5 Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Fri, 14 Oct 2022 21:47:02 +0200 Subject: [PATCH 04/14] Enable ASAN only for Debug builds, otherwise it fails with: D:\a\hidapi\hidapi\hidapisrc\windows\hid.c : error C2220: the following warning is treated as an error D:\a\hidapi\hidapi\hidapisrc\windows\hid.c : warning C5072: ASAN enabled without debug information emission. Enable debug info for better ASAN error reporting --- CMakeLists.txt | 2 +- windows/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95ef6eb37..13f94c955 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ endif() option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" OFF) -if(HIDAPI_ENABLE_ASAN) +if((HIDAPI_ENABLE_ASAN) AND (${IS_DEBUG_BUILD})) add_compile_options(-fsanitize=address) endif() diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 7fa9434a7..7df14cdb7 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -10,7 +10,7 @@ set(SOURCES hidapi_hidsdi.h ) -if(HIDAPI_ENABLE_ASAN) +if((HIDAPI_ENABLE_ASAN) AND (${IS_DEBUG_BUILD})) # Option /MTd needed to embedd ASAN library add_compile_options(/MTd) endif() From 35ac6c7c907c7f0994ad8f524d6890a87c80ba92 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Tue, 7 Feb 2023 22:21:23 +0200 Subject: [PATCH 05/14] simplify ASAN integration --- CMakeLists.txt | 6 ++++-- windows/CMakeLists.txt | 5 ----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43ae9642b..0b857cabc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,10 @@ endif() option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentation" OFF) -if((HIDAPI_ENABLE_ASAN) AND (${IS_DEBUG_BUILD})) - add_compile_options(-fsanitize=address) +if(HIDAPI_ENABLE_ASAN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") endif() if(WIN32) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 8039ccb62..efc282715 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -10,11 +10,6 @@ set(SOURCES hidapi_hidsdi.h ) -if((HIDAPI_ENABLE_ASAN) AND (${IS_DEBUG_BUILD})) - # Option /MTd needed to embedd ASAN library - add_compile_options(/MTd) -endif() - if(BUILD_SHARED_LIBS) list(APPEND SOURCES hidapi.rc) endif() From 279465dd6c64d7637d79246b2b6266fdf466af50 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Tue, 7 Feb 2023 22:35:21 +0200 Subject: [PATCH 06/14] ASAN MSVC runtime --- .github/workflows/builds.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 9cf2b9c5c..b2b01c633 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -197,8 +197,11 @@ jobs: cd build\msvc_test cmake --build . --target install - name: Run CTest MSVC + shell: cmd working-directory: build/msvc - run: ctest -C RelWithDebInfo --output-on-failure + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" + ctest -C RelWithDebInfo --output-on-failure - name: Configure CMake NMake shell: cmd @@ -233,8 +236,11 @@ jobs: cd build\nmake_test nmake install - name: Run CTest NMake + shell: cmd working-directory: build\nmake - run: ctest --output-on-failure + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" + ctest --output-on-failure - name: Configure CMake MinGW shell: cmd From 4e9a8035ceed7d6c6e6c5cb555d97582e67e9fbf Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Tue, 7 Feb 2023 22:41:47 +0200 Subject: [PATCH 07/14] CMAKE_BUILD_TYPE=RelWithDebInfo --- .github/workflows/builds.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index b2b01c633..fbc6c166d 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -42,9 +42,9 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/static -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/framework -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install @@ -110,8 +110,8 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/static -S hidapisrc -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install @@ -173,7 +173,7 @@ jobs: - name: Configure CMake MSVC shell: cmd run: | - cmake -B build\msvc -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" + cmake -B build\msvc -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\msvc -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake MSVC working-directory: build/msvc run: cmake --build . --config RelWithDebInfo --target install @@ -207,7 +207,7 @@ jobs: shell: cmd run: | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" + cmake -G"NMake Makefiles" -B build\nmake -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\nmake -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%MSVC_COMPILE_FLAGS%" - name: Build CMake NMake working-directory: build\nmake shell: cmd @@ -245,7 +245,7 @@ jobs: - name: Configure CMake MinGW shell: cmd run: | - cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" + cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" - name: Build CMake MinGW working-directory: build\mingw run: cmake --build . --target install From ab20ae06eb9b8c090ecdd9c653e3332f8bd7639b Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Tue, 7 Feb 2023 22:49:17 +0200 Subject: [PATCH 08/14] AddressSanitizer does not appear to be available for mingw-w64-x86_64-gcc https://github.com/msys2/MINGW-packages/issues/3163 --- .github/workflows/builds.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index fbc6c166d..1460cc279 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -245,7 +245,7 @@ jobs: - name: Configure CMake MinGW shell: cmd run: | - cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" + cmake -G"MinGW Makefiles" -B build\mingw -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DCMAKE_INSTALL_PREFIX=install\mingw -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=%NIX_COMPILE_FLAGS%" - name: Build CMake MinGW working-directory: build\mingw run: cmake --build . --target install From 01b6344864fd59a3da90827329129b406b6ecfd3 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Wed, 8 Feb 2023 12:53:06 +0200 Subject: [PATCH 09/14] Fix ASAN env for ctest+MSVC --- .github/workflows/builds.yml | 11 +++-------- windows/test/CMakeLists.txt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 1460cc279..040156fc5 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -199,9 +199,7 @@ jobs: - name: Run CTest MSVC shell: cmd working-directory: build/msvc - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - ctest -C RelWithDebInfo --output-on-failure + run: ctest -C RelWithDebInfo --rerun-failed --output-on-failure - name: Configure CMake NMake shell: cmd @@ -236,11 +234,8 @@ jobs: cd build\nmake_test nmake install - name: Run CTest NMake - shell: cmd working-directory: build\nmake - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - ctest --output-on-failure + run: ctest --rerun-failed --output-on-failure - name: Configure CMake MinGW shell: cmd @@ -271,7 +266,7 @@ jobs: cmake --build . --target install - name: Run CTest MinGW working-directory: build\mingw - run: ctest --output-on-failure + run: ctest --rerun-failed --output-on-failure - name: Check Meson build shell: cmd diff --git a/windows/test/CMakeLists.txt b/windows/test/CMakeLists.txt index 28f772b0f..3d3c2be9a 100644 --- a/windows/test/CMakeLists.txt +++ b/windows/test/CMakeLists.txt @@ -41,6 +41,14 @@ set(HID_DESCRIPTOR_RECONSTRUCT_TEST_CASES 047F_C056_0005_000B ) +set(CMAKE_VERSION_SUPPORTS_ENVIRONMENT_MODIFICATION "3.22") + +if(HIDAPI_ENABLE_ASAN AND MSVC) + if(CMAKE_VERSION VERSION_LESS CMAKE_VERSION_SUPPORTS_ENVIRONMENT_MODIFICATION) + message("CTest/ASAN: Make sure to run ctest from MSVC Command Prompt") + endif() +endif() + foreach(TEST_CASE ${HID_DESCRIPTOR_RECONSTRUCT_TEST_CASES}) set(TEST_PP_DATA "${CMAKE_CURRENT_LIST_DIR}/data/${TEST_CASE}.pp_data") if(NOT EXISTS "${TEST_PP_DATA}") @@ -56,6 +64,12 @@ foreach(TEST_CASE ${HID_DESCRIPTOR_RECONSTRUCT_TEST_CASES}) WORKING_DIRECTORY "$" ) if(HIDAPI_ENABLE_ASAN) + if(MSVC) + if(NOT CMAKE_VERSION VERSION_LESS CMAKE_VERSION_SUPPORTS_ENVIRONMENT_MODIFICATION) + get_filename_component(MSVC_BUILD_TOOLS_DIR "${CMAKE_LINKER}" DIRECTORY) + set_property(TEST "WinHidReportReconstructTest_${TEST_CASE}" PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_append:${MSVC_BUILD_TOOLS_DIR}") + endif() + endif() set_property(TEST "WinHidReportReconstructTest_${TEST_CASE}" PROPERTY ENVIRONMENT "ASAN_SAVE_DUMPS=AsanDump_${TEST_CASE}.dmp") endif() endforeach() From 550559065f9b5bfc4e954b648ccddde44124cecf Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Wed, 8 Feb 2023 22:20:47 +0200 Subject: [PATCH 10/14] Make MSVC linker happy --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b857cabc..9f247afba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,10 @@ option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentat if(HIDAPI_ENABLE_ASAN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") + if(NOT MSVC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") + endif() endif() if(WIN32) From 447bc4c71dc8ccc61def53f711f7600993a41b9b Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Sun, 19 Feb 2023 16:17:46 +0200 Subject: [PATCH 11/14] deal with incremental linking warning --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f247afba..30b084cd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,14 @@ option(HIDAPI_ENABLE_ASAN "Build HIDAPI with ASAN address sanitizer instrumentat if(HIDAPI_ENABLE_ASAN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") - if(NOT MSVC) + if(MSVC) + # the default is to have "/INCREMENTAL" which causes a warning when "-fsanitize=address" is present + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO") + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO") + set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO") + set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO") + else() + # MSVC doesn't recognize those options, other compilers - requiring it set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") endif() From 60123b2c8f8ddad0e7af059f19fbf60bc5561205 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Sun, 19 Feb 2023 16:44:19 +0200 Subject: [PATCH 12/14] more CI with ASAN --- .github/workflows/builds.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 040156fc5..fc4ee1620 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -42,9 +42,9 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/framework -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/framework -DCMAKE_FRAMEWORK=ON -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install @@ -110,8 +110,8 @@ jobs: - name: Configure CMake run: | rm -rf build install - cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/shared -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/shared -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" + cmake -B build/static -S hidapisrc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_ENABLE_ASAN=ON -DCMAKE_INSTALL_PREFIX=install/static -DBUILD_SHARED_LIBS=FALSE -DHIDAPI_BUILD_HIDTEST=ON "-DCMAKE_C_FLAGS=${NIX_COMPILE_FLAGS}" - name: Build CMake Shared working-directory: build/shared run: make install From bddbf48c8d1c87d3b1d8c1d981c36d8077b07449 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Sun, 19 Feb 2023 17:15:50 +0200 Subject: [PATCH 13/14] workaround for external dependency on ASAN --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30b084cd7..13f390f4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,3 +92,18 @@ option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${IS_ if(HIDAPI_BUILD_HIDTEST) add_subdirectory(hidtest) endif() + +if(HIDAPI_ENABLE_ASAN) + if(NOT MSVC) + # MSVC doesn't recognize those options, other compilers - requiring it + foreach(HIDAPI_TARGET hidapi_winapi hidapi_darwin hidapi_hidraw hidapi_libusb hidtest_hidraw hidtest_libusb hidtest) + if(TARGET ${HIDAPI_TARGET}) + if(BUILD_SHARED_LIBS) + target_link_options(${HIDAPI_TARGET} PRIVATE -fsanitize=address) + else() + target_link_options(${HIDAPI_TARGET} PUBLIC -fsanitize=address) + endif() + endif() + endforeach() + endif() +endif() From 07578470d452c76ad8c98275828320d293080854 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Sun, 19 Feb 2023 17:46:25 +0200 Subject: [PATCH 14/14] cleanup --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13f390f4e..7d747a8a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,10 +64,6 @@ if(HIDAPI_ENABLE_ASAN) set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO") set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO") set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO") - else() - # MSVC doesn't recognize those options, other compilers - requiring it - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") endif() endif()