From 94ba3ffe54d42bb24d8db25dc89e3df791b7391e Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Fri, 17 Jan 2025 15:02:31 +0000 Subject: [PATCH] Add simpler sanitizer test Signed-off-by: Evgeny Malygin --- .github/workflows/dependencies.yaml | 4 +- .github/workflows/sanitize.yaml | 88 ++++++--------------- src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp | 25 ++++++ 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/.github/workflows/dependencies.yaml b/.github/workflows/dependencies.yaml index 469c340f25..27f6e9057a 100644 --- a/.github/workflows/dependencies.yaml +++ b/.github/workflows/dependencies.yaml @@ -12,8 +12,8 @@ on: - cron: "10 0 * * *" concurrency: - group: deps-${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true + group: global + cancel-in-progress: false jobs: build_dependencies: diff --git a/.github/workflows/sanitize.yaml b/.github/workflows/sanitize.yaml index 9aa2642164..d171f2fad1 100644 --- a/.github/workflows/sanitize.yaml +++ b/.github/workflows/sanitize.yaml @@ -1,80 +1,36 @@ -name: Sanitize with AddressSanitizer, MemorySanitizer, ThreadSanitizer and UndefinedBehaviorSanitizer. +name: Sanitize on: pull_request_review: types: [submitted] + pull_request: + branches: + - main concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: - build_dependencies: - name: Build deps [ubuntu] - runs-on: ubuntu-latest - if: github.event.review.state == 'APPROVED' + get_dependencies: + name: "Dependencies" + uses: ./.github/workflows/dependencies.yaml + + build_and_run_sanitizer: + name: ${{ matrix.mode }} + needs: get_dependencies + strategy: + matrix: + mode: ["asan", "msan", "tsan", "ubsan"] + fail-fast: false + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - name: Get dependencies hash - id: get-hash - run: echo "deps_hash=`cat docker/build_deps.sh | shasum`" >> $GITHUB_OUTPUT - - name: Cache lookup - uses: actions/cache/restore@v4 - id: cache-lookup - with: - path: deps - key: deps-${{ steps.get-hash.outputs.deps_hash }} - lookup-only: true - - name: Set up dependencies - if: steps.cache-lookup.outputs.cache-hit != 'true' - run: | - sudo apt-get update - sudo apt-get install -qy build-essential \ - gdb \ - curl \ - python3.10 \ - python3-pip \ - cmake \ - ninja-build \ - pkg-config \ - bison \ - libfl-dev \ - libbenchmark-dev \ - libgmock-dev \ - libz-dev - - name: Fetch & Build non packaged dependencies - if: steps.cache-lookup.outputs.cache-hit != 'true' - run: | - mkdir -p deps - cd deps - ../docker/build_deps.sh - - name: Cache save - if: steps.cache-lookup.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 + - uses: actions/cache/restore@v4 with: path: deps - key: deps-${{ steps.get-hash.outputs.deps_hash }} - - run_asan: - needs: build_dependencies - uses: ./.github/workflows/sanitizer-check.yaml - with: - sanitizer-name: 'asan' - - run_msan: - needs: build_dependencies - uses: ./.github/workflows/sanitizer-check.yaml - with: - sanitizer-name: 'msan' - - run_tsan: - needs: build_dependencies - uses: ./.github/workflows/sanitizer-check.yaml - with: - sanitizer-name: 'tsan' - - run_ubsan: - needs: build_dependencies - uses: ./.github/workflows/sanitizer-check.yaml - with: - sanitizer-name: 'ubsan' + key: ${{ needs.get_dependencies.outputs.cache_key }} + - name: Build [${{ matrix.mode }}] + run: ${{ github.workspace }}/.github/workflows/sanitizers/build_sanitizer.sh ${{ matrix.mode }} + - name: UT [c++,${{ matrix.mode }}] + run: ${{ github.workspace }}/cmake.bld/Linux/run-unittests.sh diff --git a/src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp b/src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp index 7d3f17ba26..e3ec3dab7a 100644 --- a/src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp +++ b/src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp @@ -69,6 +69,30 @@ static void test1_partitionIdExtractor() } } +static void test2_sanitizer() +{ + bslma::Allocator *alloc = bmqtst::TestHelperUtil::allocator(); + + const char pattern[] = "^\\S+\\.([0-9]+)\\.\\S+\\.\\S+$"; + + bdlpcre::RegEx regex(alloc); + bsl::string error(alloc); + size_t errorOffset; + BSLA_MAYBE_UNUSED const int rc = regex.prepare( + &error, + &errorOffset, + pattern, + bdlpcre::RegEx::k_FLAG_JIT); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT(regex.isPrepared()); + + bsl::string str("test.123.test.test", alloc); + bsl::vector result(alloc); + const int rc = regex.match(&result, + str.data(), + str.length()); +} + // ============================================================================ // MAIN PROGRAM // ---------------------------------------------------------------------------- @@ -79,6 +103,7 @@ int main(int argc, char* argv[]) switch (_testCase) { case 0: + case 2: test2_sanitizer(); break; case 1: test1_partitionIdExtractor(); break; default: { cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;