Debian Codegraph @

testing/web-platform/mozilla/tests/webgpu/common/runtime/helper/options.js

raw
1 /**
2 * AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts
3 **/import { unreachable } from '../../util/util.js';let windowURL = undefined;
4 function getWindowURL() {
5 if (windowURL === undefined) {
6 windowURL = new URL(window.location.toString());
7 }
8 return windowURL;
9 }
10
11 /** Parse a runner option that is always boolean-typed. False if missing or '0'. */
12 export function optionEnabled(
13 opt,
14 searchParams = getWindowURL().searchParams)
15 {
16 const val = searchParams.get(opt);
17 return val !== null && val !== '0';
18 }
19
20 /** Parse a runner option that is string-typed. If the option is missing, returns `null`. */
21 export function optionString(
22 opt,
23 searchParams = getWindowURL().searchParams)
24 {
25 return searchParams.get(opt);
26 }
27
28 /** Runtime modes for running tests in different types of workers. */
29
30 /** Parse a runner option for different worker modes (as in `?worker=shared`). Null if no worker. */
31 export function optionWorkerMode(
32 opt,
33 searchParams = getWindowURL().searchParams)
34 {
35 const value = searchParams.get(opt);
36 if (value === null || value === '0') {
37 return null;
38 } else if (value === 'service') {
39 return 'service';
40 } else if (value === 'shared') {
41 return 'shared';
42 } else if (value === '' || value === '1' || value === 'dedicated') {
43 return 'dedicated';
44 }
45 unreachable('invalid worker= option value');
46 }
47
48 /**
49 * The possible options for the tests.
50 */
51
52
53
54
55
56
57
58
59
60
61
62
63 export const kDefaultCTSOptions = {
64 worker: null,
65 debug: false,
66 compatibility: false,
67 forceFallbackAdapter: false,
68 enforceDefaultLimits: false,
69 blockAllFeatures: false,
70 unrollConstEvalLoops: false,
71 powerPreference: null,
72 logToWebSocket: false
73 };
74
75 /**
76 * Extra per option info.
77 */
78
79
80
81
82
83
84 /**
85 * Type for info for every option. This definition means adding an option
86 * will generate a compile time error if no extra info is provided.
87 */
88
89
90 /**
91 * Options to the CTS.
92 */
93 export const kCTSOptionsInfo = {
94 worker: {
95 description: 'run in a worker',
96 parser: optionWorkerMode,
97 selectValueDescriptions: [
98 { value: null, description: 'no worker' },
99 { value: 'dedicated', description: 'dedicated worker' },
100 { value: 'shared', description: 'shared worker' },
101 { value: 'service', description: 'service worker' }]
102
103 },
104 debug: { description: 'show more info' },
105 compatibility: { description: 'request adapters with featureLevel: "compatibility"' },
106 forceFallbackAdapter: { description: 'pass forceFallbackAdapter: true to requestAdapter' },
107 enforceDefaultLimits: {
108 description: `force the adapter limits to the default limits.
109 Note: May fail on tests for low-power/high-performance`
110 },
111 blockAllFeatures: {
112 description: `block all features on adapter - except 'core-features-and-limits'.
113 Note: The spec requires bc or etc2+astc which means tests checking that one or other must exist will fail.
114 `
115 },
116 unrollConstEvalLoops: { description: 'unroll const eval loops in WGSL' },
117 powerPreference: {
118 description: 'set default powerPreference for some tests',
119 parser: optionString,
120 selectValueDescriptions: [
121 { value: null, description: 'default' },
122 { value: 'low-power', description: 'low-power' },
123 { value: 'high-performance', description: 'high-performance' }]
124
125 },
126 logToWebSocket: { description: 'send some logs to ws://localhost:59497/' }
127 };
128
129 /**
130 * Converts camel case to snake case.
131 * Examples:
132 * fooBar -> foo_bar
133 * parseHTMLFile -> parse_html_file
134 */
135 export function camelCaseToSnakeCase(id) {
136 return id.
137 replace(/(.)([A-Z][a-z]+)/g, '$1_$2').
138 replace(/([a-z0-9])([A-Z])/g, '$1_$2').
139 toLowerCase();
140 }
141
142 /**
143 * Creates a Options from search parameters.
144 */
145 function getOptionsInfoFromSearchString(
146 optionsInfos,
147 searchString)
148 {
149 const searchParams = new URLSearchParams(searchString);
150 const optionValues = {};
151 for (const [optionName, info] of Object.entries(optionsInfos)) {
152 const parser = info.parser || optionEnabled;
153 optionValues[optionName] = parser(camelCaseToSnakeCase(optionName), searchParams);
154 }
155 return optionValues;
156 }
157
158 /**
159 * Given a test query string in the form of `suite:foo,bar,moo&opt1=val1&opt2=val2
160 * returns the query and the options.
161 */
162 export function parseSearchParamLikeWithOptions(
163 optionsInfos,
164 query)
165
166
167
168 {
169 const searchString = query.includes('q=') || query.startsWith('?') ? query : `q=${query}`;
170 const queries = new URLSearchParams(searchString).getAll('q');
171 const options = getOptionsInfoFromSearchString(optionsInfos, searchString);
172 return { queries, options };
173 }
174
175 /**
176 * Given a test query string in the form of `suite:foo,bar,moo&opt1=val1&opt2=val2
177 * returns the query and the common options.
178 */
179 export function parseSearchParamLikeWithCTSOptions(query) {
180 return parseSearchParamLikeWithOptions(kCTSOptionsInfo, query);
181 }