mirror of https://github.com/vladmandic/human
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const process = require('process');
|
|
const { fork } = require('child_process');
|
|
const log = require('@vladmandic/pilogger');
|
|
|
|
let logFile = 'test.log';
|
|
|
|
const tests = [
|
|
'test-node.js',
|
|
'test-node-gpu.js',
|
|
'test-node-wasm.js',
|
|
];
|
|
|
|
const ignoreMessages = [
|
|
'cpu_feature_guard.cc',
|
|
'rebuild TensorFlow',
|
|
'xla_gpu_device.cc',
|
|
'cudart_stub.cc',
|
|
'cuda_driver.cc:326',
|
|
'cpu_allocator_impl.cc',
|
|
'--trace-warnings',
|
|
'ExperimentalWarning',
|
|
];
|
|
|
|
const status = {};
|
|
|
|
function logMessage(test, data) {
|
|
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++;
|
|
if (data[1][0].startsWith('failed')) status[test].failed++;
|
|
}
|
|
|
|
function logStdIO(ok, test, buffer) {
|
|
const lines = buffer.toString().split(/\r\n|\n\r|\n|\r/);
|
|
const filtered = lines.filter((line) => {
|
|
for (const ignoreString of ignoreMessages) {
|
|
if (line.includes(ignoreString)) return false;
|
|
}
|
|
return true;
|
|
});
|
|
for (const line of filtered) {
|
|
if (line.length < 2) continue;
|
|
if (ok) log.data(test, 'stdout:', line);
|
|
else log.warn(test, 'stderr:', line);
|
|
}
|
|
}
|
|
|
|
async function runTest(test) {
|
|
log.info();
|
|
log.info(test, 'start');
|
|
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));
|
|
});
|
|
}
|
|
|
|
async function testAll() {
|
|
logFile = path.join(__dirname, logFile);
|
|
if (fs.existsSync(logFile)) fs.unlinkSync(logFile);
|
|
log.logFile(logFile);
|
|
log.header();
|
|
process.on('unhandledRejection', (data) => log.error('nodejs unhandled rejection', data));
|
|
process.on('uncaughtException', (data) => log.error('nodejs unhandled exception', data));
|
|
log.info('tests:', tests);
|
|
for (const test of tests) await runTest(test);
|
|
log.info();
|
|
log.info('status:', status);
|
|
}
|
|
|
|
testAll();
|