Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: net/quic/quic_packet_generator_test.cc

Issue 1807033002: Don't copy the QuicAckFrame into the QuicPacketGenerator. Protected by quic_dont_copy_acks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116794514
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | net/quic/quic_received_packet_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_packet_generator.h" 5 #include "net/quic/quic_packet_generator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 25 matching lines...) Expand all
36 36
37 class MockDelegate : public QuicPacketGenerator::DelegateInterface { 37 class MockDelegate : public QuicPacketGenerator::DelegateInterface {
38 public: 38 public:
39 MockDelegate() {} 39 MockDelegate() {}
40 ~MockDelegate() override {} 40 ~MockDelegate() override {}
41 41
42 MOCK_METHOD2(ShouldGeneratePacket, 42 MOCK_METHOD2(ShouldGeneratePacket,
43 bool(HasRetransmittableData retransmittable, 43 bool(HasRetransmittableData retransmittable,
44 IsHandshake handshake)); 44 IsHandshake handshake));
45 MOCK_METHOD1(PopulateAckFrame, void(QuicAckFrame*)); 45 MOCK_METHOD1(PopulateAckFrame, void(QuicAckFrame*));
46 MOCK_METHOD0(GetUpdatedAckFrame, const QuicFrame());
46 MOCK_METHOD1(PopulateStopWaitingFrame, void(QuicStopWaitingFrame*)); 47 MOCK_METHOD1(PopulateStopWaitingFrame, void(QuicStopWaitingFrame*));
47 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); 48 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet));
48 MOCK_METHOD2(OnUnrecoverableError, 49 MOCK_METHOD2(OnUnrecoverableError,
49 void(QuicErrorCode, ConnectionCloseSource)); 50 void(QuicErrorCode, ConnectionCloseSource));
50 51
51 void SetCanWriteAnything() { 52 void SetCanWriteAnything() {
52 EXPECT_CALL(*this, ShouldGeneratePacket(_, _)).WillRepeatedly(Return(true)); 53 EXPECT_CALL(*this, ShouldGeneratePacket(_, _)).WillRepeatedly(Return(true));
53 EXPECT_CALL(*this, ShouldGeneratePacket(NO_RETRANSMITTABLE_DATA, _)) 54 EXPECT_CALL(*this, ShouldGeneratePacket(NO_RETRANSMITTABLE_DATA, _))
54 .WillRepeatedly(Return(true)); 55 .WillRepeatedly(Return(true));
55 } 56 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 207 }
207 208
208 QuicFramer framer_; 209 QuicFramer framer_;
209 MockRandom random_; 210 MockRandom random_;
210 SimpleBufferAllocator buffer_allocator_; 211 SimpleBufferAllocator buffer_allocator_;
211 StrictMock<MockDelegate> delegate_; 212 StrictMock<MockDelegate> delegate_;
212 QuicPacketGenerator generator_; 213 QuicPacketGenerator generator_;
213 QuicPacketCreator* creator_; 214 QuicPacketCreator* creator_;
214 SimpleQuicFramer simple_framer_; 215 SimpleQuicFramer simple_framer_;
215 vector<SerializedPacket> packets_; 216 vector<SerializedPacket> packets_;
217 QuicAckFrame ack_frame_;
216 218
217 private: 219 private:
218 scoped_ptr<char[]> data_array_; 220 scoped_ptr<char[]> data_array_;
219 struct iovec iov_; 221 struct iovec iov_;
220 }; 222 };
221 223
222 class MockDebugDelegate : public QuicPacketCreator::DebugDelegate { 224 class MockDebugDelegate : public QuicPacketCreator::DebugDelegate {
223 public: 225 public:
224 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&)); 226 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&));
225 }; 227 };
226 228
227 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) { 229 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) {
228 delegate_.SetCanNotWrite(); 230 delegate_.SetCanNotWrite();
229 231
230 generator_.SetShouldSendAck(false); 232 generator_.SetShouldSendAck(false);
231 EXPECT_TRUE(generator_.HasQueuedFrames()); 233 EXPECT_TRUE(generator_.HasQueuedFrames());
232 } 234 }
233 235
234 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) { 236 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) {
235 StrictMock<MockDebugDelegate> debug_delegate; 237 StrictMock<MockDebugDelegate> debug_delegate;
236 238
237 generator_.set_debug_delegate(&debug_delegate); 239 generator_.set_debug_delegate(&debug_delegate);
238 delegate_.SetCanWriteOnlyNonRetransmittable(); 240 delegate_.SetCanWriteOnlyNonRetransmittable();
239 generator_.StartBatchOperations(); 241 generator_.StartBatchOperations();
240 242
241 EXPECT_CALL(delegate_, PopulateAckFrame(_)); 243 if (FLAGS_quic_dont_copy_acks) {
244 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
245 .WillOnce(Return(QuicFrame(&ack_frame_)));
246 } else {
247 EXPECT_CALL(delegate_, PopulateAckFrame(_));
248 }
242 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1); 249 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1);
243 250
244 generator_.SetShouldSendAck(false); 251 generator_.SetShouldSendAck(false);
245 EXPECT_TRUE(generator_.HasQueuedFrames()); 252 EXPECT_TRUE(generator_.HasQueuedFrames());
246 } 253 }
247 254
248 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) { 255 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) {
249 delegate_.SetCanWriteOnlyNonRetransmittable(); 256 delegate_.SetCanWriteOnlyNonRetransmittable();
250 257
251 EXPECT_CALL(delegate_, PopulateAckFrame(_)); 258 if (FLAGS_quic_dont_copy_acks) {
259 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
260 .WillOnce(Return(QuicFrame(&ack_frame_)));
261 } else {
262 EXPECT_CALL(delegate_, PopulateAckFrame(_));
263 }
252 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 264 EXPECT_CALL(delegate_, OnSerializedPacket(_))
253 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 265 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
254 266
255 generator_.SetShouldSendAck(false); 267 generator_.SetShouldSendAck(false);
256 EXPECT_FALSE(generator_.HasQueuedFrames()); 268 EXPECT_FALSE(generator_.HasQueuedFrames());
257 269
258 PacketContents contents; 270 PacketContents contents;
259 contents.num_ack_frames = 1; 271 contents.num_ack_frames = 1;
260 CheckPacketContains(contents, 0); 272 CheckPacketContains(contents, 0);
261 } 273 }
262 274
263 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_MultipleCalls) { 275 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_MultipleCalls) {
264 // Make sure that calling SetShouldSendAck multiple times does not result in a 276 // Make sure that calling SetShouldSendAck multiple times does not result in a
265 // crash. Previously this would result in multiple QuicFrames queued in the 277 // crash. Previously this would result in multiple QuicFrames queued in the
266 // packet generator, with all but the last with internal pointers to freed 278 // packet generator, with all but the last with internal pointers to freed
267 // memory. 279 // memory.
268 delegate_.SetCanWriteAnything(); 280 delegate_.SetCanWriteAnything();
269 281
270 // Only one AckFrame should be created. 282 // Only one AckFrame should be created.
271 EXPECT_CALL(delegate_, PopulateAckFrame(_)).Times(1); 283 if (FLAGS_quic_dont_copy_acks) {
284 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
285 .WillOnce(Return(QuicFrame(&ack_frame_)));
286 } else {
287 EXPECT_CALL(delegate_, PopulateAckFrame(_)).Times(1);
288 }
272 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 289 EXPECT_CALL(delegate_, OnSerializedPacket(_))
273 .Times(1) 290 .Times(1)
274 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 291 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
275 292
276 generator_.StartBatchOperations(); 293 generator_.StartBatchOperations();
277 generator_.SetShouldSendAck(false); 294 generator_.SetShouldSendAck(false);
278 generator_.SetShouldSendAck(false); 295 generator_.SetShouldSendAck(false);
279 generator_.FinishBatchOperations(); 296 generator_.FinishBatchOperations();
280 } 297 }
281 298
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 506
490 generator_.SetShouldSendAck(false); 507 generator_.SetShouldSendAck(false);
491 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 508 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
492 EXPECT_TRUE(generator_.HasQueuedFrames()); 509 EXPECT_TRUE(generator_.HasQueuedFrames());
493 510
494 delegate_.SetCanWriteAnything(); 511 delegate_.SetCanWriteAnything();
495 512
496 generator_.StartBatchOperations(); 513 generator_.StartBatchOperations();
497 514
498 // When the first write operation is invoked, the ack frame will be returned. 515 // When the first write operation is invoked, the ack frame will be returned.
499 EXPECT_CALL(delegate_, PopulateAckFrame(_)); 516 if (FLAGS_quic_dont_copy_acks) {
517 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
518 .WillOnce(Return(QuicFrame(&ack_frame_)));
519 } else {
520 EXPECT_CALL(delegate_, PopulateAckFrame(_));
521 }
500 522
501 // Send some data and a control frame 523 // Send some data and a control frame
502 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, nullptr); 524 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, nullptr);
503 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame())); 525 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame()));
504 526
505 // All five frames will be flushed out in a single packet. 527 // All five frames will be flushed out in a single packet.
506 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 528 EXPECT_CALL(delegate_, OnSerializedPacket(_))
507 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 529 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
508 generator_.FinishBatchOperations(); 530 generator_.FinishBatchOperations();
509 EXPECT_FALSE(generator_.HasQueuedFrames()); 531 EXPECT_FALSE(generator_.HasQueuedFrames());
(...skipping 11 matching lines...) Expand all
521 543
522 generator_.SetShouldSendAck(false); 544 generator_.SetShouldSendAck(false);
523 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 545 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
524 EXPECT_TRUE(generator_.HasQueuedFrames()); 546 EXPECT_TRUE(generator_.HasQueuedFrames());
525 547
526 delegate_.SetCanWriteAnything(); 548 delegate_.SetCanWriteAnything();
527 549
528 generator_.StartBatchOperations(); 550 generator_.StartBatchOperations();
529 551
530 // When the first write operation is invoked, the ack frame will be returned. 552 // When the first write operation is invoked, the ack frame will be returned.
531 EXPECT_CALL(delegate_, PopulateAckFrame(_)); 553 if (FLAGS_quic_dont_copy_acks) {
554 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
555 .WillOnce(Return(QuicFrame(&ack_frame_)));
556 } else {
557 EXPECT_CALL(delegate_, PopulateAckFrame(_));
558 }
532 559
533 { 560 {
534 InSequence dummy; 561 InSequence dummy;
535 // All five frames will be flushed out in a single packet 562 // All five frames will be flushed out in a single packet
536 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 563 EXPECT_CALL(delegate_, OnSerializedPacket(_))
537 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 564 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
538 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 565 EXPECT_CALL(delegate_, OnSerializedPacket(_))
539 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 566 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
540 } 567 }
541 568
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // DFATALs are expected. 837 // DFATALs are expected.
811 // A 1 byte packet number length can't encode a gap of 1000. 838 // A 1 byte packet number length can't encode a gap of 1000.
812 QuicPacketCreatorPeer::SetPacketNumber(creator_, 1000); 839 QuicPacketCreatorPeer::SetPacketNumber(creator_, 1000);
813 840
814 delegate_.SetCanNotWrite(); 841 delegate_.SetCanNotWrite();
815 generator_.SetShouldSendAck(true); 842 generator_.SetShouldSendAck(true);
816 delegate_.SetCanWriteAnything(); 843 delegate_.SetCanWriteAnything();
817 generator_.StartBatchOperations(); 844 generator_.StartBatchOperations();
818 845
819 // Set up frames to write into the creator when control frames are written. 846 // Set up frames to write into the creator when control frames are written.
820 EXPECT_CALL(delegate_, PopulateAckFrame(_)); 847 if (FLAGS_quic_dont_copy_acks) {
848 EXPECT_CALL(delegate_, GetUpdatedAckFrame())
849 .WillOnce(Return(QuicFrame(&ack_frame_)));
850 } else {
851 EXPECT_CALL(delegate_, PopulateAckFrame(_));
852 }
821 EXPECT_CALL(delegate_, PopulateStopWaitingFrame(_)); 853 EXPECT_CALL(delegate_, PopulateStopWaitingFrame(_));
822 // Generator should have queued control frames, and creator should be empty. 854 // Generator should have queued control frames, and creator should be empty.
823 EXPECT_TRUE(generator_.HasQueuedFrames()); 855 EXPECT_TRUE(generator_.HasQueuedFrames());
824 EXPECT_FALSE(creator_->HasPendingFrames()); 856 EXPECT_FALSE(creator_->HasPendingFrames());
825 857
826 // This will not serialize any packets, because of the invalid frame. 858 // This will not serialize any packets, because of the invalid frame.
827 EXPECT_CALL(delegate_, 859 EXPECT_CALL(delegate_,
828 OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET, 860 OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET,
829 ConnectionCloseSource::FROM_SELF)); 861 ConnectionCloseSource::FROM_SELF));
830 EXPECT_DFATAL(generator_.FinishBatchOperations(), 862 EXPECT_DFATAL(generator_.FinishBatchOperations(),
(...skipping 25 matching lines...) Expand all
856 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 888 EXPECT_CALL(delegate_, OnSerializedPacket(_))
857 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 889 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
858 generator_.FlushAllQueuedFrames(); 890 generator_.FlushAllQueuedFrames();
859 EXPECT_FALSE(generator_.HasQueuedFrames()); 891 EXPECT_FALSE(generator_.HasQueuedFrames());
860 generator_.SetCurrentPath(kTestPathId1, 1, 0); 892 generator_.SetCurrentPath(kTestPathId1, 1, 0);
861 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); 893 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_));
862 } 894 }
863 895
864 } // namespace test 896 } // namespace test
865 } // namespace net 897 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | net/quic/quic_received_packet_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698