Skip to content

Commit 42fd234

Browse files
authored
Add @requires_webgpu, make WebGPU tests fail if unavailable (#21870)
This makes these tests safer so they won't just silently pass if you happen to run against a browser/system where WebGPU isn't available (currently including Chrome on Linux and Firefox/Safari).
1 parent 2a7164d commit 42fd234

File tree

5 files changed

+14
-24
lines changed

5 files changed

+14
-24
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ commands:
368368
# TODO: Do GL testing when https://bugzil.la/1375585 (lack of WebGL
369369
# support in headless mode) resolves
370370
EMTEST_LACKS_GRAPHICS_HARDWARE: "1"
371+
EMTEST_LACKS_WEBGPU: "1"
371372
EMTEST_LACKS_SOUND_HARDWARE: "1"
372373
# OffscreenCanvas support is not yet done in Firefox.
373374
EMTEST_LACKS_OFFSCREEN_CANVAS: "1"
@@ -797,6 +798,8 @@ jobs:
797798
test_targets: "other skip:other.test_native_link_error_message"
798799
test-browser-chrome:
799800
executor: bionic
801+
environment:
802+
EMTEST_LACKS_WEBGPU: "1"
800803
steps:
801804
- run-tests-chrome:
802805
title: "browser"
@@ -806,19 +809,24 @@ jobs:
806809
"
807810
test-browser-chrome-wasm64:
808811
executor: bionic
812+
environment:
813+
EMTEST_LACKS_WEBGPU: "1"
809814
steps:
810815
- run-tests-chrome:
811816
title: "browser64"
812817
test_targets: "browser64"
813818
test-browser-chrome-2gb:
814819
executor: bionic
820+
environment:
821+
EMTEST_LACKS_WEBGPU: "1"
815822
steps:
816823
- run-tests-chrome:
817824
title: "browser_2gb"
818825
test_targets: "browser_2gb"
819826
test-browser-chrome-wasm64-4gb:
820827
executor: bionic
821828
environment:
829+
EMTEST_LACKS_WEBGPU: "1"
822830
EMTEST_SKIP_NODE_CANARY: "1"
823831
steps:
824832
- run-tests-chrome:

src/library_webgpu.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
* on WebGL 1.0/2.0.
1616
*
1717
* To test this, run the following tests:
18-
* - test/runner.py other.test_webgpu_compiletest
18+
* - test/runner.py 'other.test_webgpu*'
1919
* - EMTEST_BROWSER="/path/to/chrome --user-data-dir=chromeuserdata --enable-unsafe-webgpu" \
20-
* test/runner.py browser.test_webgpu_basic_rendering
21-
* (requires WebGPU to be available - otherwise the test will skip itself and pass)
20+
* test/runner.py 'browser.test_webgpu*'
2221
*/
2322

2423
{{{

test/test_browser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def decorated(self, *args, **kwargs):
186186

187187

188188
requires_graphics_hardware = skipExecIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), 'This test requires graphics hardware')
189+
requires_webgpu = unittest.skipIf(os.getenv('EMTEST_LACKS_WEBGPU'), "This test requires WebGPU to be available")
189190
requires_sound_hardware = skipExecIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), 'This test requires sound hardware')
190191
requires_offscreen_canvas = skipExecIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), 'This test requires a browser with OffscreenCanvas')
191192

@@ -4518,16 +4519,16 @@ def test_webgl_simple_extensions(self, simple_enable_extensions, webgl_version):
45184519
'closure_advanced': (['-sASSERTIONS', '--closure=1', '-O3'],),
45194520
'main_module': (['-sMAIN_MODULE=1'],),
45204521
})
4521-
@requires_graphics_hardware
4522+
@requires_webgpu
45224523
def test_webgpu_basic_rendering(self, args):
45234524
self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU'] + args)
45244525

4525-
@requires_graphics_hardware
4526+
@requires_webgpu
45264527
def test_webgpu_required_limits(self):
45274528
self.btest_exit('webgpu_required_limits.c', args=['-sUSE_WEBGPU', '-sASYNCIFY'])
45284529

45294530
# TODO(#19645): Extend this test to proxied WebGPU when it's re-enabled.
4530-
@requires_graphics_hardware
4531+
@requires_webgpu
45314532
def test_webgpu_basic_rendering_pthreads(self):
45324533
self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sOFFSCREENCANVAS_SUPPORT'])
45334534

test/webgpu_basic_rendering.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ void GetDevice(void (*callback)(wgpu::Device)) {
2525
if (message) {
2626
printf("RequestAdapter: %s\n", message);
2727
}
28-
if (status == WGPURequestAdapterStatus_Unavailable) {
29-
printf("WebGPU unavailable; exiting cleanly\n");
30-
// exit(0) (rather than emscripten_force_exit(0)) ensures there is
31-
// no dangling keepalive.
32-
#if _REENTRANT
33-
// FIXME: In multi-threaded builds this callback runs on the main
34-
// which seems to be causing the runtime to stay alive here and
35-
// results in the 99 being returned.
36-
emscripten_force_exit(0);
37-
#else
38-
exit(0);
39-
#endif
40-
}
4128
assert(status == WGPURequestAdapterStatus_Success);
4229

4330
wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);

test/webgpu_required_limits.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ void on_adapter_request_ended(WGPURequestAdapterStatus status,
6464
WGPUAdapter adapter,
6565
char const* message,
6666
void* userdata) {
67-
if (status == WGPURequestAdapterStatus_Unavailable) {
68-
printf("WebGPU unavailable; exiting cleanly\n");
69-
exit(0);
70-
}
71-
7267
assert(status == WGPURequestAdapterStatus_Success);
7368

7469
wgpuAdapterGetLimits(adapter, &adapter_supported_limits);

0 commit comments

Comments
 (0)