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.
This commit is contained in:
def 2022-12-30 12:32:43 +01:00
parent 2847d0f6d0
commit 6691be1d90
2 changed files with 11 additions and 7 deletions

View file

@ -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

View file

@ -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);
}