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

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

Issue 12334063: Land recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more EXPECT_FALSE Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_fec_group.cc ('k') | net/quic/quic_framer.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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/quic/quic_fec_group.h" 10 #include "net/quic/quic_fec_group.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 12
13 using ::testing::_; 13 using ::testing::_;
14 using base::StringPiece; 14 using base::StringPiece;
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace { 18 namespace {
19 19
20 const char* kData[] = { 20 const char* kData[] = {
21 "abc12345678", 21 "abc12345678",
22 "987defg", 22 "987defg",
23 "ghi12345", 23 "ghi12345",
24 "987jlkmno", 24 "987jlkmno",
25 "mno4567890", 25 "mno4567890",
26 "789pqrstuvw", 26 "789pqrstuvw",
27 }; 27 };
28 28
29 const bool kEntropyFlag[] = {
30 false,
31 true,
32 true,
33 false,
34 true,
35 true,
36 };
37
38 const bool kTestFecEntropy = false;
39
29 } // namespace 40 } // namespace
30 41
31 class QuicFecGroupTest : public ::testing::Test { 42 class QuicFecGroupTest : public ::testing::Test {
32 protected: 43 protected:
33 void RunTest(size_t num_packets, size_t lost_packet, bool out_of_order) { 44 void RunTest(size_t num_packets, size_t lost_packet, bool out_of_order) {
34 size_t max_len = strlen(kData[0]); 45 size_t max_len = strlen(kData[0]);
35 scoped_array<char>redundancy(new char[max_len]); 46 scoped_array<char>redundancy(new char[max_len]);
36 for (size_t i = 0; i < max_len; i++) { 47 bool entropy_redundancy = false;
37 // Initialize to the first packet. 48 for (size_t packet = 0; packet < num_packets; ++packet) {
38 redundancy[i] = kData[0][i]; 49 for (size_t i = 0; i < max_len; i++) {
39 // XOR in the remaining packets. 50 if (packet == 0) {
40 for (size_t packet = 1; packet < num_packets; packet++) { 51 // Initialize to the first packet.
52 redundancy[i] = kData[0][i];
53 continue;
54 }
55 // XOR in the remaining packets.
41 uint8 byte = i > strlen(kData[packet]) ? 0x00 : kData[packet][i]; 56 uint8 byte = i > strlen(kData[packet]) ? 0x00 : kData[packet][i];
42 redundancy[i] = redundancy[i] ^ byte; 57 redundancy[i] = redundancy[i] ^ byte;
43 } 58 }
59 entropy_redundancy = (entropy_redundancy != kEntropyFlag[packet]);
44 } 60 }
45 61
46 QuicFecGroup group; 62 QuicFecGroup group;
47 63
48 // If we're out of order, send the FEC packet in the position of the 64 // If we're out of order, send the FEC packet in the position of the
49 // lost packet. Otherwise send all (non-missing) packets, then FEC. 65 // lost packet. Otherwise send all (non-missing) packets, then FEC.
50 if (out_of_order) { 66 if (out_of_order) {
51 // Update the FEC state for each non-lost packet. 67 // Update the FEC state for each non-lost packet.
52 for (size_t packet = 0; packet < num_packets; packet++) { 68 for (size_t packet = 0; packet < num_packets; packet++) {
53 if (packet == lost_packet) { 69 if (packet == lost_packet) {
54 ASSERT_FALSE(group.IsFinished()); 70 ASSERT_FALSE(group.IsFinished());
55 QuicFecData fec; 71 QuicFecData fec;
56 fec.fec_group = 0; 72 fec.fec_group = 0;
57 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0])); 73 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0]));
58 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); 74 ASSERT_TRUE(group.UpdateFec(num_packets, entropy_redundancy, fec));
59 } else { 75 } else {
60 QuicPacketHeader header; 76 QuicPacketHeader header;
61 header.packet_sequence_number = packet; 77 header.packet_sequence_number = packet;
78 header.entropy_flag = kEntropyFlag[packet];
62 ASSERT_TRUE(group.Update(header, kData[packet])); 79 ASSERT_TRUE(group.Update(header, kData[packet]));
63 } 80 }
64 ASSERT_TRUE(group.CanRevive() == (packet == num_packets - 1)); 81 ASSERT_TRUE(group.CanRevive() == (packet == num_packets - 1));
65 } 82 }
66 } else { 83 } else {
67 // Update the FEC state for each non-lost packet. 84 // Update the FEC state for each non-lost packet.
68 for (size_t packet = 0; packet < num_packets; packet++) { 85 for (size_t packet = 0; packet < num_packets; packet++) {
69 if (packet == lost_packet) { 86 if (packet == lost_packet) {
70 continue; 87 continue;
71 } 88 }
72 89
73 QuicPacketHeader header; 90 QuicPacketHeader header;
74 header.packet_sequence_number = packet; 91 header.packet_sequence_number = packet;
92 header.entropy_flag = kEntropyFlag[packet];
75 ASSERT_TRUE(group.Update(header, kData[packet])); 93 ASSERT_TRUE(group.Update(header, kData[packet]));
76 ASSERT_FALSE(group.CanRevive()); 94 ASSERT_FALSE(group.CanRevive());
77 } 95 }
78 96
79 ASSERT_FALSE(group.IsFinished()); 97 ASSERT_FALSE(group.IsFinished());
80 // Attempt to revive the missing packet. 98 // Attempt to revive the missing packet.
81 QuicFecData fec; 99 QuicFecData fec;
82 fec.fec_group = 0; 100 fec.fec_group = 0;
83 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0])); 101 fec.redundancy = StringPiece(redundancy.get(), strlen(kData[0]));
84 102
85 ASSERT_TRUE(group.UpdateFec(num_packets, fec)); 103 ASSERT_TRUE(group.UpdateFec(num_packets, entropy_redundancy, fec));
86 } 104 }
87 QuicPacketHeader header; 105 QuicPacketHeader header;
88 char recovered[kMaxPacketSize]; 106 char recovered[kMaxPacketSize];
89 ASSERT_TRUE(group.CanRevive()); 107 ASSERT_TRUE(group.CanRevive());
90 size_t len = group.Revive(&header, recovered, arraysize(recovered)); 108 size_t len = group.Revive(&header, recovered, arraysize(recovered));
91 ASSERT_NE(0u, len) 109 ASSERT_NE(0u, len)
92 << "Failed to revive packet " << lost_packet << " out of " 110 << "Failed to revive packet " << lost_packet << " out of "
93 << num_packets; 111 << num_packets;
94 EXPECT_EQ(lost_packet, header.packet_sequence_number) 112 EXPECT_EQ(lost_packet, header.packet_sequence_number)
95 << "Failed to revive packet " << lost_packet << " out of " 113 << "Failed to revive packet " << lost_packet << " out of "
96 << num_packets; 114 << num_packets;
115 EXPECT_EQ(kEntropyFlag[lost_packet], header.entropy_flag);
97 ASSERT_GE(len, strlen(kData[lost_packet])) << "Incorrect length"; 116 ASSERT_GE(len, strlen(kData[lost_packet])) << "Incorrect length";
98 for (size_t i = 0; i < strlen(kData[lost_packet]); i++) { 117 for (size_t i = 0; i < strlen(kData[lost_packet]); i++) {
99 EXPECT_EQ(kData[lost_packet][i], recovered[i]); 118 EXPECT_EQ(kData[lost_packet][i], recovered[i]);
100 } 119 }
101 ASSERT_TRUE(group.IsFinished()); 120 ASSERT_TRUE(group.IsFinished());
102 } 121 }
103 }; 122 };
104 123
105 TEST_F(QuicFecGroupTest, UpdateAndRevive) { 124 TEST_F(QuicFecGroupTest, UpdateAndRevive) {
106 RunTest(2, 0, false); 125 RunTest(2, 0, false);
(...skipping 23 matching lines...) Expand all
130 QuicFecGroup group; 149 QuicFecGroup group;
131 150
132 QuicPacketHeader header; 151 QuicPacketHeader header;
133 header.packet_sequence_number = 3; 152 header.packet_sequence_number = 3;
134 group.Update(header, data1); 153 group.Update(header, data1);
135 154
136 QuicFecData fec; 155 QuicFecData fec;
137 fec.fec_group = 1; 156 fec.fec_group = 1;
138 fec.redundancy = redundancy; 157 fec.redundancy = redundancy;
139 158
140 ASSERT_FALSE(group.UpdateFec(2, fec)); 159 header.packet_sequence_number = 2;
160 ASSERT_FALSE(group.UpdateFec(2, kTestFecEntropy, fec));
141 } 161 }
142 162
143 TEST_F(QuicFecGroupTest, ProtectsPacketsBefore) { 163 TEST_F(QuicFecGroupTest, ProtectsPacketsBefore) {
144 QuicPacketHeader header; 164 QuicPacketHeader header;
145 header.packet_sequence_number = 3; 165 header.packet_sequence_number = 3;
146 166
147 QuicFecGroup group; 167 QuicFecGroup group;
148 ASSERT_TRUE(group.Update(header, kData[0])); 168 ASSERT_TRUE(group.Update(header, kData[0]));
149 169
150 EXPECT_FALSE(group.ProtectsPacketsBefore(1)); 170 EXPECT_FALSE(group.ProtectsPacketsBefore(1));
(...skipping 28 matching lines...) Expand all
179 EXPECT_TRUE(group.ProtectsPacketsBefore(9)); 199 EXPECT_TRUE(group.ProtectsPacketsBefore(9));
180 EXPECT_TRUE(group.ProtectsPacketsBefore(50)); 200 EXPECT_TRUE(group.ProtectsPacketsBefore(50));
181 } 201 }
182 202
183 TEST_F(QuicFecGroupTest, ProtectsPacketsBeforeWithFecData) { 203 TEST_F(QuicFecGroupTest, ProtectsPacketsBeforeWithFecData) {
184 QuicFecData fec; 204 QuicFecData fec;
185 fec.fec_group = 2; 205 fec.fec_group = 2;
186 fec.redundancy = kData[0]; 206 fec.redundancy = kData[0];
187 207
188 QuicFecGroup group; 208 QuicFecGroup group;
189 ASSERT_TRUE(group.UpdateFec(3, fec)); 209 ASSERT_TRUE(group.UpdateFec(3, kTestFecEntropy, fec));
190 210
191 EXPECT_FALSE(group.ProtectsPacketsBefore(1)); 211 EXPECT_FALSE(group.ProtectsPacketsBefore(1));
192 EXPECT_FALSE(group.ProtectsPacketsBefore(2)); 212 EXPECT_FALSE(group.ProtectsPacketsBefore(2));
193 EXPECT_TRUE(group.ProtectsPacketsBefore(3)); 213 EXPECT_TRUE(group.ProtectsPacketsBefore(3));
194 EXPECT_TRUE(group.ProtectsPacketsBefore(4)); 214 EXPECT_TRUE(group.ProtectsPacketsBefore(4));
195 EXPECT_TRUE(group.ProtectsPacketsBefore(5)); 215 EXPECT_TRUE(group.ProtectsPacketsBefore(5));
196 EXPECT_TRUE(group.ProtectsPacketsBefore(50)); 216 EXPECT_TRUE(group.ProtectsPacketsBefore(50));
197 } 217 }
198 218
199 } // namespace net 219 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_fec_group.cc ('k') | net/quic/quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698