Skip to content

Commit

Permalink
Add service worker support
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Feb 19, 2024
1 parent ec1aee0 commit 2d441f8
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 114 deletions.
1 change: 1 addition & 0 deletions docs/intro/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The following url parameters change how the harness runs:
- `debug=1` enables verbose debug logging from tests.
- `worker=dedicated` runs the tests on a dedicated worker instead of the main thread.
- `worker=shared` runs the tests on a shared worker instead of the main thread.
- `worker=service` runs the tests on a service worker instead of the main thread.
- `power_preference=low-power` runs most tests passing `powerPreference: low-power` to `requestAdapter`
- `power_preference=high-performance` runs most tests passing `powerPreference: high-performance` to `requestAdapter`

Expand Down
3 changes: 2 additions & 1 deletion src/common/runtime/helper/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function optionString(
* The possible options for the tests.
*/
export interface CTSOptions {
worker?: 'dedicated' | 'shared' | '';
worker?: 'dedicated' | 'shared' | 'service' | '';
debug: boolean;
compatibility: boolean;
forceFallbackAdapter: boolean;
Expand Down Expand Up @@ -68,6 +68,7 @@ export const kCTSOptionsInfo: OptionsInfos<CTSOptions> = {
{ value: '', description: 'no worker' },
{ value: 'dedicated', description: 'dedicated worker' },
{ value: 'shared', description: 'shared worker' },
{ value: 'service', description: 'service worker' },
],
},
debug: { description: 'show more info' },
Expand Down
2 changes: 1 addition & 1 deletion src/common/runtime/helper/test_worker-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function reportTestResults(this: MessagePort | Worker, ev: MessageEvent) {
}

self.onmessage = (ev: MessageEvent) => {
void reportTestResults.call(self, ev);
void reportTestResults.call(ev.source || self, ev);
};

self.onconnect = (event: MessageEvent) => {
Expand Down
49 changes: 49 additions & 0 deletions src/common/runtime/helper/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,52 @@ export class TestSharedWorker {
rec.injectResult(workerResult);
}
}

export class TestServiceWorker {
private readonly ctsOptions: CTSOptions;
private readonly resolvers = new Map<string, (result: LiveTestCaseResult) => void>();

constructor(ctsOptions?: CTSOptions) {
this.ctsOptions = { ...(ctsOptions || kDefaultCTSOptions), ...{ worker: 'service' } };
}

async run(
rec: TestCaseRecorder,
query: string,
expectations: TestQueryWithExpectation[] = []
): Promise<void> {
const [suite, name] = query.split(":", 2);
const fileName = name.split(',').join('/');
const serviceWorkerPath = `/out/${suite}/webworker/${fileName}.worker.js`;

const registration = await navigator.serviceWorker.register(serviceWorkerPath, {
type: 'module',
scope: '/',
});
await navigator.serviceWorker.ready;

navigator.serviceWorker.onmessage = ev => {
const query: string = ev.data.query;
const result: TransferredTestCaseResult = ev.data.result;
if (result.logs) {
for (const l of result.logs) {
Object.setPrototypeOf(l, LogMessageWithStack.prototype);
}
}
this.resolvers.get(query)!(result as LiveTestCaseResult);

// MAINTENANCE_TODO(kainino0x): update the Logger with this result (or don't have a logger and
// update the entire results JSON somehow at some point).
};

registration.active.postMessage({
query,
expectations,
ctsOptions: this.ctsOptions,
});
const serviceWorkerResult = await new Promise<LiveTestCaseResult>(resolve => {
this.resolvers.set(query, resolve);
});
rec.injectResult(serviceWorkerResult);
}
}
5 changes: 4 additions & 1 deletion src/common/runtime/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
OptionsInfos,
camelCaseToSnakeCase,
} from './helper/options.js';
import { TestDedicatedWorker, TestSharedWorker } from './helper/test_worker.js';
import { TestDedicatedWorker, TestSharedWorker, TestServiceWorker } from './helper/test_worker.js';

const rootQuerySpec = 'webgpu:*';
let promptBeforeReload = false;
Expand Down Expand Up @@ -66,6 +66,7 @@ setBaseResourcePath('../out/resources');
const dedicatedWorker =
options.worker === 'dedicated' ? new TestDedicatedWorker(options) : undefined;
const sharedWorker = options.worker === 'shared' ? new TestSharedWorker(options) : undefined;
const serviceWorker = options.worker === 'service' ? new TestServiceWorker(options) : undefined;

