diff options
Diffstat (limited to 'testing/web-platform/mozilla/tests/webgpu/webgpu/print_environment.spec.js')
-rw-r--r-- | testing/web-platform/mozilla/tests/webgpu/webgpu/print_environment.spec.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/webgpu/webgpu/print_environment.spec.js b/testing/web-platform/mozilla/tests/webgpu/webgpu/print_environment.spec.js new file mode 100644 index 0000000000..83ef03afd3 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webgpu/webgpu/print_environment.spec.js @@ -0,0 +1,70 @@ +/** +* AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts +**/export const description = ` + +Examples of writing CTS tests with various features. + +Start here when looking for examples of basic framework usage. +`;import { getResourcePath } from '../common/framework/resources.js'; +import { globalTestConfig } from '../common/framework/test_config.js'; +import { makeTestGroup } from '../common/framework/test_group.js'; +import { getDefaultRequestAdapterOptions } from '../common/util/navigator_gpu.js'; + +import { GPUTest } from './gpu_test.js'; + +export const g = makeTestGroup(GPUTest); + +/** console.log is disallowed by WPT. Work around it when we're not in WPT. */ +function consoleLogIfNotWPT(x) { + if (!('step_timeout' in globalThis)) { + const cons = console; + cons.log(x); + } +} + +g.test('info'). +desc( + `Test which prints what global scope (e.g. worker type) it's running in. +Typically, tests will check for the presence of the feature they need (like HTMLCanvasElement) +and skip if it's not available. + +Run this test under various configurations to see different results +(Window, worker scopes, Node, etc.) + +NOTE: If your test runtime elides logs when tests pass, you won't see the prints from this test +in the logs. On non-WPT runtimes, it will also print to the console with console.log. +WPT disallows console.log and doesn't support logs on passing tests, so this does nothing on WPT.` +). +fn(async (t) => { + const adapterInfo = await t.adapter.requestAdapterInfo(); + + const info = JSON.stringify( + { + globalScope: Object.getPrototypeOf(globalThis).constructor.name, + globalTestConfig, + baseResourcePath: getResourcePath(''), + defaultRequestAdapterOptions: getDefaultRequestAdapterOptions(), + adapterInfo, + userAgent: navigator.userAgent + }, + // Flatten objects with prototype chains into plain objects, using `for..in`. (Otherwise, + // properties from the prototype chain will be ignored and things will print as `{}`.) + (_key, value) => { + if (value === undefined || value === null) return null; + if (typeof value !== 'object') return value; + + const valueObj = value; + return Object.fromEntries( + function* () { + for (const key in valueObj) { + yield [key, valueObj[key]]; + } + }() + ); + }, + 2 + ); + + t.info(info); + consoleLogIfNotWPT(info); +});
\ No newline at end of file |