Skip to content

Commit e771a76

Browse files
authored
[js/test] align web test runner flags with ort.env (#19790)
### Description the `npm test` flags are difficult to memorize, because they are different to the `ort.env` flags. This change makes those flags align with ort JS API. eg. `--wasm-enable-proxy` became `--wasm.proxy`. Old flags are marked as deprecated except `-x` (as a shortcut of `--wasm.numThreads`)
1 parent d5d9dbd commit e771a76

File tree

5 files changed

+87
-112
lines changed

5 files changed

+87
-112
lines changed

js/web/script/test-runner-cli-args.ts

+79-61
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ Options:
2929
*** General Options ***
3030
3131
-h, --help Print this message.
32-
-d, --debug Specify to run test runner in debug mode.
33-
Debug mode outputs verbose log for test runner, sets up environment debug flag, and keeps karma not to exit after tests completed.
32+
-d, --debug Specify to run test runner in debug mode. Debug mode does the following:
33+
- outputs verbose log for test runner
34+
- sets up environment debug flag (env.debug = true)
35+
- opens Chromium debug port at 9333 and keeps karma not to exit after tests completed.
3436
-b=<...>, --backend=<...> Specify one or more backend(s) to run the test upon.
3537
Backends can be one or more of the following, splitted by comma:
3638
webgl
@@ -47,38 +49,55 @@ Options:
4749
bs (for BrowserStack tests)
4850
-p, --profile Enable profiler.
4951
Profiler will generate extra logs which include the information of events time consumption
52+
-t, --trace Enable trace.
5053
-P[=<...>], --perf[=<...>] Generate performance number. Cannot be used with flag --debug.
5154
This flag can be used with a number as value, specifying the total count of test cases to run. The test cases may be used multiple times. Default value is 10.
5255
-c, --file-cache Enable file cache.
56+
57+
*** Session Options ***
58+
-u=<...>, --optimized-model-file-path=<...> Specify whether to dump the optimized model.
59+
-o=<...>, --graph-optimization-level=<...> Specify graph optimization level.
60+
Default is 'all'. Valid values are 'disabled', 'basic', 'extended', 'all'.
5361
-i=<...>, --io-binding=<...> Specify the IO binding testing type. Should be one of the following:
54-
none (default)
62+
none (default)
5563
gpu-tensor use pre-allocated GPU tensors for inputs and outputs
5664
gpu-location use pre-allocated GPU tensors for inputs and set preferredOutputLocation to 'gpu-buffer'
5765
58-
*** Session Options ***
59-
-u=<...>, --optimized-model-file-path=<...> Specify whether to dump the optimized model.
60-
-o=<...>, --graph-optimization-level=<...> Specify graph optimization level.
61-
Default is 'all'. Valid values are 'disabled', 'basic', 'extended', 'all'.
6266
*** Logging Options ***
6367
64-
--log-verbose=<...> Set log level to verbose
65-
--log-info=<...> Set log level to info
66-
--log-warning=<...> Set log level to warning
67-
--log-error=<...> Set log level to error
68-
The 4 flags above specify the logging configuration. Each flag allows to specify one or more category(s), splitted by comma. If use the flags without value, the log level will be applied to all category.
68+
--log-verbose Set log level to verbose
69+
--log-info Set log level to info
70+
--log-warning Set log level to warning
71+
--log-error Set log level to error
72+
The 4 flags above specify the logging configuration.
6973
7074
*** Backend Options ***
7175
76+
--wasm.<...>=<...> Set global environment flags for each backend.
77+
--webgl.<...>=<...> These flags can be used multiple times to set multiple flags. For example:
78+
--webgpu.<...>=<...> --webgpu.profiling.mode=default --wasm.numThreads=1 --wasm.simd=false
79+
--webnn.<...>=<...>
80+
81+
--webnn-device-type Set the WebNN device type (cpu/gpu)
82+
7283
-x, --wasm-number-threads Set the WebAssembly number of threads
84+
("--wasm-number-threads" is deprecated. use "--wasm.numThreads" or "-x" instead)
7385
--wasm-init-timeout Set the timeout for WebAssembly backend initialization, in milliseconds
86+
(deprecated. use "--wasm.initTimeout" instead)
7487
--wasm-enable-simd Set whether to enable SIMD
88+
(deprecated. use "--wasm.simd" instead)
7589
--wasm-enable-proxy Set whether to enable proxy worker
90+
(deprecated. use "--wasm.proxy" instead)
7691
--webgl-context-id Set the WebGL context ID (webgl/webgl2)
92+
(deprecated. use "--webgl.contextId" instead)
7793
--webgl-matmul-max-batch-size Set the WebGL matmulMaxBatchSize
94+
(deprecated. use "--webgl.matmulMaxBatchSize" instead)
7895
--webgl-texture-cache-mode Set the WebGL texture cache mode (initializerOnly/full)
96+
(deprecated. use "--webgl.textureCacheMode" instead)
7997
--webgl-texture-pack-mode Set the WebGL texture pack mode (true/false)
98+
(deprecated. use "--webgl.pack" instead)
8099
--webgpu-profiling-mode Set the WebGPU profiling mode (off/default)
81-
--webnn-device-type Set the WebNN device type (cpu/gpu)
100+
(deprecated. use "--webgpu.profiling.mode" instead)
82101
83102
*** Browser Options ***
84103
@@ -171,7 +190,6 @@ export interface TestRunnerCliArgs {
171190

172191
cpuOptions?: InferenceSession.CpuExecutionProviderOption;
173192
cudaOptions?: InferenceSession.CudaExecutionProviderOption;
174-
cudaFlags?: Record<string, unknown>;
175193
wasmOptions?: InferenceSession.WebAssemblyExecutionProviderOption;
176194
webglOptions?: InferenceSession.WebGLExecutionProviderOption;
177195
webnnOptions?: InferenceSession.WebNNExecutionProviderOption;
@@ -260,80 +278,73 @@ function parseCpuOptions(_args: minimist.ParsedArgs): InferenceSession.CpuExecut
260278
return {name: 'cpu'};
261279
}
262280

263-
function parseCpuFlags(_args: minimist.ParsedArgs): Record<string, unknown> {
264-
return {};
265-
}
266-
267281
function parseWasmOptions(_args: minimist.ParsedArgs): InferenceSession.WebAssemblyExecutionProviderOption {
268282
return {name: 'wasm'};
269283
}
270284

271285
function parseWasmFlags(args: minimist.ParsedArgs): Env.WebAssemblyFlags {
272-
const numThreads = args.x || args['wasm-number-threads'];
286+
const wasm = args.wasm || {};
287+
const numThreads = wasm.numThreads = wasm.numThreads ?? (args.x ?? args['wasm-number-threads']);
273288
if (typeof numThreads !== 'undefined' && typeof numThreads !== 'number') {
274-
throw new Error('Flag "x"/"wasm-number-threads" must be a number value');
289+
throw new Error('Flag "wasm.numThreads"/"x"/"wasm-number-threads" must be a number value');
275290
}
276-
const initTimeout = args['wasm-init-timeout'];
291+
const initTimeout = wasm.initTimeout = wasm.initTimeout ?? args['wasm-init-timeout'];
277292
if (typeof initTimeout !== 'undefined' && typeof initTimeout !== 'number') {
278-
throw new Error('Flag "wasm-init-timeout" must be a number value');
279-
}
280-
let simd = args['wasm-enable-simd'];
281-
if (simd === 'true') {
282-
simd = true;
283-
} else if (simd === 'false') {
284-
simd = false;
285-
} else if (typeof simd !== 'undefined' && typeof simd !== 'boolean') {
286-
throw new Error('Flag "wasm-enable-simd" must be a boolean value');
287-
}
288-
let proxy = args['wasm-enable-proxy'];
289-
if (proxy === 'true') {
290-
proxy = true;
291-
} else if (proxy === 'false') {
292-
proxy = false;
293-
} else if (typeof proxy !== 'undefined' && typeof proxy !== 'boolean') {
294-
throw new Error('Flag "wasm-enable-proxy" must be a boolean value');
295-
}
296-
return {numThreads, initTimeout, simd, proxy};
293+
throw new Error('Flag "wasm.initTimeout"/"wasm-init-timeout" must be a number value');
294+
}
295+
const simd = wasm.simd = parseBooleanArg(wasm.simd ?? args['wasm-enable-simd']);
296+
if (typeof simd !== 'undefined' && typeof simd !== 'boolean') {
297+
throw new Error('Flag "wasm.simd"/"wasm-enable-simd" must be a boolean value');
298+
}
299+
const proxy = wasm.proxy = parseBooleanArg(wasm.proxy ?? args['wasm-enable-proxy']);
300+
if (typeof proxy !== 'undefined' && typeof proxy !== 'boolean') {
301+
throw new Error('Flag "wasm.proxy"/"wasm-enable-proxy" must be a boolean value');
302+
}
303+
return wasm;
297304
}
298305

