mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-22 19:23:30 +00:00
### Description Merge main to WindowsAI ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> --------- Signed-off-by: Nash <george.nash@intel.com> Signed-off-by: Yiming Hu <yiming.hu@amd.com> Signed-off-by: Liqun Fu <liqfu@microsoft.com> Co-authored-by: Kaz Nishimura <kazssym@linuxfront.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com> Co-authored-by: Nat Kershaw (MSFT) <nakersha@microsoft.com> Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Co-authored-by: Changming Sun <chasun@microsoft.com> Co-authored-by: zesongw <zesong.wang@intel.com> Co-authored-by: Yi Zhang <zhanyi@microsoft.com> Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com> Co-authored-by: Yifan Li <109183385+yf711@users.noreply.github.com> Co-authored-by: simonjub <78098752+simonjub@users.noreply.github.com> Co-authored-by: PeixuanZuo <94887879+PeixuanZuo@users.noreply.github.com> Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> Co-authored-by: Arthur Islamov <arthur@islamov.ai> Co-authored-by: Jambay Kinley <jambaykinley@microsoft.com> Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com> Co-authored-by: Wei-Sheng Chin <wschin@outlook.com> Co-authored-by: Bowen Bao <bowbao@microsoft.com> Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com> Co-authored-by: Numfor Tiapo <numsmt2@gmail.com> Co-authored-by: Vincent Wang <wangwchpku@outlook.com> Co-authored-by: Pranav Sharma <prs@microsoft.com> Co-authored-by: George Nash <george.nash@intel.com> Co-authored-by: Abhishek Jindal <abjindal@microsoft.com> Co-authored-by: pengwa <pengwa@microsoft.com> Co-authored-by: Yiming Hu <woinck@users.noreply.github.com> Co-authored-by: Jiajia Qin <jiajia.qin@intel.com> Co-authored-by: Lukas Berbuer <36054362+lukasberbuer@users.noreply.github.com> Co-authored-by: Wanming Lin <wanming.lin@intel.com> Co-authored-by: Xavier Dupré <xadupre@users.noreply.github.com> Co-authored-by: aimilefth <60664743+aimilefth@users.noreply.github.com> Co-authored-by: Baiju Meswani <bmeswani@microsoft.com> Co-authored-by: Adam Pocock <adam.pocock@oracle.com> Co-authored-by: Chi Lo <54722500+chilo-ms@users.noreply.github.com> Co-authored-by: RandySheriffH <48490400+RandySheriffH@users.noreply.github.com> Co-authored-by: Randy Shuai <rashuai@microsoft.com> Co-authored-by: Vadym Stupakov <vadim.stupakov@gmail.com> Co-authored-by: Jian Chen <cjian@microsoft.com> Co-authored-by: Brian Lambert <98757707+brian-pieces@users.noreply.github.com> Co-authored-by: Nicolò Lucchesi <nicolo.lucchesi@gmail.com> Co-authored-by: liqun Fu <liqfu@microsoft.com> Co-authored-by: trajep <trajepl@gmail.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: Mustafa Ateş Uzun <mustafauzun0@gmail.com> Co-authored-by: MistEO <mistereo@hotmail.com> Co-authored-by: satyajandhyala <satya.k.jandhyala@gmail.com> Co-authored-by: shaahji <96227573+shaahji@users.noreply.github.com> Co-authored-by: Rachel Guo <35738743+YUNQIUGUO@users.noreply.github.com> Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net> Co-authored-by: Caroline Zhu <wolfivyaura@gmail.com> Co-authored-by: Caroline Zhu <carolinezhu@microsoft.com> Co-authored-by: Guenther Schmuelling <guschmue@microsoft.com> Co-authored-by: xhcao <xinghua.cao@intel.com> Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> Co-authored-by: Xu Xing <xing.xu@intel.com> Co-authored-by: Hector Li <hecli@microsoft.com> Co-authored-by: Ye Wang <52801275+wangyems@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: Benedikt Hilmes <benedikt.hilmes@rwth-aachen.de> Co-authored-by: rachguo <rachguo@rachguos-Mac-mini.local> Co-authored-by: George Wu <jywu@microsoft.com> Co-authored-by: JiCheng <wejoncy@163.com> Co-authored-by: Sheil Kumar <smk2007@gmail.com> Co-authored-by: Sheil Kumar <sheilk@microsoft.com> Co-authored-by: cloudhan <guangyunhan@microsoft.com> Co-authored-by: kyoshisuki <143475866+kyoshisuki@users.noreply.github.com> Co-authored-by: aciddelgado <139922440+aciddelgado@users.noreply.github.com> Co-authored-by: tlwu@microsoft.com <tlwu@a100.crj0ad2y1kku1j4yxl4sj10o4e.gx.internal.cloudapp.net> Co-authored-by: Maximilian Müller <44298237+gedoensmax@users.noreply.github.com> Co-authored-by: Tang, Cheng <souptc@gmail.com> Co-authored-by: Cheng Tang <chenta@microsoft.com@orttrainingdev9.d32nl1ml4oruzj4qz3bqlggovf.px.internal.cloudapp.net> Co-authored-by: Cheng Tang <chenta@microsoft.com> Co-authored-by: Jeff Daily <jeff.daily@amd.com> Co-authored-by: cloudhan <cloudhan@outlook.com> Co-authored-by: Yufeng Li <liyufeng1987@gmail.com> Co-authored-by: Zhang Lei <zhang.huanning@hotmail.com> Co-authored-by: Dwayne Robinson <fdwr@hotmail.com> Co-authored-by: Zhipeng Han <zhipeng.han@outlook.com> Co-authored-by: Thiago Crepaldi <thiago.crepaldi@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Patrice Vignola <vignola.patrice@gmail.com> Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com> Co-authored-by: snadampal <87143774+snadampal@users.noreply.github.com> Co-authored-by: Sumit Agarwal <sumitagarwal330@gmail.com> Co-authored-by: Ashwini Khade <askhade@microsoft.com> Co-authored-by: Yang Gu <yang.gu@intel.com> Co-authored-by: Cheng Tang <chenta@a100.crj0ad2y1kku1j4yxl4sj10o4e.gx.internal.cloudapp.net> Co-authored-by: mindest <30493312+mindest@users.noreply.github.com> Co-authored-by: Scott McKay <Scott.McKay@microsoft.com> Co-authored-by: Xavier Dupre <xadupre@microsoft.com@orttrainingdev9.d32nl1ml4oruzj4qz3bqlggovf.px.internal.cloudapp.net> Co-authored-by: guyang3532 <62738430+guyang3532@users.noreply.github.com> Co-authored-by: Carson M <carson@pyke.io> Co-authored-by: sophies927 <107952697+sophies927@users.noreply.github.com>
157 lines
6.6 KiB
JavaScript
157 lines
6.6 KiB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
const fs = require('fs-extra');
|
|
const {spawn} = require('child_process');
|
|
const startServer = require('./simple-http-server');
|
|
const minimist = require('minimist');
|
|
|
|
// copy whole folder to out-side of <ORT_ROOT>/js/ because we need to test in a folder that no `package.json` file
|
|
// exists in its parent folder.
|
|
// here we use <ORT_ROOT>/build/js/e2e/ for the test
|
|
|
|
const TEST_E2E_SRC_FOLDER = __dirname;
|
|
const JS_ROOT_FOLDER = path.resolve(__dirname, '../../..');
|
|
const TEST_E2E_RUN_FOLDER = path.resolve(JS_ROOT_FOLDER, '../build/js/e2e');
|
|
const NPM_CACHE_FOLDER = path.resolve(TEST_E2E_RUN_FOLDER, '../npm_cache');
|
|
const CHROME_USER_DATA_FOLDER = path.resolve(TEST_E2E_RUN_FOLDER, '../user_data');
|
|
fs.emptyDirSync(TEST_E2E_RUN_FOLDER);
|
|
fs.emptyDirSync(NPM_CACHE_FOLDER);
|
|
fs.emptyDirSync(CHROME_USER_DATA_FOLDER);
|
|
fs.copySync(TEST_E2E_SRC_FOLDER, TEST_E2E_RUN_FOLDER);
|
|
|
|
// always use a new folder as user-data-dir
|
|
let nextUserDataDirId = 0;
|
|
function getNextUserDataDir() {
|
|
const dir = path.resolve(CHROME_USER_DATA_FOLDER, nextUserDataDirId.toString())
|
|
nextUserDataDirId++;
|
|
fs.emptyDirSync(dir);
|
|
return dir;
|
|
}
|
|
|
|
// commandline arguments
|
|
const BROWSER = minimist(process.argv.slice(2)).browser || 'Chrome_default';
|
|
|
|
async function main() {
|
|
// find packed package
|
|
const {globbySync} = await import('globby');
|
|
|
|
const ORT_COMMON_FOLDER = path.resolve(JS_ROOT_FOLDER, 'common');
|
|
const ORT_COMMON_PACKED_FILEPATH_CANDIDATES = globbySync('onnxruntime-common-*.tgz', {cwd: ORT_COMMON_FOLDER});
|
|
|
|
const PACKAGES_TO_INSTALL = [];
|
|
|
|
if (ORT_COMMON_PACKED_FILEPATH_CANDIDATES.length === 1) {
|
|
PACKAGES_TO_INSTALL.push(path.resolve(ORT_COMMON_FOLDER, ORT_COMMON_PACKED_FILEPATH_CANDIDATES[0]));
|
|
} else if (ORT_COMMON_PACKED_FILEPATH_CANDIDATES.length > 1) {
|
|
throw new Error('multiple packages found for onnxruntime-common.');
|
|
}
|
|
|
|
const ORT_WEB_FOLDER = path.resolve(JS_ROOT_FOLDER, 'web');
|
|
const ORT_WEB_PACKED_FILEPATH_CANDIDATES = globbySync('onnxruntime-web-*.tgz', {cwd: ORT_WEB_FOLDER});
|
|
if (ORT_WEB_PACKED_FILEPATH_CANDIDATES.length !== 1) {
|
|
throw new Error('cannot find exactly single package for onnxruntime-web.');
|
|
}
|
|
PACKAGES_TO_INSTALL.push(path.resolve(ORT_WEB_FOLDER, ORT_WEB_PACKED_FILEPATH_CANDIDATES[0]));
|
|
|
|
// we start here:
|
|
|
|
// install dev dependencies
|
|
await runInShell(`npm install`);
|
|
|
|
// npm install with "--cache" to install packed packages with an empty cache folder
|
|
await runInShell(`npm install --cache "${NPM_CACHE_FOLDER}" ${PACKAGES_TO_INSTALL.map(i => `"${i}"`).join(' ')}`);
|
|
|
|
// prepare .wasm files for path override testing
|
|
prepareWasmPathOverrideFiles();
|
|
|
|
// test case run in Node.js
|
|
await testAllNodejsCases();
|
|
|
|
// test cases with self-host (ort hosted in same origin)
|
|
await testAllBrowserCases({hostInKarma: true});
|
|
|
|
// test cases without self-host (ort hosted in same origin)
|
|
startServer(path.resolve(TEST_E2E_RUN_FOLDER, 'node_modules', 'onnxruntime-web'));
|
|
await testAllBrowserCases({hostInKarma: false});
|
|
|
|
// no error occurs, exit with code 0
|
|
process.exit(0);
|
|
}
|
|
|
|
function prepareWasmPathOverrideFiles() {
|
|
const folder = path.join(TEST_E2E_RUN_FOLDER, 'test-wasm-path-override');
|
|
const sourceFile = path.join(TEST_E2E_RUN_FOLDER, 'node_modules', 'onnxruntime-web', 'dist', 'ort-wasm.wasm');
|
|
fs.emptyDirSync(folder);
|
|
fs.copyFileSync(sourceFile, path.join(folder, 'ort-wasm.wasm'));
|
|
fs.copyFileSync(sourceFile, path.join(folder, 'renamed.wasm'));
|
|
}
|
|
|
|
async function testAllNodejsCases() {
|
|
await runInShell('node ./node_modules/mocha/bin/mocha ./node-test-main-no-threads.js');
|
|
await runInShell('node --experimental-wasm-threads ./node_modules/mocha/bin/mocha ./node-test-main-no-threads.js');
|
|
|
|
// The multi-threaded export on Node.js is not working. Need a fix. Currently disable these 2 cases temporarily.
|
|
// TODO: re-enable the following commented tests once it's fixed
|
|
//
|
|
// await runInShell('node ./node_modules/mocha/bin/mocha ./node-test-main.js');
|
|
// await runInShell('node --experimental-wasm-threads ./node_modules/mocha/bin/mocha ./node-test-main.js');
|
|
|
|
await runInShell('node ./node_modules/mocha/bin/mocha ./node-test-wasm-path-override-filename.js');
|
|
await runInShell('node ./node_modules/mocha/bin/mocha ./node-test-wasm-path-override-prefix.js');
|
|
}
|
|
|
|
async function testAllBrowserCases({hostInKarma}) {
|
|
await runKarma({hostInKarma, main: './browser-test-webgl.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-webgl.js', ortMain: 'ort.webgl.min.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm.js', ortMain: 'ort.wasm.min.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-multi-session-create.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-no-threads.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-no-threads.js', ortMain: 'ort.wasm-core.min.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-proxy.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-proxy-no-threads.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-path-override-filename.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-path-override-filename.js', ortMain: 'ort.wasm.min.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-path-override-prefix.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-path-override-prefix.js', ortMain: 'ort.wasm.min.js'});
|
|
await runKarma({hostInKarma, main: './browser-test-wasm-image-tensor-image.js'});
|
|
}
|
|
|
|
async function runKarma({hostInKarma, main, browser = BROWSER, ortMain = 'ort.min.js'}) {
|
|
const selfHostFlag = hostInKarma ? '--self-host' : '';
|
|
await runInShell(`npx karma start --single-run --browsers ${browser} ${selfHostFlag} --ort-main=${
|
|
ortMain} --test-main=${main} --user-data=${getNextUserDataDir()}`);
|
|
}
|
|
|
|
async function runInShell(cmd) {
|
|
console.log('===============================================================');
|
|
console.log(' Running command in shell:');
|
|
console.log(' > ' + cmd);
|
|
console.log('===============================================================');
|
|
let complete = false;
|
|
const childProcess = spawn(cmd, {shell: true, stdio: 'inherit', cwd: TEST_E2E_RUN_FOLDER});
|
|
childProcess.on('close', function(code) {
|
|
if (code !== 0) {
|
|
process.exit(code);
|
|
} else {
|
|
complete = true;
|
|
}
|
|
});
|
|
while (!complete) {
|
|
await delay(100);
|
|
}
|
|
}
|
|
|
|
async function delay(ms) {
|
|
return new Promise(function(resolve) {
|
|
setTimeout(function() {
|
|
resolve();
|
|
}, ms);
|
|
});
|
|
}
|
|
|
|
main();
|