Commit 4d017547 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[web_tests] Rework Wasm code cache test and re-enable it

- Reworks tests to use PerformanceTestRunner to run code with timeline.
- Performs tests in iframe, and uses postMessage to coordinate.

Bug: chromium:1018029
Change-Id: Ie315516ddd90abe7538b485fd395d993a7a3e980
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1924712
Commit-Queue: Bill Budge <bbudge@chromium.org>
Reviewed-by: default avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719312}
parent b24d56b5
...@@ -5802,9 +5802,6 @@ external/wpt/trusted-types/eval-csp-no-tt.tentative.html [ Failure ] ...@@ -5802,9 +5802,6 @@ external/wpt/trusted-types/eval-csp-no-tt.tentative.html [ Failure ]
external/wpt/trusted-types/eval-no-csp-no-tt.tentative.html [ Failure ] external/wpt/trusted-types/eval-no-csp-no-tt.tentative.html [ Failure ]
external/wpt/trusted-types/eval-no-csp-no-tt-default-policy.tentative.html [ Failure ] external/wpt/trusted-types/eval-no-csp-no-tt-default-policy.tentative.html [ Failure ]
# Temporarily disabled to change the API contract in V8
crbug.com/1018029 virtual/wasm-site-isolated-code-cache/http/tests/devtools/wasm-isolated-code-cache/wasm-cache-test.js [ Pass Failure ]
# First frame not always painted in time # First frame not always painted in time
crbug.com/1024976 media/controls/paint-controls-webkit-appearance-none.html [ Pass Failure ] crbug.com/1024976 media/controls/paint-controls-webkit-appearance-none.html [ Pass Failure ]
crbug.com/1024976 media/controls/paint-controls-webkit-appearance-none-custom-bg.html [ Pass Failure ] crbug.com/1024976 media/controls/paint-controls-webkit-appearance-none-custom-bg.html [ Pass Failure ]
......
Tests V8 code cache for WebAssembly resources. Tests V8 code cache for WebAssembly resources.
---First navigation - produce and consume code cache ------ WebAssembly trace events may be generated on multiple background threads, so
the test sorts them by URL and type to make the output deterministic. We fetch
2 small and 2 large .wasm resources, from 2 different origins. From these
8 fetches, we expect:
v8.wasm.cachedModule: 2 .wasm modules are cached
v8.wasm.streamFromResponseCallback: 8 .wasm resources are fetched
v8.wasm.compiledModule: 2 for large.wasm, 4 for small.wasm
v8.wasm.moduleCacheHit: 2 for large.wasm
v8.wasm.streamFromResponseCallback Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
...@@ -26,25 +34,6 @@ v8.wasm.streamFromResponseCallback Properties: ...@@ -26,25 +34,6 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.streamFromResponseCallback Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.streamFromResponseCallback Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
--- Second navigation - from a different origin ------
v8.wasm.streamFromResponseCallback Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
......
...@@ -12,84 +12,77 @@ ...@@ -12,84 +12,77 @@
SDK.multitargetNetworkManager.clearBrowserCache(); SDK.multitargetNetworkManager.clearBrowserCache();
async function runTests() { async function runTests() {
// Loads a WASM module that is smaller than the threshold. It should compile // Asynchronous function to initiate tests in an iframe, and wait until
// but not be cached. // compilation has finished.
function loadSmallWasmModule(iframe_window) { const loadFrame = (url) => new Promise((resolve) => {
const url = 'http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors' function receiveMessage(e) {
return iframe_window.instantiateModule(url); if (e.data == 'done') {
} resolve(e);
// Loads a WASM module that is larger than the caching threshold. It should window.removeEventListener('message', receiveMessage);
// compile and be cached. }
function loadLargeWasmModule(iframe_window) { }
const url = 'http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors' window.addEventListener('message', receiveMessage);
return iframe_window.instantiateModule(url); const iframe = document.createElement('iframe');
} iframe.src = url;
// Load the same large WASM module with a different URL. It should miss document.body.appendChild(iframe);
// the cache, compile and be cached. });
function loadOtherLargeWasmModule(iframe_window) {
const url = 'http://localhost:8000/wasm/resources/load-wasm.php?name=large.wasm&cors' // Test same-origin.
return iframe_window.instantiateModule(url); await loadFrame('http://127.0.0.1:8000/wasm/resources/wasm-cache-iframe.html');
} // Ensure another origin must recompile everything.
await loadFrame('http://localhost:8000/wasm/resources/wasm-cache-iframe.html');
let script = document.createElement('script'); let script = document.createElement('script');
script.type = 'module'; script.type = 'module';
script.text = 'window.finishTest()'; script.text = 'window.finishTest()';
document.body.appendChild(script); document.body.appendChild(script);
return new Promise(resolve => window.finishTest = resolve);
const frameId = 'frame_id';
const iframe_window = document.getElementById(frameId).contentWindow;
await loadSmallWasmModule(iframe_window);
await loadLargeWasmModule(iframe_window);
// Second loads. The small module should compile again and not be cached.
await loadSmallWasmModule(iframe_window);
// The large module should hit the cache.
await loadLargeWasmModule(iframe_window);
// Loading the large module from a different URL should miss the cache,
// compile, and be cached.
await loadOtherLargeWasmModule(iframe_window);
} }
await TestRunner.evaluateInPagePromise(runTests.toString()); await TestRunner.evaluateInPagePromise(runTests.toString());
TestRunner.addResult( TestRunner.addResult(
'---First navigation - produce and consume code cache ------\n');
// Create a same origin iframe.
const scope = 'http://127.0.0.1:8000/wasm/resources/wasm-cache-iframe.html';
await TestRunner.addIframe(scope, {id: 'frame_id'});
await PerformanceTestRunner.startTimeline();
await TestRunner.callFunctionInPageAsync('runTests');
await PerformanceTestRunner.stopTimeline();
const events = new Set([ `WebAssembly trace events may be generated on multiple background threads, so
TimelineModel.TimelineModel.RecordType.WasmStreamFromResponseCallback, the test sorts them by URL and type to make the output deterministic. We fetch
TimelineModel.TimelineModel.RecordType.WasmCompiledModule, 2 small and 2 large .wasm resources, from 2 different origins. From these
TimelineModel.TimelineModel.RecordType.WasmCachedModule, 8 fetches, we expect:
TimelineModel.TimelineModel.RecordType.WasmModuleCacheHit,
TimelineModel.TimelineModel.RecordType.WasmModuleCacheInvalid]); v8.wasm.cachedModule: 2 .wasm modules are cached
const tracingModel = PerformanceTestRunner.tracingModel(); v8.wasm.streamFromResponseCallback: 8 .wasm resources are fetched
v8.wasm.compiledModule: 2 for large.wasm, 4 for small.wasm
tracingModel.sortedProcesses().forEach(p => p.sortedThreads().forEach(t => v8.wasm.moduleCacheHit: 2 for large.wasm
t.events().filter(event => events.has(event.name)).forEach(PerformanceTestRunner.printTraceEventProperties))); `
);
// Second navigation
TestRunner.addResult( await PerformanceTestRunner.invokeWithTracing('runTests', processEvents);
'\n--- Second navigation - from a different origin ------\n');
await PerformanceTestRunner.startTimeline(); function processEvents() {
// Since some WebAssembly compile events may be reported on different
// Create a cross origin iframe. // threads, sort events by URL and type, to get a deterministic test.
const other_scope = 'http://localhost:8000/wasm/resources/wasm-cache-iframe.html'; function compareEvents(a, b) {
await TestRunner.addIframe(other_scope, {id: 'frame_id'}); let url_a = a.args['url'] || '';
let url_b = b.args['url'] || '';
await TestRunner.callFunctionInPageAsync('runTests'); if (url_a != url_b)
await PerformanceTestRunner.stopTimeline(); return url_a.compareTo(url_b);
return a.name.compareTo(b.name);
tracingModel.sortedProcesses().forEach(p => p.sortedThreads().forEach(t => }
t.events().filter(event => events.has(event.name)).forEach(PerformanceTestRunner.printTraceEventProperties)));
TestRunner.completeTest(); const event_types = new Set([
TimelineModel.TimelineModel.RecordType.WasmStreamFromResponseCallback,
TimelineModel.TimelineModel.RecordType.WasmCompiledModule,
TimelineModel.TimelineModel.RecordType.WasmCachedModule,
TimelineModel.TimelineModel.RecordType.WasmModuleCacheHit,
TimelineModel.TimelineModel.RecordType.WasmModuleCacheInvalid]);
const tracingModel = PerformanceTestRunner.tracingModel();
let events = new Array();
PerformanceTestRunner.tracingModel().sortedProcesses().forEach(
p => p.sortedThreads().forEach(
t => events = events.concat(t.events().filter(event => event_types.has(event.name)))));
events.sort(compareEvents);
events.forEach(PerformanceTestRunner.printTraceEventProperties);
TestRunner.completeTest();
}
})(); })();
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script> <script>
// Instantiate a WASM test module and make sure it works. // Instantiate a WASM module and make sure it works.
function instantiateModule(url) async function instantiateModule(url)
{ {
return WebAssembly.instantiateStreaming(fetch(url)).then( await WebAssembly.instantiateStreaming(fetch(url)).then(
({module, instance}) => assert_equals(instance.exports.exported_func(), 42)); ({module, instance}) => assert_equals(instance.exports.exported_func(), 42));
} }
const url_base = 'http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=';
(async function runTests() {
await instantiateModule(url_base + 'small.wasm&cors');
await instantiateModule(url_base + 'small.wasm&cors');
await instantiateModule(url_base + 'large.wasm&cors');
await instantiateModule(url_base + 'large.wasm&cors');
window.top.postMessage('done', '*');
})();
</script> </script>
Tests V8 code cache for WebAssembly resources. Tests V8 code cache for WebAssembly resources.
---First navigation - produce and consume code cache ------ WebAssembly trace events may be generated on multiple background threads, so
the test sorts them by URL and type to make the output deterministic. We fetch
2 small and 2 large .wasm resources, from 2 different origins. From these
8 fetches, we expect:
v8.wasm.streamFromResponseCallback Properties: v8.wasm.cachedModule: 2 .wasm modules are cached
{ v8.wasm.streamFromResponseCallback: 8 .wasm resources are fetched
data : { v8.wasm.compiledModule: 2 for large.wasm, 4 for small.wasm
} v8.wasm.moduleCacheHit: 2 for large.wasm
endTime : <number>
startTime : <number> v8.wasm.cachedModule Properties:
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties:
{
data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
}
endTime : <number>
startTime : <number>
type : "v8.wasm.compiledModule"
}
v8.wasm.streamFromResponseCallback Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties:
{ {
data : { data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors producedCacheSize : <number>
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.cachedModule"
} }
v8.wasm.cachedModule Properties: v8.wasm.cachedModule Properties:
{ {
...@@ -53,14 +36,13 @@ v8.wasm.streamFromResponseCallback Properties: ...@@ -53,14 +36,13 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.compiledModule Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.streamFromResponseCallback Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
...@@ -70,15 +52,13 @@ v8.wasm.streamFromResponseCallback Properties: ...@@ -70,15 +52,13 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.moduleCacheHit Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
consumedCacheSize : <number>
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.moduleCacheHit" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.streamFromResponseCallback Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
...@@ -88,27 +68,22 @@ v8.wasm.streamFromResponseCallback Properties: ...@@ -88,27 +68,22 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.compiledModule Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
url : http://localhost:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.streamFromResponseCallback"
} }
v8.wasm.cachedModule Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
producedCacheSize : <number>
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.cachedModule" type : "v8.wasm.streamFromResponseCallback"
} }
--- Second navigation - from a different origin ------
v8.wasm.streamFromResponseCallback Properties: v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
...@@ -120,20 +95,12 @@ v8.wasm.streamFromResponseCallback Properties: ...@@ -120,20 +95,12 @@ v8.wasm.streamFromResponseCallback Properties:
v8.wasm.compiledModule Properties: v8.wasm.compiledModule Properties:
{ {
data : { data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.compiledModule"
} }
v8.wasm.streamFromResponseCallback Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties: v8.wasm.compiledModule Properties:
{ {
data : { data : {
...@@ -143,22 +110,25 @@ v8.wasm.compiledModule Properties: ...@@ -143,22 +110,25 @@ v8.wasm.compiledModule Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.compiledModule"
} }
v8.wasm.cachedModule Properties: v8.wasm.moduleCacheHit Properties:
{ {
data : { data : {
producedCacheSize : <number> consumedCacheSize : <number>
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.cachedModule" type : "v8.wasm.moduleCacheHit"
} }
v8.wasm.streamFromResponseCallback Properties: v8.wasm.moduleCacheHit Properties:
{ {
data : { data : {
consumedCacheSize : <number>
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.moduleCacheHit"
} }
v8.wasm.compiledModule Properties: v8.wasm.compiledModule Properties:
{ {
...@@ -169,48 +139,31 @@ v8.wasm.compiledModule Properties: ...@@ -169,48 +139,31 @@ v8.wasm.compiledModule Properties:
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.compiledModule"
} }
v8.wasm.streamFromResponseCallback Properties: v8.wasm.compiledModule Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.moduleCacheHit Properties:
{
data : {
consumedCacheSize : <number>
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
}
endTime : <number>
startTime : <number>
type : "v8.wasm.moduleCacheHit"
}
v8.wasm.streamFromResponseCallback Properties:
{ {
data : { data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.streamFromResponseCallback" type : "v8.wasm.compiledModule"
} }
v8.wasm.compiledModule Properties: v8.wasm.compiledModule Properties:
{ {
data : { data : {
url : http://localhost:8000/wasm/resources/load-wasm.php?name=large.wasm&cors url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.compiledModule" type : "v8.wasm.compiledModule"
} }
v8.wasm.cachedModule Properties: v8.wasm.compiledModule Properties:
{ {
data : { data : {
producedCacheSize : <number> url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
} }
endTime : <number> endTime : <number>
startTime : <number> startTime : <number>
type : "v8.wasm.cachedModule" type : "v8.wasm.compiledModule"
} }
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