| # 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_allocator/allocator.gni") |
| import("$dir_pw_bloat/bloat.gni") |
| import("$dir_pw_build/target_types.gni") |
| import("$dir_pw_docgen/docs.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") |
| |
| config("default_config") { |
| include_dirs = [ "public" ] |
| } |
| |
| config("collect_metrics") { |
| if (pw_allocator_COLLECT_METRICS) { |
| defines = [ "PW_ALLOCATOR_COLLECT_METRICS=1" ] |
| } |
| } |
| |
| group("pw_allocator") { |
| public_deps = [ |
| ":allocator", |
| ":block", |
| ":freelist", |
| ":freelist_heap", |
| ] |
| } |
| |
| pw_source_set("allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/allocator.h" ] |
| public_deps = [ |
| dir_pw_assert, |
| dir_pw_preprocessor, |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| sources = [ "allocator.cc" ] |
| } |
| |
| pw_source_set("block") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/block.h" ] |
| public_deps = [ |
| ":allocator", |
| "$dir_pw_bytes:alignment", |
| dir_pw_bytes, |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| deps = [ dir_pw_assert ] |
| sources = [ "block.cc" ] |
| } |
| |
| pw_source_set("block_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/block_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":block", |
| dir_pw_bytes, |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| deps = [ dir_pw_assert ] |
| sources = [ "block_allocator.cc" ] |
| } |
| |
| pw_source_set("buffer") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/buffer.h" ] |
| } |
| |
| pw_source_set("fallback_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/fallback_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":metrics", |
| ":tracking_allocator", |
| dir_pw_metric, |
| dir_pw_result, |
| dir_pw_status, |
| dir_pw_tokenizer, |
| ] |
| } |
| |
| pw_source_set("freelist") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/freelist.h" ] |
| public_deps = [ |
| "$dir_pw_containers:vector", |
| dir_pw_span, |
| dir_pw_status, |
| ] |
| sources = [ "freelist.cc" ] |
| } |
| |
| pw_source_set("freelist_heap") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/freelist_heap.h" ] |
| public_deps = [ |
| ":block", |
| ":freelist", |
| ] |
| deps = [ |
| dir_pw_assert, |
| dir_pw_log, |
| dir_pw_span, |
| ] |
| sources = [ "freelist_heap.cc" ] |
| } |
| |
| pw_source_set("libc_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/libc_allocator.h" ] |
| public_deps = [ ":allocator" ] |
| sources = [ "libc_allocator.cc" ] |
| } |
| |
| pw_source_set("metrics") { |
| public_configs = [ |
| ":default_config", |
| ":collect_metrics", |
| ] |
| public = [ "public/pw_allocator/metrics.h" ] |
| public_deps = [ |
| ":allocator", |
| dir_pw_metric, |
| ] |
| deps = [ dir_pw_assert ] |
| sources = [ "metrics.cc" ] |
| } |
| |
| pw_source_set("multiplex_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/multiplex_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":metrics", |
| "$dir_pw_containers:flat_map", |
| dir_pw_result, |
| dir_pw_status, |
| dir_pw_tokenizer, |
| ] |
| } |
| |
| pw_source_set("null_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/null_allocator.h" ] |
| public_deps = [ ":allocator" ] |
| } |
| |
| pw_source_set("simple_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/simple_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":block", |
| dir_pw_bytes, |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| } |
| |
| pw_source_set("split_free_list_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/split_free_list_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":block", |
| dir_pw_bytes, |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| deps = [ dir_pw_assert ] |
| sources = [ "split_free_list_allocator.cc" ] |
| } |
| |
| pw_source_set("synchronized_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/synchronized_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| "$dir_pw_sync:borrow", |
| ] |
| } |
| |
| pw_source_set("tracking_allocator") { |
| public_configs = [ ":default_config" ] |
| public = [ "public/pw_allocator/tracking_allocator.h" ] |
| public_deps = [ |
| ":allocator", |
| ":metrics", |
| dir_pw_metric, |
| dir_pw_status, |
| ] |
| deps = [ dir_pw_assert ] |
| } |
| |
| pw_size_diff("allocator_size_report") { |
| title = "Sizes of various pw_allocator implementations" |
| binaries = [ |
| { |
| target = "size_report:split_free_list_allocator" |
| base = "$dir_pw_bloat:bloat_base" |
| label = "SplitFreeListAllocator" |
| }, |
| { |
| target = "size_report:split_free_list_allocator_with_unique_ptr" |
| base = "size_report:split_free_list_allocator" |
| label = "Allocator::MakeUnique and UniquePtr" |
| }, |
| { |
| target = "size_report:split_free_list_allocator_with_metric_proxy" |
| base = "size_report:split_free_list_allocator" |
| label = "AllocatorMetricProxy wrapping another allocator" |
| }, |
| ] |
| } |
| |
| pw_test_group("tests") { |
| tests = [ |
| ":allocator_test", |
| ":block_allocator_test", |
| ":block_test", |
| ":fallback_allocator_test", |
| ":freelist_test", |
| ":freelist_heap_test", |
| ":libc_allocator_test", |
| ":multiplex_allocator_test", |
| ":null_allocator_test", |
| ":simple_allocator_test", |
| ":split_free_list_allocator_test", |
| ":synchronized_allocator_test", |
| ":tracking_allocator_test", |
| ":unique_ptr_test", |
| ] |
| } |
| |
| pw_source_set("allocator_testing") { |
| public = [ "public/pw_allocator/allocator_testing.h" ] |
| public_deps = [ |
| ":allocator", |
| ":block", |
| ":buffer", |
| ":metrics", |
| ":simple_allocator", |
| ":tracking_allocator", |
| dir_pw_bytes, |
| dir_pw_result, |
| dir_pw_status, |
| dir_pw_unit_test, |
| ] |
| deps = [ dir_pw_assert ] |
| sources = [ "allocator_testing.cc" ] |
| } |
| |
| pw_source_set("allocator_test_harness") { |
| public = [ "public/pw_allocator/allocator_test_harness.h" ] |
| public_deps = [ |
| ":allocator", |
| dir_pw_containers, |
| dir_pw_random, |
| ] |
| deps = [ |
| "$dir_pw_third_party/fuchsia:stdcompat", |
| dir_pw_assert, |
| ] |
| sources = [ "allocator_test_harness.cc" ] |
| } |
| |
| pw_source_set("allocator_fuzzing") { |
| public = [ "public/pw_allocator/allocator_fuzzing.h" ] |
| public_deps = [ |
| ":allocator_test_harness", |
| "$dir_pw_fuzzer:fuzztest", |
| ] |
| sources = [ "allocator_fuzzing.cc" ] |
| } |
| |
| pw_test("allocator_test") { |
| deps = [ |
| ":allocator", |
| ":allocator_testing", |
| ] |
| sources = [ "allocator_test.cc" ] |
| } |
| |
| pw_test("block_test") { |
| deps = [ |
| ":block", |
| dir_pw_span, |
| ] |
| sources = [ "block_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs |
| # indefinitely. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("block_allocator_test") { |
| deps = [ |
| ":block", |
| ":block_allocator", |
| ":buffer", |
| dir_pw_bytes, |
| ] |
| sources = [ "block_allocator_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs |
| # indefinitely. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("fallback_allocator_test") { |
| deps = [ |
| ":allocator_testing", |
| ":fallback_allocator", |
| dir_pw_status, |
| ] |
| sources = [ "fallback_allocator_test.cc" ] |
| } |
| |
| pw_test("freelist_test") { |
| deps = [ |
| ":freelist", |
| dir_pw_span, |
| dir_pw_status, |
| ] |
| sources = [ "freelist_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs |
| # indefinitely. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("freelist_heap_test") { |
| deps = [ ":freelist_heap" ] |
| sources = [ "freelist_heap_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; after test |
| # finishes device locks up. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("libc_allocator_test") { |
| deps = [ ":libc_allocator" ] |
| sources = [ "libc_allocator_test.cc" ] |
| } |
| |
| pw_test("multiplex_allocator_test") { |
| deps = [ |
| ":allocator_testing", |
| ":multiplex_allocator", |
| dir_pw_tokenizer, |
| ] |
| sources = [ "multiplex_allocator_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs |
| # indefinitely. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("null_allocator_test") { |
| deps = [ ":null_allocator" ] |
| sources = [ "null_allocator_test.cc" ] |
| } |
| |
| pw_test("simple_allocator_test") { |
| deps = [ |
| ":allocator_fuzzing", |
| ":allocator_testing", |
| ":simple_allocator", |
| ] |
| sources = [ "simple_allocator_test.cc" ] |
| } |
| |
| pw_fuzz_test("split_free_list_allocator_test") { |
| deps = [ |
| ":allocator_fuzzing", |
| ":buffer", |
| ":split_free_list_allocator", |
| "$dir_pw_containers:vector", |
| dir_pw_bytes, |
| ] |
| sources = [ "split_free_list_allocator_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 = [ |
| ":allocator_test_harness", |
| ":allocator_testing", |
| ":synchronized_allocator", |
| "$dir_pw_sync:binary_semaphore", |
| "$dir_pw_sync:interrupt_spin_lock", |
| "$dir_pw_sync:mutex", |
| "$dir_pw_sync:virtual_basic_lockable", |
| "$dir_pw_thread:test_thread_context", |
| "$dir_pw_thread:thread", |
| "$dir_pw_thread:thread_core", |
| "$dir_pw_thread:yield", |
| dir_pw_random, |
| ] |
| sources = [ "synchronized_allocator_test.cc" ] |
| } |
| |
| pw_test("tracking_allocator_test") { |
| deps = [ ":allocator_testing" ] |
| sources = [ "tracking_allocator_test.cc" ] |
| |
| # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs |
| # indefinitely. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("unique_ptr_test") { |
| deps = [ ":allocator_testing" ] |
| sources = [ "unique_ptr_test.cc" ] |
| } |
| |
| pw_doc_group("docs") { |
| inputs = [ |
| "doc_resources/pw_allocator_heap_visualizer_demo.png", |
| "public/pw_allocator/simple_allocator.h", |
| ] |
| sources = [ "docs.rst" ] |
| report_deps = [ ":allocator_size_report" ] |
| } |