export const description = `
Examples of writing CTS tests with various features.
Start here when looking for examples of basic framework usage.
`;
import { makeTestGroup } from '../common/framework/test_group.js';
import { AllFeaturesMaxLimitsGPUTest } from './gpu_test.js';
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
g.test('test_name').fn(_t => {});
g.test('not_implemented_yet,without_plan').unimplemented();
g.test('not_implemented_yet,with_plan')
.desc(
`
Plan for this test. What it tests. Summary of how it tests that functionality.
- Description of cases, by describing parameters {a, b, c}
- x= more parameters {x, y, z}
`
)
.unimplemented();
g.test('basic').fn(t => {
t.expect(true);
t.expect(true, 'true should be true');
t.shouldThrow(
'TypeError',
() => {
throw new TypeError();
},
{ message: 'function should throw Error' }
);
});
g.test('basic,async').fn(t => {
t.shouldReject(
'TypeError',
Promise.reject(new TypeError()),
{ message: 'Promise.reject should reject' }
);
t.shouldReject(
'TypeError',
(async () => {
throw new TypeError();
})(),
{ message: 'Promise.reject should reject' }
);
});
g.test('basic,plain_cases')
.desc(
`
A test can be parameterized with a simple array of objects using .paramsSimple([ ... ]).
Each such instance of the test is a "case".
In this example, the following cases are generated (identified by their "query string"),
each with just one subcase:
- webgpu:examples:basic,cases:x=2;y=2 runs 1 subcase, with t.params set to:
- { x: 2, y: 2 }
- webgpu:examples:basic,cases:x=-10;y=-10 runs 1 subcase, with t.params set to:
- { x: -10, y: -10 }
`
)
.paramsSimple([
{ x: 2, y: 2 },
{ x: -10, y: -10 },
])
.fn(t => {
t.expect(t.params.x === t.params.y);
});
g.test('basic,plain_cases_private')
.desc(
`
Parameters can be public ("x", "y") which means they're part of the case name.
They can also be private by starting with an underscore ("_result"), which passes
them into the test but does not make them part of the case name:
In this example, the following cases are generated, each with just one subcase:
- webgpu:examples:basic,cases:x=2;y=4 runs 1 subcase, with t.params set to:
- { x: 2, y: 4, _result: 6 }
- webgpu:examples:basic,cases:x=-10;y=18 runs 1 subcase, with t.params set to:
- { x: -10, y: 18, _result: 8 }
`
)
.paramsSimple([
{ x: 2, y: 4, _result: 6 },
{ x: -10, y: 18, _result: 8 },
])
.fn(t => {
t.expect(t.params.x + t.params.y === t.params._result);
});
g.test('basic,builder_cases')
.desc(
`
A "CaseParamsBuilder" or "SubcaseParamsBuilder" can be passed to .params() instead.
The params builder provides facilities for generating tests combinatorially (by cartesian
product). For convenience, the "unit" CaseParamsBuilder is passed as an argument ("u" below).
In this example, the following cases are generated, each with just one subcase:
- webgpu:examples:basic,cases:x=1,y=1 runs 1 subcase, with t.params set to:
- { x: 1, y: 1 }
- webgpu:examples:basic,cases:x=1,y=2 runs 1 subcase, with t.params set to:
- { x: 1, y: 2 }
- webgpu:examples:basic,cases:x=2,y=1 runs 1 subcase, with t.params set to:
- { x: 2, y: 1 }
- webgpu:examples:basic,cases:x=2,y=2 runs 1 subcase, with t.params set to:
- { x: 2, y: 2 }
`
)
.params(u =>
u
.combineWithParams([{ x: 1 }, { x: 2 }])
.combineWithParams([{ y: 1 }, { y: 2 }])
)
.fn(() => {});
g.test('basic,builder_cases_subcases')
.desc(
`
Each case sub-parameterized using .beginSubcases().
Each such instance of the test is a "subcase", which cannot be run independently of other
subcases. It is somewhat like wrapping the entire fn body in a for-loop.
In this example, the following cases are generated:
- webgpu:examples:basic,cases:x=1 runs 2 subcases, with t.params set to:
- { x: 1, y: 1 }
- { x: 1, y: 2 }
- webgpu:examples:basic,cases:x=2 runs 2 subcases, with t.params set to:
- { x: 2, y: 1 }
- { x: 2, y: 2 }
`
)
.params(u =>
u
.combineWithParams([{ x: 1 }, { x: 2 }])
.beginSubcases()
.combineWithParams([{ y: 1 }, { y: 2 }])
)
.fn(() => {});
g.test('basic,builder_subcases')
.desc(
`
In this example, the following single case is generated:
- webgpu:examples:basic,cases: runs 4 subcases, with t.params set to:
- { x: 1, y: 1 }
- { x: 1, y: 2 }
- { x: 2, y: 1 }
- { x: 2, y: 2 }
`
)
.params(u =>
u
.beginSubcases()
.combineWithParams([{ x: 1 }, { x: 2 }])
.combineWithParams([{ y: 1 }, { y: 2 }])
)
.fn(() => {});
g.test('basic,builder_subcases_short')
.desc(
`
As a shorthand, .paramsSubcasesOnly() can be used.
In this example, the following single case is generated:
- webgpu:examples:basic,cases: runs 4 subcases, with t.params set to:
- { x: 1, y: 1 }
- { x: 1, y: 2 }
- { x: 2, y: 1 }
- { x: 2, y: 2 }
`
)
.paramsSubcasesOnly(u =>
u
.combineWithParams([{ x: 1 }, { x: 2 }])
.combineWithParams([{ y: 1 }, { y: 2 }])
)
.fn(() => {});
g.test('gpu,async').fn(async t => {
const x = await t.queue.onSubmittedWorkDone();
t.expect(x === undefined);
});
g.test('gpu,buffers').fn(t => {
const data = new Uint32Array([0, 1234, 0]);
const src = t.makeBufferWithContents(data, GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST);
t.expectGPUBufferValuesEqual(src, data);
});
g.test('gpu,with_texture_compression,bc')
.desc(
`Example of a test using an optional feature.
Tests that a BC format passes validation iff the feature is enabled.`
)
.fn(t => {
t.skipIfDeviceDoesNotHaveFeature('texture-compression-bc');
t.createTextureTracked({
format: 'bc1-rgba-unorm',
size: [4, 4, 1],
usage: GPUTextureUsage.TEXTURE_BINDING,
});
});
g.test('gpu,with_texture_compression,etc2')
.desc(
`Example of a test using an optional feature.
Tests that an ETC2 format passes validation iff the feature is enabled.`
)
.fn(t => {
t.skipIfDeviceDoesNotHaveFeature('texture-compression-etc2');
t.createTextureTracked({
format: 'etc2-rgb8unorm',
size: [4, 4, 1],
usage: GPUTextureUsage.TEXTURE_BINDING,
});
});