Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OVJS] Avoid of usage global variables in tests #26393

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 40 additions & 38 deletions src/bindings/js/node/tests/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@

const { addon: ov } = require('../..');
const assert = require('assert');
const { describe, it, before } = require('node:test');
const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');

describe('ov basic tests.', () => {

let testXml = null;
let core = null;
let model = null;
let compiledModel = null;
let modelLike = null;

before(async () => {
await isModelAvailable(testModels.testModelFP32);
testXml = getModelPath().xml;
});

const testXml = getModelPath().xml;
const core = new ov.Core();
const model = core.readModelSync(testXml);
const compiledModel = core.compileModelSync(model, 'CPU');
const modelLike = [[model],
[compiledModel]];
beforeEach(() => {
core = new ov.Core();
model = core.readModelSync(testXml);
compiledModel = core.compileModelSync(model, 'CPU');
modelLike = [model,
compiledModel];
});

it('Core.getAvailableDevices()', () => {
const devices = core.getAvailableDevices();
Expand Down Expand Up @@ -164,18 +172,19 @@ describe('ov basic tests.', () => {

});

describe('Output class', () => {
describe('ov.Model/ov.CompiledModel output()', () => {

it('Output type', () => {
it('model.output() type', () => {
assert.ok(model.output() instanceof ov.Output);
});

it('ConstOutput type', () => {
it('compiledModel.output() type', () => {
assert.ok(compiledModel.output() instanceof ov.ConstOutput);
});

modelLike.forEach(([obj]) => {
it('Output getters and properties', () => {
it('output() methods/properties', () => {

modelLike.forEach((obj) => {
assert.strictEqual(obj.outputs.length, 1);
// tests for an obj with one output
assert.strictEqual(obj.output().toString(), 'fc_out');
Expand All @@ -186,60 +195,53 @@ describe('ov basic tests.', () => {
assert.strictEqual(obj.output().getAnyName(), 'fc_out');
assert.strictEqual(obj.output().anyName, 'fc_out');
});
});

});
});

describe('Input class for ov::Input<const ov::Node>', () => {
describe('ov.Model/ov.CompiledModel input()', () => {

it('Output type', () => {
it('ov.Model.input() type', () => {
assert.ok(model.input() instanceof ov.Output);
});

it('ConstOutput type', () => {
it('ov.CompiledModel.input() type', () => {
assert.ok(compiledModel.input() instanceof ov.ConstOutput);
});

modelLike.forEach(([obj]) => {
it('input() is typeof object', () => {
assert.strictEqual(typeof obj.input(), 'object');
});
it('input() methods/properties', () => {
modelLike.forEach((obj) => {

it('inputs property', () => {
assert.strictEqual(typeof obj.input(), 'object');
assert.strictEqual(obj.inputs.length, 1);
});

it('input().toString()', () => {
assert.strictEqual(obj.input().toString(), 'data');
});

it('input(idx: number).ToString() method', () => {
assert.strictEqual(obj.input(0).toString(), 'data');
});

it('input(tensorName: string).ToString() method', () => {
assert.strictEqual(obj.input('data').toString(), 'data');
});

it('input().getAnyName() and anyName', () => {
assert.strictEqual(obj.input().getAnyName(), 'data');
assert.strictEqual(obj.input().anyName, 'data');
});

it('input(idx).shape property with dimensions', () => {
assert.deepStrictEqual(obj.input(0).shape, [1, 3, 32, 32]);
assert.deepStrictEqual(obj.input(0).getShape(), [1, 3, 32, 32]);
});

});

});

describe('Test exportModel()/importModel()', () => {
const userStream = compiledModel.exportModelSync();
const epsilon = 0.5;
const tensor = Float32Array.from({ length: 3072 }, () => (Math.random() + epsilon));
const inferRequest = compiledModel.createInferRequest();
const res1 = inferRequest.infer([tensor]);
let userStream = null;
let res1 = null;

before( () => {
const core = new ov.Core();
const model = core.readModelSync(testXml);
const compiledModel = core.compileModelSync(model, 'CPU');
userStream = compiledModel.exportModelSync();
const inferRequest = compiledModel.createInferRequest();
res1 = inferRequest.infer([tensor]);
});

it('Test importModelSync(stream, device)', () => {
const newCompiled = core.importModelSync(userStream, 'CPU');
Expand Down
27 changes: 17 additions & 10 deletions src/bindings/js/node/tests/unit/compiled_model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@

const { addon: ov } = require('../..');
const assert = require('assert');
const { describe, it, before } = require('node:test');
const { describe, it, before, beforeEach } = require('node:test');
const { testModels, getModelPath, isModelAvailable } = require('./utils.js');

describe('ov.CompiledModel tests', () => {


let testXml = null;
let core = null;
let compiledModel = null;

before(async () => {
await isModelAvailable(testModels.testModelFP32);
testXml = getModelPath().xml;
core = new ov.Core();
});

beforeEach( () => {
const properties = {
'AUTO_BATCH_TIMEOUT': '1',
};
compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);
});

const testXml = getModelPath().xml;
const core = new ov.Core();
const properties = {
'AUTO_BATCH_TIMEOUT': '1',
};
const compiledModel = core.compileModelSync(testXml, 'BATCH:CPU', properties);

describe('getProperty()', () => {
it('returns the value of property from compiled model', () => {
Expand All @@ -39,7 +46,7 @@ describe('ov.CompiledModel tests', () => {

describe('setProperty()', () => {
it('sets a properties for compiled model', () => {
properties['AUTO_BATCH_TIMEOUT'] = '1000';
const properties = {'AUTO_BATCH_TIMEOUT': '1000'};
assert.doesNotThrow(() => compiledModel.setProperty(properties));
});

Expand All @@ -64,7 +71,7 @@ describe('ov.CompiledModel tests', () => {
});

it('returns the set property of the compiled model', () => {
properties['AUTO_BATCH_TIMEOUT'] = '123';
const properties = {'AUTO_BATCH_TIMEOUT': '123'};
compiledModel.setProperty(properties);
assert.strictEqual(compiledModel.getProperty('AUTO_BATCH_TIMEOUT'), 123);
});
Expand Down
7 changes: 5 additions & 2 deletions src/bindings/js/node/tests/unit/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

const { addon: ov } = require('../..');
const assert = require('assert');
const { describe, it } = require('node:test');
const { describe, it, beforeEach } = require('node:test');

describe('ov.Core tests', () => {

const core = new ov.Core();
let core = null;
beforeEach(() => {
core = new ov.Core();
});

it('Core.setProperty()', () => {
const tmpDir = '/tmp';
Expand Down
Loading
Loading