[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36504)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK.
These changes have been made using string replacement and regex.
Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced.
Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer.

Closes #36504

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36504 from tanvi-jagtap:tjagtap_src_ext_transport_binder 4669996fd8
PiperOrigin-RevId: 630652010
pull/36468/head^2
Tanvi Jagtap 7 months ago committed by Copybara-Service
parent adf042bb41
commit fb72f1df08
  1. 1
      BUILD
  2. 18
      src/core/ext/transport/binder/client/binder_connector.cc
  3. 17
      src/core/ext/transport/binder/client/channel_create.cc
  4. 6
      src/core/ext/transport/binder/client/channel_create_impl.cc
  5. 3
      src/core/ext/transport/binder/client/connection_id_generator.cc
  6. 12
      src/core/ext/transport/binder/client/endpoint_binder_pool.cc
  7. 4
      src/core/ext/transport/binder/client/jni_utils.cc
  8. 6
      src/core/ext/transport/binder/client/security_policy_setting.cc
  9. 12
      src/core/ext/transport/binder/security_policy/binder_security_policy.cc
  10. 3
      src/core/ext/transport/binder/server/binder_server.cc
  11. 4
      src/core/ext/transport/binder/server/binder_server_credentials.cc
  12. 33
      src/core/ext/transport/binder/transport/binder_transport.cc
  13. 3
      src/core/ext/transport/binder/transport/binder_transport.h
  14. 6
      src/core/ext/transport/binder/utils/ndk_binder.cc
  15. 8
      src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc
  16. 3
      src/core/ext/transport/binder/wire_format/binder_android.cc
  17. 21
      src/core/ext/transport/binder/wire_format/transaction.h
  18. 9
      src/core/ext/transport/binder/wire_format/wire_reader_impl.cc
  19. 15
      src/core/ext/transport/binder/wire_format/wire_writer.cc

