Fix some of QUICHE tests that fail due to EXPECT_QUIC_BUG aspects
Most of them are written with the assumption that EXPECT_QUIC_BUG does not use EXPECT_DEBUG_DEATH, which is not always true. This fixes some of those instances, as well as other miscellaneous failures.
PiperOrigin-RevId: 452017561
diff --git a/quiche/common/platform/default/quiche_platform_impl/quiche_logging_impl.h b/quiche/common/platform/default/quiche_platform_impl/quiche_logging_impl.h
index 1b0c764..4ad42b1 100644
--- a/quiche/common/platform/default/quiche_platform_impl/quiche_logging_impl.h
+++ b/quiche/common/platform/default/quiche_platform_impl/quiche_logging_impl.h
@@ -142,8 +142,9 @@
#define QUICHE_DCHECK_IMPL(condition) \
QUICHE_NOOP_STREAM_WITH_CONDITION((condition))
#else
-#define QUICHE_DCHECK_IMPL(condition) \
- QUICHE_LOG_IF_IMPL(DFATAL, !static_cast<bool>(condition))
+#define QUICHE_DCHECK_IMPL(condition) \
+ QUICHE_LOG_IF_IMPL(DFATAL, !static_cast<bool>(condition)) \
+ << "Check failed: " << #condition
#endif
#define QUICHE_DCHECK_EQ_IMPL(val1, val2) QUICHE_DCHECK_IMPL((val1) == (val2))
#define QUICHE_DCHECK_NE_IMPL(val1, val2) QUICHE_DCHECK_IMPL((val1) != (val2))
diff --git a/quiche/http2/decoder/decode_buffer_test.cc b/quiche/http2/decoder/decode_buffer_test.cc
index 6e5eb9c..7eaae79 100644
--- a/quiche/http2/decoder/decode_buffer_test.cc
+++ b/quiche/http2/decoder/decode_buffer_test.cc
@@ -131,14 +131,9 @@
TEST(DecodeBufferDeathTest, ModestBufferSizeRequired) {
EXPECT_QUICHE_DEBUG_DEATH(
{
- // This depends on being able to allocate a fairly large array on the
- // stack. If that fails, we can instead do this:
- //
- // std::string data(DecodeBuffer::kMaxDecodeBufferLength + 1, ' ');
- // DecodeBuffer b(data.data(), data.size());
-
- const char data[DecodeBuffer::kMaxDecodeBufferLength + 1] = {};
- DecodeBuffer b(data, sizeof data);
+ constexpr size_t kLength = DecodeBuffer::kMaxDecodeBufferLength + 1;
+ auto data = std::make_unique<char[]>(kLength);
+ DecodeBuffer b(data.get(), kLength);
},
"Max.*Length");
}
@@ -159,7 +154,7 @@
DecodeBuffer b(data, 3);
b.AdvanceCursor(4);
},
- "4 vs. 3");
+ "Remaining");
}
// Make sure that DecodeBuffer detects decode beyond end, in debug mode.
@@ -168,7 +163,7 @@
DecodeBuffer b(data, sizeof data);
EXPECT_EQ(2u, b.FullSize());
EXPECT_EQ(0x1223, b.DecodeUInt16());
- EXPECT_QUICHE_DEBUG_DEATH({ b.DecodeUInt8(); }, "1 vs. 0");
+ EXPECT_QUICHE_DEBUG_DEATH({ b.DecodeUInt8(); }, "Remaining");
}
// Make sure that DecodeBuffer detects decode beyond end, in debug mode.
@@ -177,7 +172,7 @@
DecodeBuffer b(data, sizeof data);
EXPECT_EQ(3u, b.FullSize());
EXPECT_EQ(0x1223, b.DecodeUInt16());
- EXPECT_QUICHE_DEBUG_DEATH({ b.DecodeUInt16(); }, "2 vs. 1");
+ EXPECT_QUICHE_DEBUG_DEATH({ b.DecodeUInt16(); }, "Remaining");
}
// Make sure that DecodeBuffer doesn't agree with having two subsets.
diff --git a/quiche/quic/core/crypto/transport_parameters_test.cc b/quiche/quic/core/crypto/transport_parameters_test.cc
index b8793ec..76613f0 100644
--- a/quiche/quic/core/crypto/transport_parameters_test.cc
+++ b/quiche/quic/core/crypto/transport_parameters_test.cc
@@ -484,12 +484,10 @@
orig_params.max_udp_payload_size.set_value(kMaxPacketSizeForTest);
std::vector<uint8_t> out;
- bool ok = true;
EXPECT_QUIC_BUG(
- ok = SerializeTransportParameters(orig_params, &out),
+ EXPECT_FALSE(SerializeTransportParameters(orig_params, &out)),
"Not serializing invalid transport parameters: Client cannot send "
"stateless reset token");
- EXPECT_FALSE(ok);
}
TEST_P(TransportParametersTest, ParseClientParams) {
diff --git a/quiche/quic/core/http/http_decoder_test.cc b/quiche/quic/core/http/http_decoder_test.cc
index 5e3d6d6..7f80d17 100644
--- a/quiche/quic/core/http/http_decoder_test.cc
+++ b/quiche/quic/core/http/http_decoder_test.cc
@@ -1066,9 +1066,12 @@
EXPECT_CALL(visitor, OnWebTransportStreamFrameType(_, _));
decoder.ProcessInput(input.data(), input.size());
- EXPECT_CALL(visitor, OnError(_));
- EXPECT_QUIC_BUG(decoder.ProcessInput(input.data(), input.size()),
- "HttpDecoder called after an indefinite-length frame");
+ EXPECT_QUIC_BUG(
+ {
+ EXPECT_CALL(visitor, OnError(_));
+ decoder.ProcessInput(input.data(), input.size());
+ },
+ "HttpDecoder called after an indefinite-length frame");
}
TEST_F(HttpDecoderTest, DecodeSettings) {
diff --git a/quiche/quic/core/http/quic_spdy_stream_test.cc b/quiche/quic/core/http/quic_spdy_stream_test.cc
index 834c51a..c4526ed 100644
--- a/quiche/quic/core/http/quic_spdy_stream_test.cc
+++ b/quiche/quic/core/http/quic_spdy_stream_test.cc
@@ -3212,11 +3212,12 @@
// This private method should never be called when
// `qpack_decoded_headers_accumulator_` is nullptr. The number 1 identifies
// the site where `qpack_decoded_headers_accumulator_` was last reset.
- EXPECT_CALL(*connection_, CloseConnection(_, _, _));
- bool result = true;
- EXPECT_QUIC_BUG(result = QuicSpdyStreamPeer::OnHeadersFrameEnd(stream_),
- "b215142466_OnHeadersFrameEnd.: 1$");
- EXPECT_FALSE(result);
+ EXPECT_QUIC_BUG(
+ {
+ EXPECT_CALL(*connection_, CloseConnection(_, _, _));
+ EXPECT_FALSE(QuicSpdyStreamPeer::OnHeadersFrameEnd(stream_));
+ },
+ "b215142466_OnHeadersFrameEnd.?: 1");
}
} // namespace
diff --git a/quiche/quic/core/quic_packet_creator_test.cc b/quiche/quic/core/quic_packet_creator_test.cc
index 02757bd..b0133fd 100644
--- a/quiche/quic/core/quic_packet_creator_test.cc
+++ b/quiche/quic/core/quic_packet_creator_test.cc
@@ -1549,11 +1549,13 @@
}
creator_.set_encryption_level(ENCRYPTION_INITIAL);
- EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
QuicStreamFrame stream_frame(GetNthClientInitiatedStreamId(0),
/*fin=*/false, 0u, absl::string_view());
EXPECT_QUIC_BUG(
- creator_.AddFrame(QuicFrame(stream_frame), NOT_RETRANSMISSION),
+ {
+ EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
+ creator_.AddFrame(QuicFrame(stream_frame), NOT_RETRANSMISSION);
+ },
"Cannot send stream data with level: ENCRYPTION_INITIAL");
}
@@ -1564,11 +1566,13 @@
}
creator_.set_encryption_level(ENCRYPTION_HANDSHAKE);
- EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
QuicStreamFrame stream_frame(GetNthClientInitiatedStreamId(0),
/*fin=*/false, 0u, absl::string_view());
EXPECT_QUIC_BUG(
- creator_.AddFrame(QuicFrame(stream_frame), NOT_RETRANSMISSION),
+ {
+ EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
+ creator_.AddFrame(QuicFrame(stream_frame), NOT_RETRANSMISSION);
+ },
"Cannot send stream data with level: ENCRYPTION_HANDSHAKE");
}
@@ -2563,12 +2567,15 @@
delegate_.SetCanWriteAnything();
const std::string data(10000, '?');
EXPECT_CALL(delegate_, OnSerializedPacket(_)).Times(0);
- EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
- EXPECT_QUIC_BUG(creator_.ConsumeDataFastPath(
- QuicUtils::GetFirstBidirectionalStreamId(
- framer_.transport_version(), Perspective::IS_CLIENT),
- data),
- "");
+ EXPECT_QUIC_BUG(
+ {
+ EXPECT_CALL(delegate_, OnUnrecoverableError(_, _));
+ creator_.ConsumeDataFastPath(
+ QuicUtils::GetFirstBidirectionalStreamId(
+ framer_.transport_version(), Perspective::IS_CLIENT),
+ data);
+ },
+ "");
}
TEST_F(QuicPacketCreatorMultiplePacketsTest, AddControlFrame_OnlyAckWritable) {
diff --git a/quiche/quic/core/quic_stream_sequencer_test.cc b/quiche/quic/core/quic_stream_sequencer_test.cc
index 0e57b09..bfac366 100644
--- a/quiche/quic/core/quic_stream_sequencer_test.cc
+++ b/quiche/quic/core/quic_stream_sequencer_test.cc
@@ -560,11 +560,14 @@
// Now, attempt to mark consumed more data than was readable and expect the
// stream to be closed.
- EXPECT_CALL(stream_, ResetWithError(QuicResetStreamError::FromInternal(
- QUIC_ERROR_PROCESSING_STREAM)));
- EXPECT_QUIC_BUG(sequencer_->MarkConsumed(4),
- "Invalid argument to MarkConsumed."
- " expect to consume: 4, but not enough bytes available.");
+ EXPECT_QUIC_BUG(
+ {
+ EXPECT_CALL(stream_, ResetWithError(QuicResetStreamError::FromInternal(
+ QUIC_ERROR_PROCESSING_STREAM)));
+ sequencer_->MarkConsumed(4);
+ },
+ "Invalid argument to MarkConsumed."
+ " expect to consume: 4, but not enough bytes available.");
}
TEST_F(QuicStreamSequencerTest, MarkConsumedWithMissingPacket) {
diff --git a/quiche/quic/core/tls_client_handshaker_test.cc b/quiche/quic/core/tls_client_handshaker_test.cc
index 91593d6..a1d5984 100644
--- a/quiche/quic/core/tls_client_handshaker_test.cc
+++ b/quiche/quic/core/tls_client_handshaker_test.cc
@@ -577,18 +577,22 @@
TEST_P(TlsClientHandshakerTest, ClientSendingTooManyALPNs) {
std::string long_alpn(250, 'A');
- EXPECT_CALL(*session_, GetAlpnsToOffer())
- .WillOnce(testing::Return(std::vector<std::string>({
- long_alpn + "1",
- long_alpn + "2",
- long_alpn + "3",
- long_alpn + "4",
- long_alpn + "5",
- long_alpn + "6",
- long_alpn + "7",
- long_alpn + "8",
- })));
- EXPECT_QUIC_BUG(stream()->CryptoConnect(), "Failed to set ALPN");
+ EXPECT_QUIC_BUG(
+ {
+ EXPECT_CALL(*session_, GetAlpnsToOffer())
+ .WillOnce(testing::Return(std::vector<std::string>({
+ long_alpn + "1",
+ long_alpn + "2",
+ long_alpn + "3",
+ long_alpn + "4",
+ long_alpn + "5",
+ long_alpn + "6",
+ long_alpn + "7",
+ long_alpn + "8",
+ })));
+ stream()->CryptoConnect();
+ },
+ "Failed to set ALPN");
}
TEST_P(TlsClientHandshakerTest, ServerRequiresCustomALPN) {