| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| </head> |
| <body> |
| <script> |
| function getOrCreate(id, tagName) |
| { |
| var element = document.getElementById(id); |
| if (element) |
| return element; |
| |
| element = document.createElement(tagName); |
| element.id = id; |
| var parent = document.body || document.documentElement; |
| var refNode = parent.firstChild; |
| |
| parent.insertBefore(element, refNode); |
| return element; |
| } |
| |
| function debug(msg) |
| { |
| var span = document.createElement("span"); |
| getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace |
| span.innerHTML = msg + '<br />'; |
| } |
| |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| } |
| |
| var verbose = false; |
| var measureTime = false; |
| |
| var sab = new SharedArrayBuffer(32); |
| |
| var workPerCriticalSection = 1; |
| var workBetweenCriticalSections = 0; |
| |
| var memory = new Int32Array(sab); |
| var doubleMemory = new Float64Array(sab); |
| memory[1] = workPerCriticalSection; |
| memory[2] = workBetweenCriticalSections; |
| |
| var numWorkers = 0; |
| function startWorker(file) |
| { |
| if (verbose) |
| debug("Starting worker: " + file); |
| numWorkers++; |
| var worker = new Worker(file); |
| worker.onmessage = function(event) { |
| if (event.data == "done") { |
| if (verbose) |
| debug("Finished worker: " + file); |
| if (--numWorkers) |
| return; |
| debug("All workers done!"); |
| done(); |
| return; |
| } |
| if (event.data.indexOf("Error") == 0) { |
| debug("Test failed: "+ event.data); |
| if (window.testRunner) |
| testRunner.notifyDone(); |
| } |
| |
| if (verbose) |
| debug("Event from " + file + ": " + event.data); |
| }; |
| worker.postMessage(memory); |
| } |
| |
| var count = 10000000; |
| var numThreads = 4; |
| |
| function done() |
| { |
| if (memory[0] != 0) |
| throw "Error: bad value at memory[0]: " + memory[0]; |
| if (doubleMemory[2] != count * numThreads) |
| throw "Error: bad value at doubleMemory[1]: " + doubleMemory[1]; |
| if (measureTime) |
| debug("Speed: " + count / (Date.now() - before) + " KHz."); |
| debug("Test passed!"); |
| |
| if (window.testRunner) |
| testRunner.notifyDone(); |
| } |
| |
| var before = Date.now(); |
| for (var i = 0; i < numThreads; ++i) { |
| debug("Starting worker!"); |
| startWorker("cascade_lock-worker.js"); |
| } |
| |
| </script> |
| </body> |
| </html> |