Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

name: Tests

on:
pull_request:
push:
branches:
- main

jobs:
test-sanitizers:
name: Validate sanitizer configs
runs-on: ubuntu-latest
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using latest? this can easily break our workflows in case it gets upgraded


strategy:
fail-fast: false
matrix:
config: [asan_ubsan_lsan]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.18.0
with:
disk-cache: ${{ github.workflow }}-${{ matrix.config }}
cache-save: ${{ github.event_name == 'push' }}

- name: Test with ${{ matrix.config }}
working-directory: tests
run: |
bazel test --config=${{ matrix.config }} //:sample_test --verbose_failures
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not

Suggested change
bazel test --config=${{ matrix.config }} //:sample_test --verbose_failures
bazel test --config=${{ matrix.config }} //... --verbose_failures

?
since there will be further unit tests in this repo soon


- name: Upload test logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-logs-${{ matrix.config }}-${{ github.run_id }}
path: tests/bazel-testlogs/**/test.log
if-no-files-found: ignore
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Bazel build outputs
bazel-*
.bazel-*

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db
20 changes: 20 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

exports_files(
[
"LICENSE.md",
"NOTICE",
],
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# score_cpp_policies Contribution Guide

The [Eclipse Safe Open Vehicle Core (S-CORE)](https://projects.eclipse.org/projects/automotive.score) project develops an open-source core stack for Software Defined Vehicles (SDVs). This repository centralizes the shared C++ quality tool policies (sanitizers, clang-tidy, clang-format) that S-CORE modules reuse to maintain consistent, safety-focused defaults.

Project communication happens via the [score-dev mailing list](https://accounts.eclipse.org/mailing-list/score-dev), GitHub issues and pull requests, and the [Eclipse SCORE chatroom](https://chat.eclipse.org/#/room/#automotive.score:matrix.eclipse.org).
Copy link
Member

@4og 4og Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the statement coming from? S-CORE is not using Eclipse matrix chat for communication, but Slack instead.


Please note that the [Eclipse Foundation's Terms of Use](https://www.eclipse.org/legal/terms-of-use/) apply. Contributors must sign both the [ECA](https://www.eclipse.org/legal/ECA.php) and the [DCO](https://www.eclipse.org/legal/dco/).

## Contributing changes

1. Open an issue describing the policy change you propose (e.g., enabling/disabling a sanitizer option or clang-tidy rule) and the rationale, including links to any affected projects.
2. Submit a PR referencing the issue. Keep changes minimal and well-documented, and include examples that justify the chosen defaults when possible.
3. Request reviews from the S-CORE committers. Follow the commit message rules in the [Eclipse Foundation Project Handbook](https://www.eclipse.org/projects/handbook/#resources-commit).

If you are new to the project, see the S-CORE process descriptions and templates at [https://eclipse-score.github.io/score/process_description/](https://eclipse-score.github.io/score/process_description/).
13 changes: 13 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2026 Contributors to the Eclipse Foundation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the entire license text here and remove .md extension. You can copy it,for example for here: https://github.com/eclipse-score/module_template/blob/main/LICENSE

General guideline: https://www.eclipse.org/projects/handbook/#legaldoc-license


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
19 changes: 19 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

module(
name = "score_cpp_policies",
version = "0.0.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please set the version to 0.0.0 here? The workflow in the S-CORE bazel registry is taking care of generating a patch when a release is picked.

)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
23 changes: 23 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Notices for Eclipse S-CORE

This content is produced and maintained by the Eclipse S-CORE project.

* Project home: https://projects.eclipse.org/projects/automotive.score

## Trademarks

Eclipse S-CORE is a trademark of the Eclipse Foundation.

## Copyright

All content is the property of the respective authors or their employers.
For more information regarding authorship of content, please consult the
listed source code repository logs.

## Declared Project Licenses

This program and the accompanying materials are made available under the
terms of the Apache License Version 2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0

SPDX-License-Identifier: Apache-2.0
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
# score_cpp_policies
Centralized C++ quality tool policies for S-CORE, including sanitizer configurations and safety-critical guidelines.

Centralized C++ quality tool policies for Eclipse S-CORE, including sanitizer configurations and safety-critical guidelines.

## Overview

This repository provides shared configurations for C++ quality tools used across all S-CORE modules:

- **Sanitizers** (ASan, TSan, UBSan, LSan) - Memory safety and undefined behavior detection
- **Clang-tidy** (future) - Static analysis
- **Clang-format** (future) - Code formatting
- **Code coverage** (future) - Test coverage measurement

## Usage

### Using Sanitizers in Your Module

Add to your module's `MODULE.bazel`:

```python
bazel_dep(name = "score_cpp_policies", version = "0.0.1")
```

Add to your module's `.bazelrc`:

```bazelrc
# Import centralized sanitizer configurations
try-import %workspace%/../../../external/score_cpp_policies/sanitizer/sanitizer.bazelrc
```

### Running Tests with Sanitizers

```bash
# Run all tests with ASan + UBSan + LSan (recommended)
bazel test --config=asan_ubsan_lsan //...

# Run tests with ThreadSanitizer
bazel test --config=tsan //...

# Run tests with individual sanitizers
bazel test --config=asan //...
bazel test --config=ubsan //...
bazel test --config=lsan //...
```

## Available Sanitizer Configurations

### Combined Configuration (Recommended)

- `--config=asan_ubsan_lsan` - Combines AddressSanitizer, UndefinedBehaviorSanitizer, and LeakSanitizer

### Individual Configurations

- `--config=asan` - AddressSanitizer (memory errors, buffer overflows)
- `--config=tsan` - ThreadSanitizer (data races, deadlocks)
- `--config=ubsan` - UndefinedBehaviorSanitizer (undefined behavior)
- `--config=lsan` - LeakSanitizer (memory leaks)
Comment on lines +54 to +57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer alphabetical sorting instead?

Suggested change
- `--config=asan` - AddressSanitizer (memory errors, buffer overflows)
- `--config=tsan` - ThreadSanitizer (data races, deadlocks)
- `--config=ubsan` - UndefinedBehaviorSanitizer (undefined behavior)
- `--config=lsan` - LeakSanitizer (memory leaks)
- `--config=asan` - AddressSanitizer (memory errors, buffer overflows)
- `--config=lsan` - LeakSanitizer (memory leaks)
- `--config=tsan` - ThreadSanitizer (data races, deadlocks)
- `--config=ubsan` - UndefinedBehaviorSanitizer (undefined behavior)


## Common Runtime Options

All sanitizer configurations use these common options:

- `exitcode=55` - Custom exit code for CI detection
- `allow_addr2line=1` - Enable symbolization for better stack traces
- `verbosity=1` - Enable detailed error reporting
- `halt_on_error=1` - Stop on first error (fail-fast)

## Testing This Repository

```bash
cd tests/
bazel test --config=asan_ubsan_lsan //...
```

## Contributing

See [CONTRIBUTION.md](CONTRIBUTION.md) for contribution guidelines.

## License

This project is licensed under the Apache License 2.0 - see [LICENSE.md](LICENSE.md) for details.

## Copyright

Copyright (c) 2026 Contributors to the Eclipse Foundation. See [NOTICE](NOTICE) for details.
17 changes: 17 additions & 0 deletions sanitizer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

exports_files(
["sanitizer.bazelrc"],
visibility = ["//visibility:public"],
)
46 changes: 46 additions & 0 deletions sanitizer/sanitizer.bazelrc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about preferring plural here? would be more appropriate in my eyes since it makes clear that it will contain multiple sanitizer configs

i.e. sanitizers/sanitizers.bazelrc

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

# ASan + UBSan + LSan (Combined - recommended for most testing)
test:asan_ubsan_lsan --compilation_mode=dbg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use dbg compliation mode. this would potentially enable code which is not part of the actual production code and hence you would potentially run into different code paths. just omit that everywhere since such compilation flags must come from the toolchain which defines the respective sanitizer features.
also see https://github.com/eclipse-score/communication/blob/main/quality/sanitizer/sanitizer.bazelrc#L20-L30 for further reference which flags we require for sanitizer configs

test:asan_ubsan_lsan --features=asan
test:asan_ubsan_lsan --features=ubsan
test:asan_ubsan_lsan --features=lsan
test:asan_ubsan_lsan --platform_suffix=asan_ubsan_lsan
test:asan_ubsan_lsan --test_env=ASAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:detect_leaks=1:halt_on_error=1:allocator_may_return_null=1
test:asan_ubsan_lsan --test_env=UBSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:print_stacktrace=1:halt_on_error=1
test:asan_ubsan_lsan --test_env=LSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:halt_on_error=1
Comment on lines +20 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such runtime options should get extracted into a single place and then reused here instead

Suggested change
test:asan_ubsan_lsan --test_env=ASAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:detect_leaks=1:halt_on_error=1:allocator_may_return_null=1
test:asan_ubsan_lsan --test_env=UBSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:print_stacktrace=1:halt_on_error=1
test:asan_ubsan_lsan --test_env=LSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:halt_on_error=1
test:_asan_runtime_options --test_env=ASAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:detect_leaks=1:halt_on_error=1:allocator_may_return_null=1
test:_asan_runtime_options --test_env=LSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:halt_on_error=1
test:_ubsan_runtime_options --test_env=UBSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:print_stacktrace=1:halt_on_error=1
<...>
test:asan_ubsan_lsan --config=_asan_runtime_options
test:asan_ubsan_lsan --config=_lsan_runtime_options
test:asan_ubsan_lsan --config=_ubsan_runtime_options
<...>
test:asan --config=_asan_runtime_options

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and please use the following runtime options instead:

test:_asan_runtime_options --test_env=ASAN_OPTIONS="exitcode=55 allow_addr2line=1 halt_on_error=1 print_stats=1 verbosity=1 allocator_may_return_null=1 check_initialization_order=1 detect_leaks=1 detect_stack_use_after_return=1 strict_string_checks=1"
test:_lsan_runtime_options --test_env=LSAN_OPTIONS="exitcode=55 allow_addr2line=1 halt_on_error=1 print_stats=1 verbosity=1"
test:_ubsan_runtime_options --test_env=UBSAN_OPTIONS="exitcode=55 allow_addr2line=1 halt_on_error=1 print_stacktrace=1 verbosity=1"
test:_tsan_runtime_options --test_env=TSAN_OPTIONS="exitcode=55 allow_addr2line=1 halt_on_error=1 print_stats=1 verbosity=1 detect_deadlocks=1 second_deadlock_stack=1"


# ThreadSanitizer (for concurrency issues - cannot be combined with ASan)
test:tsan --compilation_mode=dbg
test:tsan --features=tsan
test:tsan --platform_suffix=tsan
Comment on lines +25 to +27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and also for all the other configs:

Suggested change
test:tsan --compilation_mode=dbg
test:tsan --features=tsan
test:tsan --platform_suffix=tsan
build:tsan --features=tsan
build:tsan --platform_suffix=tsan

only the runtime options should get added as test config, the others are build configs!

test:tsan --test_env=TSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:halt_on_error=1:detect_deadlocks=1

# AddressSanitizer only (memory errors, no leak detection)
test:asan --compilation_mode=dbg
test:asan --features=asan
test:asan --platform_suffix=asan
test:asan --test_env=ASAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:detect_leaks=0:halt_on_error=1

# UndefinedBehaviorSanitizer only (undefined behavior detection)
test:ubsan --compilation_mode=dbg
test:ubsan --features=ubsan
test:ubsan --platform_suffix=ubsan
test:ubsan --test_env=UBSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:print_stacktrace=1:halt_on_error=1

# LeakSanitizer only (memory leak detection)
test:lsan --compilation_mode=dbg
test:lsan --features=lsan
test:lsan --platform_suffix=lsan
test:lsan --test_env=LSAN_OPTIONS=exitcode=55:allow_addr2line=1:verbosity=1:halt_on_error=1
17 changes: 17 additions & 0 deletions tests/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

try-import %workspace%/../sanitizer/sanitizer.bazelrc

common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
common --registry=https://bcr.bazel.build
23 changes: 23 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_cc//cc:defs.bzl", "cc_test")

cc_test(
name = "sample_test",
srcs = ["sample_test.cpp"],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
28 changes: 28 additions & 0 deletions tests/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

module(
name = "score_cpp_policies_tests",
version = "0.0.0",
)

bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.2.2")
bazel_dep(name = "score_bazel_platforms", version = "0.0.4")
Comment on lines +21 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two required here? Where are they used actually?


bazel_dep(name = "score_cpp_policies", version = "")
local_path_override(
module_name = "score_cpp_policies",
path = "..",
)
Loading