Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| index 49b376b6889bfd1543568c3c26284d954a3ad119..dd325d7f0ad4b6e56d351074694d6a96f2ee02b6 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| +++ b/third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js |
| @@ -35,6 +35,7 @@ |
| OscillatorTestingUtils = (function () { |
| +var audit = Audit.createTaskRunner(); |
|
hongchan
2017/02/06 17:28:43
Not really sure about this pattern. Audit should b
Raymond Toy
2017/02/06 18:36:18
Yeah, I debated on whether to bury everything here
Raymond Toy
2017/02/07 00:16:28
Done.
|
| var sampleRate = 44100.0; |
| var nyquist = 0.5 * sampleRate; |
| var lengthInSeconds = 4; |
| @@ -109,22 +110,8 @@ function calculateSNR(sPower, nPower) |
| return 10 * Math.log10(sPower / nPower); |
| } |
| -function loadReferenceAndRunTest(oscType) { |
| - var bufferLoader = new BufferLoader( |
| - context, |
| - [ "../Oscillator/oscillator-" + oscType + "-expected.wav" ], |
| - function (bufferList) { |
| - reference = bufferList[0].getChannelData(0); |
| - generateExponentialOscillatorSweep(context, oscType); |
| - context.oncomplete = checkResult; |
| - context.startRendering(); |
| - }); |
| - |
| - bufferLoader.load(); |
| -} |
| - |
| -function checkResult (event) { |
| - renderedData = event.renderedBuffer.getChannelData(0); |
| +function checkResult (renderedBuffer, should) { |
| + renderedData = renderedBuffer.getChannelData(0); |
|
hongchan
2017/02/06 17:28:43
Why isn't this a local variable? Any reason being
Raymond Toy
2017/02/06 18:36:18
Probably to make debugging easier so that it could
hongchan
2017/02/07 18:18:53
I think it's easy to put 'let' at the beginning. N
Raymond Toy
2017/02/07 18:57:58
You mean make renderedData truly local to checkRes
|
| // Compute signal to noise ratio between the result and the reference. Also keep track |
| // of the max difference (and position). |
| @@ -148,30 +135,15 @@ function checkResult (event) { |
| } |
| var snr = calculateSNR(signalPower, noisePower); |
| - if (snr >= thresholdSNR) { |
| - testPassed("Exceeded SNR threshold of " + thresholdSNR + " dB"); |
| - } else { |
| - testFailed("Expected SNR of " + thresholdSNR + " dB, but actual SNR is " + snr + " dB"); |
| - } |
| - |
| - if (maxError <= thresholdDiff) { |
| - testPassed("Maximum difference below threshold of " |
| - + (thresholdDiff * waveScaleFactor) + " ulp (16-bits)"); |
| - } else { |
| - testFailed("Maximum difference of " + (maxError * waveScaleFactor) + " at " |
| - + errorPosition + " exceeded threshold of " + (thresholdDiff * waveScaleFactor) |
| - + " ulp (16-bits)"); |
| - } |
| - |
| - if (diffCount <= thresholdDiffCount) { |
| - testPassed("Number of differences between actual and expected result is less than " + thresholdDiffCount |
| - + " out of " + renderedData.length); |
| - } else { |
| - testFailed(diffCount + " differences found but expected no more than " + thresholdDiffCount |
| - + " out of " + renderedData.length); |
| - } |
| - |
| - finishJSTest(); |
| + should(snr, "SNR") |
| + .beGreaterThanOrEqualTo(thresholdSNR); |
| + should(maxError * waveScaleFactor, "Maximum difference in ulp (16-bits)") |
| + .beLessThanOrEqualTo(thresholdDiff * waveScaleFactor); |
| + |
| + should(diffCount, |
| + "Number of differences between actual and expected result out of " |
| + + renderedData.length + " frames") |
| + .beLessThanOrEqualTo(thresholdDiffCount); |
| } |
| function setThresholds(thresholds) { |
| @@ -180,10 +152,32 @@ function setThresholds(thresholds) { |
| thresholdDiffCount = thresholds.diffCount; |
| } |
| -function runTest(oscType) { |
| - window.jsTestIsAsync = true; |
| - context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRate); |
| - loadReferenceAndRunTest(oscType); |
| +function runTest(oscType, description) { |
| + audit.define("load-ref", function (task, should) { |
| + task.describe("Load reference file"); |
| + context = new OfflineAudioContext(1, sampleRate * |
| + lengthInSeconds, sampleRate); |
| + var bufferLoader = new BufferLoader( |
| + context, ["../Oscillator/oscillator-" + oscType + |
| + "-expected.wav" |
| + ], |
| + function (bufferList) { |
| + reference = bufferList[0].getChannelData(0); |
| + task.done(); |
| + }); |
| + |
| + bufferLoader.load(); |
| + }); |
| + |
| + audit.define("test", function (task, should) { |
| + task.describe(description); |
| + generateExponentialOscillatorSweep(context, oscType); |
| + context.startRendering() |
| + .then(buffer => checkResult(buffer, should)) |
| + .then(task.done.bind(task));; |
| + }); |
| + |
| + audit.run(); |
| } |
| function createNewReference(oscType) { |
| @@ -207,7 +201,6 @@ return { |
| thresholdDiffCount: thresholdDiffCount, |
| waveScaleFactor: waveScaleFactor, |
| setThresholds: setThresholds, |
| - loadReferenceAndRunTest: loadReferenceAndRunTest, |
| runTest: runTest, |
| createNewReference: createNewReference, |
| }; |