1# Copyright 2022 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/module_config.gni") 18import("$dir_pw_docgen/docs.gni") 19import("$dir_pw_protobuf_compiler/proto.gni") 20import("$dir_pw_rpc/internal/integration_test_ports.gni") 21import("$dir_pw_thread/backend.gni") 22import("$dir_pw_toolchain/generate_toolchain.gni") 23import("$dir_pw_unit_test/test.gni") 24 25declare_args() { 26 # The build target that overrides the default configuration options for this 27 # module. This should point to a source set that provides defines through a 28 # public config (which may -include a file or add defines directly). 29 pw_transfer_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 30} 31 32config("public_include_path") { 33 include_dirs = [ "public" ] 34 visibility = [ ":*" ] 35} 36 37pw_source_set("config") { 38 public = [ "public/pw_transfer/internal/config.h" ] 39 public_configs = [ ":public_include_path" ] 40 public_deps = [ 41 "$dir_pw_chrono:system_timer", 42 pw_transfer_CONFIG, 43 ] 44 visibility = [ ":*" ] 45} 46 47pw_source_set("pw_transfer") { 48 public_configs = [ ":public_include_path" ] 49 public_deps = [ 50 ":core", 51 ":proto.raw_rpc", 52 dir_pw_assert, 53 dir_pw_bytes, 54 dir_pw_result, 55 dir_pw_status, 56 dir_pw_stream, 57 ] 58 deps = [ dir_pw_log ] 59 public = [ "public/pw_transfer/transfer.h" ] 60 sources = [ "transfer.cc" ] 61} 62 63pw_source_set("client") { 64 public_configs = [ ":public_include_path" ] 65 public_deps = [ 66 ":core", 67 ":proto.raw_rpc", 68 dir_pw_assert, 69 dir_pw_function, 70 dir_pw_stream, 71 ] 72 deps = [ dir_pw_log ] 73 public = [ "public/pw_transfer/client.h" ] 74 sources = [ "client.cc" ] 75} 76 77pw_source_set("core") { 78 public_configs = [ ":public_include_path" ] 79 public_deps = [ 80 ":config", 81 "$dir_pw_chrono:system_clock", 82 "$dir_pw_preprocessor", 83 "$dir_pw_rpc:client", 84 "$dir_pw_rpc/raw:client_api", 85 "$dir_pw_rpc/raw:server_api", 86 "$dir_pw_sync:binary_semaphore", 87 "$dir_pw_sync:timed_thread_notification", 88 "$dir_pw_thread:thread_core", 89 dir_pw_assert, 90 dir_pw_bytes, 91 dir_pw_result, 92 dir_pw_status, 93 dir_pw_stream, 94 ] 95 deps = [ 96 ":proto.pwpb", 97 dir_pw_log, 98 dir_pw_protobuf, 99 dir_pw_varint, 100 ] 101 public = [ 102 "public/pw_transfer/handler.h", 103 "public/pw_transfer/rate_estimate.h", 104 "public/pw_transfer/transfer_thread.h", 105 ] 106 sources = [ 107 "chunk.cc", 108 "client_context.cc", 109 "context.cc", 110 "public/pw_transfer/internal/chunk.h", 111 "public/pw_transfer/internal/client_context.h", 112 "public/pw_transfer/internal/context.h", 113 "public/pw_transfer/internal/event.h", 114 "public/pw_transfer/internal/server_context.h", 115 "rate_estimate.cc", 116 "server_context.cc", 117 "transfer_thread.cc", 118 ] 119 friend = [ ":*" ] 120 visibility = [ ":*" ] 121} 122 123pw_source_set("test_helpers") { 124 public_deps = [ 125 ":core", 126 dir_pw_containers, 127 ] 128 sources = [ "pw_transfer_private/chunk_testing.h" ] 129 friend = [ ":*" ] 130 visibility = [ ":*" ] 131} 132 133pw_proto_library("proto") { 134 sources = [ "transfer.proto" ] 135 python_package = "py" 136 prefix = "pw_transfer" 137} 138 139pw_test_group("tests") { 140 tests = [] 141 142 # pw_transfer requires threading. 143 if (pw_thread_THREAD_BACKEND != "") { 144 tests = [ 145 ":client_test", 146 ":transfer_thread_test", 147 ] 148 149 # TODO(pwbug/441): Fix transfer tests on Windows and non-host builds. 150 if (defined(pw_toolchain_SCOPE.is_host_toolchain) && 151 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") { 152 tests += [ 153 ":handler_test", 154 ":transfer_test", 155 ] 156 } 157 } 158} 159 160pw_test("handler_test") { 161 sources = [ "handler_test.cc" ] 162 deps = [ ":pw_transfer" ] 163} 164 165pw_test("transfer_test") { 166 sources = [ "transfer_test.cc" ] 167 deps = [ 168 ":proto.pwpb", 169 ":pw_transfer", 170 ":test_helpers", 171 "$dir_pw_rpc:thread_testing", 172 "$dir_pw_rpc/raw:test_method_context", 173 "$dir_pw_thread:thread", 174 ] 175} 176 177pw_test("transfer_thread_test") { 178 sources = [ "transfer_thread_test.cc" ] 179 deps = [ 180 ":core", 181 ":proto.raw_rpc", 182 ":pw_transfer", 183 ":test_helpers", 184 "$dir_pw_rpc:thread_testing", 185 "$dir_pw_rpc/raw:client_testing", 186 "$dir_pw_rpc/raw:test_method_context", 187 "$dir_pw_thread:thread", 188 ] 189} 190 191pw_test("client_test") { 192 sources = [ "client_test.cc" ] 193 deps = [ 194 ":client", 195 ":test_helpers", 196 "$dir_pw_rpc:thread_testing", 197 "$dir_pw_rpc/raw:client_testing", 198 "$dir_pw_thread:sleep", 199 "$dir_pw_thread:thread", 200 ] 201} 202 203pw_doc_group("docs") { 204 sources = [ "docs.rst" ] 205 inputs = [ 206 "transfer.proto", 207 "read.svg", 208 "write.svg", 209 ] 210} 211 212pw_proto_library("test_server_proto") { 213 sources = [ "test_server.proto" ] 214 prefix = "pw_transfer_test" 215 deps = [ "$dir_pw_protobuf:common_protos" ] 216} 217 218pw_executable("test_rpc_server") { 219 sources = [ "test_rpc_server.cc" ] 220 deps = [ 221 ":pw_transfer", 222 ":test_server_proto.raw_rpc", 223 "$dir_pw_rpc/system_server", 224 "$dir_pw_rpc/system_server:socket", 225 "$dir_pw_stream:std_file_stream", 226 "$dir_pw_thread:thread", 227 dir_pw_log, 228 ] 229} 230 231pw_executable("integration_test") { 232 sources = [ "integration_test.cc" ] 233 deps = [ 234 ":client", 235 ":test_server_proto.raw_rpc", 236 "$dir_pw_rpc:integration_testing", 237 "$dir_pw_sync:binary_semaphore", 238 "$dir_pw_thread:thread", 239 dir_pw_assert, 240 dir_pw_log, 241 dir_pw_unit_test, 242 ] 243} 244 245pw_python_action("cpp_client_integration_test") { 246 script = "$dir_pw_rpc/py/pw_rpc/testing.py" 247 args = [ 248 "--server", 249 "<TARGET_FILE(:test_rpc_server)>", 250 "--client", 251 "<TARGET_FILE(:integration_test)>", 252 "--", 253 "$pw_transfer_CPP_CPP_TRANSFER_TEST_PORT", 254 "(pw_rpc:CREATE_TEMP_DIR)", 255 ] 256 deps = [ 257 ":integration_test", 258 ":test_rpc_server", 259 ] 260 261 stamp = true 262} 263