Bug 929498 - fix test_asmjs.html mochitest to not run so long on slow machines (r=pending)
authorLuke Wagner <luke@mozilla.com>
Tue, 22 Oct 2013 16:16:09 -0500
changeset 166073 3650ee82a04f48bfa7aba1d8346645fedd9245a1
parent 166072 ddbec02a4ead95641eb803c2c93b27a428a7b0c3
child 166074 7aec4c2156d5be71716222d5072ce048417d7ad2
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspending
bugs929498
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 929498 - fix test_asmjs.html mochitest to not run so long on slow machines (r=pending)
js/xpconnect/tests/mochitest/file_asmjs.js
js/xpconnect/tests/mochitest/test_asmjs.html
--- a/js/xpconnect/tests/mochitest/file_asmjs.js
+++ b/js/xpconnect/tests/mochitest/file_asmjs.js
@@ -1,26 +1,71 @@
-function f(stdlib, foreign, buffer) {
+function f1() { "use asm"; function g() {} return g }
+if (this.jsFuns) {
+    ok(jsFuns.isAsmJSModule(f1), "f1 is an asm.js module");
+    ok(jsFuns.isAsmJSFunction(f1()), "f1.g is an asm.js function");
+}
+
+function f2(stdlib, foreign, buffer) {
     "use asm";
     var i32 = new stdlib.Int32Array(buffer);
     function main(n) {
         n = n|0;
         var i = 0, sum = 0;
         for (; (i|0) < (n|0); i=(i+1)|0)
             sum = (sum + (i32[(i<<2)>>2]|0))|0;
         return sum|0;
     }
     return main;
 }
-
-var i32 = new Int32Array(4096/4);
-for (var i = 0; i < 100; i++)
+if (this.jsFuns)
+    ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
+var i32 = new Int32Array(1024);
+for (var i = 0; i < i32.length; i++)
     i32[i] = i;
+var f2Main = f2(this, null, i32.buffer);
+if (this.jsFuns)
+    ok(jsFuns.isAsmJSFunction(f2Main), "f2.main is an asm.js function");
+if (f2Main(4) !== 6)
+    throw "f2Main(4)";
+if (f2Main(100) !== 4950)
+    throw "f2.main(100)";
+var sum = (((i32.length - 1) * i32.length) / 2);
+if (f2Main(i32.length) !== sum)
+    throw "f2.main(" + i32.length + ")";
+if (f2Main(i32.length + 100) !== sum)
+    throw "f2.main(" + i32.length + ")";
 
-var fMain = f(this, null, i32.buffer);
-if (fMain(4) !== 6)
-    throw "f.main(4)";
-if (fMain(100) !== 4950)
-    throw "f.main(100)";
-if (fMain(5000) !== 4950)
-    throw "f.main(5000)";
+function f3(stdlib, foreign, buffer) {
+    "use asm";
+    var done = foreign.done;
+    var i32 = new stdlib.Int32Array(buffer);
+    function main() {
+        var i = 0, sum = 0;
+        while (1) {
+            for (i = 0; (i|0) < 1000; i=(i+1)|0)
+                sum = (sum + i)|0;
+            if (done(sum|0)|0)
+                break;
+        }
+        return sum|0;
+    }
+    return main;
+}
+var begin;
+var lastSum;
+function done(sum) {
+    if (sum !== ((lastSum + 499500)|0))
+        throw "bad sum: " + sum + ", " + lastSum + ", " + ((lastSum + 499500)|0);
+    lastSum = sum;
+    return (Date.now() - begin) > 3000;
+}
+var f3Main = f3(this, {done:done}, i32.buffer);
+if (this.jsFuns)
+    ok(jsFuns.isAsmJSFunction(f3Main), "f3.main is an asm.js function");
 
-postMessage("ok");
+begin = Date.now();
+lastSum = 0;
+if (f3Main() !== lastSum)
+    throw "f3.main()";
+
+if (!this.jsFuns)
+    postMessage("ok");
--- a/js/xpconnect/tests/mochitest/test_asmjs.html
+++ b/js/xpconnect/tests/mochitest/test_asmjs.html
@@ -5,75 +5,32 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>asm.js browser tests</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854209">asm.js browser tests</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-  
-</div>
-<pre id="test">
-<script class="testbody" type="text/javascript">
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854209">asm.js browser tests</a>
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
+  <pre id="test"></pre>
 
-var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
-
-ok(jsFuns.isAsmJSCompilationAvailable());
-
-function f1() { "use asm"; function g() {} return g }
-ok(jsFuns.isAsmJSModule(f1), "f1 is an asm.js module");
-ok(jsFuns.isAsmJSFunction(f1()), "f1.g is an asm.js function");
+  <script>
+  var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
+  ok(jsFuns.isAsmJSCompilationAvailable());
+  </script>
 
-function f2(stdlib, foreign, buffer) {
-    "use asm";
-    var i32 = new stdlib.Int32Array(buffer);
-    function main(n) {
-        n = n|0;
-        var i = 0, sum = 0;
-        for (; (i|0) < (n|0); i=(i+1)|0)
-            sum = (sum + (i32[(i<<2)>>2]|0))|0;
-        return sum|0;
-    }
-    return main;
-}
-ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
-var i32 = new Int32Array(4096/4);
-for (var i = 0; i < 100; i++)
-    i32[i] = i;
-var f2Main = f2(this, null, i32.buffer);
-ok(jsFuns.isAsmJSFunction(f2Main), "f2.main is an asm.js function");
-ok(f2Main(4) == 6, "f2.main(4)");
-ok(f2Main(100) == 4950, "f2.main(100)");
-ok(f2Main(5000) == 4950, "f2.main(5000)");
+  <script src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_asmjs.js"></script>
 
-function f3(stdlib, foreign, buffer) {
-    "use asm";
-    var i32 = new stdlib.Int32Array(buffer);
-    function main(n,o) {
-        n = n|0;
-        o = o|0;
-        var i = 0, j = 0, sum = 0;
-        for (i = 0; (i|0) < (n|0); i=(i+1)|0)
-            for (j = 0; (j|0) < (o|0); j=(j+1)|0)
-                sum = (sum + (i32[(j<<2)>>2]|0))|0;
-        return sum|0;
-    }
-    return main;
-}
-var f3Main = f3(this, null, i32.buffer);
-ok(jsFuns.isAsmJSFunction(f3Main), "f3.main is an asm.js function");
-ok(f3Main(200000, 1000) == ((4950*200000)|0), "f3.main(200000, 1000)");
+  <script>
+  var w = new Worker('http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_asmjs.js');
+  w.onmessage = function(e) {
+      ok(e.data === "ok", "Worker asm.js tests");
+      SimpleTest.finish();
+  }
 
-var w = new Worker('http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_asmjs.js');
-w.onmessage = function(e) {
-    ok(e.data === "ok", "Worker asm.js tests");
-    SimpleTest.finish();
-}
+  SimpleTest.waitForExplicitFinish();
+  </script>
 
-SimpleTest.waitForExplicitFinish();
-</script>
-</pre>
 </body>
 </html>