pw_unit_test: Make framework memory pool size configurable Tested: Configured value on sh build, size of bundle changed. Change-Id: Iac834fbf8bef078fd9b2ddd6207831c5d467519b Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/45440 Commit-Queue: Max Koopman <koopman@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_unit_test/BUILD b/pw_unit_test/BUILD index 99c9eec..312efde 100644 --- a/pw_unit_test/BUILD +++ b/pw_unit_test/BUILD
@@ -23,6 +23,12 @@ licenses(["notice"]) # Apache License 2.0 pw_cc_library( + name = "config", + hdrs = ["public/pw_unit_test/config.h"], + includes = ["public"], +) + +pw_cc_library( name = "pw_unit_test", srcs = [ "framework.cc", @@ -37,6 +43,7 @@ "public_overrides", ], deps = [ + ":config", "//pw_polyfill", "//pw_preprocessor", "//pw_string",
diff --git a/pw_unit_test/BUILD.gn b/pw_unit_test/BUILD.gn index aa80fb9..2f36f7b 100644 --- a/pw_unit_test/BUILD.gn +++ b/pw_unit_test/BUILD.gn
@@ -14,11 +14,19 @@ import("//build_overrides/pigweed.gni") +import("$dir_pw_build/module_config.gni") import("$dir_pw_build/target_types.gni") import("$dir_pw_docgen/docs.gni") import("$dir_pw_protobuf_compiler/proto.gni") import("$dir_pw_unit_test/test.gni") +declare_args() { + # The build target that overrides the default configuration options for this + # module. This should point to a source set that provides defines through a + # public config (which may -include a file or add defines directly). + pw_unit_test_CONFIG = pw_build_DEFAULT_MODULE_CONFIG +} + config("default_config") { include_dirs = [ "public", @@ -26,10 +34,21 @@ ] } +pw_source_set("config") { + public = [ "public/pw_unit_test/config.h" ] + public_configs = [ ":default_config" ] + public_deps = [ + dir_pw_polyfill, + pw_unit_test_CONFIG, + ] + visibility = [ ":*" ] +} + # pw_unit_test core library. pw_source_set("pw_unit_test") { public_configs = [ ":default_config" ] public_deps = [ + ":config", dir_pw_polyfill, dir_pw_preprocessor, dir_pw_string,
diff --git a/pw_unit_test/docs.rst b/pw_unit_test/docs.rst index ac16271..e2fd02d 100644 --- a/pw_unit_test/docs.rst +++ b/pw_unit_test/docs.rst
@@ -288,3 +288,13 @@ ^^^^^^^^^^^^^^^^ .. automodule:: pw_unit_test.rpc :members: EventHandler, run_tests + +Module Configuration Options +============================ +The following configurations can be adjusted via compile-time configuration of +this module. + +.. c:macro:: PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE + + The size of the memory pool to use for test fixture instances. By default this + is set to 16K.
diff --git a/pw_unit_test/public/pw_unit_test/config.h b/pw_unit_test/public/pw_unit_test/config.h new file mode 100644 index 0000000..acdffd4 --- /dev/null +++ b/pw_unit_test/public/pw_unit_test/config.h
@@ -0,0 +1,35 @@ +// Copyright 2021 The Pigweed Authors +// +// 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 +// +// https://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. + +// Configuration macros for the unit test module. +#pragma once + +#include <cstddef> + +#include "pw_polyfill/language_feature_macros.h" + +#ifndef PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE +#define PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE 16384 +#endif // PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE + +namespace pw { +namespace unit_test { +namespace config { + +PW_INLINE_VARIABLE constexpr size_t kMemoryPoolSize = + PW_UNIT_TEST_CONFIG_MEMORY_POOL_SIZE; + +} // namespace config +} // namespace unit_test +} // namespace pw
diff --git a/pw_unit_test/public/pw_unit_test/framework.h b/pw_unit_test/public/pw_unit_test/framework.h index 959cef8..6ba5d94 100644 --- a/pw_unit_test/public/pw_unit_test/framework.h +++ b/pw_unit_test/public/pw_unit_test/framework.h
@@ -26,6 +26,7 @@ #include "pw_polyfill/standard.h" #include "pw_preprocessor/concat.h" #include "pw_preprocessor/util.h" +#include "pw_unit_test/config.h" #include "pw_unit_test/event_handler.h" #if PW_CXX_STANDARD_IS_SUPPORTED(17) @@ -300,10 +301,7 @@ std::span<std::string_view> test_suites_to_run_; #endif // PW_CXX_STANDARD_IS_SUPPORTED(17) - // Memory region in which to construct test case classes as they are run. - // TODO(frolv): Make the memory pool size configurable. - static constexpr size_t kTestMemoryPoolSizeBytes = 16384; - std::aligned_storage_t<kTestMemoryPoolSizeBytes, alignof(std::max_align_t)> + std::aligned_storage_t<config::kMemoryPoolSize, alignof(std::max_align_t)> memory_pool_; };