1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/target_types.gni") 18import("$dir_pw_docgen/docs.gni") 19import("$dir_pw_unit_test/test.gni") 20config("disable_warnings") { 21 cflags = [ "-Wno-thread-safety-analysis" ] 22 visibility = [ ":*" ] 23} 24 25declare_args() { 26 pw_assert_trap_HANDLER_BACKEND = "$dir_pw_assert_trap:trap_handler" 27} 28 29config("public_include_path") { 30 include_dirs = [ "public" ] 31 visibility = [ ":*" ] 32} 33 34config("assert_backend_config") { 35 include_dirs = [ "assert_public_overrides" ] 36 visibility = [ ":*" ] 37} 38 39config("check_backend_config") { 40 include_dirs = [ "check_public_overrides" ] 41 visibility = [ ":*" ] 42} 43 44pw_source_set("config") { 45 public = [ "public/pw_assert_trap/config.h" ] 46} 47 48pw_source_set("handler") { 49 public_configs = [ ":public_include_path" ] 50 public_deps = [ "$dir_pw_preprocessor" ] 51 public = [ "public/pw_assert_trap/handler.h" ] 52} 53 54pw_source_set("message") { 55 public_configs = [ ":public_include_path" ] 56 public = [ "public/pw_assert_trap/message.h" ] 57 public_deps = [ "$dir_pw_string:string" ] 58} 59 60pw_source_set("assert_backend") { 61 public_configs = [ 62 ":public_include_path", 63 ":assert_backend_config", 64 ] 65 public_deps = [ ":handler" ] 66 public = [ 67 "assert_public_overrides/pw_assert_backend/assert_backend.h", 68 "public/pw_assert_trap/assert_trap.h", 69 ] 70} 71 72pw_source_set("assert_backend.impl") { 73 public_deps = [ pw_assert_trap_HANDLER_BACKEND ] 74} 75 76pw_source_set("check_backend") { 77 public_configs = [ 78 ":public_include_path", 79 ":check_backend_config", 80 ] 81 public_deps = [ ":handler" ] 82 public = [ 83 "check_public_overrides/pw_assert_backend/check_backend.h", 84 "public/pw_assert_trap/check_trap.h", 85 ] 86} 87 88pw_source_set("check_backend.impl") { 89 public_deps = [ pw_assert_trap_HANDLER_BACKEND ] 90} 91 92pw_source_set("pw_assert_trap") { 93 public_deps = [ 94 ":assert_backend", 95 ":check_backend", 96 ] 97} 98 99pw_source_set("pw_assert_trap.impl") { 100 deps = [ 101 ":assert_backend.impl", 102 ":check_backend.impl", 103 ] 104} 105 106pw_source_set("trap_handler") { 107 public_deps = [ 108 ":config", 109 ":handler", 110 ":message", 111 "$dir_pw_sync:interrupt_spin_lock", 112 ] 113 deps = [ "$dir_pw_string:builder" ] 114 public_configs = [ ":disable_warnings" ] 115 sources = [ "trap_handler.cc" ] 116} 117 118pw_doc_group("docs") { 119 sources = [ "docs.rst" ] 120} 121 122pw_test_group("tests") { 123 # TODO: https://pwbug.dev/351889230 - this fails when trap is the used 124 # as the system assert backend, so disable and only run manually. 125 # tests = [ ":handler_test" ] 126} 127 128# provide a test implementation which is compiled with a different set of 129# defines to allow unittesting. 130config("test_config") { 131 defines = [ 132 # Disable the trap to allow testing to continue 133 "_PW_ASSERT_TRAP_DISABLE_TRAP_FOR_TESTING=1", 134 135 # Disable the capture of location info to ensure tests are portable 136 "PW_ASSERT_TRAP_DISABLE_LOCATION_CAPTURE=1", 137 ] 138 visibility = [ ":*" ] 139} 140 141pw_source_set("trap_handler_test") { 142 public_deps = [ 143 ":config", 144 ":handler", 145 ":message", 146 "$dir_pw_sync:interrupt_spin_lock", 147 ] 148 deps = [ "$dir_pw_string:builder" ] 149 public_configs = [ 150 ":disable_warnings", 151 ":test_config", 152 ] 153 sources = [ "trap_handler.cc" ] 154 visibility = [ ":*" ] 155} 156 157pw_test("handler_test") { 158 deps = [ ":trap_handler_test" ] 159 sources = [ "trap_handler_test.cc" ] 160} 161