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

Side by Side Diff: tools/telemetry/telemetry/web_perf/metrics/webrtc_rendering_stats_unittest.py

Issue 1254023003: Telemetry Test for WebRTC Rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove mocks to fix border effects on subsequent tests Created 5 years, 2 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
(Empty)
1 # Copyright 2015 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 import unittest
5
6 from telemetry.web_perf.metrics import webrtc_rendering_stats as stats_helper
7
8
9 class FakeEvent(object):
10 """Fake event class to mock rendering events."""
11
12 def __init__(self, **kwargs):
13 """Initializer for the fake WebMediaPlayerMS::UpdateCurrentFrame events.
14
15 The WebMediaPlayerMsRenderingStats only cares about actual render begin,
16 actual render end, ideal render instant and serial fields of the events.
17 So we only define these four fields here in this fake event class.
18 This method is written so as to take whatever valid parameters from the
19 event definition. It can also be used to craft incomplete events.
20
21 Args:
22 kwargs::= dict('actual_begin', 'actual_end', 'ideal_instant', 'serial').
23 """
24 self.args = {}
25 name_map = {
26 'Actual Render Begin': 'actual_begin',
27 'Actual Render End': 'actual_end',
28 'Ideal Render Instant': 'ideal_instant',
29 'Serial': 'serial'}
30 for internal_name, external_name in name_map.iteritems():
31 if external_name in kwargs:
32 self.args[internal_name] = kwargs[external_name]
33
34
35 class WebMediaPlayerMsRenderingStatsTest(unittest.TestCase):
36
37 def setUp(self):
38 # A local stream id always has an even number.
39 # A remote stream id always has an odd number.
40 self.local_stream = 136390988
41 self.remote_stream = 118626165
42
43 def testInitialization(self):
44 event_local_stream = FakeEvent(actual_begin=1655987203306,
45 actual_end=1655987219972, ideal_instant=1655987154324,
46 serial=self.local_stream)
47
48 event_remote_stream = FakeEvent(actual_begin=1655987203306,
49 actual_end=1655987219972, ideal_instant=1655987167999,
50 serial=self.remote_stream)
51
52 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats(
53 [event_local_stream, event_remote_stream])
54
55 self.assertEqual(2, len(stats_parser.stream_to_events))
56
57 self.assertEqual(event_local_stream.args,
58 stats_parser.stream_to_events[self.local_stream][0].args)
59
60 self.assertEqual(event_remote_stream.args,
61 stats_parser.stream_to_events[self.remote_stream][0].args)
62
63 def testInvalidEvents(self):
64 event_missing_serial = FakeEvent(actual_begin=1655987244074,
65 actual_end=1655987260740, ideal_instant=1655987204839)
66
67 event_missing_actual_begin = FakeEvent(actual_end=1655987260740,
68 ideal_instant=1655987217999, serial=self.local_stream)
69
70 event_missing_actual_end = FakeEvent(actual_end=1655987260740,
71 ideal_instant=1655987217999, serial=self.remote_stream)
72
73 event_missing_ideal_instant = FakeEvent(actual_begin=1655987260740,
74 actual_end=1655987277406, serial=self.remote_stream)
75
76 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats(
77 [event_missing_serial, event_missing_actual_begin,
78 event_missing_actual_end, event_missing_ideal_instant])
79
80 self.assertEqual(0, len(stats_parser.stream_to_events))
81
82 def _GetFakeEvents(self):
83 fake_events = [
84 FakeEvent(actual_begin=1663780195583, actual_end=1663780212249,
85 ideal_instant=1663780179998, serial=self.remote_stream),
86 FakeEvent(actual_begin=1663780212249, actual_end=1663780228915,
87 ideal_instant=1663780179998, serial=self.remote_stream),
88 FakeEvent(actual_begin=1663780228915, actual_end=1663780245581,
89 ideal_instant=1663780197998, serial=self.remote_stream),
90 FakeEvent(actual_begin=1663780245581, actual_end=1663780262247,
91 ideal_instant=1663780215998, serial=self.remote_stream),
92 FakeEvent(actual_begin=1663780262247, actual_end=1663780278913,
93 ideal_instant=1663780215998, serial=self.remote_stream),
94 FakeEvent(actual_begin=1663780278913, actual_end=1663780295579,
95 ideal_instant=1663780254998, serial=self.remote_stream),
96 FakeEvent(actual_begin=1663780295579, actual_end=1663780312245,
97 ideal_instant=1663780254998, serial=self.remote_stream),
98 FakeEvent(actual_begin=1663780312245, actual_end=1663780328911,
99 ideal_instant=1663780254998, serial=self.remote_stream),
100 FakeEvent(actual_begin=1663780328911, actual_end=1663780345577,
101 ideal_instant=1663780310998, serial=self.remote_stream),
102 FakeEvent(actual_begin=1663780345577, actual_end=1663780362243,
103 ideal_instant=1663780310998, serial=self.remote_stream),
104 FakeEvent(actual_begin=1663780362243, actual_end=1663780378909,
105 ideal_instant=1663780310998, serial=self.remote_stream),
106 FakeEvent(actual_begin=1663780378909, actual_end=1663780395575,
107 ideal_instant=1663780361998, serial=self.remote_stream),
108 FakeEvent(actual_begin=1663780395575, actual_end=1663780412241,
109 ideal_instant=1663780361998, serial=self.remote_stream),
110 FakeEvent(actual_begin=1663780412241, actual_end=1663780428907,
111 ideal_instant=1663780361998, serial=self.remote_stream),
112 FakeEvent(actual_begin=1663780428907, actual_end=1663780445573,
113 ideal_instant=1663780412998, serial=self.remote_stream)]
114
115 return fake_events
116
117 def testGetCadence(self):
118 fake_events = self._GetFakeEvents()
119 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats(fake_events)
120 # The events defined in _GetFakeEvents above show that the first source
121 # framee of ideal_instant=1663780179998 is rendered twice, then
122 # the second source frame of ideal_instant=1663780197998 is rendered once
123 # the third source frame of ideal_instant=1663780215998 is rendered twice
124 # and so on. The expected cadence will therefore be [2 1 2 etc..]
125 expected_cadence = [2, 1, 2, 3, 3, 3, 1]
126 self.assertEqual(expected_cadence, stats_parser._GetCadence(fake_events))
127
128 def testGetSourceToOutputDistribution(self):
129 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
130 cadence = [2, 1, 2, 3, 3, 3, 1]
131 expected_frame_distribution = {1: 2, 2: 2, 3: 3}
132 self.assertEqual(expected_frame_distribution,
133 stats_parser._GetSourceToOutputDistribution(cadence))
134
135 def testGetFpsFromCadence(self):
136 frame_distribution = {1: 2, 2: 2, 3: 3}
137 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
138 expected_frame_rate = 28.0
139 self.assertEqual(expected_frame_rate,
140 stats_parser._GetFpsFromCadence(frame_distribution))
141
142 def testGetFrozenFramesReports(self):
143 frame_distribution = {1: 2, 2: 2, 3: 569, 6: 1}
144 expected_frozen_reports = [{'frozen_frames': 5, 'occurrences': 1}]
145 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
146 self.assertEqual(expected_frozen_reports,
147 stats_parser._GetFrozenFramesReports(frame_distribution))
148
149 def testIsRemoteStream(self):
150 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
151 self.assertTrue(stats_parser._IsRemoteStream(self.remote_stream))
152
153 def testGetDrifTimeStats(self):
154 fake_events = self._GetFakeEvents()
155 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
156 cadence = stats_parser._GetCadence(fake_events)
157 expected_drift_time = [15585, 30917, 29583, 23915, 17913, 16911, 15909]
158 expected_rendering_length_error = 29.613733905579398
159
160 self.assertEqual((expected_drift_time, expected_rendering_length_error),
161 stats_parser._GetDrifTimeStats(fake_events, cadence))
162
163 def testGetSmoothnessStats(self):
164 norm_drift_time = [5948.2857142857138, 9383.7142857142862,
165 8049.7142857142862, 2381.7142857142862, 3620.2857142857138,
166 4622.2857142857138, 5624.2857142857138]
167 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
168 expected_percent_badly_oos = 0.0
169 expected_percent_out_of_sync = 0.0
170 expected_smoothness_score = 100.0
171 expected_smoothness_stats = (expected_percent_badly_oos,
172 expected_percent_out_of_sync, expected_smoothness_score)
173
174 self.assertEqual(expected_smoothness_stats,
175 stats_parser._GetSmoothnessStats(norm_drift_time))
176
177 def testNegativeSmoothnessScoreChangedToZero(self):
178 norm_drift_time = [15948.285714285714, 9383.714285714286,
179 28049.714285714286, 72381.71428571429, 3620.2857142857138,
180 4622.285714285714, 35624.28571428572]
181 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
182 expected_percent_badly_oos = 28.571428571428573
183 expected_percent_out_of_sync = 42.857142857142854
184 expected_smoothness_score = 0.0
185 expected_smoothness_stats = (expected_percent_badly_oos,
186 expected_percent_out_of_sync, expected_smoothness_score)
187
188 self.assertEqual(expected_smoothness_stats,
189 stats_parser._GetSmoothnessStats(norm_drift_time))
190
191 def testGetFreezingScore(self):
192 frame_distribution = {1: 2, 2: 2, 3: 569, 6: 1}
193 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
194 expected_freezing_score = 99.94182664339732
195 self.assertEqual(expected_freezing_score,
196 stats_parser._GetFreezingScore(frame_distribution))
197
198 def testNegativeFrezingScoreChangedToZero(self):
199 frame_distribution = {1: 2, 2: 2, 3: 2, 8:100}
200 stats_parser = stats_helper.WebMediaPlayerMsRenderingStats([])
201 self.assertEqual(0.0, stats_parser._GetFreezingScore(frame_distribution))
202
203 def testGetTimeStats(self):
204 fake_events = self._GetFakeEvents()
205 expected_frame_dist = {1: 2, 2: 2, 3: 3}
206 expected_frame_rate = 28.0
207 expected_drift_time = [15585, 30917, 29583, 23915, 17913, 16911, 15909]
208 expected_rendering_length_error = 29.613733905579398
209 expected_percent_badly_oos = 0.0
210 expected_percent_out_of_sync = 0.0
211 expected_smoothness_score = 100.0
212 expected_freezing_score = 100.0
213
214 stats_cls = stats_helper.WebMediaPlayerMsRenderingStats
215
216 stats_parser = stats_cls(fake_events)
217
218 expected_stats = stats_helper.TimeStats(
219 drift_time=expected_drift_time,
220 percent_badly_out_of_sync=expected_percent_badly_oos,
221 percent_out_of_sync=expected_percent_out_of_sync,
222 smoothness_score=expected_smoothness_score,
223 freezing_score=expected_freezing_score,
224 rendering_length_error=expected_rendering_length_error,
225 fps=expected_frame_rate,
226 frame_distribution=expected_frame_dist)
227
228 stats = stats_parser.GetTimeStats()
229
230 self.assertEqual(expected_stats.drift_time, stats.drift_time)
231 self.assertEqual(expected_stats.percent_badly_out_of_sync,
232 stats.percent_badly_out_of_sync)
233 self.assertEqual(expected_stats.percent_out_of_sync,
234 stats.percent_out_of_sync)
235 self.assertEqual(expected_stats.smoothness_score, stats.smoothness_score)
236 self.assertEqual(expected_stats.freezing_score, stats.freezing_score)
237 self.assertEqual(expected_stats.rendering_length_error,
238 stats.rendering_length_error)
239 self.assertEqual(expected_stats.fps, stats.fps)
240 self.assertEqual(expected_stats.frame_distribution,
241 stats.frame_distribution)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698