onnxruntime/js/web/test/test-main.ts
Ye Wang 83dc22585c
Second round cherry-pick to rel-1.9.0 (#9062)
* Adding async fetching for webgl backend (#8951)

* Adding async fetching for webgl backend

* fix PR comments and CI failure.

* fixing a bug

* adding a flag

* Enable linking in exception throwing support library when build onnxruntime wasm. (#8973)

* Enable linking in exception throwing support library when build onnxruntime webassembly containing onnxruntime-extensions.

* Add flag in build.py to enable linking exceptions throwing library.

* Update onnxruntime-extensions document and bind custom_ops build flag with use_extensions.

* Update doc.

* Update cgmanifest.json.

Co-authored-by: Zuwei Zhao <zuzhao@microsoft.com>

* Remove document text from error message in a couple of ops (#9003)

* do not add pkg wheel entry to the index html file if it already exists (#9004)

* do not add pkg wheel entry to the index html file if it already exists

* [js/web] fix ort web e2e test (#9025)

* Fix cmake POWER10 detection

Recent commit 60c98a8 changed variable mlas_common_srcs which affects
POWER10 detection.

* Fix Where op type reduction processing (#9033)

* Update type reduction script to track Where Op's second input type.

* Clean up op_kernel_type_control.h includes.

* Use more maintainable include.

* Fix ROCm wheels CI pipeline break by installing latest protobuf from source (#9047)

* install protobuf from source

* fix rm command in Dockerfile

* fix options on rm command

* fix cd into protobuf source directory

* try again

* remove strip step

* debug list the files

* ls on /usr

* more debug

* more debug

* adjust LD_LIBRARY_PATH

* try remove protobuf before ORT build

* [js/web] a bugfix and add tests for wasm proxy worker (#9048)

* [js/web] add tests for wasm proxy worker

* fix script src override

* Set onnxruntime_DISABLE_RTTI to default OFF (#9049)

Co-authored-by: Du Li <duli1@microsoft.com>
Co-authored-by: Zuwei Zhao <4123666+Zuwei-Zhao@users.noreply.github.com>
Co-authored-by: Zuwei Zhao <zuzhao@microsoft.com>
Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com>
Co-authored-by: liqun Fu <liqfu@microsoft.com>
Co-authored-by: Yulong Wang <yulongw@microsoft.com>
Co-authored-by: Rajalakshmi Srinivasaraghavan <rajis@linux.ibm.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Co-authored-by: Suffian Khan <sukha@microsoft.com>
Co-authored-by: Changming Sun <chasun@microsoft.com>
2021-09-15 18:02:07 -07:00

156 lines
4.5 KiB
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Load onnxruntime-web and testdata-config.
// NOTE: this need to be called before import any other library.
const ort = require('..');
const ORT_WEB_TEST_CONFIG = require('./testdata-config.json') as Test.Config;
import * as platform from 'platform';
import {Logger} from '../lib/onnxjs/instrument';
import {Test} from './test-types';
if (ORT_WEB_TEST_CONFIG.model.some(testGroup => testGroup.tests.some(test => test.backend === 'cpu'))) {
// require onnxruntime-node
require('../../node');
}
// set flags
const options = ORT_WEB_TEST_CONFIG.options;
if (options.debug !== undefined) {
ort.env.debug = options.debug;
}
if (options.globalEnvFlags) {
const flags = options.globalEnvFlags;
if (flags.logLevel !== undefined) {
ort.env.logLevel = flags.logLevel;
}
if (flags.webgl?.contextId !== undefined) {
ort.env.webgl.contextId = flags.webgl.contextId;
}
if (flags.webgl?.matmulMaxBatchSize !== undefined) {
ort.env.webgl.matmulMaxBatchSize = flags.webgl.matmulMaxBatchSize;
}
if (flags.webgl?.textureCacheMode !== undefined) {
ort.env.webgl.textureCacheMode = flags.webgl.textureCacheMode;
}
if (flags.webgl?.pack !== undefined) {
ort.env.webgl.pack = flags.webgl.pack;
}
if (flags.webgl?.async !== undefined) {
ort.env.webgl.async = flags.webgl.async;
}
if (flags.wasm?.numThreads !== undefined) {
ort.env.wasm.numThreads = flags.wasm.numThreads;
}
if (flags.wasm?.simd !== undefined) {
ort.env.wasm.simd = flags.wasm.simd;
}
if (flags.wasm?.proxy !== undefined) {
ort.env.wasm.proxy = flags.wasm.proxy;
}
if (flags.wasm?.initTimeout !== undefined) {
ort.env.wasm.initTimeout = flags.wasm.initTimeout;
}
}
// Set logging configuration
for (const logConfig of ORT_WEB_TEST_CONFIG.log) {
Logger.set(logConfig.category, logConfig.config);
}
import {ModelTestContext, OpTestContext, runModelTestSet, runOpTest} from './test-runner';
import {readJsonFile} from './test-shared';
// Unit test
if (ORT_WEB_TEST_CONFIG.unittest) {
require('./unittests');
}
// Set file cache
if (ORT_WEB_TEST_CONFIG.fileCacheUrls) {
before('prepare file cache', async () => {
const allJsonCache = await Promise.all(ORT_WEB_TEST_CONFIG.fileCacheUrls!.map(readJsonFile)) as Test.FileCache[];
for (const cache of allJsonCache) {
ModelTestContext.setCache(cache);
}
});
}
function shouldSkipTest(test: Test.ModelTest|Test.OperatorTest) {
if (!test.cases || test.cases.length === 0) {
return true;
}
if (!test.condition) {
return false;
}
if (!platform.description) {
throw new Error('failed to check current platform');
}
const regex = new RegExp(test.condition);
return !regex.test(platform.description);
}
// ModelTests
for (const group of ORT_WEB_TEST_CONFIG.model) {
describe(`#ModelTest# - ${group.name}`, () => {
for (const test of group.tests) {
const describeTest = shouldSkipTest(test) ? describe.skip : describe;
describeTest(`[${test.backend}] ${test.name}`, () => {
let context: ModelTestContext;
before('prepare session', async () => {
context = await ModelTestContext.create(test, ORT_WEB_TEST_CONFIG.profile);
});
after('release session', () => {
if (context) {
context.release();
}
});
for (const testCase of test.cases) {
it(testCase.name, async () => {
await runModelTestSet(context, testCase, test.name);
});
}
});
}
});
}
// OpTests
for (const group of ORT_WEB_TEST_CONFIG.op) {
describe(`#OpTest# - ${group.name}`, () => {
for (const test of group.tests) {
const describeTest = shouldSkipTest(test) ? describe.skip : describe;
describeTest(`[${test.backend!}]${test.operator} - ${test.name}`, () => {
let context: OpTestContext;
before('Initialize Context', async () => {
context = new OpTestContext(test);
await context.init();
if (ORT_WEB_TEST_CONFIG.profile) {
OpTestContext.profiler.start();
}
});
after('Dispose Context', () => {
if (ORT_WEB_TEST_CONFIG.profile) {
OpTestContext.profiler.stop();
}
context.dispose();
});
for (const testCase of test.cases) {
it(testCase.name, async () => {
await runOpTest(testCase, context);
});
}
});
}
});
}