Skip to content

Commit

Permalink
Improve sanitizer support, extended CIs in order to support multiple …
Browse files Browse the repository at this point in the history
…sanitizer combinations.
  • Loading branch information
viferga committed Jun 28, 2023
1 parent f235c6b commit 3f82218
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Fixes #(issue_no)
- [ ] I have added tests/screenshots (if any) that prove my fix is effective or that my feature works.
- [ ] I have tested the tests implicated (if any) by my own code and they pass (`make test` or `ctest -VV -R <test-name>`).
- [ ] If my change is significant or breaking, I have passed all tests with `./docker-compose.sh test &> output` and attached the output.
- [ ] I have tested my code with `OPTION_BUILD_SANITIZER` or `./docker-compose.sh test-sanitizer &> output` and `OPTION_TEST_MEMORYCHECK`.
- [ ] I have tested my code with `OPTION_BUILD_ADDRESS_SANITIZER` or `./docker-compose.sh test-address-sanitizer &> output` and `OPTION_TEST_MEMORYCHECK`.
- [ ] I have tested my code with `OPTION_BUILD_THREAD_SANITIZER` or `./docker-compose.sh test-thread-sanitizer &> output`.
- [ ] I have tested with `Helgrind` in case my code works with threading.
- [ ] I have run `make clang-format` in order to format my code and my code follows the style guidelines.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Note: This is duplicated from thread-sanitizer.yml in order to keep the ci running if one of both sanitizers fail
name: Sanitizer Test
name: Address Sanitizer Test

on:
workflow_dispatch:
Expand All @@ -16,12 +16,12 @@ concurrency:
cancel-in-progress: true

jobs:
linux-sanitizer-gcc:
name: Linux GCC Sanitizer Test
linux-address-sanitizer-gcc:
name: Linux GCC Address Sanitizer Test
runs-on: ubuntu-latest
strategy:
matrix:
build_image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"]
image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"]
env:
SANITIZER_SKIP_SUMMARY: 1

Expand All @@ -32,6 +32,6 @@ jobs:
fetch-depth: 0

- name: Install, build and run sanitizer tests
run: ./docker-compose.sh test-sanitizer
run: ./docker-compose.sh test-address-sanitizer
env:
METACALL_BASE_IMAGE: ${{ matrix.build_image }}
METACALL_BASE_IMAGE: ${{ matrix.image }}
8 changes: 4 additions & 4 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [debug, release]
build_image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"] # TODO: "alpine:3.17"
build: [ debug, release ]
image: [ "debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic" ] # TODO: "alpine:3.17"

env:
DEBIAN_FRONTEND: noninteractive
Expand All @@ -38,5 +38,5 @@ jobs:
- name: Install, build and run tests
run: ./docker-compose.sh test
env:
METACALL_BUILD_TYPE: ${{ matrix.build_type }}
METACALL_BASE_IMAGE: ${{ matrix.build_image }}
METACALL_BUILD_TYPE: ${{ matrix.build }}
METACALL_BASE_IMAGE: ${{ matrix.image }}
14 changes: 10 additions & 4 deletions .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ jobs:
runs-on: macos-latest

strategy:
matrix:
buildtype: [debug] # TODO: [debug, release]
matrix: [
{ build: debug, sanitizer: without-sanitizer },
{ build: debug, sanitizer: address-sanitizer },
{ build: debug, sanitizer: thread-sanitizer },
{ build: debug, sanitizer: memory-sanitizer },
{ build: debug, sanitizer: ub-sanitizer },
{ build: release, sanitizer: without-sanitizer }
]

env:
LTTNG_UST_REGISTER_TIMEOUT: 0
Expand Down Expand Up @@ -56,7 +62,7 @@ jobs:
cd build
bash ../tools/metacall-configure.sh $METACALL_CONFIGURE_OPTIONS
env:
METACALL_CONFIGURE_OPTIONS: ${{ matrix.buildtype }} scripts ports tests sanitizer python nodejs typescript java ruby wasm rpc file cobol # netcore5 c rust examples install pack benchmarks # v8 coverage
METACALL_CONFIGURE_OPTIONS: ${{ matrix.option.build }} ${{ matrix.option.sanitizer }} scripts ports tests sanitizer python nodejs typescript java ruby wasm rpc file cobol # netcore5 c rust examples install pack benchmarks # v8 coverage

