diff options
author | ncteisen <ncteisen@gmail.com> | 2017-11-14 16:25:25 -0800 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2017-11-14 16:29:35 -0800 |
commit | 90ffc3a6f74ee6f7db925a054b6f3973bd0d9fc5 (patch) | |
tree | 49f7b69358e4a95838e7e37e124db8f5e0a680fd | |
parent | 467e8369a896397d40abf7c3e9141c1e7440a2e4 (diff) |
Add tracer peer to keep set_enabled private()
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | build.yaml | 2 | ||||
-rw-r--r-- | grpc.gyp | 2 | ||||
-rw-r--r-- | src/core/lib/debug/trace.h | 13 | ||||
-rw-r--r-- | test/core/iomgr/timer_list_test.cc | 9 | ||||
-rw-r--r-- | test/core/transport/connectivity_state_test.cc | 3 | ||||
-rw-r--r-- | test/core/util/BUILD | 2 | ||||
-rw-r--r-- | test/core/util/tracer_peer.cc | 41 | ||||
-rw-r--r-- | test/core/util/tracer_peer.h | 29 | ||||
-rw-r--r-- | tools/run_tests/generated/sources_and_headers.json | 3 |
11 files changed, 98 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7eb0eb79c8..b72554af14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1620,6 +1620,7 @@ add_library(grpc_test_util test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/tracer_peer.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc @@ -1886,6 +1887,7 @@ add_library(grpc_test_util_unsecure test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/tracer_peer.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc @@ -3603,6 +3603,7 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/tracer_peer.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ @@ -3859,6 +3860,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/tracer_peer.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ diff --git a/build.yaml b/build.yaml index 910b00ebe2..b7b5b93f7b 100644 --- a/build.yaml +++ b/build.yaml @@ -714,6 +714,7 @@ filegroups: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/slice_splitter.h + - test/core/util/tracer_peer.h - test/core/util/trickle_endpoint.h src: - src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -730,6 +731,7 @@ filegroups: - test/core/util/port.cc - test/core/util/port_server_client.cc - test/core/util/slice_splitter.cc + - test/core/util/tracer_peer.cc - test/core/util/trickle_endpoint.cc deps: - gpr_test_util @@ -515,6 +515,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/tracer_peer.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', @@ -723,6 +724,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/tracer_peer.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index cc9d9d2b2d..5e5143e502 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -45,6 +45,8 @@ void grpc_tracer_shutdown(void); namespace grpc_core { class TraceFlag { + friend class TraceFlagPeer; + public: TraceFlag(bool default_enabled, const char* name); ~TraceFlag() {} @@ -61,8 +63,9 @@ class TraceFlag { #endif } - // Only to be used for testing purposes. Tracers should usually be set using - // the static Set function + private: + static void LogAllTracers(); + void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER gpr_atm_no_barrier_store(&value_, enabled); @@ -71,9 +74,6 @@ class TraceFlag { #endif } - private: - static void LogAllTracers(); - static TraceFlag* root_tracer_; TraceFlag* next_tracer_; const char* const name_; @@ -91,6 +91,9 @@ class DebugOnlyTraceFlag { public: DebugOnlyTraceFlag(bool default_enabled, const char* name) {} bool enabled() { return false; } + + private: + void set_enabled(bool enabled) {} }; #endif 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 */ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fce01bf8ff..63ba4f2282 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8880,6 +8880,7 @@ "test/core/util/port.h", "test/core/util/port_server_client.h", "test/core/util/slice_splitter.h", + "test/core/util/tracer_peer.h", "test/core/util/trickle_endpoint.h" ], "is_filegroup": true, @@ -8914,6 +8915,8 @@ "test/core/util/port_server_client.h", "test/core/util/slice_splitter.cc", "test/core/util/slice_splitter.h", + "test/core/util/tracer_peer.cc", + "test/core/util/tracer_peer.h", "test/core/util/trickle_endpoint.cc", "test/core/util/trickle_endpoint.h" ], |