Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 1d1a0d7

Browse files
authored
Add bazel.rc and presubmit script. (#49)
The bazel.rc file has configs for address sanitizer (--config=asan) and ubsan. The presubmit script is a heavyweight version of tools/ci.sh which builds and tests everything, including opt mode and sanitizers.
1 parent 00b3777 commit 1d1a0d7

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

tools/bazel.rc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# bazel configurations for running tests under sanitizers.
2+
# Based on https://github.com/bazelment/trunk/blob/master/tools/bazel.rc
3+
4+
# --config=asan : Address Sanitizer.
5+
common:asan --copt -fsanitize=address
6+
common:asan --copt -DADDRESS_SANITIZER
7+
common:asan --linkopt -fsanitize=address
8+
common:asan --cc_output_directory_tag=asan
9+
10+
# --config=msan : Memory Sanitizer.
11+
# TODO: This doesn't work with gcc.
12+
#common:msan --copt -fsanitize=memory
13+
#common:msan --copt -DMEMORY_SANITIZER
14+
#common:msan --linkopt -fsanitize=memory
15+
16+
# --config=tsan : Thread Sanitizer.
17+
# TODO: Enable this once it works. Currently breaks build in absl's mutex.cc.
18+
#common:tsan --copt -fsanitize=thread
19+
#common:tsan --copt -DTHREAD_SANITIZER
20+
#common:tsan --copt -DDYNAMIC_ANNOTATIONS_ENABLED=1
21+
#common:tsan --copt -DDYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1
22+
#common:tsan --linkopt -fsanitize=thread
23+
24+
# --config=ubsan : Undefined Behavior Sanitizer.
25+
common:ubsan --copt -fsanitize=undefined
26+
common:ubsan --linkopt -fsanitize=undefined
27+
common:ubsan --cc_output_directory_tag=ubsan

tools/presubmit.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2018, OpenCensus Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# presubmit:
18+
# Run a slow but complete check of the code to make sure:
19+
# - Everything builds.
20+
# - Tests pass.
21+
# - Sanitizers pass.
22+
#
23+
# This is intended to be run manually and locally, not as part of
24+
# continuous integration.
25+
26+
readonly R="======================================="
27+
readonly BOLD="\\033[1m"
28+
readonly ERR="\\033[31;1m"
29+
readonly NORMAL="\\033[0m"
30+
31+
function run() {
32+
echo ""
33+
echo -e "${BOLD}${R}${R}"
34+
echo "Running: $@"
35+
echo -e "${R}${R}${NORMAL}"
36+
$@
37+
ret="$?"
38+
if [[ "${ret}" -ne 0 ]]; then
39+
echo ""
40+
echo -e "${ERR}>>> Error: returned code ${ret} <<<${NORMAL}"
41+
exit ${ret}
42+
fi
43+
}
44+
45+
t0="$(date +%s)"
46+
47+
buildables="-- $(bazel query -k --noshow_progress "kind('^cc', //...)")"
48+
49+
tests="-- $(bazel query -k --noshow_progress \
50+
"kind(test, //...) \
51+
except attr('tags', 'manual', //...)")"
52+
53+
run bazel build $buildables
54+
run bazel test $tests
55+
56+
run bazel build -c opt $buildables
57+
run bazel test -c opt $tests
58+
59+
for config in asan ubsan; do
60+
run bazel test --config=$config $tests
61+
run bazel test --config=$config -c opt $tests
62+
done
63+
64+
t1="$(date +%s)"
65+
echo ""
66+
echo "Succeeded after $((t1 - t0)) secs."

0 commit comments

Comments
 (0)