- name: Build
working-directory: ./build
Expand All @@ -65,4 +71,4 @@ jobs:
cmake -DOPTION_FORK_SAFE=OFF ..
bash ../tools/metacall-build.sh $METACALL_BUILD_OPTIONS
env:
METACALL_BUILD_OPTIONS: ${{ matrix.buildtype }} tests
METACALL_BUILD_OPTIONS: ${{ matrix.option.build }} tests
6 changes: 3 additions & 3 deletions .github/workflows/thread-sanitizer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Note: This is duplicated from sanitizer.yml in order to keep the ci running if one of both sanitizers fail
# Note: This is duplicated from address-sanitizer.yml in order to keep the ci running if one of both sanitizers fail
name: Thread Sanitizer Test

on:
Expand All @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
build_image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"]
image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"]
env:
SANITIZER_SKIP_SUMMARY: 1

Expand All @@ -34,4 +34,4 @@ jobs:
- name: Install, build and run thread sanitizer tests
run: ./docker-compose.sh test-thread-sanitizer
env:
METACALL_BASE_IMAGE: ${{ matrix.build_image }}
METACALL_BASE_IMAGE: ${{ matrix.image }}
15 changes: 11 additions & 4 deletions .github/workflows/windows-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ concurrency:
jobs:
windows-test:
name: Windows MSVC Test
runs-on: windows-2019
runs-on: windows-2019 # TODO: Implement matrix with windows 2019 and 2022

strategy:
matrix:
options: [ {buildtype: debug, sanitizer: without-sanitizer}, {buildtype: debug, sanitizer: sanitizer} ] # TODO: Enable release when all debug tests pass {buildtype: release, sanitizer: without-sanitizer}
options: [
{ build: debug, sanitizer: without-sanitizer },
{ build: debug, sanitizer: address-sanitizer },
{ build: debug, sanitizer: thread-sanitizer },
{ build: debug, sanitizer: memory-sanitizer },
{ build: debug, sanitizer: ub-sanitizer },
{ build: release, sanitizer: without-sanitizer }
]

steps:
- name: Check out the repository
Expand All @@ -46,10 +53,10 @@ jobs:
cd "$METACALL_PATH\build"
cmd.exe /c "powershell ..\tools\metacall-configure.ps1 $Env:METACALL_BUILD_OPTIONS"
env:
METACALL_BUILD_OPTIONS: ${{ matrix.options.buildtype }} ${{ matrix.options.sanitizer }} scripts ports tests python nodejs java ruby typescript wasm # netcore5 file rpc java c cobol rust examples install pack benchmarks # v8 coverage
METACALL_BUILD_OPTIONS: ${{ matrix.options.build }} ${{ matrix.options.sanitizer }} scripts ports tests python nodejs java ruby typescript wasm # netcore5 file rpc java c cobol rust examples install pack benchmarks # v8 coverage

- name: Build
working-directory: ./build
run: cmd.exe /c "powershell ..\tools\metacall-build.ps1 $Env:METACALL_BUILD_OPTIONS"
env:
METACALL_BUILD_OPTIONS: ${{ matrix.options.buildtype }} tests
METACALL_BUILD_OPTIONS: ${{ matrix.options.build }} tests
17 changes: 9 additions & 8 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Compile options configuration
#

option(OPTION_BUILD_SANITIZER "Build with sanitizer compiler options." OFF)
option(OPTION_BUILD_MEMORY_SANITIZER "Build with memory sanitizer compiler options." OFF)
option(OPTION_BUILD_THREAD_SANITIZER "Build with thread sanitizer compiler options." OFF)
option(OPTION_BUILD_ADDRESS_SANITIZER "Build with sanitizer compiler options." OFF)
option(OPTION_BUILD_MEMORY_SANITIZER "Build with memory sanitizer compiler options." OFF)
option(OPTION_BUILD_THREAD_SANITIZER "Build with thread sanitizer compiler options." OFF)
option(OPTION_BUILD_UB_SANITIZER "Build with undefined behavior sanitizer compiler options." OFF)

if((OPTION_BUILD_SANITIZER AND OPTION_BUILD_MEMORY_SANITIZER) OR (OPTION_BUILD_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER) OR (OPTION_BUILD_MEMORY_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER))
message(FATAL_ERROR "OPTION_BUILD_SANITIZER and OPTION_BUILD_MEMORY_SANITIZER and OPTION_BUILD_THREAD_SANITIZER are mutually exclusive, choose one of them")
if((OPTION_BUILD_ADDRESS_SANITIZER AND OPTION_BUILD_MEMORY_SANITIZER) OR (OPTION_BUILD_ADDRESS_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER) OR (OPTION_BUILD_MEMORY_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER))
message(FATAL_ERROR "OPTION_BUILD_ADDRESS_SANITIZER and OPTION_BUILD_MEMORY_SANITIZER and OPTION_BUILD_THREAD_SANITIZER are mutually exclusive, choose one of them")
endif()