299306
function parseWebglOptions(_args: minimist.ParsedArgs): InferenceSession.WebGLExecutionProviderOption {
300307
return {name: 'webgl'};
301308
}
302309

303310
function parseWebglFlags(args: minimist.ParsedArgs): Partial<Env.WebGLFlags> {
304-
const contextId = args['webgl-context-id'];
311+
const webgl = args.webgl || {};
312+
const contextId = webgl.contextId = webgl.contextId ?? args['webgl-context-id'];
305313
if (contextId !== undefined && contextId !== 'webgl' && contextId !== 'webgl2') {
306-
throw new Error('Flag "webgl-context-id" is invalid');
314+
throw new Error('Flag "webgl.contextId"/"webgl-context-id" is invalid');
307315
}
308-
const matmulMaxBatchSize = args['webgl-matmul-max-batch-size'];
316+
const matmulMaxBatchSize = webgl.matmulMaxBatchSize = webgl.matmulMaxBatchSize ?? args['webgl-matmul-max-batch-size'];
309317
if (matmulMaxBatchSize !== undefined && typeof matmulMaxBatchSize !== 'number') {
310-
throw new Error('Flag "webgl-matmul-max-batch-size" must be a number value');
318+
throw new Error('Flag "webgl.matmulMaxBatchSize"/"webgl-matmul-max-batch-size" must be a number value');
311319
}
312-
const textureCacheMode = args['webgl-texture-cache-mode'];
320+
const textureCacheMode = webgl.textureCacheMode = webgl.textureCacheMode ?? args['webgl-texture-cache-mode'];
313321
if (textureCacheMode !== undefined && textureCacheMode !== 'initializerOnly' && textureCacheMode !== 'full') {
314-
throw new Error('Flag "webgl-texture-cache-mode" is invalid');
322+
throw new Error('Flag "webgl.textureCacheMode"/"webgl-texture-cache-mode" is invalid');
315323
}
316-
const pack = args['webgl-texture-pack-mode'];
324+
const pack = webgl.pack = parseBooleanArg(webgl.pack ?? args['webgl-texture-pack-mode']);
317325
if (pack !== undefined && typeof pack !== 'boolean') {
318-
throw new Error('Flag "webgl-texture-pack-mode" is invalid');
326+
throw new Error('Flag "webgl.pack"/"webgl-texture-pack-mode" is invalid');
319327
}
320-
const async = args['webgl-async'];
328+
const async = webgl.async = parseBooleanArg(webgl.async ?? args['webgl-async']);
321329
if (async !== undefined && typeof async !== 'boolean') {
322-
throw new Error('Flag "webgl-async" is invalid');
330+
throw new Error('Flag "webgl.async"/"webgl-async" is invalid');
323331
}
324-
return {contextId, matmulMaxBatchSize, textureCacheMode, pack};
332+
return webgl;
325333
}
326334

