Skip to content
Merged
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
34 changes: 21 additions & 13 deletions docs/test_suite.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,55 @@ These tests verify that specific toolchain features are correctly implemented an
- Tests strict_warnings, minimal_warnings, warnings_as_errors features
- Includes code patterns that trigger specific warnings

4. **`coverage_test`** - Code coverage instrumentation
4. **`warning_override_test`** - Warning feature override via user flags
- Regression test verifying user flags (copts) can override enabled warning features
- Enables both `strict_warnings` and `warnings_as_errors` features (making warnings into errors)
- Provides conflicting `-Wno-shadow` via copts to override the warning
- Validates that the flag ordering is correct: user_compile_flags comes after warning features,
ensuring user flags take precedence. If ordering regresses, compilation will fail with an error.

5. **`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`

5. **`pic_test`** - Position-Independent Code (`-fPIC`)
6. **`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

6. **`pthread_test`** - POSIX threading support
7. **`pthread_test`** - POSIX threading support
- Verifies `-lpthread` correctly links pthread library
- Tests thread creation, synchronization, and joining
- Validates multiple threads can safely access shared state
Comment on lines 69 to 70

7. **`multifile_test`** - Multi-file compilation and archiving
8. **`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

8. **`whole_archive_test`** - Whole-archive linking (`-Wl,--whole-archive`)
9. **`whole_archive_test`** - Whole-archive linking (`-Wl,--whole-archive`)
- Verifies `-Wl,--whole-archive` and `-Wl,--no-whole-archive` work
- Tests unused library symbols are linked when using whole-archive

9. **`preprocessor_defines_test`** - `preprocessor_defines` feature
10. **`preprocessor_defines_test`** - `preprocessor_defines` feature
- Injects defines via the `local_defines` attribute (routed through the
`preprocessor_defines` feature), unlike `defines_test` which uses `copts`
(routed through `user_compile_flags`)

10. **`include_dir_test`** - `include_paths` via the `includes` attribute
11. **`include_dir_test`** - `include_paths` via the `includes` attribute
- Includes a header exposed through a library's `includes` attribute,
exercising the `-I`/`-isystem` search paths

11. **`user_link_flags_test`** - `user_link_flags` feature
12. **`user_link_flags_test`** - `user_link_flags` feature
- Passes a linker flag through `linkopts` (`-Wl,--defsym=...`) and checks the
injected symbol's address at runtime

12. **`random_seed_test`** - `random_seed` feature
13. **`random_seed_test`** - `random_seed` feature
- Build-and-run smoke test exercising internal-linkage symbols governed by
the reproducible-build random seed

13. **`fully_static_link_test`** - `fully_static_link` feature (`-static`)
14. **`fully_static_link_test`** - `fully_static_link` feature (`-static`)
- Verifies no shared objects are mapped at runtime (fully static binary)
- Marked incompatible with toolchains lacking static system archives (AutoSD)

Expand Down Expand Up @@ -279,16 +286,16 @@ when the host equals the target).

### All tests on the host (`//...`)
```
Executed 13 tests: 13 passed
Executed 20 tests: 20 passed
```

### Feature Verification Tests
- The `feature_verification_tests` suite aggregates 7 tests. `warnings_test`
- The `feature_verification_tests` suite aggregates 13 tests. `warnings_test`
is defined separately and is picked up by wildcard targets such as
`//feature_verification/...`.
- Expected output for the suite:
```
Executed 7 tests: 7 passed
Executed 13 tests: 13 passed
```

### Language and Standards Tests
Expand Down Expand Up @@ -318,6 +325,7 @@ tests/
│ ├── random_seed_test.cpp
│ ├── fully_static_link_test.cpp
│ ├── warnings_test.cpp
│ ├── warning_override_test.cpp
│ ├── coverage_test.cpp
│ ├── pic_test_lib.h/cpp, pic_test.cpp
│ ├── multifile_lib.h and multifile_lib_*.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test_suite(
"//feature_verification:pthread_test",
"//feature_verification:random_seed_test",
"//feature_verification:user_link_flags_test",
"//feature_verification:warning_override_test",
"//feature_verification:whole_archive_test",
],
)
Expand Down
21 changes: 21 additions & 0 deletions tests/feature_verification/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ cc_test(
srcs = ["warnings_test.cpp"],
)

# Test for: warning feature override via user_compile_flags
# Verifies that user-provided flags (via copts) can override enabled warning
# features. This regression test ensures that the flag ordering between warning
# features and user_compile_flags is correct: user_compile_flags must come
# after warning features so that user flags take precedence.
#
# The test enables both strict_warnings and warnings_as_errors (making warnings
# into errors), then provides -Wno-shadow via copts. If the flag ordering is
# correct, the test compiles successfully because user's -Wno-shadow overrides
# the -Wshadow error. If ordering regresses, compilation will fail with a
# -Wshadow error, immediately catching the regression.
cc_test(
name = "warning_override_test",
srcs = ["warning_override_test.cpp"],
copts = ["-Wno-shadow"],
features = [
"strict_warnings",
"warnings_as_errors",
],
)

# Test for: coverage, gcc_coverage_map_format, dependency_file features
# Verifies that code coverage instrumentation is applied. Also used by both
# Linux and QNX CI as the `bazel coverage` smoke test (build/link/execute/gcov
Expand Down
55 changes: 55 additions & 0 deletions tests/feature_verification/warning_override_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/********************************************************************************
* 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
********************************************************************************/

// Test for: warning feature override via user flags (copts)
//
// This test verifies that the ordering between warning features and user flags
// is correct. Specifically, it tests that:
//
// 1. strict_warnings (implies minimal_warnings which enables -Wall) and
// warnings_as_errors are both enabled, making -Wshadow an error
// 2. Code with variable shadowing would trigger an error
// 3. User provides -Wno-shadow via copts (which becomes user_compile_flags)
// 4. The compilation SUCCEEDS because user_compile_flags comes AFTER warning
// features in the features list, making user flags take precedence
//
// If the flag ordering regresses (e.g., warning features come after user flags),
// this test will fail to compile with a -Wshadow error, catching the regression
// immediately.

#include <iostream>

// This function intentionally has variable shadowing, which triggers -Wshadow
// when strict_warnings or all_wall_warnings are enabled. The test provides
// -Wno-shadow via copts, so this should compile successfully if flag ordering
// is correct.
int shadow_function(int value) {
int result = value * 2; // Outer result
int final_result = result; // Use outer result to avoid -Wunused-variable
{
// Intentional shadowing to trigger -Wshadow
int result = value * 3; // Inner result shadows outer
final_result += result; // Use inner result
}
return final_result;
}

int main() {
std::cout << "Warning override test: shadow_function(5) = "
<< shadow_function(5) << std::endl;

std::cout << "Test passed! User -Wno-shadow flag successfully overrode "
<< "the strict_warnings feature." << std::endl;

return 0;
}
Loading