-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_allocator: Move code snippets from docs to examples
What is better in than code samples in module documentation? Example code that is actually compiled and tested as part of the build and the included into the documentation! This CL creates standalone examples as tests for all the code that appears in the pw_allocator docs. This helps ensures the remain fresh and accurate. Bug: b/328076428 Change-Id: I853a21801c56093b8448e04f84d92e5245eab116 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/195190 Presubmit-Verified: CQ Bot Account <[email protected]> Commit-Queue: Aaron Green <[email protected]> Reviewed-by: Taylor Cramer <[email protected]>
- Loading branch information
1 parent
c66b857
commit 8160a4d
Showing
20 changed files
with
1,323 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Copyright 2024 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. | ||
|
||
load( | ||
"//pw_build:pigweed.bzl", | ||
"pw_cc_binary", | ||
"pw_cc_test", | ||
) | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) | ||
|
||
# Libraries | ||
|
||
cc_library( | ||
name = "named_u32", | ||
testonly = True, | ||
hdrs = ["named_u32.h"], | ||
includes = [".."], | ||
deps = [ | ||
"//pw_bytes", | ||
"//pw_string", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "block_allocator", | ||
srcs = ["block_allocator.cc"], | ||
deps = [ | ||
":named_u32", | ||
"//pw_allocator:block_allocator", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "custom_allocator", | ||
testonly = True, | ||
srcs = ["custom_allocator.cc"], | ||
hdrs = ["custom_allocator.h"], | ||
includes = [".."], | ||
deps = [ | ||
"//pw_allocator:allocator", | ||
"//pw_log", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "custom_allocator_test_harness", | ||
testonly = True, | ||
hdrs = ["custom_allocator_test_harness.h"], | ||
includes = [".."], | ||
deps = [ | ||
":custom_allocator", | ||
"//pw_allocator:test_harness", | ||
"//pw_allocator:testing", | ||
], | ||
) | ||
|
||
# Examples | ||
|
||
pw_cc_test( | ||
name = "basic", | ||
srcs = ["basic.cc"], | ||
deps = [ | ||
":named_u32", | ||
"//pw_allocator:allocator", | ||
"//pw_allocator:testing", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "custom_allocator_perf_test", | ||
srcs = ["custom_allocator_perf_test.cc"], | ||
deps = [ | ||
":custom_allocator_test_harness", | ||
"//pw_perf_test", | ||
"//pw_random", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "custom_allocator_test", | ||
srcs = ["custom_allocator_test.cc"], | ||
deps = [ | ||
":custom_allocator", | ||
":custom_allocator_test_harness", | ||
":named_u32", | ||
"//pw_allocator:fuzzing", | ||
"//pw_allocator:testing", | ||
"//pw_containers:vector", | ||
"//pw_fuzzer:fuzztest", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "linker_sections", | ||
srcs = ["linker_sections.cc"], | ||
deps = [ | ||
":named_u32", | ||
"//pw_allocator:allocator", | ||
"//pw_allocator:block_allocator", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "metrics", | ||
srcs = ["metrics.cc"], | ||
deps = [ | ||
":named_u32", | ||
"//pw_allocator:testing", | ||
"//pw_allocator:tracking_allocator", | ||
"//pw_tokenizer", | ||
], | ||
) | ||
|
||
pw_cc_binary( | ||
name = "size_report", | ||
testonly = True, | ||
srcs = ["size_report.cc"], | ||
deps = [ | ||
":custom_allocator", | ||
"//pw_allocator:block_allocator", | ||
"//pw_allocator:size_reporter", | ||
], | ||
) | ||
|
||
pw_cc_test( | ||
name = "spin_lock", | ||
srcs = ["spin_lock.cc"], | ||
deps = [ | ||
":named_u32", | ||
"//pw_allocator:synchronized_allocator", | ||
"//pw_allocator:testing", | ||
"//pw_assert", | ||
"//pw_sync:interrupt_spin_lock", | ||
"//pw_thread:test_thread_context", | ||
"//pw_thread:thread", | ||
"//pw_thread:thread_core", | ||
], | ||
) |
Oops, something went wrong.