327335
function parseWebgpuFlags(args: minimist.ParsedArgs): Partial<Env.WebGpuFlags> {
328-
const profilingMode = args['webgpu-profiling-mode'];
336+
const webgpu = args.webgpu || {};
337+
const profilingMode = (webgpu.profiling = webgpu.profiling ?? {}).mode =
338+
webgpu?.profiling?.mode ?? webgpu.profilingMode ?? args['webgpu-profiling-mode'];
329339
if (profilingMode !== undefined && profilingMode !== 'off' && profilingMode !== 'default') {
330340
throw new Error('Flag "webgpu-profiling-mode" is invalid');
331341
}
332-
const validateInputContent = args['webgpu-validate-input-content'];
342+
const validateInputContent = webgpu.validateInputContent =
343+
parseBooleanArg(webgpu.validateInputContent ?? args['webgpu-validate-input-content']);
333344
if (validateInputContent !== undefined && typeof validateInputContent !== 'boolean') {
334345
throw new Error('Flag "webgpu-validate-input-content" is invalid');
335346
}
336-
return {profilingMode, validateInputContent};
347+
return webgpu;
337348
}
338349

339350
function parseWebNNOptions(args: minimist.ParsedArgs): InferenceSession.WebNNExecutionProviderOption {
@@ -344,12 +355,11 @@ function parseWebNNOptions(args: minimist.ParsedArgs): InferenceSession.WebNNExe
344355
return {name: 'webnn', deviceType};
345356
}
346357