const autoCloseOnPass = document.getElementById('autoCloseOnPass') as HTMLInputElement;
const resultsVis = document.getElementById('resultsVis')!;
Expand Down Expand Up @@ -182,6 +183,8 @@ function makeCaseHTML(t: TestTreeLeaf): VisualizedSubtree {
await dedicatedWorker.run(rec, name);
} else if (sharedWorker) {
await sharedWorker.run(rec, name);
} else if (serviceWorker) {
await serviceWorker.run(rec, name);
} else {
await t.run(rec);
}
Expand Down
3 changes: 3 additions & 0 deletions src/common/runtime/wpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void (async () => {
const workerString = optionString('worker');
const dedicatedWorker = workerString === 'dedicated' ? new TestDedicatedWorker() : undefined;
const sharedWorker = workerString === 'shared' ? new TestSharedWorker() : undefined;
const serviceWorker = workerString === 'service' ? new TestServiceWorker() : undefined;

globalTestConfig.unrollConstEvalLoops = optionEnabled('unroll_const_eval_loops');

Expand Down Expand Up @@ -68,6 +69,8 @@ void (async () => {
await dedicatedWorker.run(rec, name, expectations);
} else if (sharedWorker) {
await sharedWorker.run(rec, name, expectations);
} else if (serviceWorker) {
await serviceWorker.run(rec, name, expectations);
} else {
await testcase.run(rec, expectations);
}
Expand Down
8 changes: 6 additions & 2 deletions src/common/tools/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ app.get('/out/**/*.js', async (req, res, next) => {
const tsUrl = jsUrl.replace(/\.js$/, '.ts');
if (compileCache.has(tsUrl)) {
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Service-Worker-Allowed', '/');
res.send(compileCache.get(tsUrl));
return;
}

let absPath = path.join(srcDir, tsUrl);
// FIXME: I'm not sure if this is the way I should handle it...
const dir = jsUrl.endsWith('worker.js') ? path.resolve(srcDir, '../out') : srcDir;
let absPath = path.join(dir, tsUrl);
if (!fs.existsSync(absPath)) {
// The .ts file doesn't exist. Try .js file in case this is a .js/.d.ts pair.
absPath = path.join(srcDir, jsUrl);
absPath = path.join(dir, jsUrl);
}

try {
Expand All @@ -166,6 +169,7 @@ app.get('/out/**/*.js', async (req, res, next) => {
compileCache.set(tsUrl, result.code);

res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Service-Worker-Allowed', '/');
res.send(result.code);
} else {
throw new Error(`Failed compile ${tsUrl}.`);
Expand Down
2 changes: 1 addition & 1 deletion src/common/tools/gen_listings_and_webworkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (argv.length < 4) {
usage(0);
}

const myself = 'src/common/tools/gen_listings.ts';
const myself = 'src/common/tools/gen_listings_and_webworkers.ts';

const outDir = argv[2];

Expand Down
214 changes: 107 additions & 107 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "f9c25825",
"webgpu/shader/execution/binary/af_logical.bin": "c3c5c046",
"webgpu/shader/execution/binary/af_division.bin": "8eec7360",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "92f5acd",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "cf1920bc",
"webgpu/shader/execution/binary/af_multiplication.bin": "c3ca2d36",
"webgpu/shader/execution/binary/af_remainder.bin": "ef236c3e",
"webgpu/shader/execution/binary/af_subtraction.bin": "823c3d19",
"webgpu/shader/execution/binary/f16_addition.bin": "72625726",
"webgpu/shader/execution/binary/f16_logical.bin": "d20f2684",
"webgpu/shader/execution/binary/f16_division.bin": "865fb316",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "2908c1e6",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "dbc6dd4a",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "fff001f3",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "f6557db8",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "7d0beef1",
"webgpu/shader/execution/binary/f16_multiplication.bin": "fe1eeb2f",
"webgpu/shader/execution/binary/f16_remainder.bin": "44c68db0",
"webgpu/shader/execution/binary/f16_subtraction.bin": "4d349e03",
"webgpu/shader/execution/binary/f32_addition.bin": "3d909f18",
"webgpu/shader/execution/binary/f32_logical.bin": "300cb917",
"webgpu/shader/execution/binary/f32_division.bin": "26126d0b",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "8e3b7347",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "eba8334f",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "5f633cc4",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "ee699077",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "6e8e9044",
"webgpu/shader/execution/binary/f32_multiplication.bin": "9e8aa842",
"webgpu/shader/execution/binary/f32_remainder.bin": "44997694",
"webgpu/shader/execution/binary/f32_subtraction.bin": "7da0351c",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "78991d8",
"webgpu/shader/execution/binary/i32_comparison.bin": "eeb5a624",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "e317f38",
"webgpu/shader/execution/binary/u32_comparison.bin": "3bd52719",
"webgpu/shader/execution/abs.bin": "58d33fc0",
"webgpu/shader/execution/acos.bin": "8ab770e1",
"webgpu/shader/execution/acosh.bin": "1b797a55",
"webgpu/shader/execution/asin.bin": "49c3e54",
"webgpu/shader/execution/asinh.bin": "ec965820",
"webgpu/shader/execution/atan.bin": "13292f0c",
"webgpu/shader/execution/atan2.bin": "943937cf",
"webgpu/shader/execution/atanh.bin": "113723aa",
"webgpu/shader/execution/bitcast.bin": "49055551",
"webgpu/shader/execution/ceil.bin": "fc4d440",
"webgpu/shader/execution/clamp.bin": "f0590b61",
"webgpu/shader/execution/cos.bin": "dc6a6d3c",
"webgpu/shader/execution/cosh.bin": "682a8b93",
"webgpu/shader/execution/cross.bin": "c2cf537f",
"webgpu/shader/execution/degrees.bin": "b9044d85",
"webgpu/shader/execution/determinant.bin": "c872e66b",
"webgpu/shader/execution/distance.bin": "8df8d8a7",
"webgpu/shader/execution/dot.bin": "84aacdd9",
"webgpu/shader/execution/exp.bin": "1e815ae0",
"webgpu/shader/execution/exp2.bin": "ee9fd571",
"webgpu/shader/execution/faceForward.bin": "e2b2e81c",
"webgpu/shader/execution/floor.bin": "9d437a66",
"webgpu/shader/execution/fma.bin": "352b140",
"webgpu/shader/execution/fract.bin": "95a1650d",
"webgpu/shader/execution/frexp.bin": "c9ed5769",
"webgpu/shader/execution/inverseSqrt.bin": "8a275a8d",
"webgpu/shader/execution/ldexp.bin": "cb51dbe1",
"webgpu/shader/execution/length.bin": "53468ea4",
"webgpu/shader/execution/log.bin": "33bef86d",
"webgpu/shader/execution/log2.bin": "42fc6f07",
"webgpu/shader/execution/max.bin": "33b63886",
"webgpu/shader/execution/min.bin": "f4e85c7",
"webgpu/shader/execution/mix.bin": "b7346332",
"webgpu/shader/execution/modf.bin": "b291939c",
"webgpu/shader/execution/normalize.bin": "8d42f4e4",
"webgpu/shader/execution/pack2x16float.bin": "32836353",
"webgpu/shader/execution/pow.bin": "5fd2851d",
"webgpu/shader/execution/quantizeToF16.bin": "7a1878ee",
"webgpu/shader/execution/radians.bin": "dbb58186",
"webgpu/shader/execution/reflect.bin": "9f1132c5",
"webgpu/shader/execution/refract.bin": "508a9b82",
"webgpu/shader/execution/round.bin": "47ccb377",
"webgpu/shader/execution/saturate.bin": "771426ff",
"webgpu/shader/execution/sign.bin": "6b04f125",
"webgpu/shader/execution/sin.bin": "8e2495ec",
"webgpu/shader/execution/sinh.bin": "77ab8cf1",
"webgpu/shader/execution/smoothstep.bin": "bdd40525",
"webgpu/shader/execution/sqrt.bin": "d6b16a43",
"webgpu/shader/execution/step.bin": "34fd45ba",
"webgpu/shader/execution/tan.bin": "7df2e6b4",
"webgpu/shader/execution/tanh.bin": "e303ee3c",
"webgpu/shader/execution/transpose.bin": "985b9dd0",
"webgpu/shader/execution/trunc.bin": "b244b3d9",
"webgpu/shader/execution/unpack2x16float.bin": "c1ebb8d5",
"webgpu/shader/execution/unpack2x16snorm.bin": "f7fd89e",
"webgpu/shader/execution/unpack2x16unorm.bin": "35e0330e",
"webgpu/shader/execution/unpack4x8snorm.bin": "3d4ca4cd",
"webgpu/shader/execution/unpack4x8unorm.bin": "985e1f9a",
"webgpu/shader/execution/unary/af_arithmetic.bin": "fab31dec",
"webgpu/shader/execution/unary/af_assignment.bin": "af1899",
"webgpu/shader/execution/unary/bool_conversion.bin": "c4e6e40c",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "db964478",
"webgpu/shader/execution/unary/f16_conversion.bin": "df65cc9a",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "bd022e24",
"webgpu/shader/execution/unary/f32_conversion.bin": "ff00ace3",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "239e3b46",
"webgpu/shader/execution/unary/i32_complement.bin": "81fe7e5b",
"webgpu/shader/execution/unary/i32_conversion.bin": "24deb50a",
"webgpu/shader/execution/unary/u32_complement.bin": "37ba2547",
"webgpu/shader/execution/unary/u32_conversion.bin": "f26f8c3a",
"webgpu/shader/execution/unary/ai_assignment.bin": "46ee1c6f",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "aa09a4bc",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "6e2d927f"
"webgpu/shader/execution/binary/af_addition.bin": "a68bee8",
"webgpu/shader/execution/binary/af_logical.bin": "d918e30f",
"webgpu/shader/execution/binary/af_division.bin": "96820a8b",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "4a2ba436",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "37b9fedf",
"webgpu/shader/execution/binary/af_multiplication.bin": "dc20148e",
"webgpu/shader/execution/binary/af_remainder.bin": "1ab411eb",
"webgpu/shader/execution/binary/af_subtraction.bin": "bf8d4630",
"webgpu/shader/execution/binary/f16_addition.bin": "b5109d4b",
"webgpu/shader/execution/binary/f16_logical.bin": "92496ae9",
"webgpu/shader/execution/binary/f16_division.bin": "5629279b",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "794c648c",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "d41a4181",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "518de262",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "a63f0d8d",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "35956816",
"webgpu/shader/execution/binary/f16_multiplication.bin": "ecd1c32",
"webgpu/shader/execution/binary/f16_remainder.bin": "37f5fe21",
"webgpu/shader/execution/binary/f16_subtraction.bin": "9c1872b4",
"webgpu/shader/execution/binary/f32_addition.bin": "4323d8d8",
"webgpu/shader/execution/binary/f32_logical.bin": "dcc4de",
"webgpu/shader/execution/binary/f32_division.bin": "623c8255",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "f9c5c1d9",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "9899b0ac",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "1cb7da66",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "5a058633",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a237a6da",
"webgpu/shader/execution/binary/f32_multiplication.bin": "cf585b2a",
"webgpu/shader/execution/binary/f32_remainder.bin": "2f77b197",
"webgpu/shader/execution/binary/f32_subtraction.bin": "af5fe1a1",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "f27c0e44",
"webgpu/shader/execution/binary/i32_comparison.bin": "45e085c3",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "3999a23c",
"webgpu/shader/execution/binary/u32_comparison.bin": "8eb1e985",
"webgpu/shader/execution/abs.bin": "260ef05",
"webgpu/shader/execution/acos.bin": "84a62150",
"webgpu/shader/execution/acosh.bin": "672f6ae9",
"webgpu/shader/execution/asin.bin": "41895e51",
"webgpu/shader/execution/asinh.bin": "929dbdba",
"webgpu/shader/execution/atan.bin": "6eaf3edb",
"webgpu/shader/execution/atan2.bin": "b6a67a0",
"webgpu/shader/execution/atanh.bin": "9c3a89c3",
"webgpu/shader/execution/bitcast.bin": "c3f828d5",
"webgpu/shader/execution/ceil.bin": "3f9492f0",
"webgpu/shader/execution/clamp.bin": "e06eb0a2",
"webgpu/shader/execution/cos.bin": "434a43b0",
"webgpu/shader/execution/cosh.bin": "191be956",
"webgpu/shader/execution/cross.bin": "8a86fc0a",
"webgpu/shader/execution/degrees.bin": "69535ca4",
"webgpu/shader/execution/determinant.bin": "965baaf4",
"webgpu/shader/execution/distance.bin": "62b166b7",
"webgpu/shader/execution/dot.bin": "3d00bec2",
"webgpu/shader/execution/exp.bin": "c01fd77b",
"webgpu/shader/execution/exp2.bin": "7e5c74fb",
"webgpu/shader/execution/faceForward.bin": "625543a3",
"webgpu/shader/execution/floor.bin": "a285aa9d",
"webgpu/shader/execution/fma.bin": "b775f80f",
"webgpu/shader/execution/fract.bin": "f4ebd38",
"webgpu/shader/execution/frexp.bin": "fb7ba097",
"webgpu/shader/execution/inverseSqrt.bin": "8518a775",
"webgpu/shader/execution/ldexp.bin": "6003926c",
"webgpu/shader/execution/length.bin": "4f13ad76",
"webgpu/shader/execution/log.bin": "fa312745",
"webgpu/shader/execution/log2.bin": "fbed9711",
"webgpu/shader/execution/max.bin": "df03adbe",
"webgpu/shader/execution/min.bin": "ff1d84e2",
"webgpu/shader/execution/mix.bin": "e0c143b9",
"webgpu/shader/execution/modf.bin": "db4210ed",
"webgpu/shader/execution/normalize.bin": "d6296dfb",
"webgpu/shader/execution/pack2x16float.bin": "b6cce15",
"webgpu/shader/execution/pow.bin": "aa9dc70e",
"webgpu/shader/execution/quantizeToF16.bin": "1c9a930b",
"webgpu/shader/execution/radians.bin": "ae212178",
"webgpu/shader/execution/reflect.bin": "eb51657c",
"webgpu/shader/execution/refract.bin": "84c404d0",
"webgpu/shader/execution/round.bin": "d111c3c2",
"webgpu/shader/execution/saturate.bin": "6b709a46",
"webgpu/shader/execution/sign.bin": "3a2d4dd4",
"webgpu/shader/execution/sin.bin": "d46868f3",
"webgpu/shader/execution/sinh.bin": "76d7aa3a",
"webgpu/shader/execution/smoothstep.bin": "6c73de07",
"webgpu/shader/execution/sqrt.bin": "506a2093",
"webgpu/shader/execution/step.bin": "d26a70cc",
"webgpu/shader/execution/tan.bin": "f514bc1b",
"webgpu/shader/execution/tanh.bin": "60e1f252",
"webgpu/shader/execution/transpose.bin": "1b1108df",
"webgpu/shader/execution/trunc.bin": "11e27602",
"webgpu/shader/execution/unpack2x16float.bin": "3067a7f5",
"webgpu/shader/execution/unpack2x16snorm.bin": "61529420",
"webgpu/shader/execution/unpack2x16unorm.bin": "46d97621",
"webgpu/shader/execution/unpack4x8snorm.bin": "1ae2ce6f",
"webgpu/shader/execution/unpack4x8unorm.bin": "2a432aee",
"webgpu/shader/execution/unary/af_arithmetic.bin": "be9a86c6",
"webgpu/shader/execution/unary/af_assignment.bin": "63972495",
"webgpu/shader/execution/unary/bool_conversion.bin": "6c043c34",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "bd55368e",
"webgpu/shader/execution/unary/f16_conversion.bin": "b8215ee0",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "2a6165d4",
"webgpu/shader/execution/unary/f32_conversion.bin": "2201f531",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "eef7d8ac",
"webgpu/shader/execution/unary/i32_complement.bin": "b869f894",
"webgpu/shader/execution/unary/i32_conversion.bin": "58467190",
"webgpu/shader/execution/unary/u32_complement.bin": "186152ce",
"webgpu/shader/execution/unary/u32_conversion.bin": "54053cfd",
"webgpu/shader/execution/unary/ai_assignment.bin": "576dd458",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "f33f5692",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "44bdb6ae"
}
Loading

0 comments on commit 2d441f8

Please sign in to comment.