blob: 5cfcca1b5e141ad4759bf2daea2ed25944647515 [file] [log] [blame]
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test Error Scopes.</title>
<body>
<script src="js/webgpu-functions.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
let tests = {};
tests["Capture a single GPUValidation error."] = async device => {
device.pushErrorScope("validation");
causeValidationError(device);
return popValidationError(device);
};
tests["Capture a single GPUOutOfMemory error."] = async device => {
device.pushErrorScope("out-of-memory");
causeMemoryError(device);
return popMemoryError(device);
};
tests["Ignore errors past the first."] = async device => {
device.pushErrorScope("validation");
device.pushErrorScope("validation");
causeValidationError(device);
causeValidationError(device);
const error = await device.popErrorScope();
assertValidationError(error);
return popNullError(device);
};
tests["Captured errors match error scope filter."] = async device => {
device.pushErrorScope("validation");
device.pushErrorScope("out-of-memory");
causeValidationError(device);
const shouldBeNull = await device.popErrorScope();
assertNull(shouldBeNull);
return popValidationError(device);
};
tests["Reject popErrorScope if no scope exists."] = async device => {
const promise = device.popErrorScope().then(() => assert_unreached(), async e => {
assert_false(e === undefined);
// Pop the extra 'none' scope.
await popNullError(device);
});
// 'promise' should still reject if a scope is pushed here.
device.pushErrorScope("none");
return promise;
};
tests["Filter 'none' should capture but not report errors."] = async device => {
device.pushErrorScope("out-of-memory");
device.pushErrorScope("none");
causeMemoryError(device);
const shouldBeNull = await device.popErrorScope();
assertNull(shouldBeNull);
return popNullError(device);
};
tests["Push and pop many error scopes with no rejections."] = async device => {
const numIterations = 128;
for (let i = 0; i < numIterations; ++i)
device.pushErrorScope("out-of-memory");
for (let i = 0; i < numIterations - 1; ++i)
await popNullError(device);
return popNullError(device);
};
tests["Catch many errors in nested scopes."] = async device => {
const numIterations = 128;
for (let i = 0; i < numIterations; ++i) {
device.pushErrorScope("validation");
causeValidationError(device);
}
for (let i = 0; i < numIterations - 1; ++i)
await popValidationError(device);
return popValidationError(device);
};
const init = async () => {
try {
var device = await getBasicDevice();
} catch (e) { /* WebGPU is not supported. */ }
for (let name in tests)
devicePromiseTest(device, name);
};
window.addEventListener("load", init);
/* Helper Functions */
const causeValidationError = device => device.createBuffer({ size: 4, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.MAP_WRITE });
const causeMemoryError = device => device.createBuffer({ size: 99999999999, usage: GPUBufferUsage.NONE });
const popValidationError = device => device.popErrorScope().then(error => assertValidationError(error));
const popMemoryError = device => device.popErrorScope().then(error => assertMemoryError(error));
const popNullError = device => device.popErrorScope().then(error => assertNull(error));
const assertNull = error => assert_true(error === null, "No error expected!");
const assertValidationError = error => assert_true(error instanceof GPUValidationError, "Expected validation error!");
const assertMemoryError = error => assert_true(error instanceof GPUOutOfMemoryError, "Expected out-of-memory error!");
const devicePromiseTest = (device, name) => {
promise_test(async () => {
if (device === undefined)
return Promise.resolve();
return tests[name](device);
}, name);
};
</script>
</body>