Skip to content

Commit f9dc7a3

Browse files
committed
Add sanitizers configuration for Bazel tests and update README
Fixes eclipse-score#101
1 parent ba99dfc commit f9dc7a3

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

.bazelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ test:bl-aarch64-qnx --config=_bl_common
6868
coverage --features=coverage
6969
coverage --combined_report=lcov
7070
coverage --cache_test_results=no
71+
72+
# Sanitizer configuration for C++
73+
test:asan_ubsan_lsan --features=asan
74+
test:asan_ubsan_lsan --features=ubsan
75+
test:asan_ubsan_lsan --features=lsan
76+
test:asan_ubsan_lsan --copt -g3
77+
test:asan_ubsan_lsan --platform_suffix=asan_ubsan_lsan
78+
test:asan_ubsan_lsan --test_env=ASAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 check_initialization_order=1 detect_stack_use_after_return=1 print_stats=1 halt_on_error=1 allocator_may_return_null=1 detect_leaks=1"
79+
test:asan_ubsan_lsan --test_env=UBSAN_OPTIONS="exitcode=55 allow_addr2line=1 verbosity=1 coverage=1 print_stacktrace=1 halt_on_error=1"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
name: Bazel Sanitizers (Linux)
14+
permissions:
15+
contents: read
16+
actions: write
17+
on:
18+
pull_request:
19+
types: [opened, reopened, synchronize]
20+
push:
21+
branches:
22+
- main
23+
merge_group:
24+
types: [checks_requested]
25+
workflow_call:
26+
jobs:
27+
linux-sanitizers:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout Repository
31+
uses: actions/checkout@v6
32+
- name: Setup Bazel
33+
uses: bazel-contrib/setup-bazel@0.18.0
34+
with:
35+
bazelisk-cache: true
36+
disk-cache: ${{ github.job }}
37+
repository-cache: true
38+
cache-save: ${{ github.event_name == 'push' }}
39+
- name: Bazel Test with Sanitizers
40+
run: |
41+
bazel test --config bl-x86_64-linux --config=asan_ubsan_lsan --build_tests_only -- //score/... \
42+
-//score/language/safecpp/aborts_upon_exception:abortsuponexception_toolchain_test \
43+
-//score/containers:dynamic_array_test \
44+
-//score/containers:non_relocatable_vector_emplace_back_test \
45+
-//score/containers:non_relocatable_vector_special_member_funcs_test \
46+
-//score/containers:non_relocatable_vector_test

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ bazel build --config=bl-x86_64-qnx -- //score/...
9696

9797
Use the same command as for x86_64 QNX, but replace `--config=bl-x86_64-qnx` with `--config=bl-aarch64-qnx`.
9898

99+
### Sanitizers
100+
101+
To detect memory errors, undefined behavior, and memory leaks, run tests with sanitizers enabled:
102+
103+
```bash
104+
bazel test --config=bl-x86_64-linux --config=asan_ubsan_lsan --build_tests_only -- //score/...
105+
```
106+
107+
This configuration enables:
108+
- **AddressSanitizer (ASan)**: Fast memory error detector.
109+
- **UndefinedBehaviorSanitizer (UBSan)**: Detects undefined behavior at runtime.
110+
- **LeakSanitizer (LSan)**: Memory leak detector.
111+
112+
The sanitizers are configured with verbose output and will halt on the first error detected.
113+
99114
### Generating Documentation
100115

101116
To generate the documentation locally:

0 commit comments

Comments
 (0)