From 445db35df72a74eb67786974b176034ec4709f28 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 26 Mar 2012 15:20:34 -0400 Subject: [PATCH] Bug 734423 - refactor the gc() helper used by WebGL conformance tests - no review, will upstream - NPOTB --- .../extensions/oes-standard-derivatives.html | 23 +-- .../extensions/oes-texture-float.html | 23 +-- content/canvas/test/webgl/gc.patch | 155 ++++++++++++++++++ .../test/webgl/resources/js-test-pre.js | 37 +++-- 4 files changed, 182 insertions(+), 56 deletions(-) create mode 100644 content/canvas/test/webgl/gc.patch diff --git a/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html b/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html index f820468a40f7..f4dc9d2dc27c 100644 --- a/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html +++ b/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html @@ -342,32 +342,11 @@ function runOutputTests() { } -function attemptToForceGC() -{ - var holderArray = []; - var tempArray; - window.tempArray = holderArray; - for (var i = 0; i < 12; ++i) { - tempArray = []; - for (var j = 0; j < 1024 * 1024; ++j) { - tempArray.push(0); - } - holderArray.push(tempArray); - } - window.tempArray = null; -} - function runUniqueObjectTest() { debug("Testing that getExtension() returns the same object each time"); gl.getExtension("OES_standard_derivatives").myProperty = 2; - if (window.GCController) { - window.GCController.collect(); - } else if (window.opera && window.opera.collect) { - window.opera.collect(); - } else { - attemptToForceGC(); - } + gc(); shouldBe('gl.getExtension("OES_standard_derivatives").myProperty', '2'); } diff --git a/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html b/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html index 82b704cd371c..433928bc7058 100644 --- a/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html +++ b/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html @@ -183,32 +183,11 @@ function runRenderTargetTest(testProgram) checkRenderingResults(); } -function attemptToForceGC() -{ - var holderArray = []; - var tempArray; - window.tempArray = holderArray; - for (var i = 0; i < 12; ++i) { - tempArray = []; - for (var j = 0; j < 1024 * 1024; ++j) { - tempArray.push(0); - } - holderArray.push(tempArray); - } - window.tempArray = null; -} - function runUniqueObjectTest() { debug("Testing that getExtension() returns the same object each time"); gl.getExtension("OES_texture_float").myProperty = 2; - if (window.GCController) { - window.GCController.collect(); - } else if (window.opera && window.opera.collect) { - window.opera.collect(); - } else { - attemptToForceGC(); - } + gc(); shouldBe('gl.getExtension("OES_texture_float").myProperty', '2'); } diff --git a/content/canvas/test/webgl/gc.patch b/content/canvas/test/webgl/gc.patch new file mode 100644 index 000000000000..1bc4cae2349d --- /dev/null +++ b/content/canvas/test/webgl/gc.patch @@ -0,0 +1,155 @@ +# HG changeset patch +# Parent f9585cefcf568dbc2a6ce81f16a2048365af7ed2 + +diff --git a/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html b/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html +--- a/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html ++++ b/content/canvas/test/webgl/conformance/extensions/oes-standard-derivatives.html +@@ -337,42 +337,21 @@ function runOutputTests() { + setupBuffers(1.0, 0.5, 0.5, 0.0); + wtu.drawQuad(gl); + expectResult([3, 3, 5, 255], + "Draw 4 (variation in x & y) returned the correct data", + "Draw 4 (variation in x & y) returned incorrect data"); + + } + +-function attemptToForceGC() +-{ +- var holderArray = []; +- var tempArray; +- window.tempArray = holderArray; +- for (var i = 0; i < 12; ++i) { +- tempArray = []; +- for (var j = 0; j < 1024 * 1024; ++j) { +- tempArray.push(0); +- } +- holderArray.push(tempArray); +- } +- window.tempArray = null; +-} +- + function runUniqueObjectTest() + { + debug("Testing that getExtension() returns the same object each time"); + gl.getExtension("OES_standard_derivatives").myProperty = 2; +- if (window.GCController) { +- window.GCController.collect(); +- } else if (window.opera && window.opera.collect) { +- window.opera.collect(); +- } else { +- attemptToForceGC(); +- } ++ gc(); + shouldBe('gl.getExtension("OES_standard_derivatives").myProperty', '2'); + } + + function runReferenceCycleTest() + { + // create some reference cycles. The goal is to see if they cause leaks. The point is that + // some browser test runners have instrumentation to detect leaked refcounted objects. + +diff --git a/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html b/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html +--- a/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html ++++ b/content/canvas/test/webgl/conformance/extensions/oes-texture-float.html +@@ -178,42 +178,21 @@ function runRenderTargetTest(testProgram + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.useProgram(testProgram); + gl.uniform1i(gl.getUniformLocation(testProgram, "tex"), 0); + wtu.drawQuad(gl); + glErrorShouldBe(gl, gl.NO_ERROR, "rendering from floating-point texture should succeed"); + checkRenderingResults(); + } + +-function attemptToForceGC() +-{ +- var holderArray = []; +- var tempArray; +- window.tempArray = holderArray; +- for (var i = 0; i < 12; ++i) { +- tempArray = []; +- for (var j = 0; j < 1024 * 1024; ++j) { +- tempArray.push(0); +- } +- holderArray.push(tempArray); +- } +- window.tempArray = null; +-} +- + function runUniqueObjectTest() + { + debug("Testing that getExtension() returns the same object each time"); + gl.getExtension("OES_texture_float").myProperty = 2; +- if (window.GCController) { +- window.GCController.collect(); +- } else if (window.opera && window.opera.collect) { +- window.opera.collect(); +- } else { +- attemptToForceGC(); +- } ++ gc(); + shouldBe('gl.getExtension("OES_texture_float").myProperty', '2'); + } + + function runReferenceCycleTest() + { + // create some reference cycles. The goal is to see if they cause leaks. The point is that + // some browser test runners have instrumentation to detect leaked refcounted objects. + +diff --git a/content/canvas/test/webgl/resources/js-test-pre.js b/content/canvas/test/webgl/resources/js-test-pre.js +--- a/content/canvas/test/webgl/resources/js-test-pre.js ++++ b/content/canvas/test/webgl/resources/js-test-pre.js +@@ -435,29 +435,42 @@ function assertMsg(assertion, msg) { + if (assertion) { + testPassed(msg); + } else { + testFailed(msg); + } + } + + function gc() { +- if (typeof GCController !== "undefined") +- GCController.collect(); +- else { +- function gcRec(n) { +- if (n < 1) +- return {}; +- var temp = {i: "ab" + i + (i / 100000)}; +- temp += "foo"; +- gcRec(n-1); +- } +- for (var i = 0; i < 1000; i++) +- gcRec(10) ++ if (window.GCController) { ++ window.GCController.collect(); ++ return; + } ++ ++ if (window.opera && window.opera.collect) { ++ window.opera.collect(); ++ return; ++ } ++ ++ try { ++ window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) ++ .getInterface(Components.interfaces.nsIDOMWindowUtils) ++ .garbageCollect(); ++ return; ++ } catch(e) {} ++ ++ function gcRec(n) { ++ if (n < 1) ++ return {}; ++ var temp = {i: "ab" + i + (i / 100000)}; ++ temp += "foo"; ++ gcRec(n-1); ++ } ++ for (var i = 0; i < 1000; i++) ++ gcRec(10); + } + + function finishTest() { + successfullyParsed = true; + var epilogue = document.createElement("script"); + epilogue.onload = function() { + if (window.nonKhronosFrameworkNotifyDone) { + window.nonKhronosFrameworkNotifyDone(); diff --git a/content/canvas/test/webgl/resources/js-test-pre.js b/content/canvas/test/webgl/resources/js-test-pre.js index f7c9a21f4f70..cd989f2e2d86 100644 --- a/content/canvas/test/webgl/resources/js-test-pre.js +++ b/content/canvas/test/webgl/resources/js-test-pre.js @@ -440,19 +440,32 @@ function assertMsg(assertion, msg) { } function gc() { - if (typeof GCController !== "undefined") - GCController.collect(); - else { - function gcRec(n) { - if (n < 1) - return {}; - var temp = {i: "ab" + i + (i / 100000)}; - temp += "foo"; - gcRec(n-1); - } - for (var i = 0; i < 1000; i++) - gcRec(10) + if (window.GCController) { + window.GCController.collect(); + return; } + + if (window.opera && window.opera.collect) { + window.opera.collect(); + return; + } + + try { + window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils) + .garbageCollect(); + return; + } catch(e) {} + + function gcRec(n) { + if (n < 1) + return {}; + var temp = {i: "ab" + i + (i / 100000)}; + temp += "foo"; + gcRec(n-1); + } + for (var i = 0; i < 1000; i++) + gcRec(10); } function finishTest() {