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 ]
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 ]
# 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
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 ]
......
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:
{
......@@ -26,25 +34,6 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number>
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:
{
data : {
......
......@@ -12,84 +12,77 @@
SDK.multitargetNetworkManager.clearBrowserCache();
async function runTests() {
// Loads a WASM module that is smaller than the threshold. It should compile
// but not be cached.
function loadSmallWasmModule(iframe_window) {
const url = 'http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors'
return iframe_window.instantiateModule(url);
}
// Loads a WASM module that is larger than the caching threshold. It should
// 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'
return iframe_window.instantiateModule(url);
}
// Load the same large WASM module with a different URL. It should miss
// the cache, compile and be cached.
function loadOtherLargeWasmModule(iframe_window) {
const url = 'http://localhost:8000/wasm/resources/load-wasm.php?name=large.wasm&cors'
return iframe_window.instantiateModule(url);
}
// Asynchronous function to initiate tests in an iframe, and wait until
// compilation has finished.
const loadFrame = (url) => new Promise((resolve) => {
function receiveMessage(e) {
if (e.data == 'done') {
resolve(e);
window.removeEventListener('message', receiveMessage);
}
}
window.addEventListener('message', receiveMessage);
const iframe = document.createElement('iframe');
iframe.src = url;
document.body.appendChild(iframe);
});
// Test same-origin.
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');
script.type = 'module';
script.text = 'window.finishTest()';
document.body.appendChild(script);
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);
return new Promise(resolve => window.finishTest = resolve);
}
await TestRunner.evaluateInPagePromise(runTests.toString());
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([
TimelineModel.TimelineModel.RecordType.WasmStreamFromResponseCallback,
TimelineModel.TimelineModel.RecordType.WasmCompiledModule,
TimelineModel.TimelineModel.RecordType.WasmCachedModule,
TimelineModel.TimelineModel.RecordType.WasmModuleCacheHit,
TimelineModel.TimelineModel.RecordType.WasmModuleCacheInvalid]);
const tracingModel = PerformanceTestRunner.tracingModel();
tracingModel.sortedProcesses().forEach(p => p.sortedThreads().forEach(t =>
t.events().filter(event => events.has(event.name)).forEach(PerformanceTestRunner.printTraceEventProperties)));
// Second navigation
TestRunner.addResult(
'\n--- Second navigation - from a different origin ------\n');
await PerformanceTestRunner.startTimeline();
// Create a cross origin iframe.
const other_scope = 'http://localhost:8000/wasm/resources/wasm-cache-iframe.html';
await TestRunner.addIframe(other_scope, {id: 'frame_id'});
await TestRunner.callFunctionInPageAsync('runTests');
await PerformanceTestRunner.stopTimeline();
tracingModel.sortedProcesses().forEach(p => p.sortedThreads().forEach(t =>
t.events().filter(event => events.has(event.name)).forEach(PerformanceTestRunner.printTraceEventProperties)));
`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
`
);
await PerformanceTestRunner.invokeWithTracing('runTests', processEvents);
function processEvents() {
// Since some WebAssembly compile events may be reported on different
// threads, sort events by URL and type, to get a deterministic test.
function compareEvents(a, b) {
let url_a = a.args['url'] || '';
let url_b = b.args['url'] || '';
if (url_a != url_b)
return url_a.compareTo(url_b);
return a.name.compareTo(b.name);
}
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>
// Instantiate a WASM test module and make sure it works.
function instantiateModule(url)
// Instantiate a WASM module and make sure it works.
async function instantiateModule(url)
{
return WebAssembly.instantiateStreaming(fetch(url)).then(
({module, instance}) => assert_equals(instance.exports.exported_func(), 42));
await WebAssembly.instantiateStreaming(fetch(url)).then(
({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>
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:
{
data : {
}
endTime : <number>
startTime : <number>
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:
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.cachedModule Properties:
{
data : {
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
producedCacheSize : <number>
}
endTime : <number>
startTime : <number>
type : "v8.wasm.compiledModule"
type : "v8.wasm.cachedModule"
}
v8.wasm.cachedModule Properties:
{
......@@ -53,14 +36,13 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties:
v8.wasm.streamFromResponseCallback 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"
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.streamFromResponseCallback Properties:
{
......@@ -70,15 +52,13 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.moduleCacheHit Properties:
v8.wasm.streamFromResponseCallback 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"
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.streamFromResponseCallback Properties:
{
......@@ -88,27 +68,22 @@ v8.wasm.streamFromResponseCallback Properties:
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties:
v8.wasm.streamFromResponseCallback Properties:
{
data : {
url : http://localhost:8000/wasm/resources/load-wasm.php?name=large.wasm&cors
}
endTime : <number>
startTime : <number>
type : "v8.wasm.compiledModule"
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.cachedModule Properties:
v8.wasm.streamFromResponseCallback Properties:
{
data : {
producedCacheSize : <number>
}
endTime : <number>
startTime : <number>
type : "v8.wasm.cachedModule"
type : "v8.wasm.streamFromResponseCallback"
}
--- Second navigation - from a different origin ------
v8.wasm.streamFromResponseCallback Properties:
{
data : {
......@@ -120,20 +95,12 @@ v8.wasm.streamFromResponseCallback Properties:
v8.wasm.compiledModule Properties:
{
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>
startTime : <number>
type : "v8.wasm.compiledModule"
}
v8.wasm.streamFromResponseCallback Properties:
{
data : {
}
endTime : <number>
startTime : <number>
type : "v8.wasm.streamFromResponseCallback"
}
v8.wasm.compiledModule Properties:
{
data : {
......@@ -143,22 +110,25 @@ v8.wasm.compiledModule Properties:
startTime : <number>
type : "v8.wasm.compiledModule"
}
v8.wasm.cachedModule Properties:
v8.wasm.moduleCacheHit Properties:
{
data : {
producedCacheSize : <number>
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.cachedModule"
type : "v8.wasm.moduleCacheHit"
}
v8.wasm.streamFromResponseCallback Properties:
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.streamFromResponseCallback"
type : "v8.wasm.moduleCacheHit"
}
v8.wasm.compiledModule Properties:
{
......@@ -169,48 +139,31 @@ v8.wasm.compiledModule Properties:
startTime : <number>
type : "v8.wasm.compiledModule"
}
v8.wasm.streamFromResponseCallback 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:
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.streamFromResponseCallback"
type : "v8.wasm.compiledModule"
}
v8.wasm.compiledModule Properties:
{
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>
startTime : <number>
type : "v8.wasm.compiledModule"
}
v8.wasm.cachedModule Properties:
v8.wasm.compiledModule Properties:
{
data : {
producedCacheSize : <number>
url : http://127.0.0.1:8000/wasm/resources/load-wasm.php?name=small.wasm&cors
}
endTime : <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