Skip to content

Commit

Permalink
Add simpler sanitizer test
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeny Malygin <[email protected]>
  • Loading branch information
678098 committed Jan 17, 2025
1 parent 8c8af57 commit 94ba3ff
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
88 changes: 22 additions & 66 deletions .github/workflows/sanitize.yaml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions src/groups/mqb/mqbc/mqbc_clusterstate.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bslstl::StringRef> result(alloc);
const int rc = regex.match(&result,
str.data(),
str.length());
}

// ============================================================================
// MAIN PROGRAM
// ----------------------------------------------------------------------------
Expand All @@ -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;
Expand Down

0 comments on commit 94ba3ff

Please sign in to comment.