/** * The suite on desktop WebGPU (Google Dawn), against the real pipeline: * MATLAB source -> numbl lowering -> generated WGSL -> GPU. * * Run through vite-node, which is what resolves numbl's compiler sources and * the `?raw` .m imports: * * npm run test:node */ import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts'; import { requestAcousticDevice } from '../src/device.ts'; import { stencilChecks, propagationChecks, boundaryChecks, scatteringChecks, stabilityChecks, splitChecks, microphoneChecks, roomChecks, planChecks, } from '../test/checks.ts'; let failures = 0; const check = (name: string, ok: boolean, detail: string): void => { console.log(`${ok ? 'PASS' : 'FAIL'} ${name} — ${detail}`); if (!ok) failures++; }; const log = (s: string): void => console.log(s); /** * These checks compile MATLAB to compute shaders, so they need a GPU. * `--skip-without-gpu` lets a runner that has none say so and move on; a plain * local run still fails loudly, so a missing GPU is never mistaken for a pass. */ const skipWithoutGpu = process.argv.includes('--skip-without-gpu'); let runtime: string; let device: GPUDevice; try { runtime = await installWebGpu(); device = await requestAcousticDevice(); } catch (e) { const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`; if (skipWithoutGpu) { console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`); process.exit(0); } console.error(`test-node: ${detail}`); process.exit(1); } console.log(`acoustic-scattering-2d tests — ${runtime}\n`); await stencilChecks(device, check, log); await propagationChecks(device, check, log); await boundaryChecks(device, check, log); await scatteringChecks(device, check, log); await stabilityChecks(device, check, log); await splitChecks(device, check, log); await microphoneChecks(device, check, log); await roomChecks(device, check, log); await planChecks(device, check, log); console.log(failures ? `\n${failures} failure(s)` : '\nall checks passed'); process.exit(failures ? 1 : 0);