From 9a8b02349b67d1e9724cbcbc69c8af4e9a4beef6 Mon Sep 17 00:00:00 2001 From: czm <34388355+czm23333@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:41:24 +0800 Subject: [PATCH 1/3] [ci] Add cppcheck github action Signed-off-by: czm <34388355+czm23333@users.noreply.github.com> --- .github/workflows/cppcheck.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/cppcheck.yml diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000000..ca372958f0 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,19 @@ +name: cppcheck-action +on: [push] + +jobs: + build: + name: cppcheck-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: cppcheck + uses: deep5050/cppcheck-action@main + + + - name: publish report + uses: actions/upload-artifact@v3 + with: + name: cppcheck + path: cppcheck_report.txt From 6c95d8c6126ef1f9dd49a0992a2fe4acba7a0583 Mon Sep 17 00:00:00 2001 From: czm <34388355+czm23333@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:00:13 +0000 Subject: [PATCH 2/3] [ci] Add cpplint github action Signed-off-by: czm <34388355+czm23333@users.noreply.github.com> --- .github/workflows/cppcheck.yml | 16 +++++----------- .github/workflows/cpplint.yml | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/cpplint.yml diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index ca372958f0..1853318fd6 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -1,19 +1,13 @@ name: cppcheck-action -on: [push] +on: [push, pull_request] jobs: - build: - name: cppcheck-test + cppcheck: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: cppcheck - uses: deep5050/cppcheck-action@main - - - - name: publish report - uses: actions/upload-artifact@v3 + - uses: actions/checkout@v3 + - uses: deep5050/cppcheck-action@main + - uses: actions/upload-artifact@v3 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..b298730c3e --- /dev/null +++ b/.github/workflows/cpplint.yml @@ -0,0 +1,17 @@ +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 + with: + name: cpplint + path: cpplint_report.txt + From 2ddafb4b161965bea5ace944d16e92e3ff346609 Mon Sep 17 00:00:00 2001 From: czm <34388355+czm23333@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:58:27 +0000 Subject: [PATCH 3/3] [ci] Add sanitizers for unit tests Signed-off-by: czm <34388355+czm23333@users.noreply.github.com> --- .bazelrc | 16 ++++++++++++++++ .github/workflows/cppcheck.yml | 9 +++++++++ .github/workflows/cpplint.yml | 1 + Makefile | 2 +- ut.sh | 6 +++++- util/build_in_image.sh | 12 +++++++++++- util/ut_in_image.sh | 27 +++++++++++++++++++++++++-- 7 files changed, 68 insertions(+), 5 deletions(-) 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 index 1853318fd6..5f283241a4 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -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 diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml index b298730c3e..157e211897 100644 --- a/.github/workflows/cpplint.yml +++ b/.github/workflows/cpplint.yml @@ -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 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