aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/channel/BUILD29
-rw-r--r--test/core/channel/channel_trace_test.cc240
-rw-r--r--test/core/channel/status_util_test.cc (renamed from test/core/client_channel/status_util_test.cc)2
-rw-r--r--test/core/client_channel/BUILD12
-rw-r--r--test/core/end2end/tests/keepalive_timeout.cc2
-rw-r--r--test/core/gprpp/inlined_vector_test.cc7
-rw-r--r--test/core/surface/public_headers_must_be_c89.c2
-rw-r--r--test/cpp/end2end/async_end2end_test.cc12
-rwxr-xr-xtest/cpp/qps/gen_build_yaml.py40
-rw-r--r--test/cpp/util/BUILD19
-rw-r--r--test/cpp/util/channel_trace_proto_helper.cc56
-rw-r--r--test/cpp/util/channel_trace_proto_helper.h30
12 files changed, 407 insertions, 44 deletions
diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD
index c5dfd8ef37..6bf4fcdbb8 100644
--- a/test/core/channel/BUILD
+++ b/test/core/channel/BUILD
@@ -65,3 +65,32 @@ grpc_cc_test(
"//test/core/util:grpc_test_util",
],
)
+
+grpc_cc_test(
+ name = "channel_trace_test",
+ srcs = ["channel_trace_test.cc"],
+ language = "C++",
+ deps = [
+ "//:gpr",
+ "//:grpc",
+ "//:grpc++",
+ "//test/core/util:gpr_test_util",
+ "//test/core/util:grpc_test_util",
+ "//test/cpp/util:channel_trace_proto_helper",
+ ],
+ external_deps = [
+ "gtest",
+ ],
+)
+
+grpc_cc_test(
+ name = "status_util_test",
+ srcs = ["status_util_test.cc"],
+ language = "C++",
+ deps = [
+ "//:grpc",
+ ],
+ external_deps = [
+ "gtest",
+ ],
+)
diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc
new file mode 100644
index 0000000000..3c73e33612
--- /dev/null
+++ b/test/core/channel/channel_trace_test.cc
@@ -0,0 +1,240 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <gtest/gtest.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "src/core/lib/channel/channel_trace.h"
+#include "src/core/lib/channel/channel_trace_registry.h"
+#include "src/core/lib/gpr/useful.h"
+#include "src/core/lib/iomgr/exec_ctx.h"
+#include "src/core/lib/json/json.h"
+
+#include "test/core/util/test_config.h"
+#include "test/cpp/util/channel_trace_proto_helper.h"
+
+// remove me
+#include <grpc/support/string_util.h>
+#include <stdlib.h>
+#include <string.h>
+
+namespace grpc_core {
+namespace testing {
+namespace {
+
+grpc_json* GetJsonChild(grpc_json* parent, const char* key) {
+ EXPECT_NE(parent, nullptr);
+ for (grpc_json* child = parent->child; child != nullptr;
+ child = child->next) {
+ if (child->key != nullptr && strcmp(child->key, key) == 0) return child;
+ }
+ return nullptr;
+}
+
+void ValidateJsonArraySize(grpc_json* json, const char* key,
+ size_t expected_size) {
+ grpc_json* arr = GetJsonChild(json, key);
+ ASSERT_NE(arr, nullptr);
+ ASSERT_EQ(arr->type, GRPC_JSON_ARRAY);
+ size_t count = 0;
+ for (grpc_json* child = arr->child; child != nullptr; child = child->next) {
+ ++count;
+ }
+ ASSERT_EQ(count, expected_size);
+}
+
+void ValidateChannelTraceData(grpc_json* json,
+ size_t num_events_logged_expected,
+ size_t actual_num_events_expected) {
+ ASSERT_NE(json, nullptr);
+ grpc_json* num_events_logged_json = GetJsonChild(json, "numEventsLogged");
+ ASSERT_NE(num_events_logged_json, nullptr);
+ grpc_json* start_time = GetJsonChild(json, "creationTime");
+ ASSERT_NE(start_time, nullptr);
+ size_t num_events_logged =
+ (size_t)strtol(num_events_logged_json->value, nullptr, 0);
+ ASSERT_EQ(num_events_logged, num_events_logged_expected);
+ ValidateJsonArraySize(json, "events", actual_num_events_expected);
+}
+
+void AddSimpleTrace(RefCountedPtr<ChannelTrace> tracer) {
+ tracer->AddTraceEvent(ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("simple trace"));
+}
+
+// checks for the existence of all the required members of the tracer.
+void ValidateChannelTrace(RefCountedPtr<ChannelTrace> tracer,
+ size_t expected_num_event_logged, size_t max_nodes) {
+ if (!max_nodes) return;
+ char* json_str = tracer->RenderTrace();
+ grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str);
+ grpc_json* json = grpc_json_parse_string(json_str);
+ ValidateChannelTraceData(json, expected_num_event_logged,
+ GPR_MIN(expected_num_event_logged, max_nodes));
+ grpc_json_destroy(json);
+ gpr_free(json_str);
+}
+
+void ValidateTraceDataMatchedUuidLookup(RefCountedPtr<ChannelTrace> tracer) {
+ intptr_t uuid = tracer->GetUuid();
+ if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled
+ char* tracer_json_str = tracer->RenderTrace();
+ ChannelTrace* uuid_lookup =
+ grpc_channel_trace_registry_get_channel_trace(uuid);
+ char* uuid_lookup_json_str = uuid_lookup->RenderTrace();
+ EXPECT_EQ(strcmp(tracer_json_str, uuid_lookup_json_str), 0);
+ gpr_free(tracer_json_str);
+ gpr_free(uuid_lookup_json_str);
+}
+
+} // anonymous namespace
+
+class ChannelTracerTest : public ::testing::TestWithParam<size_t> {};
+
+// Tests basic ChannelTrace functionality like construction, adding trace, and
+// lookups by uuid.
+TEST_P(ChannelTracerTest, BasicTest) {
+ grpc_core::ExecCtx exec_ctx;
+ RefCountedPtr<ChannelTrace> tracer = MakeRefCounted<ChannelTrace>(GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateTraceDataMatchedUuidLookup(tracer);
+ tracer->AddTraceEvent(ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("trace three"));
+ tracer->AddTraceEvent(ChannelTrace::Severity::Error,
+ grpc_slice_from_static_string("trace four error"));
+ ValidateChannelTrace(tracer, 4, GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 6, GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 10, GetParam());
+ ValidateTraceDataMatchedUuidLookup(tracer);
+ tracer.reset(nullptr);
+}
+
+// Tests more complex functionality, like a parent channel tracking
+// subchannles. This exercises the ref/unref patterns since the parent tracer
+// and this function will both hold refs to the subchannel.
+TEST_P(ChannelTracerTest, ComplexTest) {
+ grpc_core::ExecCtx exec_ctx;
+ RefCountedPtr<ChannelTrace> tracer = MakeRefCounted<ChannelTrace>(GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ RefCountedPtr<ChannelTrace> sc1 = MakeRefCounted<ChannelTrace>(GetParam());
+ tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("subchannel one created"), sc1);
+ ValidateChannelTrace(tracer, 3, GetParam());
+ AddSimpleTrace(sc1);
+ AddSimpleTrace(sc1);
+ AddSimpleTrace(sc1);
+ ValidateChannelTrace(sc1, 3, GetParam());
+ AddSimpleTrace(sc1);
+ AddSimpleTrace(sc1);
+ AddSimpleTrace(sc1);
+ ValidateChannelTrace(sc1, 6, GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 5, GetParam());
+ ValidateTraceDataMatchedUuidLookup(tracer);
+ RefCountedPtr<ChannelTrace> sc2 = MakeRefCounted<ChannelTrace>(GetParam());
+ tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("LB channel two created"), sc2);
+ tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Warning,
+ grpc_slice_from_static_string("subchannel one inactive"), sc1);
+ ValidateChannelTrace(tracer, 7, GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateTraceDataMatchedUuidLookup(tracer);
+ tracer.reset(nullptr);
+ sc1.reset(nullptr);
+ sc2.reset(nullptr);
+}
+
+// Test a case in which the parent channel has subchannels and the subchannels
+// have connections. Ensures that everything lives as long as it should then
+// gets deleted.
+TEST_P(ChannelTracerTest, TestNesting) {
+ grpc_core::ExecCtx exec_ctx;
+ RefCountedPtr<ChannelTrace> tracer = MakeRefCounted<ChannelTrace>(GetParam());
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 2, GetParam());
+ RefCountedPtr<ChannelTrace> sc1 = MakeRefCounted<ChannelTrace>(GetParam());
+ tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("subchannel one created"), sc1);
+ ValidateChannelTrace(tracer, 3, GetParam());
+ AddSimpleTrace(sc1);
+ RefCountedPtr<ChannelTrace> conn1 = MakeRefCounted<ChannelTrace>(GetParam());
+ // nesting one level deeper.
+ sc1->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("connection one created"), conn1);
+ ValidateChannelTrace(tracer, 3, GetParam());
+ AddSimpleTrace(conn1);
+ AddSimpleTrace(tracer);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 5, GetParam());
+ ValidateChannelTrace(conn1, 1, GetParam());
+ RefCountedPtr<ChannelTrace> sc2 = MakeRefCounted<ChannelTrace>(GetParam());
+ tracer->AddTraceEventReferencingSubchannel(
+ ChannelTrace::Severity::Info,
+ grpc_slice_from_static_string("subchannel two created"), sc2);
+ // this trace should not get added to the parents children since it is already
+ // present in the tracer.
+ tracer->AddTraceEventReferencingChannel(
+ ChannelTrace::Severity::Warning,
+ grpc_slice_from_static_string("subchannel one inactive"), sc1);
+ AddSimpleTrace(tracer);
+ ValidateChannelTrace(tracer, 8, GetParam());
+ tracer.reset(nullptr);
+ sc1.reset(nullptr);
+ sc2.reset(nullptr);
+ conn1.reset(nullptr);
+}
+
+INSTANTIATE_TEST_CASE_P(ChannelTracerTestSweep, ChannelTracerTest,
+ ::testing::Values(0, 1, 2, 6, 10, 15));
+
+} // namespace testing
+} // namespace grpc_core
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ ::testing::InitGoogleTest(&argc, argv);
+ int ret = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return ret;
+}
diff --git a/test/core/client_channel/status_util_test.cc b/test/core/channel/status_util_test.cc
index f944990ad2..1d64bf1995 100644
--- a/test/core/client_channel/status_util_test.cc
+++ b/test/core/channel/status_util_test.cc
@@ -16,7 +16,7 @@
*
*/
-#include "src/core/ext/filters/client_channel/status_util.h"
+#include "src/core/lib/channel/status_util.h"
#include <gtest/gtest.h>
diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD
index d430b722df..5148dc5f74 100644
--- a/test/core/client_channel/BUILD
+++ b/test/core/client_channel/BUILD
@@ -53,15 +53,3 @@ grpc_cc_test(
"//test/core/util:grpc_test_util",
],
)
-
-grpc_cc_test(
- name = "status_util_test",
- srcs = ["status_util_test.cc"],
- language = "C++",
- deps = [
- "//:grpc",
- ],
- external_deps = [
- "gtest",
- ],
-)
diff --git a/test/core/end2end/tests/keepalive_timeout.cc b/test/core/end2end/tests/keepalive_timeout.cc
index f0dd061e33..c0771b8bd2 100644
--- a/test/core/end2end/tests/keepalive_timeout.cc
+++ b/test/core/end2end/tests/keepalive_timeout.cc
@@ -102,7 +102,7 @@ static void test_keepalive_timeout(grpc_end2end_test_config config) {
grpc_arg keepalive_arg_elems[3];
keepalive_arg_elems[0].type = GRPC_ARG_INTEGER;
keepalive_arg_elems[0].key = const_cast<char*>(GRPC_ARG_KEEPALIVE_TIME_MS);
- keepalive_arg_elems[0].value.integer = 1500;
+ keepalive_arg_elems[0].value.integer = 3500;
keepalive_arg_elems[1].type = GRPC_ARG_INTEGER;
keepalive_arg_elems[1].key = const_cast<char*>(GRPC_ARG_KEEPALIVE_TIMEOUT_MS);
keepalive_arg_elems[1].value.integer = 0;
diff --git a/test/core/gprpp/inlined_vector_test.cc b/test/core/gprpp/inlined_vector_test.cc
index b900afaf3d..2a357420f3 100644
--- a/test/core/gprpp/inlined_vector_test.cc
+++ b/test/core/gprpp/inlined_vector_test.cc
@@ -87,14 +87,17 @@ TEST(InlinedVectorTest, ClearAndRepopulate) {
}
TEST(InlinedVectorTest, ConstIndexOperator) {
- const int kNumElements = 10;
+ constexpr int kNumElements = 10;
InlinedVector<int, 5> v;
EXPECT_EQ(0UL, v.size());
for (int i = 0; i < kNumElements; ++i) {
v.push_back(i);
EXPECT_EQ(i + 1UL, v.size());
}
- auto const_func = [kNumElements](const InlinedVector<int, 5>& v) {
+ // The following lambda function is exceptionally allowed to use an anonymous
+ // capture due to the erroneous behavior of the MSVC compiler, that refuses to
+ // capture the kNumElements constexpr, something allowed by the standard.
+ auto const_func = [&](const InlinedVector<int, 5>& v) {
for (int i = 0; i < kNumElements; ++i) {
EXPECT_EQ(i, v[i]);
}
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index 38a7d7e709..866bee5b2f 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -106,6 +106,8 @@ int main(int argc, char **argv) {
printf("%lx", (unsigned long) grpc_insecure_channel_create);
printf("%lx", (unsigned long) grpc_lame_client_channel_create);
printf("%lx", (unsigned long) grpc_channel_destroy);
+ printf("%lx", (unsigned long) grpc_channel_get_trace);
+ printf("%lx", (unsigned long) grpc_channel_get_uuid);
printf("%lx", (unsigned long) grpc_call_cancel);
printf("%lx", (unsigned long) grpc_call_cancel_with_status);
printf("%lx", (unsigned long) grpc_call_ref);
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index d22793e23c..e8d2325b7d 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -485,7 +485,7 @@ TEST_P(AsyncEnd2endTest, DoThenAsyncNextRpc) {
EXPECT_EQ(send_request.message(), recv_request.message());
send_response.set_message(recv_request.message());
- auto lambda_3 = [&, this, resp_writer_ptr, send_response]() {
+ auto lambda_3 = [resp_writer_ptr, send_response]() {
resp_writer_ptr->Finish(send_response, Status::OK, tag(3));
};
Verifier().Expect(3, true).Expect(4, true).Verify(
@@ -1216,8 +1216,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
srv_ctx.AsyncNotifyWhenDone(tag(11));
service_->RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
tag(2));
- std::thread t1(
- [this, &cli_cq] { Verifier().Expect(1, true).Verify(&cli_cq); });
+ std::thread t1([&cli_cq] { Verifier().Expect(1, true).Verify(&cli_cq); });
Verifier().Expect(2, true).Verify(cq_.get());
t1.join();
@@ -1241,7 +1240,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
(server_try_cancel == CANCEL_BEFORE_PROCESSING);
std::thread cli_thread([&cli_cq, &cli_stream, &expected_client_cq_result,
- &ignore_client_cq_result, this] {
+ &ignore_client_cq_result] {
EchoRequest send_request;
// Client sends 3 messages (tags 3, 4 and 5)
for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
@@ -1372,8 +1371,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
service_->RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
cq_.get(), cq_.get(), tag(2));
- std::thread t1(
- [this, &cli_cq] { Verifier().Expect(1, true).Verify(&cli_cq); });
+ std::thread t1([&cli_cq] { Verifier().Expect(1, true).Verify(&cli_cq); });
Verifier().Expect(2, true).Verify(cq_.get());
t1.join();
@@ -1398,7 +1396,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
}
std::thread cli_thread([&cli_cq, &cli_stream, &expected_client_cq_result,
- &ignore_client_cq_result, this] {
+ &ignore_client_cq_result] {
// Client attempts to read the three messages from the server
for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
EchoResponse recv_response;
diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py
index bd40d0a5a2..1ef8f65b0b 100755
--- a/test/cpp/qps/gen_build_yaml.py
+++ b/test/cpp/qps/gen_build_yaml.py
@@ -101,26 +101,24 @@ print yaml.dump({
}
for scenario_json in scenario_config.CXXLanguage().scenarios()
if 'inproc' in scenario_json.get('CATEGORIES', [])
+ ] + [
+ {
+ 'name': 'json_run_localhost',
+ 'shortname': 'json_run_localhost:%s_low_thread_count' % scenario_json['name'],
+ 'args': ['--scenarios_json', _scenario_json_string(scenario_json, True)],
+ 'ci_platforms': ['linux'],
+ 'platforms': ['linux'],
+ 'flaky': False,
+ 'language': 'c++',
+ 'boringssl': True,
+ 'defaults': 'boringssl',
+ 'cpu_cost': guess_cpu(scenario_json, True),
+ 'exclude_configs': sorted(c for c in configs_from_yaml if c not in ('tsan', 'asan')),
+ 'timeout_seconds': 10*60,
+ 'excluded_poll_engines': scenario_json.get('EXCLUDED_POLL_ENGINES', []),
+ 'auto_timeout_scaling': False
+ }
+ for scenario_json in scenario_config.CXXLanguage().scenarios()
+ if 'scalable' in scenario_json.get('CATEGORIES', [])
]
- # Disabled until https://github.com/grpc/grpc/issues/13122 is resolved.
- # + [
- # {
- # 'name': 'json_run_localhost',
- # 'shortname': 'json_run_localhost:%s_low_thread_count' % scenario_json['name'],
- # 'args': ['--scenarios_json', _scenario_json_string(scenario_json, True)],
- # 'ci_platforms': ['linux'],
- # 'platforms': ['linux'],
- # 'flaky': False,
- # 'language': 'c++',
- # 'boringssl': True,
- # 'defaults': 'boringssl',
- # 'cpu_cost': guess_cpu(scenario_json, True),
- # 'exclude_configs': sorted(c for c in configs_from_yaml if c not in ('tsan', 'asan')),
- # 'timeout_seconds': 10*60,
- # 'excluded_poll_engines': scenario_json.get('EXCLUDED_POLL_ENGINES', []),
- # 'auto_timeout_scaling': False
- # }
- # for scenario_json in scenario_config.CXXLanguage().scenarios()
- # if 'scalable' in scenario_json.get('CATEGORIES', [])
- # ]
})
diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD
index 4f84c73820..f53bc7eb7f 100644
--- a/test/cpp/util/BUILD
+++ b/test/cpp/util/BUILD
@@ -85,6 +85,25 @@ grpc_cc_library(
)
grpc_cc_library(
+ name = "channel_trace_proto_helper",
+ testonly = 1,
+ srcs = [
+ "channel_trace_proto_helper.cc",
+ ],
+ hdrs = [
+ "channel_trace_proto_helper.h",
+ ],
+ deps = [
+ "//:grpc++",
+ "//src/proto/grpc/channelz:channelz_proto",
+ ],
+ external_deps = [
+ "gtest",
+ "protobuf",
+ ],
+)
+
+grpc_cc_library(
name = "test_util_unsecure",
srcs = GRPCXX_TESTUTIL_SRCS,
hdrs = GRPCXX_TESTUTIL_HDRS,
diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc
new file mode 100644
index 0000000000..fbc9f1501c
--- /dev/null
+++ b/test/cpp/util/channel_trace_proto_helper.cc
@@ -0,0 +1,56 @@
+/*
+ *
+ * Copyright 2018 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "test/cpp/util/channel_trace_proto_helper.h"
+
+#include <google/protobuf/text_format.h>
+#include <google/protobuf/util/json_util.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <gtest/gtest.h>
+
+#include "src/proto/grpc/channelz/channelz.pb.h"
+
+namespace grpc {
+namespace testing {
+
+void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) {
+ std::string tracer_json_str(tracer_json_c_str);
+ grpc::channelz::ChannelTrace channel_trace;
+ google::protobuf::util::JsonParseOptions parse_options;
+ // If the following line is failing, then uncomment the last line of the
+ // comment, and uncomment the lines that print the two strings. You can
+ // then compare the output, and determine what fields are missing.
+ //
+ // options.ignore_unknown_fields = true;
+ ASSERT_EQ(google::protobuf::util::JsonStringToMessage(
+ tracer_json_str, &channel_trace, parse_options),
+ google::protobuf::util::Status::OK);
+ std::string proto_json_str;
+ ASSERT_EQ(google::protobuf::util::MessageToJsonString(channel_trace,
+ &proto_json_str),
+ google::protobuf::util::Status::OK);
+ // uncomment these to compare the the json strings.
+ // gpr_log(GPR_ERROR, "tracer json: %s", tracer_json_str.c_str());
+ // gpr_log(GPR_ERROR, "proto json: %s", proto_json_str.c_str());
+ ASSERT_EQ(tracer_json_str, proto_json_str);
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/util/channel_trace_proto_helper.h b/test/cpp/util/channel_trace_proto_helper.h
new file mode 100644
index 0000000000..d7043d9f06
--- /dev/null
+++ b/test/cpp/util/channel_trace_proto_helper.h
@@ -0,0 +1,30 @@
+/*
+ *
+ * Copyright 2018 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H
+#define GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H
+
+namespace grpc {
+namespace testing {
+
+void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str);
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H