#
Expand Down Expand Up @@ -93,7 +94,7 @@ elseif(OPTION_BUILD_UB_SANITIZER AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"
set(SANITIZER_COMPILE_DEFINITIONS
"__UB_SANITIZER__=1"
)
elseif(OPTION_BUILD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
set(SANITIZER_LIBRARIES -lasan -lubsan)
set(TESTS_SANITIZER_ENVIRONMENT_VARIABLES
"LSAN_OPTIONS=verbosity=1:log_threads=1:print_suppressions=false:suppressions=${CMAKE_SOURCE_DIR}/source/tests/sanitizer/lsan.supp"
Expand Down Expand Up @@ -237,7 +238,7 @@ if(WIN32 AND MSVC)
if(OPTION_BUILD_THREAD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=thread)
add_link_options(/INCREMENTAL:NO)
elseif(OPTION_BUILD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=address)
add_link_options(/INCREMENTAL:NO)
elseif(OPTION_BUILD_MEMORY_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
Expand Down Expand Up @@ -279,7 +280,7 @@ if (PROJECT_OS_FAMILY MATCHES "unix" OR PROJECT_OS_FAMILY MATCHES "macos")
if(PROJECT_OS_FAMILY MATCHES "macos" OR (PROJECT_OS_FAMILY MATCHES "unix" AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
add_link_options(-fsanitize=thread)
endif()
elseif(OPTION_BUILD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(-fno-omit-frame-pointer)
add_compile_options(-fno-optimize-sibling-calls)
add_compile_options(-fsanitize=undefined)
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindNodeJS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ if(NOT NodeJS_LIBRARY)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(BUILD_DEBUG "--debug")

if(OPTION_BUILD_SANITIZER)
if(OPTION_BUILD_ADDRESS_SANITIZER)
set(BUILD_DEBUG "${BUILD_DEBUG} --enable-asan")
endif()
else()
Expand Down
16 changes: 8 additions & 8 deletions docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ sub_test() {
docker-compose -f docker-compose.yml -f docker-compose.test.yml build --force-rm dev
}

# Build MetaCall Docker Compose with Sanitizer for testing (link manually dockerignore files)
sub_test_sanitizer() {
# Build MetaCall Docker Compose with Address Sanitizer for testing (link manually dockerignore files)
sub_test_address_sanitizer() {
# Disable BuildKit as workaround due to log limits (TODO: https://github.com/docker/buildx/issues/484)
export DOCKER_BUILDKIT=0

# Enable build with sanitizer
export METACALL_BUILD_SANITIZER=${METACALL_BUILD_SANITIZER:-sanitizer}
export METACALL_BUILD_SANITIZER=${METACALL_BUILD_SANITIZER:-address-sanitizer}

# Define build type
export METACALL_BUILD_TYPE=${METACALL_BUILD_TYPE:-debug}
Expand Down Expand Up @@ -129,7 +129,7 @@ sub_test_sanitizer() {

if [ -z "${BEGIN}" ] || [ -z "${END}" ]; then
echo "ERROR! CTest failed to print properly the output, run tests again:"
echo " Recompiling everything: docker rmi metacall/core:dev && ./docker-compose.sh test-sanitizer"
echo " Recompiling everything: docker rmi metacall/core:dev && ./docker-compose.sh test-${METACALL_BUILD_SANITIZER}"
echo " Without recompiling (needs to be built successfully previously): docker run --rm -it metacall/core:dev sh -c \"cd build && ctest -j$(getconf _NPROCESSORS_ONLN) --output-on-failure\""
else
BEGIN=$((BEGIN + 1))
Expand All @@ -148,7 +148,7 @@ sub_test_thread_sanitizer() {
export METACALL_BUILD_SANITIZER="thread-sanitizer"

# Run tests with thread sanitizer
sub_test_sanitizer
sub_test_address_sanitizer
}

# Build MetaCall Docker Compose with caching (link manually dockerignore files)
Expand Down Expand Up @@ -266,7 +266,7 @@ sub_help() {
echo " build"
echo " rebuild"
echo " test"
echo " test-sanitizer"
echo " test-address-sanitizer"
echo " test-thread-sanitizer"
echo " cache"
echo " push"
Expand All @@ -287,8 +287,8 @@ case "$1" in
test)
sub_test
;;
test-sanitizer)
sub_test_sanitizer
test-address-sanitizer)
sub_test_address-sanitizer
;;
test-thread-sanitizer)
sub_test_thread_sanitizer
Expand Down
Loading

0 comments on commit 3f82218

Please sign in to comment.