From 79e54b4c9980d99b787aa3e040e7ad82f3b59cc9 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Thu, 29 Jul 2021 18:43:55 -0700 Subject: [PATCH] Add tests for behavior on lost devices --- src/manual/README.txt | 2 +- src/manual/device_lost.spec.ts | 30 +++++++++++++++++++ src/manual/listing.ts | 5 ++++ .../api/validation/state/device_lost.spec.ts | 30 +++++++++++++++++++ .../api/validation/state/device_lost.ts | 24 +++++++++++++++ .../validation/state/device_lost/README.txt | 6 +--- 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/manual/device_lost.spec.ts create mode 100644 src/manual/listing.ts create mode 100644 src/webgpu/api/validation/state/device_lost.spec.ts create mode 100644 src/webgpu/api/validation/state/device_lost.ts diff --git a/src/manual/README.txt b/src/manual/README.txt index a50ded41db70..f16e8be95993 100644 --- a/src/manual/README.txt +++ b/src/manual/README.txt @@ -2,7 +2,7 @@ WebGPU tests that require manual intervention. Many of these test may be HTML pages rather than using the harness. -Add informal notes here on possible stress tests. +Add informal notes here on possible manual tests. - Suspending or hibernating the machine. - Manually crashing or relaunching the browser's GPU process. diff --git a/src/manual/device_lost.spec.ts b/src/manual/device_lost.spec.ts new file mode 100644 index 000000000000..c28a24737231 --- /dev/null +++ b/src/manual/device_lost.spec.ts @@ -0,0 +1,30 @@ +export const description = ` +Tests of behavior while the device is lost. + +- x= every method in the API. + +TODO: implement +`; + +import { Fixture } from '../common/framework/fixture.js'; +import { makeTestGroup } from '../common/framework/test_group.js'; +import { runDeviceLossTests } from '../webgpu/api/validation/state/device_lost.js'; + +export const g = makeTestGroup(Fixture); + +g.test('no_crash') + .desc( + `Test doing a bunch of operations after the GPU process is manually terminated. + +This effectively only tests is that there are no crashes. It's not actually possible to +check for validation errors: once a device is lost, it can't _track_ validation errors +(popErrorScope throws an exception).` + ) + .params(u => u.combine('lost', [false, true])) + .fn(async t => { + const { lost } = t.params; + + await runDeviceLossTests(() => { + if (lost) alert('Please terminate the GPU process manually'); + }); + }); diff --git a/src/manual/listing.ts b/src/manual/listing.ts new file mode 100644 index 000000000000..823639c69292 --- /dev/null +++ b/src/manual/listing.ts @@ -0,0 +1,5 @@ +/* eslint-disable import/no-restricted-paths */ +import { TestSuiteListing } from '../common/internal/test_suite_listing.js'; +import { makeListing } from '../common/tools/crawl.js'; + +export const listing: Promise = makeListing(__filename); diff --git a/src/webgpu/api/validation/state/device_lost.spec.ts b/src/webgpu/api/validation/state/device_lost.spec.ts new file mode 100644 index 000000000000..8ef39e0ca9f6 --- /dev/null +++ b/src/webgpu/api/validation/state/device_lost.spec.ts @@ -0,0 +1,30 @@ +export const description = ` +Tests of behavior while the device is lost. + +- x= every method in the API. + +TODO: implement +`; + +import { Fixture } from '../../../../common/framework/fixture.js'; +import { makeTestGroup } from '../../../../common/internal/test_group.js'; +import { runDeviceLossTests } from './device_lost.js'; + +export const g = makeTestGroup(Fixture); + +g.test('no_crash') + .desc( + `Test doing a bunch of operations after device.destroy() is called. + +This effectively only tests is that there are no crashes. It's not actually possible to +check for validation errors: once a device is lost, it can't _track_ validation errors +(popErrorScope throws an exception).` + ) + .params(u => u.combine('lost', [false, true])) + .fn(async t => { + const { lost } = t.params; + + await runDeviceLossTests(device => { + if (lost) device.destroy(); + }); + }); diff --git a/src/webgpu/api/validation/state/device_lost.ts b/src/webgpu/api/validation/state/device_lost.ts new file mode 100644 index 000000000000..66a885a9a5a5 --- /dev/null +++ b/src/webgpu/api/validation/state/device_lost.ts @@ -0,0 +1,24 @@ +import { assert } from '../../../../common/util/util.js'; +import { getGPU } from '../../../util/navigator_gpu.js'; + +/** + * Run the device loss tests. This function is used in device_lost validation tests as well as + * device_lost manual tests (where the gpu process is crashed manually). + */ +export async function runDeviceLossTests(loseDevice: (device: GPUDevice) => void) { + const adapter = await getGPU().requestAdapter(); + assert(adapter !== null); + const device = await adapter.requestDevice(); + + const tests = []; + { + const cmdbuf = device.createCommandEncoder().finish(); + tests.push(() => { + device.queue.submit([cmdbuf]); + }); + } + + loseDevice(device); + + await Promise.all(tests.map(post => post())); +} diff --git a/src/webgpu/api/validation/state/device_lost/README.txt b/src/webgpu/api/validation/state/device_lost/README.txt index 319cc76e5c96..9d6cf4b7fb68 100644 --- a/src/webgpu/api/validation/state/device_lost/README.txt +++ b/src/webgpu/api/validation/state/device_lost/README.txt @@ -1,5 +1 @@ -Tests of behavior while the device is lost. - -- x= every method in the API. - -TODO: implement +FIXME