/ concept-collection / acoustic-scattering-2d
concept-collection / acoustic-scattering-2d
acoustic-scattering-2d / scripts / test-node.ts
65 lines · 2.0 KBBlameHistoryRaw
1/**
2 * The suite on desktop WebGPU (Google Dawn), against the real pipeline:
3 * MATLAB source -> numbl lowering -> generated WGSL -> GPU.
4 *
5 * Run through vite-node, which is what resolves numbl's compiler sources and
6 * the `?raw` .m imports:
7 *
8 * npm run test:node
9 */
10import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts';
11import { requestAcousticDevice } from '../src/device.ts';
12import {
13 stencilChecks,
14 propagationChecks,
15 boundaryChecks,
16 scatteringChecks,
17 stabilityChecks,
18 splitChecks,
19 microphoneChecks,
20 roomChecks,
21 planChecks,
22} from '../test/checks.ts';
24let failures = 0;
25const check = (name: string, ok: boolean, detail: string): void => {
26 console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail}`);
27 if (!ok) failures++;
28};
29const log = (s: string): void => console.log(s);
31/**
32 * These checks compile MATLAB to compute shaders, so they need a GPU.
33 * `--skip-without-gpu` lets a runner that has none say so and move on; a plain
34 * local run still fails loudly, so a missing GPU is never mistaken for a pass.
35 */
36const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
38let runtime: string;
39let device: GPUDevice;
40try {
41 runtime = await installWebGpu();
42 device = await requestAcousticDevice();
43} catch (e) {
44 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
45 if (skipWithoutGpu) {
46 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
47 process.exit(0);
48 }
49 console.error(`test-node: ${detail}`);
50 process.exit(1);
52console.log(`acoustic-scattering-2d tests — ${runtime}\n`);
54await stencilChecks(device, check, log);
55await propagationChecks(device, check, log);
56await boundaryChecks(device, check, log);
57await scatteringChecks(device, check, log);
58await stabilityChecks(device, check, log);
59await splitChecks(device, check, log);
60await microphoneChecks(device, check, log);
61await roomChecks(device, check, log);
62await planChecks(device, check, log);
64console.log(failures ? `\n${failures} failure(s)` : '\nall checks passed');
65process.exit(failures ? 1 : 0);