diff --git a/BUILD b/BUILD index 3e2a45b8a0adc19f03b37bf15e1ffdcdbf517476..ffeb31e424b852f5fdbd9a63039f08212306de96 100644 --- a/BUILD +++ b/BUILD @@ -223,6 +223,7 @@ cc_library( "src/core/surface/api_trace.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", + "src/core/surface/call_test_only.h", "src/core/surface/channel.h", "src/core/surface/completion_queue.h", "src/core/surface/event_string.h", @@ -509,6 +510,7 @@ cc_library( "src/core/surface/api_trace.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", + "src/core/surface/call_test_only.h", "src/core/surface/channel.h", "src/core/surface/completion_queue.h", "src/core/surface/event_string.h", @@ -1296,6 +1298,7 @@ objc_library( "src/core/surface/api_trace.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", + "src/core/surface/call_test_only.h", "src/core/surface/channel.h", "src/core/surface/completion_queue.h", "src/core/surface/event_string.h", diff --git a/build.yaml b/build.yaml index 98fb0348ca3bc32e78bda06193350b9fa9ff1795..e277b60b77e782c43c76e3710261e7b88a7b9dfa 100644 --- a/build.yaml +++ b/build.yaml @@ -183,6 +183,7 @@ filegroups: - src/core/surface/api_trace.h - src/core/surface/byte_buffer_queue.h - src/core/surface/call.h + - src/core/surface/call_test_only.h - src/core/surface/channel.h - src/core/surface/completion_queue.h - src/core/surface/event_string.h diff --git a/gRPC.podspec b/gRPC.podspec index 717e7005ee5d21208b301835a219ef70eb7cdc77..6378cf0413cde1dc51f3e5dea2fd800d58a576d7 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -227,6 +227,7 @@ Pod::Spec.new do |s| 'src/core/surface/api_trace.h', 'src/core/surface/byte_buffer_queue.h', 'src/core/surface/call.h', + 'src/core/surface/call_test_only.h', 'src/core/surface/channel.h', 'src/core/surface/completion_queue.h', 'src/core/surface/event_string.h', @@ -518,6 +519,7 @@ Pod::Spec.new do |s| 'src/core/surface/api_trace.h', 'src/core/surface/byte_buffer_queue.h', 'src/core/surface/call.h', + 'src/core/surface/call_test_only.h', 'src/core/surface/channel.h', 'src/core/surface/completion_queue.h', 'src/core/surface/event_string.h', diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 8a7a772821ea314efee099d77c89fa5b21f9a8fb..022ca191cd741b797dcbbd71ce05308437a94e40 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -527,9 +527,13 @@ static void set_compression_algorithm(grpc_call *call, call->compression_algorithm = algo; } -grpc_compression_algorithm grpc_call_get_compression_algorithm( - const grpc_call *call) { - return call->compression_algorithm; +grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( + grpc_call *call) { + grpc_compression_algorithm algorithm; + gpr_mu_lock(&call->mu); + algorithm = call->compression_algorithm; + gpr_mu_unlock(&call->mu); + return algorithm; } static void set_encodings_accepted_by_peer( @@ -563,12 +567,20 @@ static void set_encodings_accepted_by_peer( } } -gpr_uint32 grpc_call_get_encodings_accepted_by_peer(grpc_call *call) { - return call->encodings_accepted_by_peer; +gpr_uint32 grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { + gpr_uint32 encodings_accepted_by_peer; + gpr_mu_lock(&call->mu); + encodings_accepted_by_peer = call->encodings_accepted_by_peer; + gpr_mu_unlock(&call->mu); + return encodings_accepted_by_peer; } -gpr_uint32 grpc_call_get_message_flags(const grpc_call *call) { - return call->incoming_message_flags; +gpr_uint32 grpc_call_test_only_get_message_flags(grpc_call *call) { + gpr_uint32 flags; + gpr_mu_lock(&call->mu); + flags = call->incoming_message_flags; + gpr_mu_unlock(&call->mu); + return flags; } static void set_status_details(grpc_call *call, status_source source, diff --git a/src/core/surface/call.h b/src/core/surface/call.h index f421a81619f7854c0f3024afea7721feadc5876c..9b7c6f9bfbed9e4bc174820fac8759bb5b449c9a 100644 --- a/src/core/surface/call.h +++ b/src/core/surface/call.h @@ -169,17 +169,6 @@ void *grpc_call_context_get(grpc_call *call, grpc_context_index elem); gpr_uint8 grpc_call_is_client(grpc_call *call); -grpc_compression_algorithm grpc_call_get_compression_algorithm( - const grpc_call *call); - -gpr_uint32 grpc_call_get_message_flags(const grpc_call *call); - -/** Returns a bitset for the encodings (compression algorithms) supported by \a - * call's peer. - * - * To be indexed by grpc_compression_algorithm enum values. */ -gpr_uint32 grpc_call_get_encodings_accepted_by_peer(grpc_call *call); - #ifdef __cplusplus } #endif diff --git a/src/core/surface/call_test_only.h b/src/core/surface/call_test_only.h new file mode 100644 index 0000000000000000000000000000000000000000..df4be3248b2a0baa58f16fdfcea7c10f131f01bb --- /dev/null +++ b/src/core/surface/call_test_only.h @@ -0,0 +1,65 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_INTERNAL_CORE_SURFACE_CALL_TEST_ONLY_H +#define GRPC_INTERNAL_CORE_SURFACE_CALL_TEST_ONLY_H + +#include <grpc/grpc.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** Return the compression algorithm from \a call. + * + * \warning This function should \b only be used in test code. */ +grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( + grpc_call *call); + +/** Return the message flags from \a call. + * + * \warning This function should \b only be used in test code. */ +gpr_uint32 grpc_call_test_only_get_message_flags(grpc_call *call); + +/** Returns a bitset for the encodings (compression algorithms) supported by \a + * call's peer. + * + * To be indexed by grpc_compression_algorithm enum values. */ +gpr_uint32 grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call); + + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_TEST_ONLY_H */ diff --git a/test/core/end2end/tests/compressed_payload.c b/test/core/end2end/tests/compressed_payload.c index a4614a2aba4b15d7cbfe52fc79b6b2bcfde52d4e..f321fe1e7c7f8f09769e64dab29394912f336172 100644 --- a/test/core/end2end/tests/compressed_payload.c +++ b/test/core/end2end/tests/compressed_payload.c @@ -46,7 +46,7 @@ #include "test/core/end2end/cq_verifier.h" #include "src/core/channel/channel_args.h" #include "src/core/channel/compress_filter.h" -#include "src/core/surface/call.h" +#include "src/core/surface/call_test_only.h" enum { TIMEOUT = 200000 }; @@ -196,12 +196,13 @@ static void request_with_payload_template( cq_expect_completion(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(GPR_BITCOUNT(grpc_call_get_encodings_accepted_by_peer(s)) == 3); - GPR_ASSERT(GPR_BITGET(grpc_call_get_encodings_accepted_by_peer(s), + GPR_ASSERT( + GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(s)) == 3); + GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_NONE) != 0); - GPR_ASSERT(GPR_BITGET(grpc_call_get_encodings_accepted_by_peer(s), + GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_DEFLATE) != 0); - GPR_ASSERT(GPR_BITGET(grpc_call_get_encodings_accepted_by_peer(s), + GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s), GRPC_COMPRESS_GZIP) != 0); op = ops; diff --git a/test/cpp/interop/client_helper.h b/test/cpp/interop/client_helper.h index 0221df93db5a715bd93781b2077297d1a64014b1..ace193042ee39b1ed88a4226773e4257a678e13d 100644 --- a/test/cpp/interop/client_helper.h +++ b/test/cpp/interop/client_helper.h @@ -38,7 +38,7 @@ #include <grpc++/channel.h> -#include "src/core/surface/call.h" +#include "src/core/surface/call_test_only.h" namespace grpc { namespace testing { @@ -57,11 +57,11 @@ class InteropClientContextInspector { // Inspector methods, able to peek inside ClientContext, follow. grpc_compression_algorithm GetCallCompressionAlgorithm() const { - return grpc_call_get_compression_algorithm(context_.call_); + return grpc_call_test_only_get_compression_algorithm(context_.call_); } gpr_uint32 GetMessageFlags() const { - return grpc_call_get_message_flags(context_.call_); + return grpc_call_test_only_get_message_flags(context_.call_); } private: diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index 4570750846674f276d0444f8ccbe782f0c8648f2..5138a38170a0797fcd2b77360a66afc45b4a8ca9 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -38,7 +38,7 @@ #include <gflags/gflags.h> #include <grpc++/security/server_credentials.h> -#include "src/core/surface/call.h" +#include "src/core/surface/call_test_only.h" #include "test/core/end2end/data/ssl_test_data.h" DECLARE_bool(use_tls); @@ -65,11 +65,11 @@ InteropServerContextInspector::InteropServerContextInspector( grpc_compression_algorithm InteropServerContextInspector::GetCallCompressionAlgorithm() const { - return grpc_call_get_compression_algorithm(context_.call_); + return grpc_call_test_only_get_compression_algorithm(context_.call_); } gpr_uint32 InteropServerContextInspector::GetEncodingsAcceptedByClient() const { - return grpc_call_get_encodings_accepted_by_peer(context_.call_); + return grpc_call_test_only_get_encodings_accepted_by_peer(context_.call_); } std::shared_ptr<const AuthContext> diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 5658a102d75d36deccc0e1aaa99210a32c3253a2..5fd3ee70d635517f8678b6f851a20b98a5333488 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -858,6 +858,7 @@ src/core/statistics/census_rpc_stats.h \ src/core/surface/api_trace.h \ src/core/surface/byte_buffer_queue.h \ src/core/surface/call.h \ +src/core/surface/call_test_only.h \ src/core/surface/channel.h \ src/core/surface/completion_queue.h \ src/core/surface/event_string.h \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 1ceff15a3be19ad9625bd90a0650f9b07652b58b..76d66ed7a07a81052fe74dc641249df75d26ba0d 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12365,6 +12365,7 @@ "src/core/surface/api_trace.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", + "src/core/surface/call_test_only.h", "src/core/surface/channel.h", "src/core/surface/completion_queue.h", "src/core/surface/event_string.h", @@ -12607,6 +12608,7 @@ "src/core/surface/call.h", "src/core/surface/call_details.c", "src/core/surface/call_log_batch.c", + "src/core/surface/call_test_only.h", "src/core/surface/channel.c", "src/core/surface/channel.h", "src/core/surface/channel_connectivity.c", @@ -12861,6 +12863,7 @@ "src/core/surface/api_trace.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", + "src/core/surface/call_test_only.h", "src/core/surface/channel.h", "src/core/surface/completion_queue.h", "src/core/surface/event_string.h", @@ -13073,6 +13076,7 @@ "src/core/surface/call.h", "src/core/surface/call_details.c", "src/core/surface/call_log_batch.c", + "src/core/surface/call_test_only.h", "src/core/surface/channel.c", "src/core/surface/channel.h", "src/core/surface/channel_connectivity.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 183edbc05bf7cd124537104857d68049da4de391..88b883f67cfc519d0c0f8c5697fea7be4671fa7c 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -344,6 +344,7 @@ <ClInclude Include="..\..\..\src\core\surface\api_trace.h" /> <ClInclude Include="..\..\..\src\core\surface\byte_buffer_queue.h" /> <ClInclude Include="..\..\..\src\core\surface\call.h" /> + <ClInclude Include="..\..\..\src\core\surface\call_test_only.h" /> <ClInclude Include="..\..\..\src\core\surface\channel.h" /> <ClInclude Include="..\..\..\src\core\surface\completion_queue.h" /> <ClInclude Include="..\..\..\src\core\surface\event_string.h" /> diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 66ce9ca05be6387db553db3a0be7571d201cf373..1a46ac8e34b79036b9be797bb278f767b8fc197a 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -743,6 +743,9 @@ <ClInclude Include="..\..\..\src\core\surface\call.h"> <Filter>src\core\surface</Filter> </ClInclude> + <ClInclude Include="..\..\..\src\core\surface\call_test_only.h"> + <Filter>src\core\surface</Filter> + </ClInclude> <ClInclude Include="..\..\..\src\core\surface\channel.h"> <Filter>src\core\surface</Filter> </ClInclude> diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index b527179f9f314935c5bac6aade3c72617646481c..cddd00374b2d2c1d3d80512873e3497c571aa9cc 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -323,6 +323,7 @@ <ClInclude Include="..\..\..\src\core\surface\api_trace.h" /> <ClInclude Include="..\..\..\src\core\surface\byte_buffer_queue.h" /> <ClInclude Include="..\..\..\src\core\surface\call.h" /> + <ClInclude Include="..\..\..\src\core\surface\call_test_only.h" /> <ClInclude Include="..\..\..\src\core\surface\channel.h" /> <ClInclude Include="..\..\..\src\core\surface\completion_queue.h" /> <ClInclude Include="..\..\..\src\core\surface\event_string.h" /> diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 7be3c9ec93b65d5cfd028d9f04de7f987e01d998..01e0d8daddea8ddac0725b3814bc39fafb7fc68e 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -641,6 +641,9 @@ <ClInclude Include="..\..\..\src\core\surface\call.h"> <Filter>src\core\surface</Filter> </ClInclude> + <ClInclude Include="..\..\..\src\core\surface\call_test_only.h"> + <Filter>src\core\surface</Filter> + </ClInclude> <ClInclude Include="..\..\..\src\core\surface\channel.h"> <Filter>src\core\surface</Filter> </ClInclude>