38 lines
1.8 KiB
JavaScript
38 lines
1.8 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { loadWasmProbe } from './wasm-probe-runtime.mjs';
|
|
|
|
const name = process.argv[2];
|
|
const manifest = JSON.parse(fs.readFileSync('web/public/modules/manifest.json', 'utf8'));
|
|
const module = manifest.modules[name];
|
|
assert.ok(module, `Unknown module ${name}`);
|
|
const runtimes = [...new Set(Object.values(module.workers).map(worker => worker.runtimeUrl))];
|
|
assert.ok(runtimes.length, 'No runtime declared');
|
|
const results = [];
|
|
try {
|
|
for (const runtime of runtimes) {
|
|
assert.ok(runtime?.startsWith('/kernel/'), 'Expected local published runtime');
|
|
const stem = path.basename(runtime, '.js');
|
|
const { kernel } = await loadWasmProbe('web/public/kernel', stem);
|
|
try {
|
|
assert.equal(typeof kernel.ccall, 'function');
|
|
const entries = Object.keys(kernel).filter(key => /^_fc_web_.*_initialize$/.test(key));
|
|
const initialized = [];
|
|
for (const entry of entries) {
|
|
const nativeName = {Assembly: 'AssemblyApp', CAM: 'PathApp'}[name] ?? name;
|
|
const result = kernel.ccall(entry.slice(1), 'number', ['string'], [nativeName]);
|
|
assert.equal(result, 1, `${entry} returned ${result}`);
|
|
initialized.push(entry.slice(1));
|
|
}
|
|
results.push({runtime, status: 'pass', initialized,
|
|
coverage: initialized.length ? 'WASM instantiation and exported initialization' : 'WASM instantiation only; business behavior covered separately'});
|
|
} finally { kernel.PThread?.terminateAllThreads?.(); }
|
|
}
|
|
console.log(JSON.stringify({status:'pass', module:name, runtimes:results}));
|
|
} catch (error) {
|
|
console.error(error.stack ?? String(error));
|
|
console.log(JSON.stringify({status:'fail', module:name, runtimes:results, error:String(error)}));
|
|
process.exitCode = 1;
|
|
}
|