1/**
2 * The suite on desktop WebGPU (Google Dawn), against the real pipeline:
3 * SceneSpec -> generated MATLAB -> 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 planChecks,
14 codegenChecks,
15 stringChecks,
16 barChecks,
17 membraneChecks,
18 wallChecks,
19 duetChecks,
20 placementChecks,
21 spectrumChecks,
22 splitChecks,
23} from '../test/checks.ts';
25let failures = 0;
26const check = (name: string, ok: boolean, detail: string): void => {
27 console.log(`${ok ? 'PASS' : 'FAIL'} ${name} — ${detail}`);
28 if (!ok) failures++;
29};
30const log = (s: string): void => console.log(s);
32/**
33 * These checks compile MATLAB to compute shaders, so they need a GPU.
34 * `--skip-without-gpu` lets a runner that has none say so and move on; a plain
35 * local run still fails loudly, so a missing GPU is never mistaken for a pass.
36 */
37const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
39let runtime: string;
40let device: GPUDevice;
41try {
42 runtime = await installWebGpu();
43 device = await requestAcousticDevice();
44} catch (e) {
45 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
46 if (skipWithoutGpu) {
47 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
48 process.exit(0);
49 }
50 console.error(`test-node: ${detail}`);
51 process.exit(1);
52}
53console.log(`soundbox tests — ${runtime}\n`);
55await planChecks(device, check, log);
56await codegenChecks(device, check, log);
57await stringChecks(device, check, log);
58await barChecks(device, check, log);
59await membraneChecks(device, check, log);
60await wallChecks(device, check, log);
61await duetChecks(device, check, log);
62await placementChecks(device, check, log);
63await spectrumChecks(device, check, log);
64await splitChecks(device, check, log);
66console.log(failures ? `\n${failures} failure(s)` : '\nall checks passed');
67process.exit(failures ? 1 : 0);