Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for behavior on lost devices #687

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/manual/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions src/manual/device_lost.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 5 additions & 0 deletions src/manual/listing.ts
Original file line number Diff line number Diff line change
@@ -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<TestSuiteListing> = makeListing(__filename);
30 changes: 30 additions & 0 deletions src/webgpu/api/validation/state/device_lost.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
24 changes: 24 additions & 0 deletions src/webgpu/api/validation/state/device_lost.ts
Original file line number Diff line number Diff line change
@@ -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()));
}
6 changes: 1 addition & 5 deletions src/webgpu/api/validation/state/device_lost/README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
Tests of behavior while the device is lost.

- x= every method in the API.

TODO: implement
FIXME