summaryrefslogtreecommitdiffstats
path: root/dom/asmjscache/test
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/asmjscache/test
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/asmjscache/test')
-rw-r--r--dom/asmjscache/test/file_slow.js73
-rw-r--r--dom/asmjscache/test/mochitest.ini10
-rw-r--r--dom/asmjscache/test/test_cachingBasic.html70
-rw-r--r--dom/asmjscache/test/test_cachingMulti.html85
-rw-r--r--dom/asmjscache/test/test_slow.html48
-rw-r--r--dom/asmjscache/test/test_workers.html74
6 files changed, 360 insertions, 0 deletions
diff --git a/dom/asmjscache/test/file_slow.js b/dom/asmjscache/test/file_slow.js
new file mode 100644
index 000000000..963422143
--- /dev/null
+++ b/dom/asmjscache/test/file_slow.js
@@ -0,0 +1,73 @@
+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;
+}
+if (this.jsFuns)
+ ok(jsFuns.isAsmJSModule(f2), "f2 is an asm.js module");
+var i32 = new Int32Array(16384); // Smallest allowed buffer size is 64KBy
+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 + ")";
+
+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");
+
+begin = Date.now();
+lastSum = 0;
+if (f3Main() !== lastSum)
+ throw "f3.main()";
+
+if (!this.jsFuns)
+ postMessage("ok");
+else
+ complete();
diff --git a/dom/asmjscache/test/mochitest.ini b/dom/asmjscache/test/mochitest.ini
new file mode 100644
index 000000000..a4f8dba7e
--- /dev/null
+++ b/dom/asmjscache/test/mochitest.ini
@@ -0,0 +1,10 @@
+[DEFAULT]
+support-files =
+ file_slow.js
+
+[test_cachingBasic.html]
+[test_workers.html]
+[test_cachingMulti.html]
+[test_slow.html]
+# bug 929498
+skip-if = os == 'android'
diff --git a/dom/asmjscache/test/test_cachingBasic.html b/dom/asmjscache/test/test_cachingBasic.html
new file mode 100644
index 000000000..e84fdba8b
--- /dev/null
+++ b/dom/asmjscache/test/test_cachingBasic.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=929236
+-->
+<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=929236">asm.js browser tests</a>
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+
+ <script>
+ var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
+
+ var code = "function f() { 'use asm';\n";
+ for (var i = 0; i < 5000; i++)
+ code += "function g" + i + "() { return " + i + "}\n";
+ code += "return g42 }\n";
+ code += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
+ code += "var g42 = f();\n";
+ code += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function')\n";
+ code += "ok(g42() === 42, 'g42 returns the correct result')\n";
+ code += "finishedEvalAsync(f);";
+ ok(code.length > 100000, "code is long enough to definitely hit the cache");
+
+ function evalAsync(code) {
+ var blob = new Blob([code], {type:"application/javascript"});
+ var script = document.createElement('script');
+ script.src = URL.createObjectURL(blob);
+ document.body.appendChild(script);
+ }
+
+ var state = 0;
+ function finishedEvalAsync(module) {
+ switch (state) {
+ case 0:
+ state++;
+ evalAsync(code);
+ break;
+ case 1:
+ ok(!jsFuns.isAsmJSModuleLoadedFromCache(module), 'module not loaded from cache');
+ SimpleTest.finish();
+ break;
+ default:
+ throw "huh?";
+ }
+ }
+
+ function runTest() {
+ // generate a big ol asm.js module and compile it async so that we can hit
+ // the asm.js cache.
+ SimpleTest.waitForExplicitFinish();
+ evalAsync(code);
+ }
+
+ if (!jsFuns.isAsmJSCompilationAvailable()) {
+ ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
+ } else {
+ runTest();
+ }
+ </script>
+
+</body>
+</html>
diff --git a/dom/asmjscache/test/test_cachingMulti.html b/dom/asmjscache/test/test_cachingMulti.html
new file mode 100644
index 000000000..ca092fda0
--- /dev/null
+++ b/dom/asmjscache/test/test_cachingMulti.html
@@ -0,0 +1,85 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=944821
+-->
+<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=944821">asm.js browser tests</a>
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+
+ <script>
+ var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
+
+ var assertCacheHit = false;
+
+ // generate four slightly different big asm.js modules and compile them async
+ // so that we can hit the asm.js cache.
+
+ var code = "function f() { 'use asm';\n";
+ for (var i = 0; i < 5000; i++)
+ code += "function g" + i + "() { return " + i + "}\n";
+ ok(code.length > 100000, "code is long enough to definitely hit the cache");
+
+ const N = 4;
+
+ var codes = [];
+ for (var i = 0; i < N; i++) {
+ var code2 = code;
+ code2 += "return g" + i + ";\n";
+ code2 += "}\n";
+ code2 += "ok(jsFuns.isAsmJSModule(f), 'f is an asm.js module')\n";
+ code2 += "if (assertCacheHit) ok(!jsFuns.isAsmJSModuleLoadedFromCache(f), 'cache disabled');\n";
+ code2 += "var gX = f();\n";
+ code2 += "ok(jsFuns.isAsmJSFunction(gX), 'gX is an asm.js function')\n";
+ code2 += "ok(gX() === " + i + ", 'gX returns the correct result')\n";
+ code2 += "finishedEvalAsync();\n";
+ codes.push(code2);
+ }
+
+ function evalAsync(code) {
+ var blob = new Blob([code], {type:"application/javascript"});
+ var script = document.createElement('script');
+ script.src = URL.createObjectURL(blob);
+ document.body.appendChild(script);
+ }
+
+ var finishedCount = 0;
+ function finishedEvalAsync() {
+ finishedCount++;
+
+ if (finishedCount < 1 || finishedCount > 2*N) {
+ throw "Huh?!";
+ } else if (finishedCount == N) {
+ assertCacheHit = true;
+ for (var i = 0; i < N; i++)
+ evalAsync(codes[i]);
+ } else if (finishedCount == 2*N) {
+ SimpleTest.finish();
+ }
+ }
+
+ function runTest() {
+ for (var i = 0; i < N; i++)
+ evalAsync(codes[i]);
+
+ SimpleTest.waitForExplicitFinish();
+ }
+
+ if (!jsFuns.isAsmJSCompilationAvailable()) {
+ ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
+ } else {
+ runTest();
+ }
+ </script>
+
+</body>
+</html>
+
diff --git a/dom/asmjscache/test/test_slow.html b/dom/asmjscache/test/test_slow.html
new file mode 100644
index 000000000..2f19041b3
--- /dev/null
+++ b/dom/asmjscache/test/test_slow.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=854209
+-->
+<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"></pre>
+
+ <script>
+ var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
+
+ var completed = 0;
+ function complete() {
+ if (++completed == 2)
+ SimpleTest.finish();
+ }
+
+ if (!jsFuns.isAsmJSCompilationAvailable()) {
+ ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
+ } else {
+ var script = document.createElement("script");
+ script.src = "http://mochi.test:8888/tests/dom/asmjscache/test/file_slow.js";
+ document.body.appendChild(script);
+
+ var w = new Worker('http://mochi.test:8888/tests/dom/asmjscache/test/file_slow.js');
+ w.onmessage = function(e) {
+ ok(e.data === "ok", "Worker asm.js tests");
+ complete();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ }
+ </script>
+
+ <script>
+ </script>
+
+</body>
+</html>
diff --git a/dom/asmjscache/test/test_workers.html b/dom/asmjscache/test/test_workers.html
new file mode 100644
index 000000000..992ed785b
--- /dev/null
+++ b/dom/asmjscache/test/test_workers.html
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=941830
+-->
+<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=941830">asm.js browser tests</a>
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test"></pre>
+
+ <script>
+ var jsFuns = SpecialPowers.Cu.getJSTestingFunctions();
+
+ function runTest() {
+ var asmjsCode = "function f() { 'use asm';";
+ for (var i = 0; i < 5000; i++)
+ asmjsCode += "function g" + i + "() { return " + i + "}";
+ asmjsCode += "return g42 }";
+ ok(asmjsCode.length > 100000, "code is long enough to definitely hit the cache");
+
+ var workerCode = asmjsCode;
+ workerCode += "if (f()() !== 42) postMessage('fail'); else postMessage('ok');";
+ workerCode = 'var code = "' + workerCode + '"; eval(code); eval(code)';
+ var workerBlob = new Blob([workerCode], {type:"application/javascript"});
+
+ var mainCode = asmjsCode;
+ mainCode += "ok(!jsFuns.isAsmJSModuleLoadedFromCache(f), 'f is not a cache hit')\n";
+ mainCode += "var g42 = f();\n";
+ mainCode += "ok(jsFuns.isAsmJSFunction(g42), 'g42 is an asm.js function');\n";
+ mainCode += "ok(g42() === 42, 'g42 returns the correct result');\n";
+ mainCode += "SimpleTest.finish();\n";
+ var mainBlob = new Blob([mainCode], {type:"application/javascript"});
+
+ var w = new Worker(URL.createObjectURL(workerBlob));
+
+ var received = 0;
+ w.onmessage = function(e) {
+ switch (received) {
+ case 0:
+ ok(e.data === "ok", "Received first message");
+ received = 1;
+ break;
+ case 1:
+ ok(e.data === "ok", "Received second message");
+ received = 2;
+
+ var script = document.createElement('script');
+ script.src = URL.createObjectURL(mainBlob);
+ document.body.appendChild(script);
+ break;
+ default:
+ throw "Huh?";
+ }
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ }
+
+ if (!jsFuns.isAsmJSCompilationAvailable()) {
+ ok(true, "isAsmJSCompilationAvailable is false, skipping this test!");
+ } else {
+ runTest();
+ }
+ </script>
+
+</body>
+</html>