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

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

Issue 210303003: Cast: Remove LoggingStats in favor of event subscribers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 6 years, 8 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 | « media/cast/logging/stats_event_subscriber.cc ('k') | media/cast/logging/stats_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/tick_clock.h"
9 #include "media/cast/cast_environment.h"
10 #include "media/cast/logging/logging_defines.h"
11 #include "media/cast/logging/stats_event_subscriber.h"
12 #include "media/cast/test/fake_single_thread_task_runner.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16 namespace cast {
17
18 class StatsEventSubscriberTest : public ::testing::Test {
19 protected:
20 StatsEventSubscriberTest()
21 : testing_clock_(new base::SimpleTestTickClock()),
22 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
23 cast_environment_(new CastEnvironment(
24 scoped_ptr<base::TickClock>(testing_clock_).Pass(),
25 task_runner_,
26 task_runner_,
27 task_runner_)) {}
28
29 virtual ~StatsEventSubscriberTest() {
30 if (subscriber_.get())
31 cast_environment_->Logging()->RemoveRawEventSubscriber(subscriber_.get());
32 }
33
34 void Init(EventMediaType event_media_type) {
35 DCHECK(!subscriber_.get());
36 subscriber_.reset(new StatsEventSubscriber(event_media_type));
37 cast_environment_->Logging()->AddRawEventSubscriber(subscriber_.get());
38 }
39
40 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
41 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
42 scoped_refptr<CastEnvironment> cast_environment_;
43 scoped_ptr<StatsEventSubscriber> subscriber_;
44 };
45
46 TEST_F(StatsEventSubscriberTest, FrameStats) {
47 Init(VIDEO_EVENT);
48 uint32 rtp_timestamp = 0;
49 uint32 frame_id = 0;
50 int num_frames = 10;
51 int frame_size = 123;
52 int delay_base_ms = 10;
53 base::TimeTicks now;
54 for (int i = 0; i < num_frames; i++) {
55 now = testing_clock_->NowTicks();
56 cast_environment_->Logging()->InsertFrameEvent(
57 now, kVideoFrameReceived, rtp_timestamp, frame_id);
58 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
59
60 cast_environment_->Logging()->InsertFrameEventWithSize(
61 now, kVideoFrameEncoded, rtp_timestamp, i, frame_size);
62 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
63
64 cast_environment_->Logging()->InsertFrameEventWithDelay(
65 now,
66 kVideoRenderDelay,
67 rtp_timestamp,
68 i,
69 base::TimeDelta::FromMilliseconds(i * delay_base_ms));
70 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
71
72 rtp_timestamp += 90;
73 }
74
75 // Verify stats.
76 FrameStatsMap frame_stats;
77 subscriber_->GetFrameStats(&frame_stats);
78
79 // Size of stats equals the number of events.
80 EXPECT_EQ(3u, frame_stats.size());
81 FrameStatsMap::const_iterator it = frame_stats.find(kVideoFrameReceived);
82 ASSERT_TRUE(it != frame_stats.end());
83 EXPECT_EQ(num_frames, it->second.event_counter);
84
85 it = frame_stats.find(kVideoFrameEncoded);
86 ASSERT_TRUE(it != frame_stats.end());
87
88 EXPECT_EQ(num_frames * frame_size, static_cast<int>(it->second.sum_size));
89
90 it = frame_stats.find(kVideoRenderDelay);
91 ASSERT_TRUE(it != frame_stats.end());
92
93 EXPECT_EQ(0, it->second.min_delay.InMilliseconds());
94 EXPECT_EQ((num_frames - 1) * delay_base_ms,
95 it->second.max_delay.InMilliseconds());
96 EXPECT_EQ((num_frames - 1) * num_frames / 2 * delay_base_ms,
97 it->second.sum_delay.InMilliseconds());
98 }
99
100 TEST_F(StatsEventSubscriberTest, PacketStats) {
101 Init(AUDIO_EVENT);
102 uint32 rtp_timestamp = 0;
103 uint32 frame_id = 0;
104 int num_packets = 10;
105 int packet_size = 123;
106 base::TimeTicks first_event_time = testing_clock_->NowTicks();
107 base::TimeTicks now;
108 for (int i = 0; i < num_packets; i++) {
109 now = testing_clock_->NowTicks();
110 cast_environment_->Logging()->InsertPacketEvent(now,
111 kAudioPacketSentToPacer,
112 rtp_timestamp,
113 frame_id,
114 0,
115 10,
116 packet_size);
117 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
118 }
119
120 PacketStatsMap stats_map;
121 subscriber_->GetPacketStats(&stats_map);
122
123 // Size of stats equals the number of event types.
124 EXPECT_EQ(1u, stats_map.size());
125 PacketStatsMap::const_iterator it = stats_map.find(kAudioPacketSentToPacer);
126 ASSERT_NE(stats_map.end(), it);
127
128 EXPECT_EQ(first_event_time, it->second.first_event_time);
129 EXPECT_EQ(now, it->second.last_event_time);
130 EXPECT_EQ(num_packets, it->second.event_counter);
131 EXPECT_EQ(num_packets * packet_size, static_cast<int>(it->second.sum_size));
132 }
133
134 TEST_F(StatsEventSubscriberTest, GenericStats) {
135 Init(OTHER_EVENT);
136 int num_generic_events = 10;
137 int value = 123;
138 for (int i = 0; i < num_generic_events; i++) {
139 cast_environment_->Logging()->InsertGenericEvent(
140 testing_clock_->NowTicks(), kRttMs, value);
141 }
142
143 GenericStatsMap stats_map;
144 subscriber_->GetGenericStats(&stats_map);
145
146 EXPECT_EQ(1u, stats_map.size());
147 GenericStatsMap::const_iterator it = stats_map.find(kRttMs);
148 ASSERT_NE(stats_map.end(), it);
149
150 EXPECT_EQ(num_generic_events, it->second.event_counter);
151 EXPECT_EQ(num_generic_events * value, it->second.sum);
152 EXPECT_EQ(static_cast<uint64>(num_generic_events * value * value),
153 it->second.sum_squared);
154 EXPECT_LE(value, it->second.min);
155 EXPECT_GE(value, it->second.max);
156 }
157
158 TEST_F(StatsEventSubscriberTest, Reset) {
159 Init(VIDEO_EVENT);
160 cast_environment_->Logging()->InsertFrameEvent(
161 testing_clock_->NowTicks(), kVideoFrameReceived, 0, 0);
162
163 FrameStatsMap frame_stats;
164 subscriber_->GetFrameStats(&frame_stats);
165 EXPECT_EQ(1u, frame_stats.size());
166
167 subscriber_->Reset();
168 subscriber_->GetFrameStats(&frame_stats);
169 EXPECT_TRUE(frame_stats.empty());
170 }
171
172 } // namespace cast
173 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/logging/stats_event_subscriber.cc ('k') | media/cast/logging/stats_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698