testing_channel_create.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <utility>
18 
20 
27 
28 namespace grpc_binder {
29 namespace end2end_testing {
30 
31 namespace {
32 // Since we assume the first half of the transport setup is completed before the
33 // server side enters WireReader::SetupTransport, we need this helper to wait
34 // and finish that part of the negotiation for us.
35 class ServerSetupTransportHelper {
36  public:
37  ServerSetupTransportHelper()
38  : wire_reader_(absl::make_unique<WireReaderImpl>(
39  /*transport_stream_receiver=*/nullptr, /*is_client=*/false,
40  std::make_shared<
41  grpc::experimental::binder::UntrustedSecurityPolicy>())) {
43  [this](transaction_code_t tx_code, ReadableParcel* parcel, int uid) {
44  return this->wire_reader_->ProcessTransaction(tx_code, parcel, uid);
45  });
46  }
47  std::unique_ptr<Binder> WaitForClientBinder() {
48  return wire_reader_->RecvSetupTransport();
49  }
50 
51  std::unique_ptr<Binder> GetEndpointBinderForClient() {
53  }
54 
55  private:
56  std::unique_ptr<WireReaderImpl> wire_reader_;
57  // The endpoint binder for client.
58  std::unique_ptr<Binder> endpoint_binder_;
59  std::unique_ptr<TransactionReceiver> tx_receiver_;
60 };
61 } // namespace
62 
63 std::pair<grpc_transport*, grpc_transport*>
65  ServerSetupTransportHelper helper;
66  std::unique_ptr<Binder> endpoint_binder = helper.GetEndpointBinderForClient();
67  grpc_transport* client_transport = nullptr;
68 
69  struct ThreadArgs {
70  std::unique_ptr<Binder> endpoint_binder;
71  grpc_transport** client_transport;
72  } args;
73 
74  args.endpoint_binder = std::move(endpoint_binder);
75  args.client_transport = &client_transport;
76 
78  "client-thread",
79  [](void* arg) {
80  ThreadArgs* args = static_cast<ThreadArgs*>(arg);
81  std::unique_ptr<Binder> endpoint_binder =
82  std::move(args->endpoint_binder);
83  *args->client_transport = grpc_create_binder_transport_client(
84  std::move(endpoint_binder),
85  std::make_shared<
87  },
88  &args);
89  client_thread.Start();
91  helper.WaitForClientBinder(),
92  std::make_shared<grpc::experimental::binder::UntrustedSecurityPolicy>());
93  client_thread.Join();
94  return std::make_pair(client_transport, server_transport);
95 }
96 
97 std::shared_ptr<grpc::Channel> BinderChannelForTesting(
99  grpc_channel_args channel_args = args.c_channel_args();
101  "",
102  grpc_binder_channel_create_for_testing(server->c_server(), &channel_args,
103  nullptr),
104  std::vector<std::unique_ptr<
106 }
107 
108 } // namespace end2end_testing
109 } // namespace grpc_binder
110 
112  grpc_server* server, const grpc_channel_args* args, void* /*reserved*/) {
114 
118  .ToC();
119  auto client_args = grpc_core::ChannelArgs::FromC(args).Set(
120  GRPC_ARG_DEFAULT_AUTHORITY, "test.authority");
121 
122  grpc_transport *client_transport, *server_transport;
123  std::tie(client_transport, server_transport) =
126  server_transport, nullptr, args, nullptr);
129  "binder", client_args, GRPC_CLIENT_DIRECT_CHANNEL, client_transport);
130  GPR_ASSERT(channel.ok());
132  return channel->release()->c_ptr();
133 }
grpc_core::Server::SetupTransport
grpc_error_handle SetupTransport(grpc_transport *transport, grpc_pollset *accepting_pollset, const grpc_channel_args *args, const RefCountedPtr< channelz::SocketNode > &socket_node)
Definition: src/core/lib/surface/server.cc:605
grpc::CreateChannelInternal
std::shared_ptr< Channel > CreateChannelInternal(const std::string &host, grpc_channel *c_channel, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
grpc_binder_channel_create_for_testing
grpc_channel * grpc_binder_channel_create_for_testing(grpc_server *server, const grpc_channel_args *args, void *)
Definition: testing_channel_create.cc:111
tx_receiver_
std::unique_ptr< TransactionReceiver > tx_receiver_
Definition: testing_channel_create.cc:59
core_configuration.h
grpc
Definition: grpcpp/alarm.h:33
false
#define false
Definition: setup_once.h:323
grpc::experimental::binder::UntrustedSecurityPolicy
Definition: binder_security_policy.h:44
GRPC_CLIENT_DIRECT_CHANNEL
@ GRPC_CLIENT_DIRECT_CHANNEL
Definition: channel_stack_type.h:34
grpc_binder
Definition: connection_id_generator.cc:45
grpc::experimental::ClientInterceptorFactoryInterface
Definition: impl/codegen/client_interceptor.h:48
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_core::ChannelArgs::FromC
static ChannelArgs FromC(const grpc_channel_args *args)
Definition: channel_args.cc:84
transaction_code_t
uint32_t transaction_code_t
Definition: binder_constants.h:24
endpoint_binder_
std::unique_ptr< Binder > endpoint_binder_
Definition: testing_channel_create.cc:58
absl::make_unique
memory_internal::MakeUniqueResult< T >::scalar make_unique(Args &&... args)
Definition: third_party/abseil-cpp/absl/memory/memory.h:168
tx_code
int tx_code
Definition: fake_binder_test.cc:241
grpc_create_binder_transport_client
grpc_transport * grpc_create_binder_transport_client(std::unique_ptr< grpc_binder::Binder > endpoint_binder, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy)
Definition: binder_transport.cc:737
grpc_channel_args
Definition: grpc_types.h:132
wire_reader_
std::unique_ptr< WireReaderImpl > wire_reader_
Definition: testing_channel_create.cc:56
GRPC_ARG_DEFAULT_AUTHORITY
#define GRPC_ARG_DEFAULT_AUTHORITY
Definition: grpc_types.h:251
binder_security_policy.h
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_binder::end2end_testing::CreateClientServerBindersPairForTesting
std::pair< grpc_transport *, grpc_transport * > CreateClientServerBindersPairForTesting()
Definition: testing_channel_create.cc:64
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
wire_reader_impl.h
grpc_core::ChannelArgs::ToC
const grpc_channel_args * ToC() const
Definition: channel_args.cc:94
grpc_channel_args_destroy
void grpc_channel_args_destroy(grpc_channel_args *a)
Definition: channel_args.cc:360
arg
Definition: cmdline.cc:40
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
grpc_binder::end2end_testing::BinderChannelForTesting
std::shared_ptr< grpc::Channel > BinderChannelForTesting(grpc::Server *server, const grpc::ChannelArguments &args)
Definition: testing_channel_create.cc:97
grpc_create_binder_transport_server
grpc_transport * grpc_create_binder_transport_server(std::unique_ptr< grpc_binder::Binder > client_binder, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy)
Definition: binder_transport.cc:752
grpc_core::CoreConfiguration::channel_args_preconditioning
const ChannelArgsPreconditioning & channel_args_preconditioning() const
Definition: core_configuration.h:139
grpc_core::ExecCtx
Definition: exec_ctx.h:97
grpc_binder::end2end_testing::NewBinderPair
std::pair< std::unique_ptr< Binder >, std::unique_ptr< TransactionReceiver > > NewBinderPair(TransactionReceiver::OnTransactCb transact_cb)
Definition: fake_binder.cc:267
grpc_core::ChannelArgs::Set
GRPC_MUST_USE_RESULT ChannelArgs Set(absl::string_view name, Value value) const
Definition: channel_args.cc:113
grpc::ChannelArguments
Definition: grpcpp/support/channel_arguments.h:39
server
Definition: examples/python/async_streaming/server.py:1
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
grpc::Server
Definition: include/grpcpp/server.h:59
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
arg
struct arg arg
grpc_core::Thread
Definition: thd.h:43
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
grpc_transport
Definition: transport_impl.h:89
channel_args.h
client_thread
static void client_thread(thread_args *args)
Definition: low_level_ping_pong.cc:294
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
grpc_error
Definition: error_internal.h:42
testing_channel_create.h
grpc_core::CppImplOf< Server, grpc_server >::FromC
static Server * FromC(grpc_server *c_type)
Definition: cpp_impl_of.h:30
grpc_core::ChannelArgsPreconditioning::PreconditionChannelArgs
ChannelArgs PreconditionChannelArgs(const grpc_channel_args *args) const
Definition: channel_args_preconditioning.cc:34
grpc_core::Channel::Create
static absl::StatusOr< RefCountedPtr< Channel > > Create(const char *target, ChannelArgs args, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport)
Definition: channel.cc:202
error_utils.h
binder_transport.h
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241
channel.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:34