diff --git a/.bazelrc b/.bazelrc index bd9e2fd766..7c1adc7ea9 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000000..5f283241a4 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,22 @@ +name: cppcheck-action +on: [push, pull_request] + +jobs: + cppcheck: + runs-on: ubuntu-latest + 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 diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml new file mode 100644 index 0000000000..157e211897 --- /dev/null +++ b/.github/workflows/cpplint.yml @@ -0,0 +1,18 @@ +name: cpplint-action +on: [push, pull_request] + +jobs: + cpplint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - run: pip install cpplint + - 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 + diff --git a/Makefile b/Makefile index 7016723580..3fffc4e073 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ut.sh b/ut.sh index 74326eb7e5..8a3599f800 100644 --- a/ut.sh +++ b/ut.sh @@ -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 @@ -56,6 +56,10 @@ get_options() { g_ci=$2 shift 2 ;; + -S|--sanitizer) + g_san=$2 + shift 2 + ;; --os) g_os=$2 shift 2 diff --git a/util/build_in_image.sh b/util/build_in_image.sh index fea01388e3..6b18aa2a49 100644 --- a/util/build_in_image.sh +++ b/util/build_in_image.sh @@ -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 @@ -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 diff --git a/util/ut_in_image.sh b/util/ut_in_image.sh index 56cecaceb8..227e1f47e7 100644 --- a/util/ut_in_image.sh +++ b/util/ut_in_image.sh @@ -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 @@ -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