From a6219434b97af42b310c39f4c60dd5e76d81c8b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 20:52:53 -1000 Subject: [PATCH] Move core benchmarks to tests/benchmarks/core/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core is not a component — its benchmarks belong in tests/benchmarks/core/ not tests/benchmarks/components/core/. Add extra_include_dirs parameter to build_and_run to support non-component benchmark directories. --- script/cpp_benchmark.py | 4 ++++ script/test_helpers.py | 15 ++++++++++++++- .../core/bench_application_loop.cpp | 0 .../{components => }/core/bench_helpers.cpp | 0 .../{components => }/core/bench_scheduler.cpp | 0 5 files changed, 18 insertions(+), 1 deletion(-) rename tests/benchmarks/{components => }/core/bench_application_loop.cpp (100%) rename tests/benchmarks/{components => }/core/bench_helpers.cpp (100%) rename tests/benchmarks/{components => }/core/bench_scheduler.cpp (100%) diff --git a/script/cpp_benchmark.py b/script/cpp_benchmark.py index f630aac3d44..31a6896f477 100755 --- a/script/cpp_benchmark.py +++ b/script/cpp_benchmark.py @@ -11,6 +11,9 @@ from test_helpers import PLATFORMIO_GOOGLE_BENCHMARK_LIB, build_and_run # Path to /tests/benchmarks/components BENCHMARKS_DIR: Path = Path(root_path) / "tests" / "benchmarks" / "components" +# Path to /tests/benchmarks/core (always included, not a component) +CORE_BENCHMARKS_DIR: Path = Path(root_path) / "tests" / "benchmarks" / "core" + # Components whose to_code should run during benchmark builds. # core/host/logger are infrastructure. json is needed because its # to_code adds the ArduinoJson library (it's auto-loaded by api but @@ -37,6 +40,7 @@ def run_benchmarks(selected_components: list[str], build_only: bool = False) -> main_entry="main.cpp", label="benchmarks", build_only=build_only, + extra_include_dirs=[CORE_BENCHMARKS_DIR], ) diff --git a/script/test_helpers.py b/script/test_helpers.py index 3a7e23c0a78..fa79210172b 100644 --- a/script/test_helpers.py +++ b/script/test_helpers.py @@ -300,6 +300,7 @@ def build_and_run( label: str = "build", build_only: bool = False, extra_run_args: list[str] | None = None, + extra_include_dirs: list[Path] | None = None, ) -> int: """Build and optionally run a C++ test/benchmark binary. @@ -318,6 +319,8 @@ def build_and_run( label: Label for log messages build_only: If True, print binary path and return without running extra_run_args: Extra arguments to pass to the binary + extra_include_dirs: Additional directories (relative to tests_dir) + whose .cpp files should be compiled Returns: Exit code @@ -339,8 +342,18 @@ def build_and_run( components = sorted(components) - # Build include list: main entry point + component folders + # Build include list: main entry point + component folders + extra dirs includes: list[str] = [main_entry] + components + if extra_include_dirs: + for d in extra_include_dirs: + if d.is_dir() and (any(d.glob("*.cpp")) or any(d.glob("*.h"))): + # Use path relative to tests_dir for PlatformIO includes + try: + rel = d.relative_to(tests_dir) + includes.append(str(rel)) + except ValueError: + # Not relative to tests_dir, use absolute + includes.append(str(d)) # Discover platform sub-components try: diff --git a/tests/benchmarks/components/core/bench_application_loop.cpp b/tests/benchmarks/core/bench_application_loop.cpp similarity index 100% rename from tests/benchmarks/components/core/bench_application_loop.cpp rename to tests/benchmarks/core/bench_application_loop.cpp diff --git a/tests/benchmarks/components/core/bench_helpers.cpp b/tests/benchmarks/core/bench_helpers.cpp similarity index 100% rename from tests/benchmarks/components/core/bench_helpers.cpp rename to tests/benchmarks/core/bench_helpers.cpp diff --git a/tests/benchmarks/components/core/bench_scheduler.cpp b/tests/benchmarks/core/bench_scheduler.cpp similarity index 100% rename from tests/benchmarks/components/core/bench_scheduler.cpp rename to tests/benchmarks/core/bench_scheduler.cpp