Skip to content

Commit

Permalink
[ci] Add sanitizers for unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: czm <[email protected]>
  • Loading branch information
czm23333 committed Sep 16, 2023
1 parent 6c95d8c commit 2ddafb4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,20 @@ build:gcc7-later --cxxopt -faligned-new
build --incompatible_blacklisted_protos_requires_proto_info=false
build --copt=-fdiagnostics-color=always

build:sanitize-common --strip=never
build:sanitize-common --copt -O1
build:sanitize-common --copt -g
build:sanitize-common --copt -fno-omit-frame-pointer

build:asan --config=sanitize-common
build:asan --copt -fsanitize=address
build:asan --copt -DADDRESS_SANITIZER
build:asan --linkopt -fsanitize=address

build:asan --config=sanitize-common
build:msan --copt -fsanitize=memory
build:msan --copt -fsanitize=undefined
build:msan --linkopt -fsanitize=address
build:msan --linkopt -fsanitize=undefined

run --copt=-fdiagnostics-color=always
9 changes: 9 additions & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: deep5050/cppcheck-action@main
with:
inconclusive: disable
other_options: "--suppress=syntaxError:* --suppress=danglingTemporaryLifetime:* --suppress=deallocuse:* --suppress=uninitvar:* --suppress=unknownMacro:* --suppress=ctuOneDefinitionRuleViolation:*"
- name: Error check
run: |
if grep -qF 'error: ' cppcheck_report.txt; then
exit 1
fi
- uses: actions/upload-artifact@v3
if: always()
with:
name: cppcheck
path: cppcheck_report.txt
1 change: 1 addition & 0 deletions .github/workflows/cpplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
- run: cpplint --recursive . > cpplint_report.txt 2>&1
continue-on-error: true
- uses: actions/upload-artifact@v3
if: always()
with:
name: cpplint
path: cpplint_report.txt
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dep:
@bash util/build.sh --stor=$(stor) --only="" --dep=1

ci-build:
@bash util/build_in_image.sh --stor=$(stor) --only=$(only) --dep=$(dep) --release=$(release) --ci=$(ci) --os=$(os)
@bash util/build_in_image.sh --stor=$(stor) --only=$(only) --dep=$(dep) --release=$(release) --ci=$(ci) --os=$(os) --sanitizer=$(sanitizer)

ci-dep:
@bash util/build_in_image.sh --stor=$(stor) --only="" --dep=1
Expand Down
6 changes: 5 additions & 1 deletion ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ print_title() {
############################ FUNCTIONS

get_options() {
local args=`getopt -o ldorh --long stor:,list,dep:,only:,os:,release:,ci:,build_rocksdb: -n "$0" -- "$@"`
local args=`getopt -o ldorhS --long sanitizer:,stor:,list,dep:,only:,os:,release:,ci:,build_rocksdb: -n "$0" -- "$@"`
eval set -- "${args}"
while true
do
Expand Down Expand Up @@ -56,6 +56,10 @@ get_options() {
g_ci=$2
shift 2
;;
-S|--sanitizer)
g_san=$2
shift 2
;;
--os)
g_os=$2
shift 2
Expand Down
12 changes: 11 additions & 1 deletion util/build_in_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ _EOC_
}

get_options() {
local args=`getopt -o ldorh --long stor:,list,dep:,only:,os:,release:,ci:,build_rocksdb: -n "$0" -- "$@"`
local args=`getopt -o ldorhS --long sanitizer:,stor:,list,dep:,only:,os:,release:,ci:,build_rocksdb: -n "$0" -- "$@"`
eval set -- "${args}"
while true
do
case "$1" in
-S|--sanitizer)
g_san=$2
shift 2
;;
-s|--stor)
g_stor=$2
shift 2
Expand Down Expand Up @@ -199,6 +203,12 @@ build_target() {
target_array=("...")
fi

if [ $g_san == 1 ]; then
g_build_opts+=("--config=asan")
elif [ $g_san == 2 ]; then
g_build_opts+=("--config=msan")
fi

for target in "${target_array[@]}"
do
bazel build ${g_build_opts[@]} $target
Expand Down
27 changes: 25 additions & 2 deletions util/ut_in_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
#!/bin/bash
get_options() {
local args=`getopt -o S --long sanitizer: -n "$0" -- "$@"`
eval set -- "${args}"
while true
do
case "$1" in
-S|--sanitizer)
g_san=$2
shift 2
;;
--)
shift
break
;;
*)
exit 1
;;
esac
done
}

get_options "$@"

WORKSPACE="/var/lib/jenkins/workspace/curve/curve_multijob/"
sudo mkdir -p /var/lib/jenkins/log/curve_unittest/$BUILD_NUMBER
git config --global --add safe.directory /var/lib/jenkins/workspace/curve/curve_multijob
Expand Down Expand Up @@ -68,10 +91,10 @@ set -e

#test_bin_dirs="bazel-bin/test/ bazel-bin/nebd/test/ bazel-bin/curvefs/test/"
if [ $1 == "curvebs" ];then
make ci-build stor=bs ci=1 dep=1
make ci-build stor=bs ci=1 dep=1 sanitizer=$g_san
test_bin_dirs="bazel-bin/test/ bazel-bin/nebd/test/"
elif [ $1 == "curvefs" ];then
make ci-build stor=fs ci=1 dep=1 only=curvefs/test/*
make ci-build stor=fs ci=1 dep=1 only=curvefs/test/* sanitizer=$g_san
test_bin_dirs="bazel-bin/curvefs/test/"
fi
echo $test_bin_dirs
Expand Down

0 comments on commit 2ddafb4

Please sign in to comment.