Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 1 | # Copyright 2019 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 | |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 15 | import("$dir_pw_bloat/bloat.gni") |
Wyatt Hepler | fe85de2 | 2019-11-19 17:10:20 -0800 | [diff] [blame] | 16 | import("$dir_pw_docgen/docs.gni") |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 17 | import("$dir_pw_unit_test/test.gni") |
| 18 | |
| 19 | config("default_config") { |
| 20 | include_dirs = [ "public" ] |
| 21 | } |
| 22 | |
| 23 | source_set("pw_string") { |
Wyatt Hepler | 2119240 | 2020-01-15 15:40:51 -0800 | [diff] [blame] | 24 | public_configs = [ ":default_config" ] |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 25 | public = [ |
Wyatt Hepler | e2dc6d1 | 2019-11-15 09:05:07 -0800 | [diff] [blame] | 26 | "public/pw_string/format.h", |
Wyatt Hepler | 9971393 | 2019-12-17 10:20:42 -0800 | [diff] [blame] | 27 | "public/pw_string/string_builder.h", |
Wyatt Hepler | 58823c1 | 2019-11-13 14:27:31 -0800 | [diff] [blame] | 28 | "public/pw_string/to_string.h", |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 29 | "public/pw_string/type_to_string.h", |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 30 | "public/pw_string/util.h", |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 31 | ] |
| 32 | sources = [ |
Wyatt Hepler | e2dc6d1 | 2019-11-15 09:05:07 -0800 | [diff] [blame] | 33 | "format.cc", |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 34 | "string_builder.cc", |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 35 | "type_to_string.cc", |
| 36 | ] |
| 37 | sources += public |
| 38 | public_deps = [ |
| 39 | "$dir_pw_preprocessor", |
| 40 | "$dir_pw_span", |
| 41 | "$dir_pw_status", |
| 42 | ] |
| 43 | } |
| 44 | |
Alexei Frolov | a454c68 | 2019-11-19 10:55:07 -0800 | [diff] [blame] | 45 | pw_test_group("tests") { |
| 46 | tests = [ |
| 47 | ":format_test", |
Wyatt Hepler | 706a5ae | 2020-01-09 17:01:38 -0800 | [diff] [blame] | 48 | ":string_builder_test", |
Alexei Frolov | a454c68 | 2019-11-19 10:55:07 -0800 | [diff] [blame] | 49 | ":to_string_test", |
| 50 | ":type_to_string_test", |
Wyatt Hepler | 706a5ae | 2020-01-09 17:01:38 -0800 | [diff] [blame] | 51 | ":util_test", |
Alexei Frolov | a454c68 | 2019-11-19 10:55:07 -0800 | [diff] [blame] | 52 | ] |
| 53 | group_deps = [ |
| 54 | "$dir_pw_preprocessor:tests", |
| 55 | "$dir_pw_span:tests", |
| 56 | "$dir_pw_status:tests", |
| 57 | ] |
| 58 | } |
| 59 | |
Wyatt Hepler | e2dc6d1 | 2019-11-15 09:05:07 -0800 | [diff] [blame] | 60 | pw_test("format_test") { |
| 61 | deps = [ |
| 62 | ":pw_string", |
Wyatt Hepler | e2dc6d1 | 2019-11-15 09:05:07 -0800 | [diff] [blame] | 63 | ] |
| 64 | sources = [ |
| 65 | "format_test.cc", |
| 66 | ] |
| 67 | } |
| 68 | |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 69 | pw_test("string_builder_test") { |
| 70 | deps = [ |
| 71 | ":pw_string", |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 72 | ] |
| 73 | sources = [ |
| 74 | "string_builder_test.cc", |
| 75 | ] |
| 76 | } |
| 77 | |
Wyatt Hepler | 58823c1 | 2019-11-13 14:27:31 -0800 | [diff] [blame] | 78 | pw_test("to_string_test") { |
| 79 | deps = [ |
| 80 | ":pw_string", |
Wyatt Hepler | 58823c1 | 2019-11-13 14:27:31 -0800 | [diff] [blame] | 81 | ] |
| 82 | sources = [ |
| 83 | "to_string_test.cc", |
| 84 | ] |
| 85 | } |
| 86 | |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 87 | pw_test("type_to_string_test") { |
| 88 | deps = [ |
| 89 | ":pw_string", |
Wyatt Hepler | 48db4d6 | 2019-11-11 10:32:45 -0800 | [diff] [blame] | 90 | ] |
| 91 | sources = [ |
| 92 | "type_to_string_test.cc", |
| 93 | ] |
| 94 | } |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 95 | |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 96 | pw_test("util_test") { |
| 97 | deps = [ |
| 98 | ":pw_string", |
Wyatt Hepler | ce9b952 | 2019-11-11 10:45:48 -0800 | [diff] [blame] | 99 | ] |
| 100 | sources = [ |
| 101 | "util_test.cc", |
| 102 | ] |
| 103 | } |
| 104 | |
Wyatt Hepler | fe85de2 | 2019-11-19 17:10:20 -0800 | [diff] [blame] | 105 | pw_doc_group("docs") { |
| 106 | sources = [ |
| 107 | "docs.rst", |
| 108 | ] |
| 109 | report_deps = [ |
| 110 | ":format_size_report", |
| 111 | ":string_builder_size_report", |
| 112 | ] |
| 113 | } |
| 114 | |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 115 | pw_size_report("format_size_report") { |
| 116 | title = "Using pw::string::Format instead of snprintf" |
| 117 | |
| 118 | binaries = [ |
| 119 | { |
| 120 | target = "size_report:single_write_format" |
| 121 | base = "size_report:single_write_snprintf" |
Wyatt Hepler | fe85de2 | 2019-11-19 17:10:20 -0800 | [diff] [blame] | 122 | label = "Format instead of snprintf once, return size" |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 123 | }, |
| 124 | { |
| 125 | target = "size_report:multiple_writes_format" |
| 126 | base = "size_report:multiple_writes_snprintf" |
Wyatt Hepler | fe85de2 | 2019-11-19 17:10:20 -0800 | [diff] [blame] | 127 | label = "Format instead of snprintf 10 times, handle errors" |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 128 | }, |
| 129 | { |
| 130 | target = "size_report:many_writes_format" |
| 131 | base = "size_report:many_writes_snprintf" |
Wyatt Hepler | fe85de2 | 2019-11-19 17:10:20 -0800 | [diff] [blame] | 132 | label = "Format instead of snprintf 50 times, no error handling" |
| 133 | }, |
| 134 | ] |
| 135 | } |
| 136 | |
| 137 | pw_size_report("string_builder_size_report") { |
| 138 | title = "Using pw::StringBuilder instead of snprintf" |
| 139 | |
| 140 | binaries = [ |
| 141 | { |
| 142 | target = "size_report:build_string_with_string_builder" |
| 143 | base = "size_report:build_string_with_snprintf" |
| 144 | label = "Total StringBuilder cost when used alongside snprintf" |
| 145 | }, |
| 146 | { |
| 147 | target = "size_report:build_string_with_string_builder_no_base_snprintf" |
| 148 | base = "size_report:build_string_with_snprintf_no_base_snprintf" |
| 149 | label = "StringBuilder cost when completely replacing snprintf" |
| 150 | }, |
| 151 | { |
| 152 | target = "size_report:build_string_incremental_with_string_builder" |
| 153 | base = "size_report:build_string_incremental_with_snprintf" |
| 154 | label = "Incremental cost relative to snprintf for 10 strings" |
Wyatt Hepler | 8a823ce | 2019-11-15 12:03:57 -0800 | [diff] [blame] | 155 | }, |
| 156 | ] |
| 157 | } |