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

Side by Side Diff: webrtc/test/fuzzers/transport_feedback_packet_loss_tracker_fuzzer.cc

Issue 2632203002: Packet Loss Tracker - Stream Separation (Closed)
Patch Set: . Created 3 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 | « no previous file | webrtc/voice_engine/transport_feedback_packet_loss_tracker.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 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 26 matching lines...) Expand all
37 RTC_CHECK_LT(upper - lower, 1 << (8 * sizeof(uint16_t))); 37 RTC_CHECK_LT(upper - lower, 1 << (8 * sizeof(uint16_t)));
38 const size_t range = upper - lower; 38 const size_t range = upper - lower;
39 const uint16_t fuzzed = FuzzInput<uint16_t>(data, size); 39 const uint16_t fuzzed = FuzzInput<uint16_t>(data, size);
40 const size_t offset = (static_cast<float>(fuzzed) / 0x10000) * (range + 1); 40 const size_t offset = (static_cast<float>(fuzzed) / 0x10000) * (range + 1);
41 RTC_CHECK_LE(offset, range); // (fuzzed <= 0xffff) -> (offset < range + 1) 41 RTC_CHECK_LE(offset, range); // (fuzzed <= 0xffff) -> (offset < range + 1)
42 return lower + offset; 42 return lower + offset;
43 } 43 }
44 44
45 class TransportFeedbackGenerator { 45 class TransportFeedbackGenerator {
46 public: 46 public:
47 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) 47 explicit TransportFeedbackGenerator(const uint8_t** data, size_t* size)
48 : data_(data), ended_(false), data_idx_(0) {} 48 : data_(data), size_(size) {}
49 49
50 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { 50 bool GetNextTransportFeedback(rtcp::TransportFeedback* feedback) {
51 uint16_t base_seq_num = 0; 51 uint16_t base_seq_num = 0;
52 if (!ReadData<uint16_t>(&base_seq_num)) { 52 if (!ReadData<uint16_t>(&base_seq_num)) {
53 return; 53 return false;
54 }
55 constexpr int64_t kBaseTimeUs = 1234; // Irrelevant to this test.
56 feedback->SetBase(base_seq_num, kBaseTimeUs);
57
58 uint16_t remaining_packets = 0;
59 if (!ReadData<uint16_t>(&remaining_packets))
60 return false;
61 // Range is [0x00001 : 0x10000], but we keep it 0x0000 to 0xffff for now,
62 // and add the last status as RECEIVED. That is because of a limitation
63 // that says that the last status cannot be LOST.
64
65 uint16_t seq_num = base_seq_num;
66 while (remaining_packets > 0) {
67 uint8_t status_byte = 0;
68 if (!ReadData<uint8_t>(&status_byte)) {
69 return false;
70 }
71 // Each status byte contains 8 statuses.
72 for (size_t i = 0; i < 8 && remaining_packets > 0; ++i) {
73 const bool received = (status_byte & (0x01 << i));
74 if (received) {
75 feedback->AddReceivedPacket(seq_num, kBaseTimeUs);
76 }
77 ++seq_num;
78 --remaining_packets;
79 }
54 } 80 }
55 81
56 const int64_t kBaseTimeUs = 1234; // Irrelevant to this test. 82 // As mentioned above, all feedbacks must report with a received packet.
57 feedback->SetBase(base_seq_num, kBaseTimeUs); 83 feedback->AddReceivedPacket(seq_num, kBaseTimeUs);
58 84
59 uint16_t num_statuses = 0; 85 return true;
60 if (!ReadData<uint16_t>(&num_statuses))
61 return;
62 num_statuses = std::max<uint16_t>(num_statuses, 1);
63
64 uint16_t seq_num = base_seq_num;
65 while (true) {
66 uint8_t status_byte = 0;
67 if (!ReadData<uint8_t>(&status_byte))
68 return;
69 // Each status byte contains 8 statuses.
70 for (size_t j = 0; j < 8; ++j) {
71 if (status_byte & 0x01) {
72 feedback->AddReceivedPacket(seq_num, kBaseTimeUs);
73 }
74 seq_num++;
75 if (seq_num >= base_seq_num + num_statuses) {
76 feedback->AddReceivedPacket(seq_num, kBaseTimeUs);
77 return;
78 }
79 status_byte >>= 1;
80 }
81 }
82 } 86 }
83 87
84 bool ended() const { return ended_; }
85
86 private: 88 private:
87 template <typename T> 89 template <typename T>
88 bool ReadData(T* value) { 90 bool ReadData(T* value) {
89 RTC_CHECK(!ended_); 91 if (*size_ < sizeof(T)) {
90 if (data_idx_ + sizeof(T) > data_.size()) { 92 return false;
91 ended_ = true; 93 } else {
94 *value = FuzzInput<T>(data_, size_);
95 return true;
96 }
97 }
98
99 const uint8_t** data_;
100 size_t* size_;
101 };
102
103 bool Setup(const uint8_t** data,
104 size_t* size,
105 std::unique_ptr<TransportFeedbackPacketLossTracker>* tracker) {
106 if (*size < 3 * sizeof(uint16_t)) {
107 return false;
108 }
109
110 constexpr size_t kSeqNumHalf = 0x8000u;
111
112 // 0x8000 >= max_window_size >= plr_min_num_packets > rplr_min_num_pairs >= 1
113 // (The distribution isn't uniform, but it's enough; more would be overkill.)
114 const size_t max_window_size = FuzzInRange(data, size, 2, kSeqNumHalf);
115 const size_t plr_min_num_packets =
116 FuzzInRange(data, size, 2, max_window_size);
117 const size_t rplr_min_num_pairs =
118 FuzzInRange(data, size, 1, plr_min_num_packets - 1);
119
120 tracker->reset(new TransportFeedbackPacketLossTracker(
121 max_window_size, plr_min_num_packets, rplr_min_num_pairs));
122
123 return true;
124 }
125
126 bool FuzzSequenceNumberDelta(const uint8_t** data,
127 size_t* size,
128 uint16_t* delta) {
129 // Fuzz with a higher likelihood for immediately consecutive pairs
130 // than you would by just fuzzing 1-256.
131 // Note: Values higher than 256 still possible, but that would be in a new
132 // packet-sending block.
133 // * Fuzzed value in [0 : 127] (50% chance) -> delta is 1.
134 // * Fuzzed value in [128 : 255] (50% chance) -> delta in range [2 : 129].
135 if (*size < sizeof(uint8_t)) {
136 return false;
137 }
138 uint8_t fuzzed = FuzzInput<uint8_t>(data, size);
139 *delta = (fuzzed < 128) ? 1 : (fuzzed - 128 + 2);
140 return true;
141 }
142
143 bool FuzzPacketSendBlock(
144 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker,
145 const uint8_t** data,
146 size_t* size) {
147 // We want to test with block lengths between 1 and 2^16, inclusive.
148 if (*size < sizeof(uint8_t)) {
149 return false;
150 }
151 size_t packet_block_len = 1 + FuzzInput<uint8_t>(data, size);
152
153 // First sent sequence number uniformly selected.
154 if (*size < sizeof(uint16_t)) {
155 return false;
156 }
157 uint16_t seq_num = FuzzInput<uint16_t>(data, size);
158 tracker->OnPacketAdded(seq_num);
159 tracker->Validate();
160
161 for (size_t i = 1; i < packet_block_len; i++) {
162 uint16_t delta;
163 bool may_continue = FuzzSequenceNumberDelta(data, size, &delta);
164 if (!may_continue)
165 return false;
166 seq_num += delta;
167 tracker->OnPacketAdded(seq_num);
168 tracker->Validate();
169 }
170
171 return true;
172 }
173
174 bool FuzzTransportFeedbackBlock(
175 std::unique_ptr<TransportFeedbackPacketLossTracker>& tracker,
176 const uint8_t** data,
177 size_t* size) {
178 // Fuzz the number of back-to-back feedbacks. At least one, or this would
179 // be meaningless - we'd go straight back to fuzzing another packet
180 // transmission block.
181 if (*size < sizeof(uint8_t)) {
182 return false;
183 }
184
185 size_t feedbacks_num = 1 + (FuzzInput<uint8_t>(data, size) & 0x3f);
186 TransportFeedbackGenerator feedback_generator(data, size);
187
188 for (size_t i = 0; i < feedbacks_num; i++) {
189 rtcp::TransportFeedback feedback;
190 bool may_continue = feedback_generator.GetNextTransportFeedback(&feedback);
191 if (!may_continue) {
92 return false; 192 return false;
93 } 193 }
94 *value = ByteReader<T>::ReadBigEndian(&data_[data_idx_]); 194 tracker->OnReceivedTransportFeedback(feedback);
95 data_idx_ += sizeof(T); 195 tracker->Validate();
96 return true;
97 } 196 }
98 197
99 const rtc::ArrayView<const uint8_t> data_; 198 return true;
100 bool ended_; 199 }
101 size_t data_idx_;
102 };
103 200
104 } // namespace 201 } // namespace
105 202
106 void FuzzOneInput(const uint8_t* data, size_t size) { 203 void FuzzOneInput(const uint8_t* data, size_t size) {
107 if (size < 3 * sizeof(uint16_t)) { 204 std::unique_ptr<TransportFeedbackPacketLossTracker> tracker;
108 return; 205 bool may_continue;
109 }
110 constexpr size_t kSeqNumHalf = 0x8000u;
111 206
112 // 0x8000 >= max_window_size >= plr_min_num_packets > rplr_min_num_pairs >= 1 207 may_continue = Setup(&data, &size, &tracker);
113 // (The distribution isn't uniform, but it's enough; more would be overkill.)
114 const size_t max_window_size = FuzzInRange(&data, &size, 2, kSeqNumHalf);
115 const size_t plr_min_num_packets =
116 FuzzInRange(&data, &size, 2, max_window_size);
117 const size_t rplr_min_num_pairs =
118 FuzzInRange(&data, &size, 1, plr_min_num_packets - 1);
119 208
120 TransportFeedbackPacketLossTracker tracker( 209 while (may_continue) {
121 max_window_size, plr_min_num_packets, rplr_min_num_pairs); 210 may_continue = FuzzPacketSendBlock(tracker, &data, &size);
122 211 if (!may_continue) {
123 TransportFeedbackGenerator feedback_generator( 212 return;
124 rtc::ArrayView<const uint8_t>(data, size)); 213 }
125 214 may_continue = FuzzTransportFeedbackBlock(tracker, &data, &size);
126 while (!feedback_generator.ended()) {
127 rtcp::TransportFeedback feedback;
128 feedback_generator.GetNextTransportFeedback(&feedback);
129 tracker.OnReceivedTransportFeedback(feedback);
130 tracker.Validate();
131 } 215 }
132 } 216 }
133 217
134 } // namespace webrtc 218 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/voice_engine/transport_feedback_packet_loss_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698