Skip to content

Commit

Permalink
Merge branch 'main' into type-texture
Browse files Browse the repository at this point in the history
  • Loading branch information
shrekshao authored Mar 13, 2024
2 parents 12b6a91 + 3b0f7f1 commit 0aff4ca
Show file tree
Hide file tree
Showing 250 changed files with 5,017 additions and 2,810 deletions.
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = function (grunt) {
cmd: 'node',
args: ['tools/gen_version'],
},
'generate-listings': {
'generate-listings-and-webworkers': {
cmd: 'node',
args: ['tools/gen_listings', 'gen/', ...kAllSuites.map(s => 'src/' + s)],
args: ['tools/gen_listings_and_webworkers', 'gen/', ...kAllSuites.map(s => 'src/' + s)],
},
validate: {
cmd: 'node',
Expand Down Expand Up @@ -159,14 +159,14 @@ module.exports = function (grunt) {
// Must run after generate-common and run:build-out.
files: [
{ expand: true, dest: 'out/', cwd: 'gen', src: 'common/internal/version.js' },
{ expand: true, dest: 'out/', cwd: 'gen', src: '*/listing.js' },
{ expand: true, dest: 'out/', cwd: 'gen', src: '*/**/*.js' },
],
},
'gen-to-out-wpt': {
// Must run after generate-common and run:build-out-wpt.
files: [
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'common/internal/version.js' },
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'webgpu/listing.js' },
{ expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'webgpu/**/*.js' },
],
},
'htmlfiles-to-out': {
Expand Down Expand Up @@ -243,7 +243,7 @@ module.exports = function (grunt) {

grunt.registerTask('generate-common', 'Generate files into gen/ and src/', [
'run:generate-version',
'run:generate-listings',
'run:generate-listings-and-webworkers',
'run:generate-cache',
]);
grunt.registerTask('build-standalone', 'Build out/ (no checks; run after generate-common)', [
Expand Down
3 changes: 2 additions & 1 deletion docs/intro/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ The following url parameters change how the harness runs:

- `runnow=1` runs all matching tests on page load.
- `debug=1` enables verbose debug logging from tests.
- `worker=dedicated` runs the tests on a dedicated worker instead of the main thread.
- `worker=dedicated` (or `worker` or `worker=1`) 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
2 changes: 1 addition & 1 deletion docs/terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Each Suite has one Listing File (`suite/listing.[tj]s`), containing a list of th
in the suite.

In `src/suite/listing.ts`, this is computed dynamically.
In `out/suite/listing.js`, the listing has been pre-baked (by `tools/gen_listings`).
In `out/suite/listing.js`, the listing has been pre-baked (by `tools/gen_listings_and_webworkers`).

**Type:** Once `import`ed, `ListingFile`

Expand Down
5 changes: 4 additions & 1 deletion src/common/internal/query/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ function compareOneLevel(ordering: Ordering, aIsBig: boolean, bIsBig: boolean):
return Ordering.Unordered;
}

function comparePaths(a: readonly string[], b: readonly string[]): Ordering {
/**
* Compare two file paths, or file-local test paths, returning an Ordering between the two.
*/
export function comparePaths(a: readonly string[], b: readonly string[]): Ordering {
const shorter = Math.min(a.length, b.length);

for (let i = 0; i < shorter; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/internal/query/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestParams } from '../../framework/fixture.js';
import { optionString } from '../../runtime/helper/options.js';
import { optionWorkerMode } from '../../runtime/helper/options.js';
import { assert, unreachable } from '../../util/util.js';
import { Expectation } from '../logging/result.js';

Expand Down Expand Up @@ -193,7 +193,7 @@ Expectation should be of the form path/to/cts.https.html?debug=0&q=suite:test_pa
);

const params = expectationURL.searchParams;
if (optionString('worker', params) !== optionString('worker', wptURL.searchParams)) {
if (optionWorkerMode('worker', params) !== optionWorkerMode('worker', wptURL.searchParams)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/internal/test_suite_listing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// A listing of all specs within a single suite. This is the (awaited) type of
// `groups` in '{cts,unittests}/listing.ts' and `listing` in the auto-generated
// 'out/{cts,unittests}/listing.js' files (see tools/gen_listings).
// 'out/{cts,unittests}/listing.js' files (see tools/gen_listings_and_webworkers).
export type TestSuiteListing = TestSuiteListingEntry[];

export type TestSuiteListingEntry = TestSuiteListingEntrySpec | TestSuiteListingEntryReadme;
Expand Down
35 changes: 30 additions & 5 deletions src/common/runtime/helper/options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { unreachable } from '../../util/util.js';

let windowURL: URL | undefined = undefined;
function getWindowURL() {
if (windowURL === undefined) {
Expand All @@ -6,6 +8,7 @@ function getWindowURL() {
return windowURL;
}

/** Parse a runner option that is always boolean-typed. False if missing or '0'. */
export function optionEnabled(
opt: string,
searchParams: URLSearchParams = getWindowURL().searchParams
Expand All @@ -14,27 +17,48 @@ export function optionEnabled(
return val !== null && val !== '0';
}

/** Parse a runner option that is always string-typed. If the option is missing, returns `''`. */
export function optionString(
opt: string,
searchParams: URLSearchParams = getWindowURL().searchParams
): string {
return searchParams.get(opt) || '';
}

/** Runtime modes for whether to run tests in a worker. '0' means no worker. */
type WorkerMode = '0' | 'dedicated' | 'service' | 'shared';
/** Parse a runner option for different worker modes (as in `?worker=shared`). */
export function optionWorkerMode(
opt: string,
searchParams: URLSearchParams = getWindowURL().searchParams
): WorkerMode {
const value = searchParams.get(opt);
if (value === null || value === '0') {
return '0';
} else if (value === 'service') {
return 'service';
} else if (value === 'shared') {
return 'shared';
} else if (value === '' || value === '1' || value === 'dedicated') {
return 'dedicated';
}
unreachable('invalid worker= option value');
}

/**
* The possible options for the tests.
*/
export interface CTSOptions {
worker?: 'dedicated' | 'shared' | '';
worker: WorkerMode;
debug: boolean;
compatibility: boolean;
forceFallbackAdapter: boolean;
unrollConstEvalLoops: boolean;
powerPreference?: GPUPowerPreference | '';
powerPreference: GPUPowerPreference | '';
}

export const kDefaultCTSOptions: CTSOptions = {
worker: '',
worker: '0',
debug: true,
compatibility: false,
forceFallbackAdapter: false,
Expand Down Expand Up @@ -63,11 +87,12 @@ export type OptionsInfos<Type> = Record<keyof Type, OptionInfo>;
export const kCTSOptionsInfo: OptionsInfos<CTSOptions> = {
worker: {
description: 'run in a worker',
parser: optionString,
parser: optionWorkerMode,
selectValueDescriptions: [
{ value: '', description: 'no worker' },
{ value: '0', 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
27 changes: 4 additions & 23 deletions src/common/runtime/helper/test_worker-worker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { setBaseResourcePath } from '../../framework/resources.js';
import { globalTestConfig } from '../../framework/test_config.js';
import { DefaultTestFileLoader } from '../../internal/file_loader.js';
import { Logger } from '../../internal/logging/logger.js';
import { parseQuery } from '../../internal/query/parseQuery.js';
import { TestQueryWithExpectation } from '../../internal/query/query.js';
import { setDefaultRequestAdapterOptions } from '../../util/navigator_gpu.js';
import { assert } from '../../util/util.js';

import { CTSOptions } from './options.js';
import { setupWorkerEnvironment, WorkerTestRunRequest } from './utils_worker.js';

// Should be WorkerGlobalScope, but importing lib "webworker" conflicts with lib "dom".
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
Expand All @@ -18,24 +14,9 @@ const loader = new DefaultTestFileLoader();
setBaseResourcePath('../../../resources');

async function reportTestResults(this: MessagePort | Worker, ev: MessageEvent) {
const query: string = ev.data.query;
const expectations: TestQueryWithExpectation[] = ev.data.expectations;
const ctsOptions: CTSOptions = ev.data.ctsOptions;
const { query, expectations, ctsOptions } = ev.data as WorkerTestRunRequest;

const { debug, unrollConstEvalLoops, powerPreference, compatibility } = ctsOptions;
globalTestConfig.unrollConstEvalLoops = unrollConstEvalLoops;
globalTestConfig.compatibility = compatibility;

Logger.globalDebugMode = debug;
const log = new Logger();

if (powerPreference || compatibility) {
setDefaultRequestAdapterOptions({
...(powerPreference && { powerPreference }),
// MAINTENANCE_TODO: Change this to whatever the option ends up being
...(compatibility && { compatibilityMode: true }),
});
}
const log = setupWorkerEnvironment(ctsOptions);

const testcases = Array.from(await loader.loadCases(parseQuery(query)));
assert(testcases.length === 1, 'worker query resulted in != 1 cases');
Expand All @@ -48,7 +29,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
Loading

0 comments on commit 0aff4ca

Please sign in to comment.