@ -1131,6 +1131,7 @@ grpc_cc_library(
"absl/container:flat_hash_map",
"absl/functional:any_invocable",
"absl/hash",
"absl/log:check",
"absl/memory",
"absl/meta:type_traits",
"absl/status",

@ -33,6 +33,8 @@
#include <functional>
#include <map>
#include "absl/log/check.h"
#include <grpcpp/security/binder_security_policy.h>
#include "src/core/client_channel/connector.h"
@ -60,21 +62,21 @@ class BinderConnector : public grpc_core::SubchannelConnector {
size_t id_length = args.address->len - sizeof(un->sun_family);
// The c-style string at least will have a null terminator, and the
// connection id itself should not be empty
GPR_ASSERT(id_length >= 2);
CHECK_GE(id_length, 2u);
// Make sure there is null terminator at the expected location before
// reading from it
GPR_ASSERT(un->sun_path[id_length - 1] == '\0');
CHECK_EQ(un->sun_path[id_length - 1], '\0');
conn_id_ = un->sun_path;
}
#else
GPR_ASSERT(0);
CHECK(0);
#endif
gpr_log(GPR_INFO, "BinderConnector %p conn_id_ = %s", this,
conn_id_.c_str());
args_ = args;
GPR_ASSERT(notify_ == nullptr);
GPR_ASSERT(notify != nullptr);
CHECK_EQ(notify_, nullptr);
CHECK_NE(notify, nullptr);
notify_ = notify;
result_ = result;
@ -86,15 +88,15 @@ class BinderConnector : public grpc_core::SubchannelConnector {
}
void OnConnected(std::unique_ptr<grpc_binder::Binder> endpoint_binder) {
GPR_ASSERT(endpoint_binder != nullptr);
CHECK(endpoint_binder != nullptr);
grpc_core::Transport* transport = grpc_create_binder_transport_client(
std::move(endpoint_binder),
grpc_binder::GetSecurityPolicySetting()->Get(conn_id_));
GPR_ASSERT(transport != nullptr);
CHECK_NE(transport, nullptr);
result_->channel_args = args_.channel_args;
result_->transport = transport;
GPR_ASSERT(notify_ != nullptr);
CHECK_NE(notify_, nullptr);
// ExecCtx is required here for running grpc_closure because this callback
// might be invoked from non-gRPC code
if (grpc_core::ExecCtx::Get() == nullptr) {

@ -34,6 +34,7 @@
#ifdef GPR_SUPPORT_BINDER_TRANSPORT
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "absl/time/clock.h"
@ -102,8 +103,8 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
const ChannelArguments& args) {
grpc_init();
GPR_ASSERT(jni_env_void != nullptr);
GPR_ASSERT(security_policy != nullptr);
CHECK_NE(jni_env_void, nullptr);
CHECK_NE(security_policy, nullptr);
// Generate an unique connection ID that identifies this connection (Useful
// for mapping connection between Java and C++ code).
@ -163,7 +164,7 @@ std::shared_ptr<grpc::Channel> CreateBinderChannel(
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}
@ -175,7 +176,7 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}
@ -186,7 +187,7 @@ std::shared_ptr<grpc::Channel> CreateBinderChannel(
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}
@ -198,7 +199,7 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}
@ -207,7 +208,7 @@ bool InitializeBinderChannelJavaClass(void* jni_env_void) {
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}
@ -217,7 +218,7 @@ bool InitializeBinderChannelJavaClass(
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
GPR_ASSERT(0);
CHECK(0);
return {};
}

@ -21,6 +21,8 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include "src/core/ext/transport/binder/client/binder_connector.h"
#include "src/core/ext/transport/binder/transport/binder_transport.h"
#include "src/core/ext/transport/binder/wire_format/binder.h"
@ -50,7 +52,7 @@ grpc_channel* CreateDirectBinderChannelImplForTesting(
grpc_core::Transport* transport = grpc_create_binder_transport_client(
std::move(endpoint_binder), security_policy);
GPR_ASSERT(transport != nullptr);
CHECK_NE(transport, nullptr);
auto channel_args = grpc_core::CoreConfiguration::Get()
.channel_args_preconditioning()
@ -60,7 +62,7 @@ grpc_channel* CreateDirectBinderChannelImplForTesting(
grpc_core::ChannelCreate("binder_target_placeholder", channel_args,
GRPC_CLIENT_DIRECT_CHANNEL, transport);
// TODO(mingcl): Handle error properly
GPR_ASSERT(channel.ok());
CHECK(channel.ok());
grpc_channel_args_destroy(args);
return channel->release()->c_ptr();
}

@ -18,6 +18,7 @@
#ifndef GRPC_NO_BINDER
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
namespace {
@ -55,7 +56,7 @@ std::string ConnectionIdGenerator::Generate(absl::string_view uri) {
// Insert a hyphen before serial number
ret = absl::StrCat(s, "-", ++count_);
}
GPR_ASSERT(ret.length() < kPathLengthLimit);
CHECK_LT(ret.length(), kPathLengthLimit);
return ret;
}

@ -14,6 +14,8 @@
#include "src/core/ext/transport/binder/client/endpoint_binder_pool.h"
#include "absl/log/check.h"
#include <grpc/support/port_platform.h>
#ifndef GRPC_NO_BINDER
@ -35,12 +37,12 @@ Java_io_grpc_binder_cpp_GrpcBinderConnection_notifyConnected__Ljava_lang_String_
jboolean isCopy;
const char* conn_id = jni_env->GetStringUTFChars(conn_id_jstring, &isCopy);
gpr_log(GPR_INFO, "%s invoked with conn_id = %s", __func__, conn_id);
GPR_ASSERT(ibinder != nullptr);
CHECK_NE(ibinder, nullptr);
grpc_binder::ndk_util::SpAIBinder aibinder =
grpc_binder::FromJavaBinder(jni_env, ibinder);
gpr_log(GPR_INFO, "%s got aibinder = %p", __func__, aibinder.get());
auto b = std::make_unique<grpc_binder::BinderAndroid>(aibinder);
GPR_ASSERT(b != nullptr);
CHECK(b != nullptr);
grpc_binder::GetEndpointBinderPool()->AddEndpointBinder(conn_id,
std::move(b));
if (isCopy == JNI_TRUE) {
@ -63,7 +65,7 @@ void EndpointBinderPool::GetEndpointBinder(
if (binder_map_.count(conn_id)) {
b = std::move(binder_map_[conn_id]);
binder_map_.erase(conn_id);
GPR_ASSERT(b != nullptr);
CHECK(b != nullptr);
} else {
if (pending_requests_.count(conn_id) != 0) {
gpr_log(GPR_ERROR,
@ -75,14 +77,14 @@ void EndpointBinderPool::GetEndpointBinder(
return;
}
}
GPR_ASSERT(b != nullptr);
CHECK(b != nullptr);
cb(std::move(b));
}
void EndpointBinderPool::AddEndpointBinder(
std::string conn_id, std::unique_ptr<grpc_binder::Binder> b) {
gpr_log(GPR_INFO, "EndpointBinder added. conn_id = %s", conn_id.c_str());
GPR_ASSERT(b != nullptr);
CHECK(b != nullptr);
// cb will be set in the following block if there is a pending callback
std::function<void(std::unique_ptr<grpc_binder::Binder>)> cb = nullptr;
{

@ -14,6 +14,8 @@
#include "src/core/ext/transport/binder/client/jni_utils.h"
#include "absl/log/check.h"
#include <grpc/support/port_platform.h>
#ifndef GRPC_NO_BINDER
@ -41,7 +43,7 @@ jclass FindNativeConnectionHelper(
}
jclass global_cl = static_cast<jclass>(env->NewGlobalRef(cl));
env->DeleteLocalRef(cl);
GPR_ASSERT(global_cl != nullptr);
CHECK_NE(global_cl, nullptr);
return global_cl;
};
static jclass connection_helper_class = do_find();

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/log/check.h"
#include <grpc/support/port_platform.h>
#ifndef GRPC_NO_BINDER
@ -25,14 +27,14 @@ void SecurityPolicySetting::Set(
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy) {
grpc_core::MutexLock l(&m_);
GPR_ASSERT(security_policy_map_.count(std::string(connection_id)) == 0);
CHECK_EQ(security_policy_map_.count(std::string(connection_id)), 0u);
security_policy_map_[std::string(connection_id)] = security_policy;
}
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
SecurityPolicySetting::Get(absl::string_view connection_id) {
grpc_core::MutexLock l(&m_);
GPR_ASSERT(security_policy_map_.count(std::string(connection_id)) != 0);
CHECK_NE(security_policy_map_.count(std::string(connection_id)), 0u);
return security_policy_map_[std::string(connection_id)];
}

@ -23,6 +23,8 @@
#include <jni.h>
#include <unistd.h>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "src/core/ext/transport/binder/client/jni_utils.h"
@ -61,8 +63,8 @@ JNIEnv* GetEnv(JavaVM* vm) {
JNIEnv* result = nullptr;
jint attach = vm->AttachCurrentThread(&result, nullptr);
GPR_ASSERT(JNI_OK == attach);
GPR_ASSERT(nullptr != result);
CHECK(JNI_OK == attach);
CHECK_NE(result, nullptr);
return result;
}
} // namespace
@ -70,14 +72,14 @@ JNIEnv* GetEnv(JavaVM* vm) {
SameSignatureSecurityPolicy::SameSignatureSecurityPolicy(JavaVM* jvm,
jobject context)
: jvm_(jvm) {
GPR_ASSERT(jvm != nullptr);
GPR_ASSERT(context != nullptr);
CHECK_NE(jvm, nullptr);
CHECK_NE(context, nullptr);
JNIEnv* env = GetEnv(jvm_);
// Make sure the context is still valid when IsAuthorized() is called
context_ = env->NewGlobalRef(context);
GPR_ASSERT(context_ != nullptr);
CHECK_NE(context_, nullptr);
}
SameSignatureSecurityPolicy::~SameSignatureSecurityPolicy() {

@ -22,6 +22,7 @@
#include <string>
#include <utility>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include <grpc/grpc.h>
@ -212,7 +213,7 @@ class BinderServerListener : public Server::ListenerInterface {
// grpc_create_binder_transport_server().
Transport* server_transport = grpc_create_binder_transport_server(
std::move(client_binder), security_policy_);
GPR_ASSERT(server_transport);
CHECK(server_transport);
grpc_error_handle error = server_->SetupTransport(
server_transport, nullptr, server_->channel_args(), nullptr);
return grpc_error_to_absl_status(error);

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/log/check.h"
#include <grpc/support/port_platform.h>
#ifndef GRPC_NO_BINDER
@ -59,7 +61,7 @@ class BinderServerCredentialsImpl final : public ServerCredentials {
std::shared_ptr<ServerCredentials> BinderServerCredentials(
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy) {
GPR_ASSERT(security_policy != nullptr);
CHECK_NE(security_policy, nullptr);
return std::shared_ptr<ServerCredentials>(
new BinderServerCredentialsImpl(security_policy));
}

@ -23,6 +23,7 @@
#include <string>
#include <utility>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
@ -142,7 +143,7 @@ static void cancel_stream_locked(grpc_binder_transport* transport,
grpc_error_handle error) {
gpr_log(GPR_INFO, "cancel_stream_locked");
if (!stream->is_closed) {
GPR_ASSERT(stream->cancel_self_error.ok());
CHECK(stream->cancel_self_error.ok());
stream->is_closed = true;
stream->cancel_self_error = error;
transport->transport_stream_receiver->CancelStream(stream->tx_code);
@ -196,8 +197,8 @@ static void recv_initial_metadata_locked(void* arg,
if (!stream->is_closed) {
grpc_error_handle error = [&] {
GPR_ASSERT(stream->recv_initial_metadata);
GPR_ASSERT(stream->recv_initial_metadata_ready);
CHECK(stream->recv_initial_metadata);
CHECK(stream->recv_initial_metadata_ready);
if (!args->initial_metadata.ok()) {
gpr_log(GPR_ERROR, "Failed to parse initial metadata");
return absl_status_to_grpc_error(args->initial_metadata.status());
@ -233,8 +234,8 @@ static void recv_message_locked(void* arg, grpc_error_handle /*error*/) {
if (!stream->is_closed) {
grpc_error_handle error = [&] {
GPR_ASSERT(stream->recv_message);
GPR_ASSERT(stream->recv_message_ready);
CHECK(stream->recv_message);
CHECK(stream->recv_message_ready);
if (!args->message.ok()) {
gpr_log(GPR_ERROR, "Failed to receive message");
if (args->message.status().message() ==
@ -277,8 +278,8 @@ static void recv_trailing_metadata_locked(void* arg,
if (!stream->is_closed) {
grpc_error_handle error = [&] {
GPR_ASSERT(stream->recv_trailing_metadata);
GPR_ASSERT(stream->recv_trailing_metadata_finished);
CHECK(stream->recv_trailing_metadata);
CHECK(stream->recv_trailing_metadata_finished);
if (!args->trailing_metadata.ok()) {
gpr_log(GPR_ERROR, "Failed to receive trailing metadata");
return absl_status_to_grpc_error(args->trailing_metadata.status());
@ -339,11 +340,11 @@ class MetadataEncoder {
void Encode(grpc_core::HttpPathMetadata, const grpc_core::Slice& value) {
// TODO(b/192208403): Figure out if it is correct to simply drop '/'
// prefix and treat it as rpc method name
GPR_ASSERT(value[0] == '/');
CHECK(value[0] == '/');
std::string path = std::string(value.as_string_view().substr(1));
// Only client send method ref.
GPR_ASSERT(is_client_);
CHECK(is_client_);
tx_->SetMethodRef(path);
}
@ -390,9 +391,9 @@ static void perform_stream_op_locked(void* stream_op,
grpc_binder_transport* transport = stream->t;
if (op->cancel_stream) {
// TODO(waynetu): Is this true?
GPR_ASSERT(!op->send_initial_metadata && !op->send_message &&
!op->send_trailing_metadata && !op->recv_initial_metadata &&
!op->recv_message && !op->recv_trailing_metadata);
CHECK(!op->send_initial_metadata && !op->send_message &&
!op->send_trailing_metadata && !op->recv_initial_metadata &&
!op->recv_message && !op->recv_trailing_metadata);
gpr_log(GPR_INFO, "cancel_stream is_client = %d", stream->is_client);
if (!stream->is_client) {
// Send trailing metadata to inform the other end about the cancellation,
@ -741,8 +742,8 @@ grpc_core::Transport* grpc_create_binder_transport_client(
security_policy) {
gpr_log(GPR_INFO, __func__);
GPR_ASSERT(endpoint_binder != nullptr);
GPR_ASSERT(security_policy != nullptr);
CHECK(endpoint_binder != nullptr);
CHECK_NE(security_policy, nullptr);
grpc_binder_transport* t = new grpc_binder_transport(
std::move(endpoint_binder), /*is_client=*/true, security_policy);
@ -756,8 +757,8 @@ grpc_core::Transport* grpc_create_binder_transport_server(
security_policy) {
gpr_log(GPR_INFO, __func__);
GPR_ASSERT(client_binder != nullptr);
GPR_ASSERT(security_policy != nullptr);
CHECK(client_binder != nullptr);
CHECK_NE(security_policy, nullptr);
grpc_binder_transport* t = new grpc_binder_transport(
std::move(client_binder), /*is_client=*/false, security_policy);

@ -22,6 +22,7 @@
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -74,7 +75,7 @@ struct grpc_binder_transport final : public grpc_core::FilterStackTransport {
// TODO(mingcl): Wrap around when all tx codes are used. "If we do detect a
// collision however, we will fail the new call with UNAVAILABLE, and shut
// down the transport gracefully."
GPR_ASSERT(next_free_tx_code <= LAST_CALL_TRANSACTION);
CHECK(next_free_tx_code <= LAST_CALL_TRANSACTION);
return next_free_tx_code++;
}

@ -22,6 +22,8 @@
#include <dlfcn.h>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
@ -36,7 +38,7 @@ void* GetNdkBinderHandle() {
gpr_log(
GPR_ERROR,
"Cannot open libbinder_ndk.so. Does this device support API level 29?");
GPR_ASSERT(0);
CHECK(0);
}
return handle;
}
@ -102,7 +104,7 @@ namespace ndk_util {
"dlsym failed. Cannot find %s in libbinder_ndk.so. " \
"BinderTransport requires API level >= 33", \
#name); \
GPR_ASSERT(0); \
CHECK(0); \
} \
return ptr

@ -22,6 +22,8 @@
#include <string>
#include <utility>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
@ -38,7 +40,7 @@ void TransportStreamReceiverImpl::RegisterRecvInitialMetadata(
absl::StatusOr<Metadata> initial_metadata{};
{
grpc_core::MutexLock l(&m_);
GPR_ASSERT(initial_metadata_cbs_.count(id) == 0);
CHECK_EQ(initial_metadata_cbs_.count(id), 0u);
auto iter = pending_initial_metadata_.find(id);
if (iter == pending_initial_metadata_.end()) {
if (trailing_metadata_recvd_.count(id)) {
@ -66,7 +68,7 @@ void TransportStreamReceiverImpl::RegisterRecvMessage(
absl::StatusOr<std::string> message{};
{
grpc_core::MutexLock l(&m_);
GPR_ASSERT(message_cbs_.count(id) == 0);
CHECK_EQ(message_cbs_.count(id), 0u);
auto iter = pending_message_.find(id);
if (iter == pending_message_.end()) {
// If we'd already received trailing-metadata and there's no pending
@ -100,7 +102,7 @@ void TransportStreamReceiverImpl::RegisterRecvTrailingMetadata(
std::pair<absl::StatusOr<Metadata>, int> trailing_metadata{};
{
grpc_core::MutexLock l(&m_);
GPR_ASSERT(trailing_metadata_cbs_.count(id) == 0);
CHECK_EQ(trailing_metadata_cbs_.count(id), 0u);
auto iter = pending_trailing_metadata_.find(id);
if (iter == pending_trailing_metadata_.end()) {
trailing_metadata_cbs_[id] = std::move(cb);

@ -20,6 +20,7 @@
#include <map>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
@ -152,7 +153,7 @@ TransactionReceiverAndroid::TransactionReceiverAndroid(
args.wire_reader_ref = wire_reader_ref;
args.callback = &transact_cb_;
binder_ = ndk_util::AIBinder_new(aibinder_class, &args);
GPR_ASSERT(binder_);
CHECK(binder_);
gpr_log(GPR_INFO, "ndk_util::AIBinder_associateClass = %d",
static_cast<int>(
ndk_util::AIBinder_associateClass(binder_, aibinder_class)));

@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include "absl/log/check.h"
#include "absl/strings/string_view.h"
#include <grpc/support/log.h>
@ -45,33 +46,33 @@ class Transaction {
// TODO(mingcl): Consider using string_view
void SetPrefix(Metadata prefix_metadata) {
prefix_metadata_ = prefix_metadata;
GPR_ASSERT((flags_ & kFlagPrefix) == 0);
CHECK_EQ((flags_ & kFlagPrefix), 0);
flags_ |= kFlagPrefix;
}
void SetMethodRef(std::string method_ref) {
GPR_ASSERT(is_client_);
CHECK(is_client_);
method_ref_ = method_ref;
}
void SetData(std::string message_data) {
message_data_ = message_data;
GPR_ASSERT((flags_ & kFlagMessageData) == 0);
CHECK_EQ((flags_ & kFlagMessageData), 0);
flags_ |= kFlagMessageData;
}
void SetSuffix(Metadata suffix_metadata) {
if (is_client_) GPR_ASSERT(suffix_metadata.empty());
if (is_client_) CHECK(suffix_metadata.empty());
suffix_metadata_ = suffix_metadata;
GPR_ASSERT((flags_ & kFlagSuffix) == 0);
CHECK_EQ((flags_ & kFlagSuffix), 0);
flags_ |= kFlagSuffix;
}
void SetStatusDescription(std::string status_desc) {
GPR_ASSERT(!is_client_);
GPR_ASSERT((flags_ & kFlagStatusDescription) == 0);
CHECK(!is_client_);
CHECK_EQ((flags_ & kFlagStatusDescription), 0);
status_desc_ = status_desc;
}
void SetStatus(int status) {
GPR_ASSERT(!is_client_);
GPR_ASSERT((flags_ >> 16) == 0);
GPR_ASSERT(status < (1 << 16));
CHECK(!is_client_);
CHECK_EQ((flags_ >> 16), 0);
CHECK(status < (1 << 16));
flags_ |= (status << 16);
}

@ -25,6 +25,7 @@
#include <vector>
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/status/statusor.h"
@ -305,7 +306,7 @@ absl::Status WireReaderImpl::ProcessStreamingTransaction(
absl::Seconds(5))) {
return absl::DeadlineExceededError("wire_writer_ is not ready in time!");
}
GPR_ASSERT(wire_writer_);
CHECK(wire_writer_);
// wire_writer_ should not be accessed while holding mu_!
// Otherwise, it is possible that
// 1. wire_writer_::mu_ is acquired before mu_ (NDK call back during
@ -323,7 +324,7 @@ absl::Status WireReaderImpl::ProcessStreamingTransaction(
absl::Status WireReaderImpl::ProcessStreamingTransactionImpl(
transaction_code_t code, ReadableParcel* parcel, int* cancellation_flags,
std::queue<absl::AnyInvocable<void() &&>>& deferred_func_queue) {
GPR_ASSERT(cancellation_flags);
CHECK(cancellation_flags);
num_incoming_bytes_ += parcel->GetDataSize();
gpr_log(GPR_INFO, "Total incoming bytes: %" PRId64, num_incoming_bytes_);
@ -360,8 +361,8 @@ absl::Status WireReaderImpl::ProcessStreamingTransactionImpl(
// TODO(waynetu): According to the protocol, "The sequence number will wrap
// around to 0 if more than 2^31 messages are sent." For now we'll just
// assert that it never reach such circumstances.
GPR_ASSERT(expectation < std::numeric_limits<int32_t>::max() &&
"Sequence number too large");
CHECK(expectation < std::numeric_limits<int32_t>::max())
<< "Sequence number too large";
expectation++;
gpr_log(GPR_DEBUG, "sequence number = %d", seq_num);
if (flags & kFlagPrefix) {

@ -21,6 +21,7 @@
#include <utility>
#include "absl/cleanup/cleanup.h"
#include "absl/log/check.h"
#include "absl/types/variant.h"
#include <grpc/support/log.h>
@ -122,7 +123,7 @@ absl::Status WireWriterImpl::MakeBinderTransaction(
gpr_log(GPR_INFO, "Total outgoing bytes: %" PRId64,
num_outgoing_bytes_.load());
}
GPR_ASSERT(!is_transacting_);
CHECK(!is_transacting_);
is_transacting_ = true;
absl::Status result = binder_->Transact(tx_code);
is_transacting_ = false;
@ -155,10 +156,10 @@ absl::Status WireWriterImpl::RunStreamTx(
bool* is_last_chunk) {
Transaction* tx = stream_tx->tx.get();
// Transaction without data flag should go to fast path.
GPR_ASSERT(tx->GetFlags() & kFlagMessageData);
CHECK(tx->GetFlags() & kFlagMessageData);
absl::string_view data = tx->GetMessageData();
GPR_ASSERT(stream_tx->bytes_sent <= static_cast<int64_t>(data.size()));
CHECK(stream_tx->bytes_sent <= static_cast<int64_t>(data.size()));
int flags = kFlagMessageData;
@ -206,7 +207,7 @@ absl::Status WireWriterImpl::RunStreamTx(
}
void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) {
GPR_ASSERT(args->writer == this);
CHECK(args->writer == this);
if (absl::holds_alternative<RunScheduledTxArgs::AckTx>(args->tx)) {
int64_t num_bytes =
absl::get<RunScheduledTxArgs::AckTx>(args->tx).num_bytes;
@ -223,7 +224,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) {
delete args;
return;
}
GPR_ASSERT(absl::holds_alternative<RunScheduledTxArgs::StreamTx>(args->tx));
CHECK(absl::holds_alternative<RunScheduledTxArgs::StreamTx>(args->tx));
RunScheduledTxArgs::StreamTx* stream_tx =
&absl::get<RunScheduledTxArgs::StreamTx>(args->tx);
// Be reservative. Decrease CombinerTxCount after the data size of this
@ -232,7 +233,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) {
auto decrease_combiner_tx_count = absl::MakeCleanup([this]() {
{
grpc_core::MutexLock lock(&flow_control_mu_);
GPR_ASSERT(num_non_acked_tx_in_combiner_ > 0);
CHECK_GT(num_non_acked_tx_in_combiner_, 0);
num_non_acked_tx_in_combiner_--;
}
// New transaction might be ready to be scheduled.
@ -271,7 +272,7 @@ void WireWriterImpl::RunScheduledTxInternal(RunScheduledTxArgs* args) {
absl::Status WireWriterImpl::RpcCall(std::unique_ptr<Transaction> tx) {
// TODO(mingcl): check tx_code <= last call id
GPR_ASSERT(tx->GetTxCode() >= kFirstCallId);
CHECK(tx->GetTxCode() >= kFirstCallId);
auto args = new RunScheduledTxArgs();
args->writer = this;
args->tx = RunScheduledTxArgs::StreamTx();

Loading…
Cancel
Save