Commit da8bfdca authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

WebAudio: Fix testStoppedSourceGC for unified heap

GCs should be run async if they require that objects are guaranteed to
be collected.

Bug: 843903
Change-Id: I1e55646e3c2e9f9625c71b45d0c16d8477b4566d
Reviewed-on: https://chromium-review.googlesource.com/c/1488880Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635561}
parent 47ca9747
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<title>Test GC of Stopped AudioBufferSourceNode </title> <title>Test GC of Stopped AudioBufferSourceNode </title>
<script src="../../resources/gc.js"></script>
<script src="../../resources/testharness.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script> <script src="../resources/audit-util.js"></script>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<title>Test GC of Stopped ConstantSourceNode </title> <title>Test GC of Stopped ConstantSourceNode </title>
<script src="../../resources/gc.js"></script>
<script src="../../resources/testharness.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script> <script src="../resources/audit-util.js"></script>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<title>Test GC of Stopped OscillatorNode </title> <title>Test GC of Stopped OscillatorNode </title>
<script src="../../resources/gc.js"></script>
<script src="../../resources/testharness.js"></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script> <script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script> <script src="../resources/audit-util.js"></script>
......
...@@ -15,10 +15,11 @@ function testStoppedSourceGC(task, should, options) { ...@@ -15,10 +15,11 @@ function testStoppedSourceGC(task, should, options) {
lastSrc1.connect(gain); lastSrc1.connect(gain);
lastSrc0.onended = () => { lastSrc0.onended = () => {
// Have |lastSrc1| stop 10 render quanta from now (pretty arbitrary). asyncGC().then(function () {
lastSrc1.stop( // Have |lastSrc1| stop 10 render quanta from now (pretty arbitrary).
lastSrc1.stop(
context.currentTime + 10 * RENDER_QUANTUM_FRAMES / context.sampleRate); context.currentTime + 10 * RENDER_QUANTUM_FRAMES / context.sampleRate);
should(() => gc(), 'GC').notThrow(); });
}; };
lastSrc1.onended = () => { lastSrc1.onended = () => {
...@@ -28,35 +29,37 @@ function testStoppedSourceGC(task, should, options) { ...@@ -28,35 +29,37 @@ function testStoppedSourceGC(task, should, options) {
task.done(); task.done();
}; };
gc(); let initialCount = 0;
let initialCount = internals.audioHandlerCount(); asyncGC().then(function () {
initialCount = internals.audioHandlerCount();
// For information only. This should obviously always pass. // For information only. This should obviously always pass.
should(initialCount, 'Number of handlers before test') should(initialCount, 'Number of handlers before test')
.beEqualTo(initialCount); .beEqualTo(initialCount);
// Create a bunch of sources for testing. Since we call stop(), these // Create a bunch of sources for testing. Since we call stop(), these
// should all get collected, even though they're no longer connected to // should all get collected, even though they're no longer connected to
// the destination. // the destination.
for (let k = 0; k < numberOfNodes; ++k) { for (let k = 0; k < numberOfNodes; ++k) {
let src = constructorMethod(); let src = constructorMethod();
src.start(); src.start();
src.connect(gain); src.connect(gain);
src.onended = () => { src.onended = () => {
++countEndedNodes; ++countEndedNodes;
if (countEndedNodes == numberOfNodes) { if (countEndedNodes == numberOfNodes) {
// For information only // For information only
should(countEndedNodes, `Number of ${nodeName}s tested`) should(countEndedNodes, `Number of ${nodeName}s tested`)
.beEqualTo(numberOfNodes); .beEqualTo(numberOfNodes);
lastSrc0.stop(); lastSrc0.stop();
} }
}; };
// Stop it after about 2 renders // Stop it after about 2 renders
src.stop( src.stop(
context.currentTime + 2 * RENDER_QUANTUM_FRAMES / context.sampleRate); context.currentTime + 2 * RENDER_QUANTUM_FRAMES / context.sampleRate);
src.disconnect(); src.disconnect();
} }
// Start the sources // Start the sources
lastSrc0.start(); lastSrc0.start();
lastSrc1.start(); lastSrc1.start();
});
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment