Chromium Code Reviews| Index: tracing/tracing/metrics/webrtc/webrtc_rendering_metric_test.html |
| diff --git a/tracing/tracing/metrics/webrtc/webrtc_rendering_metric_test.html b/tracing/tracing/metrics/webrtc/webrtc_rendering_metric_test.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8c82b9c4902538b0ebdce0bb70dcea1c5abd0e8b |
| --- /dev/null |
| +++ b/tracing/tracing/metrics/webrtc/webrtc_rendering_metric_test.html |
| @@ -0,0 +1,125 @@ |
| +<!DOCTYPE html> |
| +<!-- |
| +Copyright 2016 The Chromium Authors. All rights reserved. |
| +Use of this source code is governed by a BSD-style license that can be |
| +found in the LICENSE file. |
| +--> |
| + |
| +<link rel="import" href="/tracing/core/test_utils.html"> |
| +<link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> |
| +<link rel="import" href="/tracing/metrics/webrtc/webrtc_rendering_metric.html"> |
| +<link rel="import" href="/tracing/model/slice_group.html"> |
| +<link rel="import" href="/tracing/value/histogram.html"> |
| +<link rel="import" href="/tracing/value/histogram_set.html"> |
| + |
| +<script> |
| +'use strict'; |
| + |
| +tr.b.unittest.testSuite(function() { |
| + function eventFromPair(pair) { |
| + return { |
| + title: 'WebMediaPlayerMS::UpdateCurrentFrame', |
| + start: pair[1], |
| + duration: 1, |
| + args: { |
| + 'Ideal Render Instant': pair[0], |
| + 'Actual Render Begin': pair[1], |
| + 'Actual Render End': 0, |
| + 'Serial': 0, |
| + } |
| + }; |
| + } |
| + |
| + function newModel(fakeEvents) { |
| + function customizeModelCallback(model) { |
| + const rendererProcess = model.getOrCreateProcess(1); |
| + const mainThread = rendererProcess.getOrCreateThread(2); |
| + for (const event of fakeEvents) { |
| + mainThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx(event)); |
| + } |
| + } |
| + return tr.c.TestUtils.newModelWithEvents([], {customizeModelCallback}); |
| + } |
| + |
| + function runWebrtcRenderingMetric(fakeEvents) { |
| + let values = new tr.v.HistogramSet(); |
| + let model = newModel(fakeEvents); |
| + tr.metrics.webrtc.webrtcRenderingMetric(values, model); |
| + return values; |
| + } |
| + |
| + test('driftTime', function() { |
| + // These numbers don't mean anything. We just want to make sure we can |
|
ehmaldonado_chromium
2017/03/01 21:59:05
Tim, what do you think of this way to test driftTi
tdresser
2017/03/02 13:19:01
This LGTM, thanks.
|
| + // recover them after running the metric. |
| + let fakeDriftTimes = [67, 764, 15, 3447, 67, 43, 767]; |
| + |
| + // Create fake events from the fake drift times. For the i-th drift time, |
| + // we'll create an event with 'Ideal Render Instant' = i and |
| + // 'Actual Render Instant' = i + fakeDriftTimes[i]. |
| + let fakeEvents = []; |
| + for (const driftTime of fakeDriftTimes) { |
| + let lastTime = 0; |
| + if (fakeEvents.length > 0) { |
| + lastTime = fakeEvents[fakeEvents.length - 1][0] + 1; |
| + } |
| + fakeEvents.push([lastTime, lastTime + driftTime]); |
| + } |
|
tdresser
2017/03/02 13:19:01
It's a bit confusing to keep track of what's ideal
ehmaldonado_chromium
2017/03/02 20:19:55
Can you take a look at the latest patch, please? :
|
| + fakeEvents = fakeEvents.map(eventFromPair); |
| + |
| + // We don't have access to the values stored in the histogram, so we check |
| + // for equality in the summary statistics. |
| + let values = runWebrtcRenderingMetric(fakeEvents); |
| + let hist = values.getHistogramNamed('WebRTCRendering_drift_time'); |
| + assert.strictEqual(hist.sum, tr.b.Statistics.sum(fakeDriftTimes)); |
| + assert.strictEqual(hist.numValues, fakeDriftTimes.length); |
| + assert.strictEqual(hist.running.min, tr.b.Statistics.min(fakeDriftTimes)); |
| + assert.strictEqual(hist.running.max, tr.b.Statistics.max(fakeDriftTimes)); |
| + assert.closeTo(hist.standardDeviation, |
| + tr.b.Statistics.stddev(fakeDriftTimes), 1e-2); |
| + }); |
| + |
| + test('percentBadlyOutOfSync', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = |
| + values.getHistogramNamed('WebRTCRendering_percent_badly_out_of_sync'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.strictEqual(hist.sum, 0); |
| + }); |
| + |
| + test('percentOutOfSync', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = values.getHistogramNamed('WebRTCRendering_percent_out_of_sync'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.strictEqual(hist.sum, 5); |
| + }); |
| + |
| + test('fps', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = values.getHistogramNamed('WebRTCRendering_fps'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.strictEqual(hist.sum, 60); |
| + }); |
| + |
| + test('smoothnessScore', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = values.getHistogramNamed('WebRTCRendering_smoothness_score'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.strictEqual(hist.sum, 95); |
| + }); |
| + |
| + test('freezingScore', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = values.getHistogramNamed('WebRTCRendering_freezing_score'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.strictEqual(hist.sum, 100); |
| + }); |
| + |
| + test('renderingLengthError', function() { |
| + let values = runWebrtcRenderingMetric(FAKE_EVENTS); |
| + let hist = |
| + values.getHistogramNamed('WebRTCRendering_rendering_length_error'); |
| + assert.strictEqual(hist.numValues, 1); |
| + assert.closeTo(hist.sum, 36.1, 1e-3); |
| + }); |
| +}); |
| +</script> |