347-
function parseGlobalEnvFlags(args: minimist.ParsedArgs): NonNullable<TestRunnerCliArgs['globalEnvFlags']> {
358+
function parseGlobalEnvFlags(args: minimist.ParsedArgs) {
348359
const wasm = parseWasmFlags(args);
349360
const webgl = parseWebglFlags(args);
350361
const webgpu = parseWebgpuFlags(args);
351-
const cpuFlags = parseCpuFlags(args);
352-
return {webgl, wasm, webgpu, ...cpuFlags};
362+
return {webgl, wasm, webgpu};
353363
}
354364

355365
export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs {
@@ -394,25 +404,33 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs
394404
}
395405
}
396406

397-
const globalEnvFlags = parseGlobalEnvFlags(args);
398-
399407
// Options:
400408
// --log-verbose=<...>
401409
// --log-info=<...>
402410
// --log-warning=<...>
403411
// --log-error=<...>
404412
const logConfig = parseLogConfig(args);
405-
globalEnvFlags.logLevel = logConfig[0]?.config.minimalSeverity;
413+
let logLevel = logConfig[0]?.config.minimalSeverity;
414+
406415
// Option: -p, --profile
407416
const profile = (args.profile || args.p) ? true : false;
408417
if (profile) {
409418
logConfig.push({category: 'Profiler.session', config: {minimalSeverity: 'verbose'}});
410419
logConfig.push({category: 'Profiler.node', config: {minimalSeverity: 'verbose'}});
411420
logConfig.push({category: 'Profiler.op', config: {minimalSeverity: 'verbose'}});
412421
logConfig.push({category: 'Profiler.backend', config: {minimalSeverity: 'verbose'}});
413-
globalEnvFlags.logLevel = 'verbose';
422+
logLevel = 'verbose';
414423
}
415424

425+
// Option: -t, --trace
426+
const trace = parseBooleanArg(args.trace || args.t, false);
427+
428+
// Options:
429+
// --wasm.<...>=<...>
430+
// --webgl.<...>=<...>
431+
// --webgpu.<...>=<...>
432+
const globalEnvFlags = {...parseGlobalEnvFlags(args), debug, trace, logLevel};
433+
416434
// Option: -P[=<...>], --perf[=<...>]
417435
const perfArg = (args.perf || args.P);
418436
const perf = perfArg ? true : false;

js/web/test/test-main.ts

