h2_uds.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <inttypes.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 
24 #include <string>
25 
26 #include "absl/strings/str_format.h"
27 
28 #include <grpc/grpc_security.h>
29 #include <grpc/support/alloc.h>
30 #include <grpc/support/log.h>
31 #include <grpc/support/sync.h>
32 
41 #include "test/core/util/port.h"
43 
46 };
47 
48 static int unique = 1;
49 
51  std::string addr) {
53  ffd->localaddr = std::move(addr);
54 
56  memset(&f, 0, sizeof(f));
57  f.fixture_data = ffd;
59 
60  return f;
61 }
62 
64  const grpc_channel_args* /*client_args*/,
65  const grpc_channel_args* /*server_args*/) {
67  const std::string localaddr = absl::StrFormat(
68  "unix:/tmp/grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d", getpid(),
69  now.tv_sec, now.tv_nsec, unique++);
70  return chttp2_create_fixture_fullstack_base(localaddr);
71 }
72 
75  const grpc_channel_args* /*client_args*/,
76  const grpc_channel_args* /*server_args*/) {
78  const std::string localaddr = absl::StrFormat(
79  "unix-abstract:grpc_fullstack_test.%d.%" PRId64 ".%" PRId32 ".%d",
80  getpid(), now.tv_sec, now.tv_nsec, unique++);
81  return chttp2_create_fixture_fullstack_base(localaddr);
82 }
83 
85  const grpc_channel_args* client_args) {
87  static_cast<fullstack_fixture_data*>(f->fixture_data);
89  f->client = grpc_channel_create(ffd->localaddr.c_str(), creds, client_args);
91 }
92 
94  const grpc_channel_args* server_args) {
96  static_cast<fullstack_fixture_data*>(f->fixture_data);
97  if (f->server) {
98  grpc_server_destroy(f->server);
99  }
100  f->server = grpc_server_create(server_args, nullptr);
101  grpc_server_register_completion_queue(f->server, f->cq, nullptr);
102  grpc_server_credentials* server_creds =
104  GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr.c_str(),
105  server_creds));
106  grpc_server_credentials_release(server_creds);
107  grpc_server_start(f->server);
108 }
109 
112  static_cast<fullstack_fixture_data*>(f->fixture_data);
113  delete ffd;
114 }
115 
116 /* All test configurations */
118  {"chttp2/fullstack_uds",
124 #ifndef GPR_APPLE // Apple doesn't support an abstract socket
125  {"chttp2/fullstack_uds_abstract_namespace",
132 #endif
133 };
134 
135 int main(int argc, char** argv) {
136  size_t i;
137 
138  grpc::testing::TestEnvironment env(&argc, argv);
140  grpc_init();
141 
142  for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
143  grpc_end2end_tests(argc, argv, configs[i]);
144  }
145 
146  grpc_shutdown();
147 
148  return 0;
149 }
FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER
#define FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER
Definition: end2end_tests.h:38
now
static double now(void)
Definition: test/core/fling/client.cc:130
log.h
port.h
generate.env
env
Definition: generate.py:37
memset
return memset(p, 0, total)
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
grpc_end2end_tests_pre_init
void grpc_end2end_tests_pre_init(void)
Definition: end2end_tests.cc:221
string.h
fullstack_fixture_data
struct fullstack_fixture_data fullstack_fixture_data
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
client_channel.h
grpc_server_create
GRPCAPI grpc_server * grpc_server_create(const grpc_channel_args *args, void *reserved)
Definition: src/core/lib/surface/server.cc:1456
chttp2_init_server_fullstack
void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, const grpc_channel_args *server_args)
Definition: h2_uds.cc:93
main
int main(int argc, char **argv)
Definition: h2_uds.cc:135
grpc_server_register_completion_queue
GRPCAPI void grpc_server_register_completion_queue(grpc_server *server, grpc_completion_queue *cq, void *reserved)
Definition: src/core/lib/surface/server.cc:1466
grpc_security.h
grpc_end2end_test_config
Definition: end2end_tests.h:53
grpc_channel_args
Definition: grpc_types.h:132
chttp2_create_fixture_fullstack
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(const grpc_channel_args *, const grpc_channel_args *)
Definition: h2_uds.cc:63
grpc_end2end_test_fixture
Definition: end2end_tests.h:46
grpc_insecure_server_credentials_create
GRPCAPI grpc_server_credentials * grpc_insecure_server_credentials_create()
Definition: core/lib/security/credentials/insecure/insecure_credentials.cc:71
chttp2_tear_down_fullstack
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture *f)
Definition: h2_uds.cc:110
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
#define FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
Definition: end2end_tests.h:28
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
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_server_credentials_release
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Definition: credentials.cc:95
grpc_server_add_http2_port
GRPCAPI int grpc_server_add_http2_port(grpc_server *server, const char *addr, grpc_server_credentials *creds)
Definition: chttp2_server.cc:1029
fullstack_fixture_data::localaddr
std::string localaddr
Definition: h2_census.cc:39
grpc_insecure_credentials_create
GRPCAPI grpc_channel_credentials * grpc_insecure_credentials_create()
Definition: core/lib/security/credentials/insecure/insecure_credentials.cc:64
chttp2_init_client_fullstack
void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, const grpc_channel_args *client_args)
Definition: h2_uds.cc:84
grpc_server_destroy
GRPCAPI void grpc_server_destroy(grpc_server *server)
Definition: src/core/lib/surface/server.cc:1519
end2end_tests.h
gpr_now
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
chttp2_create_fixture_fullstack_base
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_base(std::string addr)
Definition: h2_uds.cc:50
configs
static grpc_end2end_test_config configs[]
Definition: h2_uds.cc:117
test_config.h
grpc_channel_credentials_release
GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials *creds)
Definition: credentials.cc:36
grpc_end2end_tests
void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config)
Definition: end2end_tests.cc:321
grpc_server_credentials
Definition: src/core/lib/security/credentials/credentials.h:259
grpc_channel_create
GRPCAPI grpc_channel * grpc_channel_create(const char *target, grpc_channel_credentials *creds, const grpc_channel_args *args)
Definition: chttp2_connector.cc:366
http_server_filter.h
alloc.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
chttp2_transport.h
unique
static int unique
Definition: h2_uds.cc:48
server.h
grpc_completion_queue_create_for_next
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_next(void *reserved)
Definition: completion_queue_factory.cc:62
connected_channel.h
chttp2_create_fixture_fullstack_abstract_namespace
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_abstract_namespace(const grpc_channel_args *, const grpc_channel_args *)
Definition: h2_uds.cc:74
gpr_timespec
Definition: gpr_types.h:50
fullstack_fixture_data
Definition: h2_census.cc:38
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_server_start
GRPCAPI void grpc_server_start(grpc_server *server)
Definition: src/core/lib/surface/server.cc:1497
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Definition: gpr_types.h:39
sync.h
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
grpc_channel_credentials
Definition: src/core/lib/security/credentials/credentials.h:96
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL
#define FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL
Definition: end2end_tests.h:37
channel.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:00