Skip to content

Commit 4b3e642

Browse files
committed
Bug 1865921 Part 2: Add a test that awaits the device.lost promise. r=ErichDonGubler
This also drive-by marks all WebGPU mochitests as failing on macos, to honor the current status of the blocklist. Differential Revision: https://phabricator.services.mozilla.com/D194311
1 parent 7c0d0c2 commit 4b3e642

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

dom/webgpu/mochitest/mochitest.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fail-if = [
3232
["test_buffer_mapping_invalid_device.html"]
3333
fail-if = [
3434
"os == 'linux' && os_version == '18.04'",
35+
"os == 'mac'",
3536
]
3637

3738
["test_command_buffer_creation.html"]
@@ -43,6 +44,7 @@ fail-if = [
4344
["test_context_configure.html"]
4445
fail-if = [
4546
"os == 'linux' && os_version == '18.04'",
47+
"os == 'mac'",
4648
]
4749

4850
["test_device_creation.html"]
@@ -51,9 +53,16 @@ fail-if = [
5153
"os == 'mac'",
5254
]
5355

56+
["test_device_lost.html"]
57+
fail-if = [
58+
"os == 'linux' && os_version == '18.04'",
59+
"os == 'mac'",
60+
]
61+
5462
["test_double_encoder_finish.html"]
5563
fail-if = [
5664
"os == 'linux' && os_version == '18.04'",
65+
"os == 'mac'",
5766
]
5867

5968
["test_enabled.html"]
@@ -85,6 +94,7 @@ fail-if = [
8594
["test_queue_write_invalid_device.html"]
8695
fail-if = [
8796
"os == 'linux' && os_version == '18.04'",
97+
"os == 'mac'",
8898
]
8999

90100
["test_submit_compute_empty.html"]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="/tests/SimpleTest/SimpleTest.js"></script>
6+
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
7+
</head>
8+
<body>
9+
<script>
10+
ok(
11+
SpecialPowers.getBoolPref("dom.webgpu.enabled"),
12+
"Pref should be enabled."
13+
);
14+
15+
const destroy_causes_lost = async function () {
16+
const adapter = await navigator.gpu.requestAdapter();
17+
ok(adapter !== undefined, "adapter !== undefined");
18+
const device = await adapter.requestDevice();
19+
ok(device !== undefined, "device !== undefined");
20+
21+
const lostPromise = device.lost;
22+
device.destroy();
23+
const deviceLostReason = await lostPromise;
24+
25+
is(
26+
deviceLostReason.reason,
27+
"destroyed",
28+
"Destroy reason should correspond to GPUDeviceLostReason.destroyed"
29+
);
30+
is(deviceLostReason.message, "", "Destroy message should be blank");
31+
};
32+
33+
const drop_causes_lost_is_unobservable = async function () {
34+
const adapter = await navigator.gpu.requestAdapter();
35+
ok(adapter !== undefined, "adapter !== undefined");
36+
37+
let lostPromise;
38+
// Create a scope with a device that will go out of scope
39+
// and then be dropped.
40+
{
41+
const device = await adapter.requestDevice();
42+
ok(device !== undefined, "device !== undefined");
43+
44+
lostPromise = device.lost;
45+
}
46+
47+
SimpleTest.requestFlakyTimeout(
48+
"Racing against promise that should never resolve."
49+
);
50+
const TIMEOUT_MS = 5000;
51+
let timeoutPromise = new Promise(resolve => {
52+
let timeoutValue = { reason: "timeout" };
53+
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
54+
setTimeout(() => resolve(timeoutValue), TIMEOUT_MS);
55+
});
56+
57+
const firstPromise = await Promise.race([lostPromise, timeoutPromise]);
58+
is(
59+
firstPromise.reason,
60+
"timeout",
61+
"timeoutPromise should return before lostPromise."
62+
);
63+
};
64+
65+
SimpleTest.waitForExplicitFinish();
66+
67+
destroy_causes_lost()
68+
.then(() => drop_causes_lost_is_unobservable())
69+
.catch(e => ok(false, `Unhandled exception ${e}`))
70+
.finally(() => SimpleTest.finish());
71+
</script>
72+
</body>
73+
</html>

0 commit comments

Comments
 (0)