This document provides comprehensive information about the SCORE Bazel C++ toolchain test suite, which validates toolchain functionality across different platforms and language standards.
The test suite is organized into two main categories:
- Feature Verification Tests - Validate specific toolchain compilation and linking features
- Language and Standards Tests - Verify support for different programming languages and C++ standards
All tests are located in the tests/ directory of the repository.
All tests are defined in a separate Bazel workspace; therefore, Bazel commands must be run from the tests/ directory.
Run all tests:
bazel test --config x86_64-linux //...Run specific test suites:
bazel test --config x86_64-linux //:feature_verification_tests
bazel test --config x86_64-linux //:language_and_standards_testsThese tests verify that specific toolchain features are correctly implemented and functioning. They validate compilation flags, linking behavior, and advanced toolchain capabilities.
-
defines_test- Preprocessor defines (-Dflags)- Verifies preprocessor defines are applied during compilation
- Tests multiple defines can be specified via
copts
-
include_paths_test- Include path handling (-I,-iquote,-isystem)- Validates
-Iinclude directories are correctly handled - Tests
-iquotequote search paths - Verifies
-isystemsystem include paths
- Validates
-
warnings_test- Warning level configuration- Tests strict_warnings, minimal_warnings, warnings_as_errors features
- Includes code patterns that trigger specific warnings
-
coverage_test- Code coverage instrumentation- Verifies code coverage instrumentation flags are applied
- Provides multiple code paths for coverage analysis
- Can be analyzed with:
bazel coverage --combined_report=lcov //feature_verification:coverage_test
-
pic_test- Position-Independent Code (-fPIC)- Tests -fPIC flag is correctly applied
- Validates position-independent code patterns
- Tests polymorphism, static variables, and C linkage with PIC
-
pthread_test- POSIX threading support- Verifies
-lpthreadcorrectly links pthread library - Tests thread creation, synchronization, and joining
- Validates multiple threads can safely access shared state
- Verifies
-
multifile_test- Multi-file compilation and archiving- Tests multiple source files compile into separate object files
- Validates object files are combined by archiver into static libraries
- Complex operations across multiple object files link correctly
-
whole_archive_test- Whole-archive linking (-Wl,--whole-archive)- Verifies
-Wl,--whole-archiveand-Wl,--no-whole-archivework - Tests unused library symbols are linked when using whole-archive
- Verifies
-
preprocessor_defines_test-preprocessor_definesfeature- Injects defines via the
local_definesattribute (routed through thepreprocessor_definesfeature), unlikedefines_testwhich usescopts(routed throughuser_compile_flags)
- Injects defines via the
-
include_dir_test-include_pathsvia theincludesattribute- Includes a header exposed through a library's
includesattribute, exercising the-I/-isystemsearch paths
- Includes a header exposed through a library's
-
user_link_flags_test-user_link_flagsfeature- Passes a linker flag through
linkopts(-Wl,--defsym=...) and checks the injected symbol's address at runtime
- Passes a linker flag through
-
random_seed_test-random_seedfeature- Build-and-run smoke test exercising internal-linkage symbols governed by the reproducible-build random seed
-
fully_static_link_test-fully_static_linkfeature (-static)- Verifies no shared objects are mapped at runtime (fully static binary)
- Marked incompatible with toolchains lacking static system archives (AutoSD)
Opt-in feature tests (
tests/feature_verification/opt_in_features/) cover features that are disabled by default or only emit flags under a specific build mode (per_object_debug_info,fission_support,linkstamps,includes,force_pic_flags,strip_debug_symbols,static_libgcc). They are taggedmanualand excluded from CI (exceptforce_pic_flags_test, run in a dedicated--force_picCI step). See that package's BUILD file for the exact command to exercise each one.
# All feature verification tests
bazel test --config x86_64-linux //:feature_verification_tests
# Individual tests
bazel test --config x86_64-linux //feature_verification:defines_test
bazel test --config x86_64-linux //feature_verification:pic_test
bazel test --config x86_64-linux //feature_verification:pthread_testThe feature verification tests cover 16 implemented toolchain features:
- ✅
random_seed- Deterministic builds - ✅
include_paths- Header search paths - ✅
preprocessor_defines- Macro definitions - ✅
user_compile_flags- Custom compilation flags - ✅
compiler_input_flags- Input file handling - ✅
compiler_output_flags- Output file handling - ✅
archiver_flags- Static library creation - ✅
user_link_flags- Custom linking flags - ✅
linker_param_file- Parameter file support - ✅
library_search_directories- Library path handling - ✅
shared_flag- Shared library compilation - ✅
output_execpath_flags- Executable output - ✅
libraries_to_link- Library linking (static, dynamic, whole-archive) - ✅
coverage- Code coverage instrumentation - ✅
supports_pic- Position-independent code - ✅
pthread- POSIX threading
These tests verify support for different programming languages and C++ standard versions. All tests execute on the host machine (Linux x86_64) and provide immediate feedback on toolchain language support.
-
c_lang_test- C language support (C99 and later)- Struct packing with
#pragma pack - Designated initializers (C99)
- Compound literals
- Loop variable declarations
- Restrict keyword
- Struct packing with
-
cpp11_test- C++11 language featuresautokeywordnullptr- Range-based for loops
- Lambda expressions
- Smart pointers (
unique_ptr,shared_ptr) - Move semantics
- Variadic templates
- Rvalue references
-
cpp14_test- C++14 language features- Auto return type deduction
- Generic lambdas
std::make_unique- Variable templates
- Binary literals (
0b1010) - Digit separators (
1'000'000) - Relaxed constexpr
- Tuple support
-
cpp17_test- C++17 language features- Structured bindings (
auto [x, y] = point;) if constexprstd::optionalstd::variantstd::string_view- Fold expressions
- Inline variables
- Nested namespaces (
namespace A::B::C {})
- Structured bindings (
-
cpp20_test- C++20 language features- Concepts and concept constraints
std::span- Designated initializers (enhanced)
- Spaceship operator (
<=>) - Ranges and views
consteval- Requires clauses
- Three-way comparison
# All language and standards tests
bazel test --config x86_64-linux //:language_and_standards_tests
# Individual tests
bazel test --config x86_64-linux //language_and_standards:c_lang_test
bazel test --config x86_64-linux //language_and_standards:cpp11_test
bazel test --config x86_64-linux //language_and_standards:cpp20_testEach test is compiled with specific flags to enable the corresponding language standard:
| Test | Compilation Flag | GCC Version Required |
|---|---|---|
| c_lang_test | -std=c99 | Any (C99 support) |
| cpp11_test | -std=c++11 | GCC 4.8+ |
| cpp14_test | -std=c++14 | GCC 5+ |
| cpp17_test | -std=c++17 | GCC 7+ |
| cpp20_test | -std=c++20 | GCC 10+ |
# Run all tests
bazel test --config x86_64-linux //...
# Run with verbose output
bazel test --config x86_64-linux --test_output=all //feature_verification:defines_test
# Run specific test directory
bazel test --config x86_64-linux //feature_verification/...
bazel test --config x86_64-linux //language_and_standards/...Bazel test compiles a test binary and executes it. A binary built for a
target platform can only be executed on that target platform (or a
binary-compatible one). This has a direct consequence for how the suites are
run:
bazel testis only valid when the execution machine matches the target platform. When the host equals the target — for example running thex86_64-linuxconfig on anx86_64Linux host — the binaries build and run directly on the host.- For every other configuration the tests must be executed on the
corresponding target platform. On a non-matching host, use
bazel buildto verify only compilation and linking, then deploy and run the resulting binaries on the target — or invokebazel testdirectly from that target platform.
# Host is the target: binaries build and execute locally
bazel test --config x86_64-linux //...Configs such as x86_64-qnx, aarch64-qnx, aarch64-linux,
x86_64-linux-autosd10, and aarch64-linux-ebclfsa target platforms that
differ from a typical x86_64 Linux host. Do not run bazel test for these
configs on the host — the produced binaries are not executable there.
# On the host: verify compilation and linking only (no execution)
bazel build --config x86_64-qnx //...
bazel build --config aarch64-qnx //...
bazel build --config aarch64-linux //...
# On the matching target platform: build and execute the tests
bazel test --config x86_64-qnx //...IMPORTANT:
x86_64-qnxtests must be executed on anx86_64QNX system,aarch64-qnxtests on anaarch64QNX system,aarch64-linuxtests on anaarch64Linux system, and so on. Running them on a mismatched host will fail because the test binaries cannot be executed there.
The counts below assume execution on a matching target platform (or the host when the host equals the target).
Executed 13 tests: 13 passed
- The
feature_verification_testssuite aggregates 7 tests.warnings_testis defined separately and is picked up by wildcard targets such as//feature_verification/.... - Expected output for the suite:
Executed 7 tests: 7 passed
- All 5 tests pass when executed on a matching target platform.
- Each test verifies the appropriate language features and standard version.
- Expected output:
Executed 5 tests: 5 passed
tests/
├── BUILD # Root build file
├── README.md # Quick reference
├── feature_verification/
│ ├── BUILD # Feature test definitions
│ ├── feature_test.h/cpp # Test infrastructure
│ ├── defines_test.cpp # Individual feature tests
│ ├── preprocessor_defines_test.cpp
│ ├── include_paths_test.cpp
│ ├── include_dir/custom_math.h and include_dir_test.cpp
│ ├── user_link_flags_test.cpp
│ ├── random_seed_test.cpp
│ ├── fully_static_link_test.cpp
│ ├── warnings_test.cpp
│ ├── coverage_test.cpp
│ ├── pic_test_lib.h/cpp, pic_test.cpp
│ ├── multifile_lib.h and multifile_lib_*.cpp
│ ├── multifile_test.cpp
│ ├── whole_archive_lib.h/cpp
│ ├── whole_archive_test.cpp
│ ├── pthread_test_lib.h/cpp
│ ├── pthread_test.cpp
│ └── opt_in_features/ # Manual, disabled-by-default features
│ ├── BUILD
│ ├── opt_in_smoke.cpp
│ └── force_pic_test.cpp
└── language_and_standards/
├── BUILD # Language test definitions
├── c_lang_test.c # C language tests
├── cpp11_test.cpp # C++11 tests
├── cpp14_test.cpp # C++14 tests
├── cpp17_test.cpp # C++17 tests
└── cpp20_test.cpp # C++20 tests
- Feature Isolation - Each test targets a specific feature or small group of related features
- Self-Contained - Tests include all necessary source code and infrastructure
- Minimal Dependencies - External dependencies are limited to standard libraries
- Clear Output - Each test produces clear pass/fail output for verification
- Cross-Platform - Feature tests work on both native and cross-compilation platforms
Issue: Test fails to compile with -std=c++XX flags
# Solution: Check if compiler supports the requested C++ standard
g++ --versionIssue: Cross-compilation tests fail with architecture mismatch
This happens when bazel test is run for a target platform on a mismatched
host. Build only on the host, then execute the tests on the matching target
platform:
# On the host: build only (no execution)
bazel build --config aarch64-qnx //...
# On the matching target platform: build and execute
bazel test --config aarch64-qnx //...Issue: Tests timeout or hang
# Solution: Get detailed timeout information
bazel test --config x86_64-linux --test_verbose_timeout_warnings //...Issue: Cannot find pthread library
# Solution: Install pthread development library
sudo apt-get install libpthread-stubs0-devIssue: Assertion failures in test output
# Solution: Run with full output for debugging
bazel test --config x86_64-linux --test_output=all //language_and_standards:cpp20_testIssue: Error about unsupported language feature
# Solution: Upgrade GCC to a version supporting the feature
sudo apt-get install g++-11
# Set as default
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
# Verify new version
g++ --version- Create test source files in
tests/feature_verification/ - Add library targets (if needed) and test target in BUILD file:
cc_test( name = "my_feature_test", srcs = ["my_feature_test.cpp"], copts = ["-DTEST_FEATURE=1"], deps = [":feature_test_lib"], )
- Add test name to
feature_verification_testssuite in BUILD - Document the test in this file
- Create test source file in
tests/language_and_standards/ - Add test target in BUILD file:
cc_test( name = "cpp23_test", srcs = ["cpp23_test.cpp"], copts = ["-std=c++23"], )
- Add test name to
language_and_standards_testssuite in BUILD - Document the test in this file
The test suite can be integrated into continuous integration pipelines:
# Full validation (native + cross-compilation builds)
bazel test --config x86_64-linux //language_and_standards/...
bazel build --config aarch64-qnx //feature_verification/...
# Generate test reports
bazel test --config x86_64-linux --test_summary=detailed //...- Feature Verification Tests: ~10-30 seconds total
- Language and Standards Tests: ~20-50 seconds total
- Full Suite: ~30-80 seconds total (depends on compiler and system)