| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 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/metrics/system_health/hazard_metric.html"> |
| <link rel="import" href="/tracing/value/value_set.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| function computeHazardValue(customizeModelCallback) { |
| var model = tr.c.TestUtils.newModel(function(model) { |
| model.rendererProcess = model.getOrCreateProcess(2); |
| model.rendererMain = model.rendererProcess.getOrCreateThread(3); |
| model.rendererMain.name = 'CrRendererMain'; |
| |
| customizeModelCallback(model); |
| }); |
| var values = new tr.v.ValueSet(); |
| tr.metrics.sh.hazardMetric(values, model); |
| return tr.b.getOnlyElement(values); |
| } |
| |
| test('minimalHazard', function() { |
| var duration = 50 + 1e-4; |
| var value = computeHazardValue(function(model) { |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: duration |
| })); |
| }); |
| assert.notEqual(0, value.average); |
| assert.closeTo(value.average, 0.1611, 1e-5); |
| }); |
| |
| test('maximalHazard', function() { |
| var value = computeHazardValue(function(model) { |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: 2200 |
| })); |
| }); |
| assert.closeTo(value.average, 1, 1e-5); |
| }); |
| |
| test('blendedHazards', function() { |
| var value = computeHazardValue(function(model) { |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: 100 |
| })); |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: 200 |
| })); |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: 300 |
| })); |
| model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| type: tr.model.ThreadSlice, |
| isTopLevel: true, |
| start: 0, |
| duration: 400 |
| })); |
| }); |
| assert.closeTo(0.92144, value.average, 1e-4); |
| }); |
| }); |
| </script> |