Skip to content

Commit

Permalink
[OV JS] Perform inference in electron app in nodejs e2e test (#27131)
Browse files Browse the repository at this point in the history
### Details:
 - Extend e2e test of Node.js API by performing test inference

### Tickets:
 - 154192
  • Loading branch information
vishniakov-nikolai authored Oct 23, 2024
1 parent 56a0dca commit a852c4a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
40 changes: 34 additions & 6 deletions src/bindings/js/node/tests/e2e/demo-electron-app/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
const { app } = require('electron');
const { addon: ov } = require('openvino-node');

app.whenReady().then(() => {
console.log('Creating OpenVINO Runtime Core');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const core = new ov.Core();
console.log('Created OpenVINO Runtime Core');
const epsilon = 0.5; // To avoid very small numbers
const pathToModel = '../tests/unit/test_models/test_model_fp32.xml';

main();

async function main() {
await app.whenReady();

try {
console.log('Creating OpenVINO Runtime Core');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const core = new ov.Core();
console.log('Created OpenVINO Runtime Core');

const model = await core.readModel(pathToModel);
console.log('Model read successfully:', model);
const compiledModel = await core.compileModel(model, 'CPU');
const inferRequest = compiledModel.createInferRequest();
console.log('Infer request created:', inferRequest);

const tensorData = Float32Array.from(
{ length: 3072 },
() => Math.random() + epsilon,
);
const tensor = new ov.Tensor(ov.element.f32, [1, 3, 32, 32], tensorData);
console.log('Tensor created:', tensor);

const result = await inferRequest.inferAsync([tensor]);
console.log('Infer request result:', result);
} catch (error) {
console.error('Error:', error);
app.exit(1);
}

app.exit(0);
});
}
29 changes: 15 additions & 14 deletions src/bindings/js/node/tests/e2e/electron-app.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
/* global describe, it, before, after */
const fs = require('node:fs');
const util = require('node:util');
const assert = require('node:assert');
const { exec } = require('child_process');
const execPromise = util.promisify(exec);
const { testModels, downloadTestModel } = require('../unit/utils.js');

describe('E2E testing for OpenVINO as an Electron dependency.', function() {
this.timeout(50000);

before((done) => {
exec(
'cp -r ./tests/e2e/demo-electron-app/ demo-electron-app-project',
(error) => {
if (error) {
console.error(`exec error: ${error}`);

return done(error);
}

done();
},
);
before(async () => {
await downloadTestModel(testModels.testModelFP32);
await execPromise('cp -r ./tests/e2e/demo-electron-app/ demo-electron-app-project');
});

it('should install dependencies', (done) => {
Expand All @@ -37,7 +30,7 @@ describe('E2E testing for OpenVINO as an Electron dependency.', function() {
});

it('should run electron package and verify output', (done) => {
exec('cd demo-electron-app-project && npm start', (error, stdout) => {
exec(`cd demo-electron-app-project && npm start`, (error, stdout) => {
if (error) {
console.error(`exec error: ${error}`);

Expand All @@ -48,6 +41,14 @@ describe('E2E testing for OpenVINO as an Electron dependency.', function() {
stdout.includes('Created OpenVINO Runtime Core'),
'Check that openvino-node operates fine',
);
assert(
stdout.includes('Model read successfully: ModelWrap {}'),
'Check that model is read successfully',
);
assert(
stdout.includes('Infer request result: { fc_out: TensorWrap {} }'),
'Check that infer request result is successful',
);
done();
});
});
Expand Down

0 comments on commit a852c4a

Please sign in to comment.