Files
firefox/testing/web-platform/tests/webgpu/framework/test_group.js
T
Kai Ninomiya 49ef6c3779 Bug 1594612 [wpt PR 20140] - Roll WebGPU CTS, a=testonly
Automatic update from web-platform-tests
Roll WebGPU CTS

Prepares us to roll the vertex state CTS changes along with the vertex
state changes in Dawn and Chrome.

TBR: [email protected]
Change-Id: I5ed5eebdff7d8e7559b0044686caacea9defd850
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902131
Reviewed-by: Kai Ninomiya <[email protected]>
Commit-Queue: Kai Ninomiya <[email protected]>
Cr-Commit-Position: refs/heads/master@{#713275}

--

wpt-commits: b490a2b1777c8062c0eb3ff0115735a5bc9c1bab
wpt-pr: 20140
2019-11-29 10:55:53 +00:00

164 lines
4.4 KiB
JavaScript

/**
* AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts
**/
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { allowedTestNameCharacters } from './allowed_characters.js';
import { paramsEquals } from './params/index.js';
import { checkPublicParamType, extractPublicParams } from './url_query.js';
const validNames = new RegExp('^[' + allowedTestNameCharacters + ']+$');
export class TestGroup {
constructor(fixture) {
_defineProperty(this, "fixture", void 0);
_defineProperty(this, "seen", new Set());
_defineProperty(this, "tests", []);
this.fixture = fixture;
}
*iterate(log) {
for (const test of this.tests) {
yield* test.iterate(log);
}
}
checkName(name) {
if (!validNames.test(name)) {
throw new Error(`Invalid test name ${name}; must match [${validNames}]+`);
}
if (name !== decodeURIComponent(name)) {
// Shouldn't happen due to the rule above. Just makes sure that treated
// unencoded strings as encoded strings is OK.
throw new Error(`Not decodeURIComponent-idempotent: ${name} !== ${decodeURIComponent(name)}`);
}
if (this.seen.has(name)) {
throw new Error(`Duplicate test name: ${name}`);
}
this.seen.add(name);
} // TODO: This could take a fixture, too, to override the one for the group.
test(name, fn) {
// Replace spaces with underscores for readability.
if (name.indexOf('_') !== -1) {
throw new Error('Invalid test name ${name}: contains underscore (use space)');
}
name = name.replace(/ /g, '_');
this.checkName(name);
const test = new Test(name, this.fixture, fn);
this.tests.push(test);
return test;
}
} // This test is created when it's inserted, but may be parameterized afterward (.params()).
class Test {
constructor(name, fixture, fn) {
_defineProperty(this, "name", void 0);
_defineProperty(this, "fixture", void 0);
_defineProperty(this, "fn", void 0);
_defineProperty(this, "cases", null);
this.name = name;
this.fixture = fixture;
this.fn = fn;
}
params(specs) {
if (this.cases !== null) {
throw new Error('test case is already parameterized');
}
const cases = Array.from(specs);
const seen = []; // This is n^2.
for (const spec of cases) {
const publicParams = extractPublicParams(spec); // Check type of public params: can only be (currently):
// number, string, boolean, undefined, number[]
for (const v of Object.values(publicParams)) {
checkPublicParamType(v);
}
if (seen.some(x => paramsEquals(x, publicParams))) {
throw new Error('Duplicate test case params');
}
seen.push(publicParams);
}
this.cases = cases;
}
*iterate(rec) {
for (const params of this.cases || [null]) {
yield new RunCaseSpecific(rec, this.name, params, this.fixture, this.fn);
}
}
}
class RunCaseSpecific {
constructor(recorder, test, params, fixture, fn) {
_defineProperty(this, "id", void 0);
_defineProperty(this, "params", void 0);
_defineProperty(this, "recorder", void 0);
_defineProperty(this, "fixture", void 0);
_defineProperty(this, "fn", void 0);
this.id = {
test,
params: params ? extractPublicParams(params) : null
};
this.params = params;
this.recorder = recorder;
this.fixture = fixture;
this.fn = fn;
}
async run(debug) {
const [rec, res] = this.recorder.record(this.id.test, this.id.params);
rec.start(debug);
try {
const inst = new this.fixture(rec, this.params || {});
try {
await inst.init();
await this.fn(inst);
} finally {
// Runs as long as constructor succeeded, even if initialization or the test failed.
await inst.finalize();
}
} catch (ex) {
// There was an exception from constructor, init, test, or finalize.
// An error from init or test may have been a SkipTestCase.
// An error from finalize may have been an eventualAsyncExpectation failure.
rec.threw(ex);
}
rec.finish();
return res;
}
injectResult(result) {
const [, res] = this.recorder.record(this.id.test, this.id.params);
Object.assign(res, result);
}
}
//# sourceMappingURL=test_group.js.map