blob: fb5d1def1c7d3731c112e6000666ce300e3f6fa6 [file]
# Copyright 2023 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.
import("//build_overrides/pigweed.gni")
import("$dir_pw_bloat/bloat.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_fuzzer/fuzz_test.gni")
import("$dir_pw_sync/backend.gni")
import("$dir_pw_thread/backend.gni")
import("$dir_pw_unit_test/test.gni")
# The core target of this module.
pw_source_set("pw_allocator") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_allocator/allocator.h",
"public/pw_allocator/capability.h",
"public/pw_allocator/deallocator.h",
"public/pw_allocator/internal/control_block.h",
"public/pw_allocator/internal/managed_ptr.h",
"public/pw_allocator/layout.h",
"public/pw_allocator/pool.h",
"public/pw_allocator/shared_ptr.h",
"public/pw_allocator/unique_ptr.h",
"public/pw_allocator/weak_ptr.h",
]
public_deps = [
":config",
":fragmentation",
":hardening",
"$dir_pw_numeric:checked_arithmetic",
dir_pw_bytes,
dir_pw_preprocessor,
dir_pw_result,
dir_pw_status,
]
deps = [
"$dir_pw_assert:check",
"$dir_pw_bytes:alignment",
"$pw_external_fuchsia:stdcompat",
]
sources = [
"allocator.cc",
"control_block.cc",
"managed_ptr.cc",
]
}
# Module configuration
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_allocator_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}
config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}
pw_source_set("config") {
public = [ "public/pw_allocator/config.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [ pw_allocator_CONFIG ]
}
config("hardening_basic") {
defines = [ "PW_ALLOCATOR_HARDENING=PW_ALLOCATOR_HARDENING_BASIC" ]
}
config("hardening_robust") {
defines = [ "PW_ALLOCATOR_HARDENING=PW_ALLOCATOR_HARDENING_ROBUST" ]
}
config("hardening_debug") {
defines = [ "PW_ALLOCATOR_HARDENING=PW_ALLOCATOR_HARDENING_DEBUG" ]
}
config("test_config") {
defines = [
"PW_ALLOCATOR_HARDENING=PW_ALLOCATOR_HARDENING_DEBUG",
"PW_ALLOCATOR_BLOCK_POISON_INTERVAL=4",
]
}
config("private_override_config") {
include_dirs = [ "private_overrides" ]
visibility = [ ":*" ]
}
# Libraries
pw_source_set("abstract_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/abstract_allocator.h" ]
public_deps = [ ":pw_allocator" ]
}
pw_source_set("allocator_as_pool") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/allocator_as_pool.h" ]
public_deps = [
":pw_allocator",
dir_pw_status,
]
sources = [ "allocator_as_pool.cc" ]
}
pw_source_set("async_pool") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/async_pool.h" ]
public_deps = [
":pw_allocator",
"$dir_pw_async2:pw_async2",
]
sources = [ "async_pool.cc" ]
}
pw_source_set("best_fit") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/best_fit.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
"bucket:fast_sorted",
"bucket:sorted",
]
}
pw_source_set("block_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/block_allocator.h" ]
public_deps = [
":config",
":fragmentation",
":hardening",
":pw_allocator",
"$dir_pw_assert:assert",
"block:allocatable",
"block:basic",
"block:iterable",
"block:poisonable",
"block:result",
"block:with_layout",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
]
deps = [ "$dir_pw_assert:check" ]
sources = [ "block_allocator.cc" ]
}
pw_source_set("bucket_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/bucket_allocator.h" ]
public_deps = [
":block_allocator",
"block:detailed_block",
"bucket:unordered",
dir_pw_status,
]
}
pw_source_set("buddy_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/buddy_allocator.h" ]
public_deps = [
":abstract_allocator",
":hardening",
"$dir_pw_containers:vector",
"block:basic",
"bucket:unordered",
dir_pw_bytes,
dir_pw_status,
]
deps = [
"$dir_pw_assert:check",
"$dir_pw_bytes:alignment",
"$pw_external_fuchsia:stdcompat",
]
sources = [ "buddy_allocator.cc" ]
}
pw_source_set("bump_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/bump_allocator.h" ]
public_deps = [
":abstract_allocator",
":pw_allocator",
"$dir_pw_bytes:alignment",
dir_pw_bytes,
]
sources = [ "bump_allocator.cc" ]
}
pw_source_set("chunk_pool") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/chunk_pool.h" ]
public_deps = [
":pw_allocator",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
]
deps = [
"$dir_pw_assert:check",
"$dir_pw_bytes:alignment",
"$pw_external_fuchsia:stdcompat",
]
sources = [ "chunk_pool.cc" ]
}
pw_source_set("dl_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/dl_allocator.h" ]
public_deps = [
":block_allocator",
":config",
"$pw_external_fuchsia:stdcompat",
"block:detailed_block",
"bucket:fast_sorted",
"bucket:unordered",
]
}
pw_source_set("fallback_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/fallback_allocator.h" ]
public_deps = [
":pw_allocator",
dir_pw_result,
dir_pw_status,
]
sources = [ "fallback_allocator.cc" ]
deps = [ "$dir_pw_assert:check" ]
}
pw_source_set("first_fit") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/first_fit.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
"bucket:sequenced",
]
}
pw_source_set("fragmentation") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/fragmentation.h" ]
sources = [ "fragmentation.cc" ]
deps = [
"$dir_pw_assert:check",
"$dir_pw_numeric:checked_arithmetic",
]
}
pw_source_set("freertos_allocator") {
public_deps = [ ":freertos_allocator_headers" ]
deps = [ "$pw_external_freertos" ]
sources = [ "freertos_allocator.cc" ]
}
# Provide a separate header library to allow the unit tests to use a stub
# implementation of FreeRTOS.
pw_source_set("freertos_allocator_headers") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/freertos_allocator.h" ]
public_deps = [ ":abstract_allocator" ]
}
pw_source_set("guarded_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/guarded_allocator.h" ]
public_deps = [
":pw_allocator",
":synchronized_allocator",
"$dir_pw_sync:borrow",
dir_pw_result,
]
deps = [
"$dir_pw_bytes:alignment",
"$dir_pw_third_party/fuchsia:stdcompat",
dir_pw_assert,
dir_pw_span,
]
sources = [ "guarded_allocator.cc" ]
}
pw_source_set("hardening") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/hardening.h" ]
public_deps = [
":config",
"$dir_pw_assert:assert",
"$dir_pw_numeric:checked_arithmetic",
]
}
pw_source_set("libc_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/libc_allocator.h" ]
public_deps = [
":abstract_allocator",
":pw_allocator",
]
sources = [ "libc_allocator.cc" ]
}
pw_source_set("null_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/null_allocator.h" ]
public_deps = [
":abstract_allocator",
":pw_allocator",
]
sources = [ "null_allocator.cc" ]
}
pw_source_set("metrics") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/metrics.h" ]
public_deps = [
":pw_allocator",
dir_pw_metric,
]
}
pw_source_set("pmr_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/pmr_allocator.h" ]
public_deps = [
":config",
":pw_allocator",
dir_pw_status,
]
sources = [ "pmr_allocator.cc" ]
deps = [ "$dir_pw_assert:check" ]
}
pw_source_set("synchronized_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/synchronized_allocator.h" ]
public_deps = [
":pw_allocator",
"$dir_pw_sync:borrow",
"$dir_pw_sync:lock_annotations",
"$dir_pw_sync:no_lock",
]
}
pw_source_set("tlsf_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/tlsf_allocator.h" ]
public_deps = [
":block_allocator",
":config",
"$pw_external_fuchsia:stdcompat",
"block:detailed_block",
"bucket:fast_sorted",
"bucket:sorted",
]
}
pw_source_set("tracking_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/tracking_allocator.h" ]
public_deps = [
":metrics",
":pw_allocator",
"$dir_pw_assert:assert",
dir_pw_status,
]
}
pw_source_set("typed_pool") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/typed_pool.h" ]
public_deps = [
":chunk_pool",
":hardening",
dir_pw_bytes,
]
}
pw_source_set("worst_fit") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/worst_fit.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
"bucket:fast_sorted",
"bucket:sorted",
]
}
# Test support
pw_source_set("testing") {
public_configs = [ ":test_config" ]
public = [
"public/pw_allocator/fault_injecting_allocator.h",
"public/pw_allocator/testing.h",
]
public_deps = [
":first_fit",
":hardening",
":metrics",
":pw_allocator",
":tracking_allocator",
"$dir_pw_assert:assert",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
dir_pw_unit_test,
]
}
pw_source_set("block_allocator_testing") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/block_allocator_testing.h" ]
public_deps = [
":block_allocator",
":fuzzing",
":pw_allocator",
":test_harness",
"$dir_pw_assert:assert",
"$dir_pw_bytes:alignment",
"$pw_external_fuchsia:stdcompat",
"block:detailed_block",
"block:testing",
dir_pw_status,
dir_pw_unit_test,
]
}
pw_source_set("counter") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/internal/counter.h" ]
public_deps = [
":pw_allocator",
":testing",
dir_pw_unit_test,
]
sources = [ "counter.cc" ]
}
pw_source_set("freertos_testing") {
testonly = pw_unit_test_TESTONLY
visibility = [ "$dir_pw_allocator/*" ]
public_configs = [ ":private_override_config" ]
public = [ "private_overrides/FreeRTOS.h" ]
sources = [ "freertos_testing.cc" ]
deps = [
":pw_allocator",
":testing",
]
}
pw_source_set("sync_allocator_testing") {
public_configs = [ ":test_config" ]
public = [ "public/pw_allocator/sync_allocator_testing.h" ]
public_deps = [
"$dir_pw_containers:vector",
"$dir_pw_sync:binary_semaphore",
"$dir_pw_thread:test_thread_context",
"$dir_pw_thread:thread",
"$dir_pw_thread:thread_core",
"$dir_pw_unit_test",
dir_pw_allocator,
]
deps = [
"$dir_pw_status",
"$dir_pw_thread:yield",
]
sources = [ "sync_allocator_testing.cc" ]
}
pw_source_set("test_harness") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/test_harness.h" ]
public_deps = [
":pw_allocator",
"$dir_pw_containers:intrusive_list",
"$dir_pw_containers:vector",
dir_pw_random,
]
deps = [
"$dir_pw_assert:assert",
"$dir_pw_assert:check",
"$pw_external_fuchsia:stdcompat",
]
sources = [ "test_harness.cc" ]
}
pw_source_set("fuzzing") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/fuzzing.h" ]
public_deps = [
":pw_allocator",
":test_harness",
"$dir_pw_fuzzer:fuzztest",
]
sources = [ "fuzzing.cc" ]
}
# Tests
pw_test("allocator_as_pool_test") {
deps = [
":allocator_as_pool",
":pw_allocator",
":testing",
]
sources = [ "allocator_as_pool_test.cc" ]
}
pw_test("allocator_test") {
deps = [
":counter",
":pw_allocator",
":testing",
]
sources = [ "allocator_test.cc" ]
}
pw_test("async_pool_test") {
deps = [
":async_pool",
":chunk_pool",
":pw_allocator",
":testing",
"$dir_pw_async2:testing",
]
sources = [ "async_pool_test.cc" ]
}
pw_test("best_fit_test") {
deps = [
":best_fit",
":block_allocator_testing",
]
sources = [ "best_fit_test.cc" ]
}
pw_test("bucket_allocator_test") {
deps = [
":block_allocator_testing",
":bucket_allocator",
":pw_allocator",
]
sources = [ "bucket_allocator_test.cc" ]
}
pw_test("buddy_allocator_test") {
deps = [
":buddy_allocator",
":fuzzing",
":testing",
"$dir_pw_bytes:alignment",
]
sources = [ "buddy_allocator_test.cc" ]
}
pw_test("bump_allocator_test") {
deps = [
":bump_allocator",
":testing",
"$pw_external_fuchsia:stdcompat",
]
sources = [ "bump_allocator_test.cc" ]
}
pw_test("chunk_pool_test") {
deps = [
":chunk_pool",
":counter",
":testing",
]
sources = [ "chunk_pool_test.cc" ]
}
pw_test("dl_allocator_test") {
deps = [
":block_allocator_testing",
":dl_allocator",
]
sources = [ "dl_allocator_test.cc" ]
}
pw_test("fault_injecting_allocator_test") {
deps = [ ":testing" ]
sources = [ "fault_injecting_allocator_test.cc" ]
}
pw_test("fallback_allocator_test") {
deps = [
":fallback_allocator",
":testing",
dir_pw_status,
]
sources = [ "fallback_allocator_test.cc" ]
}
pw_test("first_fit_test") {
deps = [
":block_allocator_testing",
":first_fit",
"$pw_external_fuchsia:stdcompat",
"block:detailed_block",
]
sources = [ "first_fit_test.cc" ]
}
pw_test("fragmentation_test") {
deps = [
":fragmentation",
":testing",
]
sources = [ "fragmentation_test.cc" ]
}
pw_test("freertos_allocator_test") {
deps = [
":freertos_allocator_headers",
":freertos_testing",
":testing",
]
sources = [
"freertos_allocator.cc",
"freertos_allocator_test.cc",
]
}
pw_test("guarded_allocator_test") {
enable_if =
pw_sync_BINARY_SEMAPHORE_BACKEND != "" && pw_sync_MUTEX_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
pw_thread_YIELD_BACKEND != "" &&
pw_thread_TEST_THREAD_CONTEXT_BACKEND != ""
deps = [
":first_fit",
":guarded_allocator",
":sync_allocator_testing",
"$dir_pw_sync:interrupt_spin_lock",
"$dir_pw_sync:mutex",
]
sources = [ "guarded_allocator_test.cc" ]
}
pw_test("layout_test") {
deps = [
":pw_allocator",
":testing",
dir_pw_result,
dir_pw_status,
]
sources = [ "layout_test.cc" ]
}
pw_test("libc_allocator_test") {
deps = [
":libc_allocator",
":testing",
]
sources = [ "libc_allocator_test.cc" ]
}
pw_test("metrics_test") {
deps = [ ":metrics" ]
sources = [ "metrics_test.cc" ]
}
pw_test("null_allocator_test") {
deps = [
":null_allocator",
":testing",
]
sources = [ "null_allocator_test.cc" ]
}
pw_test("pmr_allocator_test") {
deps = [
":pmr_allocator",
":testing",
]
sources = [ "pmr_allocator_test.cc" ]
}
pw_test("shared_ptr_test") {
deps = [
":counter",
":pw_allocator",
":testing",
]
sources = [ "shared_ptr_test.cc" ]
}
pw_test("synchronized_allocator_test") {
enable_if =
pw_sync_BINARY_SEMAPHORE_BACKEND != "" && pw_sync_MUTEX_BACKEND != "" &&
pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" &&
pw_thread_YIELD_BACKEND != "" &&
pw_thread_TEST_THREAD_CONTEXT_BACKEND != ""
deps = [
":sync_allocator_testing",
":synchronized_allocator",
":test_harness",
":testing",
"$dir_pw_sync:interrupt_spin_lock",
"$dir_pw_sync:mutex",
]
sources = [ "synchronized_allocator_test.cc" ]
}
pw_test("tlsf_allocator_test") {
deps = [
":block_allocator_testing",
":tlsf_allocator",
]
sources = [ "tlsf_allocator_test.cc" ]
}
pw_test("tracking_allocator_test") {
deps = [
":first_fit",
":metrics",
":pw_allocator",
":testing",
":tracking_allocator",
dir_pw_log,
dir_pw_metric,
]
sources = [ "tracking_allocator_test.cc" ]
}
pw_test("typed_pool_test") {
deps = [
":pw_allocator",
":testing",
":typed_pool",
"$dir_pw_bytes:alignment",
]
sources = [ "typed_pool_test.cc" ]
}
pw_test("unique_ptr_test") {
deps = [
":counter",
":pw_allocator",
":testing",
]
sources = [ "unique_ptr_test.cc" ]
negative_compilation_tests = true
}
pw_test("weak_ptr_test") {
deps = [
":counter",
":pw_allocator",
":testing",
]
sources = [ "weak_ptr_test.cc" ]
}
pw_test("worst_fit_test") {
deps = [
":block_allocator_testing",
":worst_fit",
]
sources = [ "worst_fit_test.cc" ]
}
pw_test_group("tests") {
tests = [
":allocator_as_pool_test",
":allocator_test",
":best_fit_test",
":bucket_allocator_test",
":buddy_allocator_test",
":bump_allocator_test",
":chunk_pool_test",
":dl_allocator_test",
":fault_injecting_allocator_test",
":fallback_allocator_test",
":first_fit_test",
":fragmentation_test",
":freertos_allocator_test",
":guarded_allocator_test",
":layout_test",
":libc_allocator_test",
":metrics_test",
":null_allocator_test",
":pmr_allocator_test",
":shared_ptr_test",
":synchronized_allocator_test",
":tlsf_allocator_test",
":tracking_allocator_test",
":typed_pool_test",
":unique_ptr_test",
":weak_ptr_test",
":worst_fit_test",
]
group_deps = [
"benchmarks:tests",
"block:tests",
"bucket:tests",
]
}