2021-04-27 07:04:25 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
2023-10-06 20:37:37 +00:00
|
|
|
// Load onnxruntime-common and testdata-config.
|
2021-05-15 01:15:38 +00:00
|
|
|
// NOTE: this need to be called before import any other library.
|
2023-10-06 20:37:37 +00:00
|
|
|
import * as ort from 'onnxruntime-common';
|
|
|
|
|
|
2021-05-15 01:15:38 +00:00
|
|
|
const ORT_WEB_TEST_CONFIG = require('./testdata-config.json') as Test.Config;
|
2021-04-27 07:04:25 +00:00
|
|
|
|
|
|
|
|
import * as platform from 'platform';
|
|
|
|
|
|
|
|
|
|
import {Logger} from '../lib/onnxjs/instrument';
|
|
|
|
|
|
|
|
|
|
import {Test} from './test-types';
|
|
|
|
|
|
2021-05-15 01:15:38 +00:00
|
|
|
if (ORT_WEB_TEST_CONFIG.model.some(testGroup => testGroup.tests.some(test => test.backend === 'cpu'))) {
|
|
|
|
|
// require onnxruntime-node
|
|
|
|
|
require('../../node');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set flags
|
2024-03-13 19:00:36 +00:00
|
|
|
Object.assign(ort.env, ORT_WEB_TEST_CONFIG.options.globalEnvFlags);
|
2021-04-27 07:04:25 +00:00
|
|
|
|
|
|
|
|
// Set logging configuration
|
2021-05-07 19:12:37 +00:00
|
|
|
for (const logConfig of ORT_WEB_TEST_CONFIG.log) {
|
2021-04-27 07:04:25 +00:00
|
|
|
Logger.set(logConfig.category, logConfig.config);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 15:35:19 +00:00
|
|
|
import {ModelTestContext, OpTestContext, ProtoOpTestContext, runModelTestSet, runOpTest} from './test-runner';
|
2021-04-27 07:04:25 +00:00
|
|
|
import {readJsonFile} from './test-shared';
|
|
|
|
|
|
|
|
|
|
// Unit test
|
2021-05-07 19:12:37 +00:00
|
|
|
if (ORT_WEB_TEST_CONFIG.unittest) {
|
2021-04-27 07:04:25 +00:00
|
|
|
require('./unittests');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set file cache
|
2021-05-07 19:12:37 +00:00
|
|
|
if (ORT_WEB_TEST_CONFIG.fileCacheUrls) {
|
2021-04-27 07:04:25 +00:00
|
|
|
before('prepare file cache', async () => {
|
2021-05-07 19:12:37 +00:00
|
|
|
const allJsonCache = await Promise.all(ORT_WEB_TEST_CONFIG.fileCacheUrls!.map(readJsonFile)) as Test.FileCache[];
|
2021-04-27 07:04:25 +00:00
|
|
|
for (const cache of allJsonCache) {
|
|
|
|
|
ModelTestContext.setCache(cache);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function shouldSkipTest(test: Test.ModelTest|Test.OperatorTest) {
|
|
|
|
|
if (!test.cases || test.cases.length === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-08-03 21:20:20 +00:00
|
|
|
if (!test.platformCondition) {
|
2021-04-27 07:04:25 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!platform.description) {
|
|
|
|
|
throw new Error('failed to check current platform');
|
|
|
|
|
}
|
2023-08-03 21:20:20 +00:00
|
|
|
const regex = new RegExp(test.platformCondition);
|
2021-04-27 07:04:25 +00:00
|
|
|
return !regex.test(platform.description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ModelTests
|
2021-05-07 19:12:37 +00:00
|
|
|
for (const group of ORT_WEB_TEST_CONFIG.model) {
|
2021-04-27 07:04:25 +00:00
|
|
|
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 () => {
|
2024-01-09 18:10:57 +00:00
|
|
|
context = await ModelTestContext.create(test, ORT_WEB_TEST_CONFIG.profile, ORT_WEB_TEST_CONFIG.options);
|
2021-04-27 07:04:25 +00:00
|
|
|
});
|
|
|
|
|
|
2023-09-12 23:59:13 +00:00
|
|
|
after('release session', async () => {
|
2021-04-27 07:04:25 +00:00
|
|
|
if (context) {
|
2023-09-12 23:59:13 +00:00
|
|
|
await context.release();
|
2021-04-27 07:04:25 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const testCase of test.cases) {
|
|
|
|
|
it(testCase.name, async () => {
|
2021-05-03 22:03:25 +00:00
|
|
|
await runModelTestSet(context, testCase, test.name);
|
2021-04-27 07:04:25 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OpTests
|
2021-05-07 19:12:37 +00:00
|
|
|
for (const group of ORT_WEB_TEST_CONFIG.op) {
|
2021-04-27 07:04:25 +00:00
|
|
|
describe(`#OpTest# - ${group.name}`, () => {
|
|
|
|
|
for (const test of group.tests) {
|
|
|
|
|
const describeTest = shouldSkipTest(test) ? describe.skip : describe;
|
2023-07-06 15:35:19 +00:00
|
|
|
const backend = test.backend!;
|
|
|
|
|
const useProtoOpTest = backend !== 'webgl';
|
|
|
|
|
describeTest(`[${backend}]${test.operator} - ${test.name}`, () => {
|
|
|
|
|
let context: ProtoOpTestContext|OpTestContext;
|
2021-04-27 07:04:25 +00:00
|
|
|
|
|
|
|
|
before('Initialize Context', async () => {
|
2023-08-16 04:00:23 +00:00
|
|
|
context = useProtoOpTest ? new ProtoOpTestContext(test, ORT_WEB_TEST_CONFIG.options.sessionOptions) :
|
|
|
|
|
new OpTestContext(test);
|
2021-04-27 07:04:25 +00:00
|
|
|
await context.init();
|
2021-05-07 19:12:37 +00:00
|
|
|
if (ORT_WEB_TEST_CONFIG.profile) {
|
2023-07-06 15:35:19 +00:00
|
|
|
if (context instanceof ProtoOpTestContext) {
|
|
|
|
|
context.session.startProfiling();
|
|
|
|
|
} else {
|
|
|
|
|
OpTestContext.profiler.start();
|
|
|
|
|
}
|
2021-04-27 07:04:25 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-06 15:35:19 +00:00
|
|
|
after('Dispose Context', async () => {
|
2023-08-03 21:20:20 +00:00
|
|
|
if (context) {
|
|
|
|
|
if (ORT_WEB_TEST_CONFIG.profile) {
|
|
|
|
|
if (context instanceof ProtoOpTestContext) {
|
|
|
|
|
context.session.endProfiling();
|
|
|
|
|
} else {
|
|
|
|
|
OpTestContext.profiler.stop();
|
|
|
|
|
}
|
2023-07-06 15:35:19 +00:00
|
|
|
}
|
2023-08-03 21:20:20 +00:00
|
|
|
await context.dispose();
|
2021-04-27 07:04:25 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const testCase of test.cases) {
|
|
|
|
|
it(testCase.name, async () => {
|
|
|
|
|
await runOpTest(testCase, context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|