6207: Run C++ unit tests with sanitizers (fixes #6205) r=Chairn a=def-

<!-- What is the motivation for the changes of this pull request? -->

<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-12-30 23:28:17 +00:00 committed by GitHub
commit 21b3b3b098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 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

@ -2842,7 +2842,7 @@ int str_comp_filenames(const char *a, const char *b)
return 1;
else if(*b >= '0' && *b <= '9')
return -1;
else if(!(!result && *a && *b))
else if(result || *a == '\0' || *b == '\0')
return result;
}

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