Skip to content

Commit

Permalink
Simple test to do clang/asan builds on gz-utils
Browse files Browse the repository at this point in the history
Inspired by robotlocomotion/drake's approach

Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Nov 15, 2024
1 parent 7daf8e7 commit 7b4858e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ build --features=per_object_debug_info

# Enable header processing, required for layering checks with parse_header.
build --process_headers_in_dependencies

import %workspace%/tools/bazel.rc
13 changes: 10 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ cc_library(
"test/integration/implptr/implptr_test_classes.hh",
],
includes = ["test/integration/implptr"],
deps = [":ImplPtr"],
deps = [
":Export",
":ImplPtr",
],
)

cc_test(
Expand All @@ -122,6 +125,7 @@ cc_test(
srcs = ["test/integration/implptr/ImplPtr_TEST.cc"],
deps = [
":implptr_test_classes",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
Expand All @@ -131,6 +135,7 @@ cc_test(
srcs = ["src/Environment_TEST.cc"],
deps = [
":Environment",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
Expand All @@ -140,7 +145,7 @@ cc_binary(
srcs = ["test/integration/subprocess/subprocess_main.cc"],
deps = [
":Environment",
"//cli",
"//cli:cli11",
],
)

Expand All @@ -149,8 +154,10 @@ cc_test(
srcs = ["test/integration/subprocess_TEST.cc"],
local_defines = ['SUBPROCESS_EXECUTABLE_PATH=\\"subprocess_main\\"'],
deps = [
":gz-utils",
":Environment",
":Subprocess",
":subprocess_main",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
Expand Down
5 changes: 4 additions & 1 deletion cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cc_library(
"-parse_headers",
],
includes = ["include/vendored-cli"],
visibility = ["//visibility:public"],
)

cc_library(
Expand Down Expand Up @@ -45,7 +46,9 @@ cc_test(
name = "cli_TEST",
srcs = ["src/cli_TEST.cc"],
deps = [
":cli",
":GzFormatter",
":cli11",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
12 changes: 10 additions & 2 deletions log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ cc_library(
],
includes = ["include"],
visibility = ["//visibility:public"],
deps = [":SplitSink"],
deps = [
":Export",
":SplitSink",
"//:Config",
"//:ImplPtr",
"@spdlog",
],
)

cc_library(
Expand All @@ -61,7 +67,9 @@ cc_test(
srcs = ["src/SplitSink_TEST.cc"],
visibility = ["//visibility:public"],
deps = [
":log",
":SplitSink",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@spdlog",
],
)
5 changes: 5 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sh_binary(
name = "asan",
srcs = ["asan.sh"],
data = ["asan.supp"],
)
10 changes: 10 additions & 0 deletions tools/asan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
me=$(python3 -c 'import os; print(os.path.realpath("'"$0"'"))')
mydir=$(dirname "$me")
export ASAN_OPTIONS="$ASAN_OPTIONS:check_initialization_order=1:detect_container_overflow=0:detect_invalid_pointer_pairs=1:detect_stack_use_after_return=1:strict_init_order=1:strict_string_checks=1:strip_path_prefix=/proc/self/cwd/:suppressions=$mydir/asan.supp"
# LSan is run with ASan by default, ASAN_OPTIONS can't be used to suppress LSan
# errors
export LSAN_OPTIONS="$LSAN_OPTIONS:strip_path_prefix=/proc/self/cwd/:suppressions=$mydir/lsan.supp"
# Ensure executable named llvm-symbolizer is on the PATH.
export PATH="$PATH:/usr/lib/llvm-14/bin:/usr/lib/llvm-12/bin:/usr/local/opt/llvm/bin"
"$@"
Empty file added tools/asan.supp
Empty file.
36 changes: 36 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
common:clang --repo_env=CC=clang-15
common:clang --repo_env=CXX=clang++-15
build:clang --action_env=CC=clang-15
build:clang --action_env=CXX=clang++-15
build:clang --host_action_env=CC=clang-15
build:clang --host_action_env=CXX=clang++-15

### ASan build. Clang only. ###
build:asan --build_tests_only
build:asan --copt=-g
# https://github.com/google/sanitizers/wiki/AddressSanitizer#faq
build:asan --copt=-fno-common
build:asan --copt=-fsanitize=address
build:asan --copt=-fsanitize-address-use-after-scope
build:asan --copt=-fstandalone-debug
build:asan --copt=-O0
build:asan --copt=-fno-omit-frame-pointer
build:asan --linkopt=-fsanitize=address
build:asan --linkopt=-fsanitize-address-use-after-scope
build:asan --run_under=//tools:asan
build:asan --test_env=ASAN_OPTIONS
build:asan --test_env=LSAN_OPTIONS
build:asan --test_env=ASAN_SYMBOLIZER_PATH
build:asan --test_env=LSAN_SYMBOLIZER_PATH
# LSan is run with ASan by default
build:asan --test_tag_filters=-gurobi,-mosek,-snopt,-no_asan,-no_lsan
build:asan --test_lang_filters=-sh,-py
# Typical slowdown introduced by AddressSanitizer is 2x.
# See https://clang.llvm.org/docs/AddressSanitizer.html
build:asan --test_timeout=150,750,2250,9000 # 2.5x
build:asan --define=USING_SANITIZER=ON
# Due to https://sourceware.org/bugzilla/show_bug.cgi?id=25975, we see ...
# ld.gold: warning: Cannot export local symbol __asan_extra_spill_area
# ... spammed millions of times in ASan builds. The only way to silence that
# warning is to silence ALL WARNINGS AT ALL EVER in ASan builds.
build:asan --auto_output_filter=all

0 comments on commit 7b4858e

Please sign in to comment.