2021-05-24 17:10:13 +02:00
|
|
|
const fs = require('fs');
|
2021-04-15 15:43:55 +02:00
|
|
|
const path = require('path');
|
|
|
|
const process = require('process');
|
|
|
|
const { fork } = require('child_process');
|
|
|
|
const log = require('@vladmandic/pilogger');
|
|
|
|
|
2021-05-24 17:10:13 +02:00
|
|
|
let logFile = 'test.log';
|
2022-08-15 17:29:56 +02:00
|
|
|
log.configure({ inspect: { breakLength: 350 } });
|
2021-05-24 17:10:13 +02:00
|
|
|
|
2021-04-15 15:43:55 +02:00
|
|
|
const tests = [
|
2022-08-30 16:28:33 +02:00
|
|
|
'test-node-load.js',
|
|
|
|
'test-node-gear.js',
|
|
|
|
'test-backend-node.js',
|
|
|
|
'test-backend-node-gpu.js',
|
|
|
|
'test-backend-node-wasm.js',
|
|
|
|
// 'test-backend-node-cpu.js',
|
2021-04-15 15:43:55 +02:00
|
|
|
];
|
|
|
|
|
2021-09-19 20:20:22 +02:00
|
|
|
const demos = [
|
2022-08-10 19:44:38 +02:00
|
|
|
{ cmd: '../demo/nodejs/node.js', args: [] },
|
|
|
|
{ cmd: '../demo/nodejs/node-simple.js', args: [] },
|
|
|
|
{ cmd: '../demo/nodejs/node-event.js', args: ['samples/in/ai-body.jpg'] },
|
|
|
|
{ cmd: '../demo/nodejs/node-similarity.js', args: ['samples/in/ai-face.jpg', 'samples/in/ai-upper.jpg'] },
|
|
|
|
{ cmd: '../demo/nodejs/node-canvas.js', args: ['samples/in/ai-body.jpg', 'samples/out/ai-body.jpg'] },
|
2022-09-19 16:46:11 +02:00
|
|
|
{ cmd: '../demo/nodejs/process-folder.js', args: ['samples'] },
|
2022-08-10 19:44:38 +02:00
|
|
|
{ cmd: '../demo/multithread/node-multiprocess.js', args: [] },
|
2022-08-20 15:38:08 +02:00
|
|
|
{ cmd: '../demo/facematch/node-match.js', args: [] },
|
2022-08-10 19:44:38 +02:00
|
|
|
// { cmd: '../demo/nodejs/node-video.js', args: [] },
|
|
|
|
// { cmd: '../demo/nodejs/node-webcam.js', args: [] },
|
2021-09-19 20:20:22 +02:00
|
|
|
];
|
|
|
|
|
2021-08-19 22:16:56 +02:00
|
|
|
const ignoreMessages = [
|
2021-04-15 15:43:55 +02:00
|
|
|
'cpu_feature_guard.cc',
|
|
|
|
'rebuild TensorFlow',
|
|
|
|
'xla_gpu_device.cc',
|
|
|
|
'cudart_stub.cc',
|
|
|
|
'cuda_driver.cc:326',
|
|
|
|
'cpu_allocator_impl.cc',
|
2021-09-13 19:28:35 +02:00
|
|
|
'--trace-warnings',
|
|
|
|
'ExperimentalWarning',
|
2021-04-15 15:43:55 +02:00
|
|
|
];
|
|
|
|
|
2021-09-24 15:55:27 +02:00
|
|
|
const failedMessages = [];
|
|
|
|
|
2021-09-19 20:07:53 +02:00
|
|
|
const status = {};
|
2021-04-15 15:43:55 +02:00
|
|
|
|
|
|
|
function logMessage(test, data) {
|
2021-09-19 20:07:53 +02:00
|
|
|
if (!status[test]) status[test] = { passed: 0, failed: 0 };
|
|
|
|
if (log[data[0]]) {
|
|
|
|
log[data[0]](test, ...data[1]);
|
|
|
|
} else {
|
|
|
|
log.error('unknown facility', test, ...data[1]);
|
|
|
|
status[test].failed++;
|
|
|
|
}
|
|
|
|
if (data[1][0].startsWith('passed')) status[test].passed++;
|
2021-09-24 15:55:27 +02:00
|
|
|
if (data[1][0].startsWith('failed')) {
|
|
|
|
status[test].failed++;
|
|
|
|
failedMessages.push({ test, data });
|
|
|
|
}
|
2021-04-15 15:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function logStdIO(ok, test, buffer) {
|
|
|
|
const lines = buffer.toString().split(/\r\n|\n\r|\n|\r/);
|
|
|
|
const filtered = lines.filter((line) => {
|
2021-08-19 22:16:56 +02:00
|
|
|
for (const ignoreString of ignoreMessages) {
|
2021-04-15 15:43:55 +02:00
|
|
|
if (line.includes(ignoreString)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
for (const line of filtered) {
|
|
|
|
if (line.length < 2) continue;
|
2022-08-10 19:44:38 +02:00
|
|
|
if (ok) {
|
|
|
|
log.data(test, 'stdout:', line);
|
|
|
|
} else {
|
|
|
|
if (status[test]) status[test].failed = 'critical';
|
|
|
|
log.warn(test, 'stderr:', line);
|
|
|
|
}
|
2021-04-15 15:43:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function runTest(test) {
|
2021-09-13 19:28:35 +02:00
|
|
|
log.info();
|
|
|
|
log.info(test, 'start');
|
2021-04-15 15:43:55 +02:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
const child = fork(path.join(__dirname, test), [], { silent: true });
|
|
|
|
child.on('message', (data) => logMessage(test, data));
|
|
|
|
child.on('error', (data) => log.error(test, ':', data.message || data));
|
|
|
|
child.on('close', (code) => resolve(code));
|
|
|
|
child.stdout?.on('data', (data) => logStdIO(true, test, data));
|
|
|
|
child.stderr?.on('data', (data) => logStdIO(false, test, data));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:20:22 +02:00
|
|
|
async function runDemo(demo) {
|
2022-08-20 15:38:08 +02:00
|
|
|
// log.info();
|
2021-09-19 20:20:22 +02:00
|
|
|
log.info(demo, 'start');
|
2022-08-10 19:44:38 +02:00
|
|
|
status[demo.cmd] = { passed: 0, failed: 0 };
|
2021-09-19 20:20:22 +02:00
|
|
|
return new Promise((resolve) => {
|
2022-08-10 19:44:38 +02:00
|
|
|
const child = fork(path.join(__dirname, demo.cmd), [...demo.args], { silent: true });
|
|
|
|
child.on('message', (data) => logMessage(demo.cmd, data));
|
|
|
|
child.on('error', (data) => {
|
|
|
|
status[demo.cmd].failed++;
|
|
|
|
log.error(demo.cmd, ':', data.message || data);
|
|
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
|
|
status[demo.cmd].passed++;
|
|
|
|
resolve(code);
|
|
|
|
});
|
|
|
|
// child.stdout?.on('data', (data) => logStdIO(true, demo.cmd, data));
|
|
|
|
child.stderr?.on('data', (data) => logStdIO(false, demo.cmd, data));
|
2021-09-19 20:20:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-15 15:43:55 +02:00
|
|
|
async function testAll() {
|
2021-05-24 17:10:13 +02:00
|
|
|
logFile = path.join(__dirname, logFile);
|
|
|
|
if (fs.existsSync(logFile)) fs.unlinkSync(logFile);
|
|
|
|
log.logFile(logFile);
|
2021-04-15 15:43:55 +02:00
|
|
|
log.header();
|
|
|
|
process.on('unhandledRejection', (data) => log.error('nodejs unhandled rejection', data));
|
|
|
|
process.on('uncaughtException', (data) => log.error('nodejs unhandled exception', data));
|
2021-09-20 15:42:34 +02:00
|
|
|
log.info('demos:', demos);
|
2022-08-10 19:44:38 +02:00
|
|
|
for (const demo of demos) await runDemo(demo);
|
|
|
|
log.info('tests:', tests);
|
2021-04-15 15:43:55 +02:00
|
|
|
for (const test of tests) await runTest(test);
|
2022-08-10 19:44:38 +02:00
|
|
|
log.state('all tests complete');
|
2021-11-23 16:40:40 +01:00
|
|
|
for (const [test, result] of Object.entries(status)) {
|
2022-08-10 19:44:38 +02:00
|
|
|
log.info(' status', { test, ...result });
|
2021-11-23 16:40:40 +01:00
|
|
|
}
|
2022-08-10 19:44:38 +02:00
|
|
|
log.info('failures', { count: failedMessages.length });
|
|
|
|
for (const msg of failedMessages) log.warn(' failed', { test: msg.test, message: msg.data });
|
2021-04-15 15:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
testAll();
|