Switch to message protocol

Switches the WebGPU CTS test runner JavaScript code to use the defined
message protocol instead of the ad-hoc solution we were using before.

Bug: chromium:1340602
Change-Id: Ieaf26b5b2409f69d7859d3db4ce7757780de6712
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98684
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Brian Sheedy <bsheedy@google.com>
This commit is contained in:
Brian Sheedy 2022-08-11 14:39:51 +00:00 committed by Dawn LUCI CQ
parent 6af4c8b97d
commit 0653501212
1 changed files with 51 additions and 29 deletions

View File

@ -55,6 +55,7 @@ async function runCtsTest(query, use_worker) {
const name = testcase.query.toString(); const name = testcase.query.toString();
const wpt_fn = async () => { const wpt_fn = async () => {
sendMessageTestStarted();
const [rec, res] = log.record(name); const [rec, res] = log.record(name);
if (worker) { if (worker) {
await worker.run(rec, name, expectations); await worker.run(rec, name, expectations);
@ -62,41 +63,62 @@ async function runCtsTest(query, use_worker) {
await testcase.run(rec, expectations); await testcase.run(rec, expectations);
} }
sendMessageTestStatus(res.status, res.timems);
let fullLogs = (res.logs ?? []).map(prettyPrintLog); let fullLogs = (res.logs ?? []).map(prettyPrintLog);
fullLogs = fullLogs.join('\n\n\n'); fullLogs = fullLogs.join('\n\n\n');
let logPieces = [fullLogs] let logPieces = splitLogsForPayload(fullLogs);
// Split the log pieces until they all are guaranteed to fit into a sendMessageTestLog(logPieces);
// websocket payload. sendMessageTestFinished();
while (true) {
let tempLogPieces = []
for (const piece of logPieces) {
if (byteSize(piece) > LOGS_MAX_BYTES) {
let midpoint = Math.floor(piece.length / 2);
tempLogPieces.push(piece.substring(0, midpoint));
tempLogPieces.push(piece.substring(midpoint));
} else {
tempLogPieces.push(piece)
}
}
// Didn't make any changes - all pieces are under the size limit.
if (logPieces.every((value, index) => value == tempLogPieces[index])) {
break;
}
logPieces = tempLogPieces;
}
logPieces.forEach((piece, index, arr) => {
let isFinal = index == arr.length - 1;
socket.send(JSON.stringify({'s': res.status,
'l': piece,
'final': isFinal,
'js_duration_ms': res.timems,
'type': 'TEST_FINISHED'}));
});
}; };
await wpt_fn(); await wpt_fn();
} }
} }
function splitLogsForPayload(fullLogs) {
let logPieces = [fullLogs]
// Split the log pieces until they all are guaranteed to fit into a
// websocket payload.
while (true) {
let tempLogPieces = []
for (const piece of logPieces) {
if (byteSize(piece) > LOGS_MAX_BYTES) {
let midpoint = Math.floor(piece.length / 2);
tempLogPieces.push(piece.substring(0, midpoint));
tempLogPieces.push(piece.substring(midpoint));
} else {
tempLogPieces.push(piece)
}
}
// Didn't make any changes - all pieces are under the size limit.
if (logPieces.every((value, index) => value == tempLogPieces[index])) {
break;
}
logPieces = tempLogPieces;
}
return logPieces
}
function sendMessageTestStarted() {
socket.send(JSON.stringify({'type': 'TEST_STARTED'}));
}
function sendMessageTestStatus(status, jsDurationMs) {
socket.send(JSON.stringify({'type': 'TEST_STATUS',
'status': status,
'js_duration_ms': jsDurationMs}));
}
function sendMessageTestLog(logPieces) {
logPieces.forEach((piece) => {
socket.send(JSON.stringify({'type': 'TEST_LOG',
'log': piece}));
});
}
function sendMessageTestFinished() {
socket.send(JSON.stringify({'type': 'TEST_FINISHED'}));
}
window.runCtsTest = runCtsTest; window.runCtsTest = runCtsTest;
window.setupWebsocket = setupWebsocket window.setupWebsocket = setupWebsocket