Skip to content

Commit

Permalink
[js/webgpu] use Headless for webgpu test by default (#19702)
Browse files Browse the repository at this point in the history
### Description
use Chromium Headless for webgpu test by default. Still use normal
Chromium with window when debug=true or perfMode=true.

Use the
[`--headless=new`](https://developer.chrome.com/docs/chromium/new-headless)
mode.



### Motivation and Context
try to use a more stable way to launch npm tests to avoid a "chrome not
found" issue in pipeline, which may potentially caused by windowed
application.
  • Loading branch information
fs-eire committed Mar 15, 2024
1 parent cf4537e commit 7c081b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
4 changes: 2 additions & 2 deletions js/web/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ module.exports = function(config) {
hostname,
listenAddress,
customLaunchers: {
// the following flags are used to make sure Edge on CI agents to initialize WebGPU correctly.
// Chromium-based browsers
EdgeTest: {base: 'Edge', flags: chromiumFlags},
ChromeTest: {base: 'Chrome', flags: chromiumFlags},
ChromeTestHeadless: {base: 'ChromeHeadless', flags: chromiumFlags},
ChromeCanaryTest: {base: 'ChromeCanary', flags: chromiumFlags},

//
// ==== BrowserStack browsers ====
//
Expand Down
29 changes: 7 additions & 22 deletions js/web/script/test-runner-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,13 @@ async function main() {
npmlog.info('TestRunnerCli.Run', '(4/4) Running karma to start test runner...');
const webgpu = args.backends.indexOf('webgpu') > -1;
const webnn = args.backends.indexOf('webnn') > -1;
const browser = getBrowserNameFromEnv(
args.env,
args.bundleMode === 'perf' ? 'perf' :
args.debug ? 'debug' :
'test',
webgpu);
const browser = getBrowserNameFromEnv(args.env);
const karmaArgs = ['karma', 'start', `--browsers ${browser}`];
const chromiumFlags = ['--enable-features=SharedArrayBuffer', ...args.chromiumFlags];
if (args.bundleMode === 'dev' && !args.debug) {
// use headless for 'test' mode (when 'perf' and 'debug' are OFF)
chromiumFlags.push('--headless=new');
}
if (args.debug) {
karmaArgs.push('--log-level info --timeout-mocha 9999999');
chromiumFlags.push('--remote-debugging-port=9333');
Expand Down Expand Up @@ -615,10 +614,10 @@ async function main() {
fs.writeJSONSync(path.join(TEST_ROOT, './testdata-config.json'), config);
}

function getBrowserNameFromEnv(env: TestRunnerCliArgs['env'], mode: 'debug'|'perf'|'test', webgpu: boolean) {
function getBrowserNameFromEnv(env: TestRunnerCliArgs['env']) {
switch (env) {
case 'chrome':
return selectChromeBrowser(mode, webgpu);
return 'ChromeTest';
case 'edge':
return 'EdgeTest';
case 'firefox':
Expand All @@ -633,20 +632,6 @@ async function main() {
throw new Error(`env "${env}" not supported.`);
}
}

function selectChromeBrowser(mode: 'debug'|'perf'|'test', webgpu: boolean) {
if (webgpu) {
return 'ChromeTest';
} else {
switch (mode) {
case 'debug':
case 'perf':
return 'ChromeTest';
default:
return 'ChromeTestHeadless';
}
}
}
}

void main();

0 comments on commit 7c081b2

Please sign in to comment.