aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2017-11-14 16:25:25 -0800
committerGravatar ncteisen <ncteisen@gmail.com>2017-11-14 16:29:35 -0800
commit90ffc3a6f74ee6f7db925a054b6f3973bd0d9fc5 (patch)
tree49f7b69358e4a95838e7e37e124db8f5e0a680fd /test/core
parent467e8369a896397d40abf7c3e9141c1e7440a2e4 (diff)
Add tracer peer to keep set_enabled private()
Diffstat (limited to 'test/core')
-rw-r--r--test/core/iomgr/timer_list_test.cc9
-rw-r--r--test/core/transport/connectivity_state_test.cc3
-rw-r--r--test/core/util/BUILD2
-rw-r--r--test/core/util/tracer_peer.cc41
-rw-r--r--test/core/util/tracer_peer.h29
5 files changed, 79 insertions, 5 deletions
diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc
index 8976894689..6aec1ec13d 100644
--- a/test/core/iomgr/timer_list_test.cc
+++ b/test/core/iomgr/timer_list_test.cc
@@ -28,6 +28,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/debug/trace.h"
#include "test/core/util/test_config.h"
+#include "test/core/util/tracer_peer.h"
#define MAX_CB 30
@@ -48,8 +49,8 @@ static void add_test(void) {
gpr_log(GPR_INFO, "add_test");
grpc_timer_list_init(&exec_ctx);
- grpc_timer_trace.set_enabled(1);
- grpc_timer_check_trace.set_enabled(1);
+ grpc_tracer_peer_enable_flag(&grpc_timer_trace);
+ grpc_tracer_peer_enable_flag(&grpc_timer_check_trace);
memset(cb_called, 0, sizeof(cb_called));
grpc_millis start = grpc_exec_ctx_now(&exec_ctx);
@@ -117,8 +118,8 @@ void destruction_test(void) {
exec_ctx.now_is_valid = true;
exec_ctx.now = 0;
grpc_timer_list_init(&exec_ctx);
- grpc_timer_trace.set_enabled(1);
- grpc_timer_check_trace.set_enabled(1);
+ grpc_tracer_peer_enable_flag(&grpc_timer_trace);
+ grpc_tracer_peer_enable_flag(&grpc_timer_check_trace);
memset(cb_called, 0, sizeof(cb_called));
grpc_timer_init(
diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc
index f42937ee14..1eab6d7ea2 100644
--- a/test/core/transport/connectivity_state_test.cc
+++ b/test/core/transport/connectivity_state_test.cc
@@ -23,6 +23,7 @@
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
+#include "test/core/util/tracer_peer.h"
#define THE_ARG ((void*)(size_t)0xcafebabe)
@@ -136,7 +137,7 @@ static void test_subscribe_with_failure_then_destroy(void) {
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
- grpc_connectivity_state_trace.set_enabled(1);
+ grpc_tracer_peer_enable_flag(&grpc_connectivity_state_trace);
test_connectivity_state_name();
test_check();
test_subscribe_then_unsubscribe();
diff --git a/test/core/util/BUILD b/test/core/util/BUILD
index 2437923435..684986aa3e 100644
--- a/test/core/util/BUILD
+++ b/test/core/util/BUILD
@@ -57,6 +57,7 @@ grpc_cc_library(
"reconnect_server.cc",
"slice_splitter.cc",
"test_tcp_server.cc",
+ "tracer_peer.cc",
"trickle_endpoint.cc",
],
hdrs = [
@@ -69,6 +70,7 @@ grpc_cc_library(
"reconnect_server.h",
"slice_splitter.h",
"test_tcp_server.h",
+ "tracer_peer.h",
"trickle_endpoint.h",
],
language = "C++",
diff --git a/test/core/util/tracer_peer.cc b/test/core/util/tracer_peer.cc
new file mode 100644
index 0000000000..6c18430f89
--- /dev/null
+++ b/test/core/util/tracer_peer.cc
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright 2015 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/core/util/test_config.h"
+
+#include "src/core/lib/debug/trace.h"
+
+namespace grpc_core {
+
+// This class is a friend of TraceFlag, and can be used to manually turn on
+// certain tracers for tests.
+class TraceFlagPeer {
+ public:
+ TraceFlagPeer(TraceFlag* flag) : flag_(flag) {}
+ void enable() { flag_->set_enabled(1); }
+ void disable() { flag_->set_enabled(0); }
+
+ private:
+ TraceFlag* flag_;
+};
+} // namespace grpc_core
+
+void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag) {
+ grpc_core::TraceFlagPeer peer(flag);
+ peer.enable();
+}
diff --git a/test/core/util/tracer_peer.h b/test/core/util/tracer_peer.h
new file mode 100644
index 0000000000..e8a5f6c31a
--- /dev/null
+++ b/test/core/util/tracer_peer.h
@@ -0,0 +1,29 @@
+/*
+ *
+ * Copyright 2015 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_CORE_UTIL_TRACER_PEER_H
+#define GRPC_TEST_CORE_UTIL_TRACER_PEER_H
+
+namespace grpc_core {
+class TraceFlag;
+}
+
+// enables the TraceFlag passed to it. Used for testing purposes.
+void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag);
+
+#endif /* GRPC_TEST_CORE_UTIL_TRACER_PEER_H */