+1-43
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,7 @@ if (ORT_WEB_TEST_CONFIG.model.some(testGroup => testGroup.tests.some(test => tes
1919
}
2020

2121
// set flags
22-
const options = ORT_WEB_TEST_CONFIG.options;
23-
if (options.debug !== undefined) {
24-
ort.env.debug = options.debug;
25-
}
26-
if (options.globalEnvFlags) {
27-
const flags = options.globalEnvFlags;
28-
if (flags.logLevel !== undefined) {
29-
ort.env.logLevel = flags.logLevel;
30-
}
31-
if (flags.webgl?.contextId !== undefined) {
32-
ort.env.webgl.contextId = flags.webgl.contextId;
33-
}
34-
if (flags.webgl?.matmulMaxBatchSize !== undefined) {
35-
ort.env.webgl.matmulMaxBatchSize = flags.webgl.matmulMaxBatchSize;
36-
}
37-
if (flags.webgl?.textureCacheMode !== undefined) {
38-
ort.env.webgl.textureCacheMode = flags.webgl.textureCacheMode;
39-
}
40-
if (flags.webgl?.pack !== undefined) {
41-
ort.env.webgl.pack = flags.webgl.pack;
42-
}
43-
if (flags.webgl?.async !== undefined) {
44-
ort.env.webgl.async = flags.webgl.async;
45-
}
46-
if (flags.wasm?.numThreads !== undefined) {
47-
ort.env.wasm.numThreads = flags.wasm.numThreads;
48-
}
49-
if (flags.wasm?.simd !== undefined) {
50-
ort.env.wasm.simd = flags.wasm.simd;
51-
}
52-
if (flags.wasm?.proxy !== undefined) {
53-
ort.env.wasm.proxy = flags.wasm.proxy;
54-
}
55-
if (flags.wasm?.initTimeout !== undefined) {
56-
ort.env.wasm.initTimeout = flags.wasm.initTimeout;
57-
}
58-
if (flags.webgpu?.profilingMode !== undefined) {
59-
ort.env.webgpu.profiling = {mode: flags.webgpu.profilingMode};
60-
}
61-
if (flags.webgpu?.validateInputContent !== undefined) {
62-
ort.env.webgpu.validateInputContent = flags.webgpu.validateInputContent;
63-
}
64-
}
22+
Object.assign(ort.env, ORT_WEB_TEST_CONFIG.options.globalEnvFlags);
6523

6624
// Set logging configuration
6725
for (const logConfig of ORT_WEB_TEST_CONFIG.log) {

tools/ci_build/github/azure-pipelines/templates/web-browserstack-ci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
timeoutInMinutes: 20
7272
- script: |
7373
export ORT_WEB_TEST_BS_BROWSERS=BS_MAC_11_Safari_14,BS_MAC_11_Chrome_91,BS_ANDROID_11_Pixel_5
74-
npm test -- suite0 --env=bs --wasm-init-timeout=30000 --file-cache
74+
npm test -- suite0 -e=bs --wasm.initTimeout=30000 --file-cache
7575
workingDirectory: '$(Build.SourcesDirectory)/js/web'
7676
displayName: 'npm test (Suite0, BS_ANDROID, BS_MAC)'
7777
env:
@@ -80,7 +80,7 @@ jobs:
8080
continueOnError: true
8181
- script: |
8282
export ORT_WEB_TEST_BS_BROWSERS=BS_IOS_14_iPhoneXS
83-
npm test -- suite1 --env=bs --wasm-init-timeout=30000 --file-cache --backend=wasm
83+
npm test -- suite1 -e=bs --wasm.initTimeout=30000 --file-cache --backend=wasm
8484
workingDirectory: '$(Build.SourcesDirectory)/js/web'
8585
displayName: 'npm test (Suite1, BS_IOS)'
8686
continueOnError: true
@@ -95,4 +95,3 @@ jobs:
9595
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3
9696
displayName: 'Clean Agent Directories'
9797
condition: always()
98-

tools/ci_build/github/azure-pipelines/templates/win-web-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ jobs:
173173
displayName: 'Run ort-web tests (Suite1, webgpu, IO-binding=gpu-location)'
174174
condition: eq('${{ parameters.RunWebGpuTests }}', 'true')
175175
- script: |
176-
npm test -- --webgl-texture-pack-mode -b=webgl -e=chrome --karma-debug
176+
npm test -- --webgl.pack -b=webgl -e=chrome --karma-debug
177177
workingDirectory: '$(Build.SourcesDirectory)\js\web'
178178
displayName: 'Run ort-web tests - WebGL: packed mode'
179179
- script: |
180-
npm test -- --wasm-enable-proxy -b=wasm -e=chrome --karma-debug
180+
npm test -- --wasm.proxy -b=wasm -e=chrome --karma-debug
181181
workingDirectory: '$(Build.SourcesDirectory)\js\web'
182182
displayName: 'Run ort-web tests - WebAssembly: proxy'
183183
condition: and(succeeded(), eq('${{ parameters.BuildConfig }}', 'Release'))

tools/ci_build/github/azure-pipelines/templates/win-web-multi-browsers.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ jobs:
6868
workingDirectory: '$(Build.SourcesDirectory)\js\web'
6969
displayName: 'npm ci /js/web/'
7070
- script: |
71-
npm test -- suite0 -b=wasm,webgl --wasm-init-timeout=30000 --file-cache
71+
npm test -- suite0 -b=wasm,webgl --wasm.initTimeout=30000 --file-cache
7272
workingDirectory: '$(Build.SourcesDirectory)\js\web'
7373
displayName: 'npm test (Suite0, Chrome)'
7474
- script: |
75-
npm test -- suite0 -b=wasm,webgl --env=firefox --wasm-init-timeout=30000 --file-cache
75+
npm test -- suite0 -b=wasm,webgl -e=firefox --wasm.initTimeout=30000 --file-cache
7676
workingDirectory: '$(Build.SourcesDirectory)\js\web'
7777
displayName: 'npm test (Suite0, Firefox)'
7878
- script: |
79-
npm test -- suite0 -b=wasm,webgl --env=edge --wasm-init-timeout=30000 --file-cache
79+
npm test -- suite0 -b=wasm,webgl -e=edge --wasm.initTimeout=30000 --file-cache
8080
workingDirectory: '$(Build.SourcesDirectory)\js\web'
8181
displayName: 'npm test (Suite0, Edge)'
8282
- task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3

0 commit comments

Comments
 (0)