summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts')
-rw-r--r--dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts
new file mode 100644
index 0000000000..44a34c22cb
--- /dev/null
+++ b/dom/webgpu/tests/cts/checkout/src/webgpu/print_environment.spec.ts
@@ -0,0 +1,70 @@
+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: unknown) {
+ 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 as Record<string, unknown>;
+ return Object.fromEntries(
+ (function* () {
+ for (const key in valueObj) {
+ yield [key, valueObj[key]];
+ }
+ })()
+ );
+ },
+ 2
+ );
+
+ t.info(info);
+ consoleLogIfNotWPT(info);
+ });