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

Side by Side Diff: media/cast/logging/logging_impl_unittest.cc

Issue 184853003: Cast: Add GetStats() extensions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <vector> 5 #include <vector>
6 6
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "base/time/tick_clock.h" 9 #include "base/time/tick_clock.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } while (time_interval.InSeconds() < kIntervalTime1S); 70 } while (time_interval.InSeconds() < kIntervalTime1S);
71 base::TimeTicks end_time = now; 71 base::TimeTicks end_time = now;
72 72
73 // Get logging data. 73 // Get logging data.
74 std::vector<FrameEvent> frame_events; 74 std::vector<FrameEvent> frame_events;
75 event_subscriber_.GetFrameEventsAndReset(&frame_events); 75 event_subscriber_.GetFrameEventsAndReset(&frame_events);
76 // Size of vector should be equal to the number of events logged, 76 // Size of vector should be equal to the number of events logged,
77 // which equals to number of frames in this case. 77 // which equals to number of frames in this case.
78 EXPECT_EQ(frame_id, frame_events.size()); 78 EXPECT_EQ(frame_id, frame_events.size());
79 // Verify stats. 79 // Verify stats.
80 FrameStatsMap frame_stats = logging_->GetFrameStatsData(); 80 FrameStatsMap frame_stats = logging_->GetFrameStatsData(AUDIO_EVENT);
81 // Size of stats equals the number of events. 81 // Size of stats equals the number of events.
82 EXPECT_EQ(1u, frame_stats.size()); 82 EXPECT_EQ(1u, frame_stats.size());
83 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured); 83 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
84 EXPECT_TRUE(it != frame_stats.end()); 84 EXPECT_TRUE(it != frame_stats.end());
85 EXPECT_EQ(0, it->second.max_delay.InMilliseconds()); 85 EXPECT_EQ(0, it->second.max_delay.InMilliseconds());
86 EXPECT_EQ(0, it->second.min_delay.InMilliseconds()); 86 EXPECT_EQ(0, it->second.min_delay.InMilliseconds());
87 EXPECT_EQ(start_time, it->second.first_event_time); 87 EXPECT_EQ(start_time, it->second.first_event_time);
88 EXPECT_EQ(end_time, it->second.last_event_time); 88 EXPECT_EQ(end_time, it->second.last_event_time);
89 EXPECT_EQ(0u, it->second.sum_size); 89 EXPECT_EQ(0u, it->second.sum_size);
90 // Number of events is equal to the number of frames. 90 // Number of events is equal to the number of frames.
(...skipping 21 matching lines...) Expand all
112 ++frame_id; 112 ++frame_id;
113 time_interval = testing_clock_.NowTicks() - start_time; 113 time_interval = testing_clock_.NowTicks() - start_time;
114 } while (time_interval.InSeconds() < kIntervalTime1S); 114 } while (time_interval.InSeconds() < kIntervalTime1S);
115 // Get logging data. 115 // Get logging data.
116 std::vector<FrameEvent> frame_events; 116 std::vector<FrameEvent> frame_events;
117 event_subscriber_.GetFrameEventsAndReset(&frame_events); 117 event_subscriber_.GetFrameEventsAndReset(&frame_events);
118 // Size of vector should be equal to the number of events logged, which 118 // Size of vector should be equal to the number of events logged, which
119 // equals to number of frames in this case. 119 // equals to number of frames in this case.
120 EXPECT_EQ(frame_id, frame_events.size()); 120 EXPECT_EQ(frame_id, frame_events.size());
121 // Verify stats. 121 // Verify stats.
122 FrameStatsMap frame_stats = logging_->GetFrameStatsData(); 122 FrameStatsMap frame_stats = logging_->GetFrameStatsData(AUDIO_EVENT);
123 // Size of stats equals the number of events. 123 // Size of stats equals the number of events.
124 EXPECT_EQ(1u, frame_stats.size()); 124 EXPECT_EQ(1u, frame_stats.size());
125 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured); 125 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
126 EXPECT_TRUE(it != frame_stats.end()); 126 EXPECT_TRUE(it != frame_stats.end());
127 EXPECT_EQ(0, it->second.max_delay.InMilliseconds()); 127 EXPECT_EQ(0, it->second.max_delay.InMilliseconds());
128 EXPECT_EQ(0, it->second.min_delay.InMilliseconds()); 128 EXPECT_EQ(0, it->second.min_delay.InMilliseconds());
129 EXPECT_EQ(0, it->second.sum_delay.InMilliseconds()); 129 EXPECT_EQ(0, it->second.sum_delay.InMilliseconds());
130 EXPECT_EQ(sum_size, it->second.sum_size); 130 EXPECT_EQ(sum_size, it->second.sum_size);
131 } 131 }
132 132
(...skipping 15 matching lines...) Expand all
148 rtp_timestamp += kFrameIntervalMs * 90; 148 rtp_timestamp += kFrameIntervalMs * 90;
149 ++frame_id; 149 ++frame_id;
150 time_interval = testing_clock_.NowTicks() - start_time; 150 time_interval = testing_clock_.NowTicks() - start_time;
151 } while (time_interval.InSeconds() < kIntervalTime1S); 151 } while (time_interval.InSeconds() < kIntervalTime1S);
152 // Get logging data. 152 // Get logging data.
153 std::vector<FrameEvent> frame_events; 153 std::vector<FrameEvent> frame_events;
154 event_subscriber_.GetFrameEventsAndReset(&frame_events); 154 event_subscriber_.GetFrameEventsAndReset(&frame_events);
155 // Size of vector should be equal to the number of frames logged. 155 // Size of vector should be equal to the number of frames logged.
156 EXPECT_EQ(frame_id, frame_events.size()); 156 EXPECT_EQ(frame_id, frame_events.size());
157 // Verify stats. 157 // Verify stats.
158 FrameStatsMap frame_stats = logging_->GetFrameStatsData(); 158 FrameStatsMap frame_stats = logging_->GetFrameStatsData(AUDIO_EVENT);
159 // Size of stats equals the number of events. 159 // Size of stats equals the number of events.
160 EXPECT_EQ(1u, frame_stats.size()); 160 EXPECT_EQ(1u, frame_stats.size());
161 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured); 161 FrameStatsMap::const_iterator it = frame_stats.find(kAudioFrameCaptured);
162 EXPECT_TRUE(it != frame_stats.end()); 162 EXPECT_TRUE(it != frame_stats.end());
163 EXPECT_GE(kPlayoutDelayMs + kRandomSizeInterval, 163 EXPECT_GE(kPlayoutDelayMs + kRandomSizeInterval,
164 it->second.max_delay.InMilliseconds()); 164 it->second.max_delay.InMilliseconds());
165 EXPECT_LE(kPlayoutDelayMs - kRandomSizeInterval, 165 EXPECT_LE(kPlayoutDelayMs - kRandomSizeInterval,
166 it->second.min_delay.InMilliseconds()); 166 it->second.min_delay.InMilliseconds());
167 } 167 }
168 168
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Size of vector should be equal to the number of frames logged. 201 // Size of vector should be equal to the number of frames logged.
202 EXPECT_EQ(num_events, frame_events.size()); 202 EXPECT_EQ(num_events, frame_events.size());
203 // Multiple events captured per frame. 203 // Multiple events captured per frame.
204 } 204 }
205 205
206 TEST_F(LoggingImplTest, PacketLogging) { 206 TEST_F(LoggingImplTest, PacketLogging) {
207 const int kNumPacketsPerFrame = 10; 207 const int kNumPacketsPerFrame = 10;
208 const int kBaseSize = 2500; 208 const int kBaseSize = 2500;
209 const int kSizeInterval = 100; 209 const int kSizeInterval = 100;
210 base::TimeTicks start_time = testing_clock_.NowTicks(); 210 base::TimeTicks start_time = testing_clock_.NowTicks();
211 base::TimeTicks latest_time;
211 base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time; 212 base::TimeDelta time_interval = testing_clock_.NowTicks() - start_time;
212 uint32 rtp_timestamp = 0; 213 RtpTimestamp rtp_timestamp = 0;
213 uint32 frame_id = 0; 214 int frame_id = 0;
215 int num_packets = 0;
216 int sum_size = 0u;
214 do { 217 do {
215 for (int i = 0; i < kNumPacketsPerFrame; ++i) { 218 for (int i = 0; i < kNumPacketsPerFrame; ++i) {
216 int size = kBaseSize + base::RandInt(-kSizeInterval, kSizeInterval); 219 int size = kBaseSize + base::RandInt(-kSizeInterval, kSizeInterval);
217 logging_->InsertPacketEvent(testing_clock_.NowTicks(), kPacketSentToPacer, 220 sum_size += size;
218 rtp_timestamp, frame_id, i, 221 latest_time = testing_clock_.NowTicks();
219 kNumPacketsPerFrame, size); 222 ++num_packets;
223 logging_->InsertPacketEvent(latest_time,
224 kDuplicateVideoPacketReceived,
225 rtp_timestamp,
226 frame_id,
227 i,
228 kNumPacketsPerFrame,
229 size);
220 } 230 }
221 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs)); 231 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(kFrameIntervalMs));
222 rtp_timestamp += kFrameIntervalMs * 90; 232 rtp_timestamp += kFrameIntervalMs * 90;
223 ++frame_id; 233 ++frame_id;
224 time_interval = testing_clock_.NowTicks() - start_time; 234 time_interval = testing_clock_.NowTicks() - start_time;
225 } while (time_interval.InSeconds() < kIntervalTime1S); 235 } while (time_interval.InSeconds() < kIntervalTime1S);
226 // Get logging data. 236 // Get logging data.
227 std::vector<PacketEvent> packet_events; 237 std::vector<PacketEvent> packet_events;
228 event_subscriber_.GetPacketEventsAndReset(&packet_events); 238 event_subscriber_.GetPacketEventsAndReset(&packet_events);
229 // Size of vector should be equal to the number of packets logged. 239 // Size of vector should be equal to the number of packets logged.
230 EXPECT_EQ(frame_id * kNumPacketsPerFrame, packet_events.size()); 240 EXPECT_EQ(num_packets, static_cast<int>(packet_events.size()));
231 // Verify stats. 241 // Verify stats.
232 PacketStatsMap stats_map = logging_->GetPacketStatsData(); 242 PacketStatsMap stats_map = logging_->GetPacketStatsData(VIDEO_EVENT);
233 // Size of stats equals the number of events. 243 // Size of stats equals the number of event types.
234 EXPECT_EQ(1u, stats_map.size()); 244 EXPECT_EQ(1u, stats_map.size());
235 PacketStatsMap::const_iterator it = stats_map.find(kPacketSentToPacer); 245 PacketStatsMap::const_iterator it =
236 EXPECT_TRUE(it != stats_map.end()); 246 stats_map.find(kDuplicateVideoPacketReceived);
247 ASSERT_NE(stats_map.end(), it);
248 EXPECT_EQ(start_time, it->second.first_event_time);
249 EXPECT_EQ(latest_time, it->second.last_event_time);
250 EXPECT_EQ(num_packets, it->second.event_counter);
251 EXPECT_EQ(sum_size, static_cast<int>(it->second.sum_size));
237 } 252 }
238 253
239 TEST_F(LoggingImplTest, GenericLogging) { 254 TEST_F(LoggingImplTest, GenericLogging) {
240 // Insert multiple generic types. 255 // Insert multiple generic types.
241 const size_t kNumRuns = 20;//1000; 256 const size_t kNumRuns = 20;//1000;
242 const int kBaseValue = 20; 257 const int kBaseValue = 20;
243 int sum_value_rtt = 0; 258 int sum_value_rtt = 0;
244 int sum_value_pl = 0; 259 int sum_value_pl = 0;
245 int sum_value_jitter = 0; 260 int sum_value_jitter = 0;
246 uint64 sumsq_value_rtt = 0; 261 uint64 sumsq_value_rtt = 0;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 EXPECT_EQ(1u, frame_events.size()); 354 EXPECT_EQ(1u, frame_events.size());
340 frame_events.clear(); 355 frame_events.clear();
341 event_subscriber_2.GetFrameEventsAndReset(&frame_events); 356 event_subscriber_2.GetFrameEventsAndReset(&frame_events);
342 EXPECT_EQ(1u, frame_events.size()); 357 EXPECT_EQ(1u, frame_events.size());
343 358
344 logging_->RemoveRawEventSubscriber(&event_subscriber_2); 359 logging_->RemoveRawEventSubscriber(&event_subscriber_2);
345 } 360 }
346 361
347 } // namespace cast 362 } // namespace cast
348 } // namespace media 363 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698