diff options
author | 2017-11-14 16:25:25 -0800 | |
---|---|---|
committer | 2017-11-14 16:29:35 -0800 | |
commit | 90ffc3a6f74ee6f7db925a054b6f3973bd0d9fc5 (patch) | |
tree | 49f7b69358e4a95838e7e37e124db8f5e0a680fd /test/core/util | |
parent | 467e8369a896397d40abf7c3e9141c1e7440a2e4 (diff) |
Add tracer peer to keep set_enabled private()
Diffstat (limited to 'test/core/util')
-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 |
3 files changed, 72 insertions, 0 deletions
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 */ |