From f4789286cc5662ce44a7684b3f9e7974bd41643c Mon Sep 17 00:00:00 2001 From: Max Koopman Date: Fri, 14 May 2021 11:01:55 -0700 Subject: [PATCH] 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 Reviewed-by: Wyatt Hepler --- pw_unit_test/BUILD | 7 ++++ pw_unit_test/BUILD.gn | 19 +++++++++++ pw_unit_test/docs.rst | 10 ++++++ pw_unit_test/public/pw_unit_test/config.h | 35 ++++++++++++++++++++ pw_unit_test/public/pw_unit_test/framework.h | 6 ++-- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 pw_unit_test/public/pw_unit_test/config.h diff --git a/pw_unit_test/BUILD b/pw_unit_test/BUILD index 99c9eeced..312efde3a 100644 --- a/pw_unit_test/BUILD +++ b/pw_unit_test/BUILD @@ -22,6 +22,12 @@ package(default_visibility = ["//visibility:public"]) 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 = [ @@ -37,6 +43,7 @@ pw_cc_library( "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 aa80fb9e0..2f36f7ba1 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 @@ config("default_config") { ] } +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 ac16271b5..e2fd02d24 100644 --- a/pw_unit_test/docs.rst +++ b/pw_unit_test/docs.rst @@ -288,3 +288,13 @@ pw_unit_test.rpc ^^^^^^^^^^^^^^^^ .. 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 000000000..acdffd491 --- /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 + +#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 959cef874..6ba5d9410 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 @@ class Framework { std::span 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 + std::aligned_storage_t memory_pool_; };