|
|
|
@ -31,8 +31,6 @@ |
|
|
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
|
|
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
#include "absl/strings/str_format.h" |
|
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
@ -51,9 +49,9 @@ |
|
|
|
|
#include "test/core/util/test_config.h" |
|
|
|
|
|
|
|
|
|
// use CHECK_STACK instead
|
|
|
|
|
static void check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
grpc_channel_args* init_args, |
|
|
|
|
unsigned channel_stack_type, ...); |
|
|
|
|
static int check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
grpc_channel_args* init_args, |
|
|
|
|
unsigned channel_stack_type, ...); |
|
|
|
|
|
|
|
|
|
// arguments: const char *transport_name - the name of the transport type to
|
|
|
|
|
// simulate
|
|
|
|
@ -64,54 +62,68 @@ static void check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
// filters to instantiate, terminated with NULL
|
|
|
|
|
#define CHECK_STACK(...) check_stack(__FILE__, __LINE__, __VA_ARGS__) |
|
|
|
|
|
|
|
|
|
TEST(MinimalStackIsMinimalTest, MainTest) { |
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
grpc::testing::TestEnvironment env(&argc, argv); |
|
|
|
|
grpc_init(); |
|
|
|
|
int errors = 0; |
|
|
|
|
|
|
|
|
|
// tests with a minimal stack
|
|
|
|
|
grpc_arg minimal_stack_arg; |
|
|
|
|
minimal_stack_arg.type = GRPC_ARG_INTEGER; |
|
|
|
|
minimal_stack_arg.key = const_cast<char*>(GRPC_ARG_MINIMAL_STACK); |
|
|
|
|
minimal_stack_arg.value.integer = 1; |
|
|
|
|
grpc_channel_args minimal_stack_args = {1, &minimal_stack_arg}; |
|
|
|
|
CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, |
|
|
|
|
"authority", "connected", NULL); |
|
|
|
|
CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, |
|
|
|
|
"authority", "connected", NULL); |
|
|
|
|
CHECK_STACK("unknown", &minimal_stack_args, GRPC_SERVER_CHANNEL, "server", |
|
|
|
|
"connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, |
|
|
|
|
"authority", "http-client", "connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, |
|
|
|
|
"authority", "http-client", "connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", &minimal_stack_args, GRPC_SERVER_CHANNEL, "server", |
|
|
|
|
"http-server", "connected", NULL); |
|
|
|
|
CHECK_STACK(nullptr, &minimal_stack_args, GRPC_CLIENT_CHANNEL, |
|
|
|
|
"client-channel", NULL); |
|
|
|
|
errors += |
|
|
|
|
CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, |
|
|
|
|
"authority", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, |
|
|
|
|
"authority", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_SERVER_CHANNEL, |
|
|
|
|
"server", "connected", NULL); |
|
|
|
|
errors += |
|
|
|
|
CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, |
|
|
|
|
"authority", "http-client", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, |
|
|
|
|
"authority", "http-client", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("chttp2", &minimal_stack_args, GRPC_SERVER_CHANNEL, |
|
|
|
|
"server", "http-server", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK(nullptr, &minimal_stack_args, GRPC_CLIENT_CHANNEL, |
|
|
|
|
"client-channel", NULL); |
|
|
|
|
|
|
|
|
|
// tests with a default stack
|
|
|
|
|
CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority", |
|
|
|
|
"message_size", "deadline", "connected", NULL); |
|
|
|
|
CHECK_STACK("unknown", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", |
|
|
|
|
"message_size", "connected", NULL); |
|
|
|
|
CHECK_STACK("unknown", nullptr, GRPC_SERVER_CHANNEL, "server", "message_size", |
|
|
|
|
"deadline", "connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority", |
|
|
|
|
"message_size", "deadline", "http-client", "message_decompress", |
|
|
|
|
"message_compress", "connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", |
|
|
|
|
"message_size", "http-client", "message_decompress", |
|
|
|
|
"message_compress", "connected", NULL); |
|
|
|
|
CHECK_STACK("chttp2", nullptr, GRPC_SERVER_CHANNEL, "server", "message_size", |
|
|
|
|
"deadline", "http-server", "message_decompress", |
|
|
|
|
"message_compress", "connected", NULL); |
|
|
|
|
CHECK_STACK(nullptr, nullptr, GRPC_CLIENT_CHANNEL, "client-channel", NULL); |
|
|
|
|
errors += |
|
|
|
|
CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority", |
|
|
|
|
"message_size", "deadline", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("unknown", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", |
|
|
|
|
"message_size", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("unknown", nullptr, GRPC_SERVER_CHANNEL, "server", |
|
|
|
|
"message_size", "deadline", "connected", NULL); |
|
|
|
|
errors += |
|
|
|
|
CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority", |
|
|
|
|
"message_size", "deadline", "http-client", |
|
|
|
|
"message_decompress", "message_compress", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", |
|
|
|
|
"message_size", "http-client", "message_decompress", |
|
|
|
|
"message_compress", "connected", NULL); |
|
|
|
|
errors += |
|
|
|
|
CHECK_STACK("chttp2", nullptr, GRPC_SERVER_CHANNEL, "server", |
|
|
|
|
"message_size", "deadline", "http-server", |
|
|
|
|
"message_decompress", "message_compress", "connected", NULL); |
|
|
|
|
errors += CHECK_STACK(nullptr, nullptr, GRPC_CLIENT_CHANNEL, "client-channel", |
|
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
GPR_ASSERT(errors == 0); |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* End of tests definitions, start of test infrastructure |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
static void check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
grpc_channel_args* init_args, |
|
|
|
|
unsigned channel_stack_type, ...) { |
|
|
|
|
static int check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
grpc_channel_args* init_args, |
|
|
|
|
unsigned channel_stack_type, ...) { |
|
|
|
|
// create phony channel stack
|
|
|
|
|
grpc_core::ChannelStackBuilderImpl builder( |
|
|
|
|
"test", static_cast<grpc_channel_stack_type>(channel_stack_type)); |
|
|
|
@ -127,7 +139,7 @@ static void check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
ASSERT_TRUE(grpc_core::CoreConfiguration::Get().channel_init().CreateStack( |
|
|
|
|
GPR_ASSERT(grpc_core::CoreConfiguration::Get().channel_init().CreateStack( |
|
|
|
|
&builder)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -153,17 +165,22 @@ static void check_stack(const char* file, int line, const char* transport_name, |
|
|
|
|
std::string got = absl::StrJoin(parts, ", "); |
|
|
|
|
|
|
|
|
|
// figure out result, log if there's an error
|
|
|
|
|
EXPECT_EQ(got, expect) << "file=" << file << " line=" << line |
|
|
|
|
<< " transport=" << transport_name << " stack_type=" |
|
|
|
|
<< grpc_channel_stack_type_string( |
|
|
|
|
static_cast<grpc_channel_stack_type>( |
|
|
|
|
channel_stack_type)) |
|
|
|
|
<< " channel_args=" << channel_args.ToString(); |
|
|
|
|
} |
|
|
|
|
int result = 0; |
|
|
|
|
if (got != expect) { |
|
|
|
|
std::string args_str = channel_args.ToString(); |
|
|
|
|
|
|
|
|
|
gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, |
|
|
|
|
"**************************************************"); |
|
|
|
|
gpr_log( |
|
|
|
|
file, line, GPR_LOG_SEVERITY_ERROR, |
|
|
|
|
"FAILED transport=%s; stack_type=%s; channel_args=%s:", transport_name, |
|
|
|
|
grpc_channel_stack_type_string( |
|
|
|
|
static_cast<grpc_channel_stack_type>(channel_stack_type)), |
|
|
|
|
args_str.c_str()); |
|
|
|
|
gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "EXPECTED: %s", expect.c_str()); |
|
|
|
|
gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "GOT: %s", got.c_str()); |
|
|
|
|
result = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
grpc::testing::TestEnvironment env(&argc, argv); |
|
|
|
|
::testing::InitGoogleTest(&argc, argv); |
|
|
|
|
grpc::testing::TestGrpcScope grpc_scope; |
|
|
|
|
return RUN_ALL_TESTS(); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|