From 6691be1d900f413202908ed5e14ba715309788be Mon Sep 17 00:00:00 2001 From: def Date: Fri, 30 Dec 2022 12:32:43 +0100 Subject: [PATCH] Run unit tests with sanitizers (fixes #6205) Also fix memory leak in Net.Ipv4AndIpv6Work Rust tests fail to link when building in san directory, works in source directory. --- .github/workflows/clang-sanitizer.yml | 15 ++++++++------- src/test/net.cpp | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/clang-sanitizer.yml b/.github/workflows/clang-sanitizer.yml index f6359f02f..840afbc40 100644 --- a/.github/workflows/clang-sanitizer.yml +++ b/.github/workflows/clang-sanitizer.yml @@ -23,20 +23,17 @@ jobs: sudo apt-get install pkg-config cmake ninja-build libfreetype6-dev libnotify-dev libsdl2-dev libsqlite3-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libx264-dev libvulkan-dev glslang-tools spirv-tools -y - name: Build with ASan and UBSan run: | - mkdir san - cd san export CC=clang export CXX=clang++ export CXXFLAGS="-fsanitize=address,undefined -fsanitize-recover=address,undefined -fno-omit-frame-pointer" export CFLAGS="-fsanitize=address,undefined -fsanitize-recover=address,undefined -fno-omit-frame-pointer" - cmake -DCMAKE_BUILD_TYPE=Debug -DHEADLESS_CLIENT=ON .. + cmake -DCMAKE_BUILD_TYPE=Debug -DHEADLESS_CLIENT=ON -Werror=dev -DDOWNLOAD_GTEST=ON -DDEV=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. . make -j"$(nproc)" - name: Run server and headless client with ASan and UBSan run: | - cd san - export UBSAN_OPTIONS=suppressions=../ubsan.supp:log_path=./SAN:print_stacktrace=1:halt_on_errors=0 + export UBSAN_OPTIONS=suppressions=./ubsan.supp:log_path=./SAN:print_stacktrace=1:halt_on_errors=0 export ASAN_OPTIONS=log_path=./SAN:print_stacktrace=1:check_initialization_order=1:detect_leaks=1:halt_on_errors=0 - export LSAN_OPTIONS=suppressions=../lsan.supp + export LSAN_OPTIONS=suppressions=./lsan.supp ./DDNet "cl_download_skins 0;quit" || true ./DDNet-Server shutdown || true if test -n "$(find . -maxdepth 1 -name 'SAN.*' -print -quit)" @@ -44,7 +41,11 @@ jobs: cat ./SAN.* exit 1 fi + - name: Run unit tests with ASan and UBSan + run: | + export UBSAN_OPTIONS=suppressions=./ubsan.supp:log_path=./SAN:print_stacktrace=1:halt_on_errors=0 + cmake --build . --config Debug --target run_cxx_tests + # Rust tests work locally, but still not in CI, even with the same directory - name: Run integration tests with ASan and UBSan run: | - cd san make run_integration_tests diff --git a/src/test/net.cpp b/src/test/net.cpp index d4d3b751a..7ffc2efc5 100644 --- a/src/test/net.cpp +++ b/src/test/net.cpp @@ -44,4 +44,7 @@ TEST(Net, Ipv4AndIpv6Work) Addr.port = 0; EXPECT_EQ(Addr, LocalhostV6); EXPECT_EQ(mem_comp(pData, "def", 3), 0); + + net_udp_close(Socket1); + net_udp_close(Socket2); }