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>
This commit is contained in:
Max Koopman 2021-05-14 11:01:55 -07:00 committed by CQ Bot Account
parent dfa75eee6f
commit f4789286cc
5 changed files with 73 additions and 4 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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.

View File

@ -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

View File

@ -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<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_;
};