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

[OV JS] Perform inference in electron app in nodejs e2e test #27131

Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading