Remove QuicTestUtils::GetPacketLengthForOneStream and change three QUIC tests to instead send full sized packets followed by a partially full packet. gfe-relnote: n/a (Test only) PiperOrigin-RevId: 241926261 Change-Id: I84dc9dedb30a809cb800bc4e0c3460c7383415af
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc index b01906d..3d1e483 100644 --- a/quic/core/quic_connection_test.cc +++ b/quic/core/quic_connection_test.cc
@@ -5354,89 +5354,35 @@ if (connection_.SupportsMultiplePacketNumberSpaces()) { return; } - // All packets carry version info till version is negotiated. - size_t payload_length; - size_t length = GetPacketLengthForOneStream( - connection_.version().transport_version, kIncludeVersion, - !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, - PACKET_0BYTE_CONNECTION_ID, - QuicPacketCreatorPeer::GetPacketNumberLength(creator_), - QuicPacketCreatorPeer::GetRetryTokenLengthLength(creator_), - QuicPacketCreatorPeer::GetLengthLength(creator_), &payload_length); - connection_.SetMaxPacketLength(length); // Queue the first packet. + size_t payload_length = connection_.max_packet_length(); EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(testing::Return(false)); const std::string payload(payload_length, 'a'); - EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, NO_FIN) + QuicStreamId first_bidi_stream_id(QuicUtils::GetFirstBidirectionalStreamId( + connection_.version().transport_version, Perspective::IS_CLIENT)); + EXPECT_EQ(0u, connection_ + .SendStreamDataWithString(first_bidi_stream_id, payload, 0, + NO_FIN) .bytes_consumed); EXPECT_EQ(0u, connection_.NumQueuedPackets()); } -TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { +TEST_P(QuicConnectionTest, SendingThreePackets) { if (connection_.SupportsMultiplePacketNumberSpaces()) { return; } - // All packets carry version info till version is negotiated. - size_t payload_length; - // Number of packets this test generates. The goal is to have - // kPacketCount packets, each the same size (overhead and payload). - // The payload will vary depending on the overhead (which in turn - // varies per the QUIC packet encoding rules). - const int kPacketCount = 7; - - // Get the basic packet size. This assumes, among other things, a - // stream offset of 0. - size_t length = GetPacketLengthForOneStream( - connection_.version().transport_version, kIncludeVersion, - !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, - PACKET_0BYTE_CONNECTION_ID, - QuicPacketCreatorPeer::GetPacketNumberLength(creator_), - QuicPacketCreatorPeer::GetRetryTokenLengthLength(creator_), - QuicPacketCreatorPeer::GetLengthLength(creator_), &payload_length); - // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining - // packet length. The size of the offset field in a stream frame is - // 0 for offset 0, and 2 for non-zero offsets up through 16K (for - // versions other than 99) and 1 for non-zero offsets through 16K - // for version 99. Increase the length by 1 or 2, as apporpriate, so - // that subsequent packets containing subsequent stream frames with - // non-zero offsets will fit within the packet length. - if (connection_.version().transport_version == QUIC_VERSION_99) { - length = length + 1; - } else { - length = length + 2; - } - - connection_.SetMaxPacketLength(length); - - // Queue the first packet. - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) - .Times(kPacketCount); - - size_t total_payload_length = payload_length * kPacketCount; - // The first frame of the stream is at offset 0. When the offset is - // 0, it is not included in the stream frame. Increase the total - // payload so that the "missing" offset byte in the first packet is - // occupied by a payload byte. The net result is that each of the N - // packets of the test will contain a single stream frame, each of - // which will be the same size (overhead + data). - if (connection_.version().transport_version == QUIC_VERSION_99) { - // Version 99 encodes the offset in 1 byte for the scope of this test. - total_payload_length = total_payload_length + 1; - } else { - // Versions other than 99 encode the offset in 2 bytes for the - // scope of this test. - total_payload_length = total_payload_length + 2; - } + // Make the payload twice the size of the packet, so 3 packets are written. + size_t total_payload_length = 2 * connection_.max_packet_length(); const std::string payload(total_payload_length, 'a'); - - EXPECT_EQ(payload.size(), - connection_ - .SendStreamDataWithString(QuicUtils::GetCryptoStreamId( - connection_.transport_version()), - payload, 0, NO_FIN) - .bytes_consumed); + QuicStreamId first_bidi_stream_id(QuicUtils::GetFirstBidirectionalStreamId( + connection_.version().transport_version, Perspective::IS_CLIENT)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); + EXPECT_EQ(payload.size(), connection_ + .SendStreamDataWithString(first_bidi_stream_id, + payload, 0, NO_FIN) + .bytes_consumed); } TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) {
diff --git a/quic/core/quic_packet_creator_test.cc b/quic/core/quic_packet_creator_test.cc index 45f2651..1cdc3e4 100644 --- a/quic/core/quic_packet_creator_test.cc +++ b/quic/core/quic_packet_creator_test.cc
@@ -1197,18 +1197,9 @@ } creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); // A string larger than fits into a frame. - size_t payload_length; - creator_.SetMaxPacketLength(GetPacketLengthForOneStream( - client_framer_.transport_version(), - QuicPacketCreatorPeer::SendVersionInPacket(&creator_), - !kIncludeDiversificationNonce, - creator_.GetDestinationConnectionIdLength(), - creator_.GetSourceConnectionIdLength(), - QuicPacketCreatorPeer::GetPacketNumberLength(&creator_), - QuicPacketCreatorPeer::GetRetryTokenLengthLength(&creator_), - QuicPacketCreatorPeer::GetLengthLength(&creator_), &payload_length)); QuicFrame frame; - const std::string too_long_payload(payload_length * 2, 'a'); + size_t payload_length = creator_.max_packet_length(); + const std::string too_long_payload(payload_length, 'a'); MakeIOVector(too_long_payload, &iov_); EXPECT_CALL(delegate_, OnSerializedPacket(_)) .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); @@ -1217,9 +1208,8 @@ ASSERT_TRUE(creator_.ConsumeData(stream_id, &iov_, 1u, iov_.iov_len, 0u, 0u, true, false, NOT_RETRANSMISSION, &frame)); size_t consumed = frame.stream_frame.data_length; - EXPECT_EQ(payload_length, consumed); - const std::string payload(payload_length, 'a'); - CheckStreamFrame(frame, stream_id, payload, 0u, false); + // The entire payload could not be consumed. + EXPECT_GT(payload_length, consumed); creator_.Flush(); DeleteSerializedPacket(); }
diff --git a/quic/test_tools/quic_test_utils.cc b/quic/test_tools/quic_test_utils.cc index c80a055..db57071 100644 --- a/quic/test_tools/quic_test_utils.cc +++ b/quic/test_tools/quic_test_utils.cc
@@ -982,45 +982,6 @@ << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); } -size_t GetPacketLengthForOneStream( - QuicTransportVersion version, - bool include_version, - bool include_diversification_nonce, - QuicConnectionIdLength destination_connection_id_length, - QuicConnectionIdLength source_connection_id_length, - QuicPacketNumberLength packet_number_length, - QuicVariableLengthIntegerLength retry_token_length_length, - QuicVariableLengthIntegerLength length_length, - size_t* payload_length) { - *payload_length = 1; - const size_t stream_length = - NullEncrypter(Perspective::IS_CLIENT).GetCiphertextSize(*payload_length) + - QuicPacketCreator::StreamFramePacketOverhead( - version, destination_connection_id_length, - source_connection_id_length, include_version, - include_diversification_nonce, packet_number_length, - retry_token_length_length, length_length, 0u); - const size_t ack_length = - NullEncrypter(Perspective::IS_CLIENT) - .GetCiphertextSize(QuicFramer::GetMinAckFrameSize( - version, PACKET_1BYTE_PACKET_NUMBER)) + - GetPacketHeaderSize(version, destination_connection_id_length, - source_connection_id_length, include_version, - include_diversification_nonce, packet_number_length, - retry_token_length_length, 0, length_length); - if (stream_length < ack_length) { - *payload_length = 1 + ack_length - stream_length; - } - - return NullEncrypter(Perspective::IS_CLIENT) - .GetCiphertextSize(*payload_length) + - QuicPacketCreator::StreamFramePacketOverhead( - version, destination_connection_id_length, - source_connection_id_length, include_version, - include_diversification_nonce, packet_number_length, - retry_token_length_length, length_length, 0u); -} - QuicConfig DefaultQuicConfig() { QuicConfig config; config.SetInitialStreamFlowControlWindowToSend(
diff --git a/quic/test_tools/quic_test_utils.h b/quic/test_tools/quic_test_utils.h index f61bd25..00c9748 100644 --- a/quic/test_tools/quic_test_utils.h +++ b/quic/test_tools/quic_test_utils.h
@@ -158,20 +158,6 @@ const char* expected, const int expected_len); -// Returns the length of a QuicPacket that is capable of holding either a -// stream frame or a minimal ack frame. Sets |*payload_length| to the number -// of bytes of stream data that will fit in such a packet. -size_t GetPacketLengthForOneStream( - QuicTransportVersion version, - bool include_version, - bool include_diversification_nonce, - QuicConnectionIdLength destination_connection_id_length, - QuicConnectionIdLength source_connection_id_length, - QuicPacketNumberLength packet_number_length, - QuicVariableLengthIntegerLength retry_token_length_length, - QuicVariableLengthIntegerLength length_length, - size_t* payload_length); - // Returns QuicConfig set to default values. QuicConfig DefaultQuicConfig();