/ proof-of-concept / soundbox
Sign in
proof-of-concept / soundbox
soundbox / scripts / test-node.ts
69 lines · 2.1 KBBlameHistoryRaw
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 sceneFileChecks,
16 stringChecks,
17 barChecks,
18 membraneChecks,
19 wallChecks,
20 duetChecks,
21 placementChecks,
22 spectrumChecks,
23 splitChecks,
24} from '../test/checks.ts';
26let failures = 0;
27const check = (name: string, ok: boolean, detail: string): void => {
28 console.log(`${ok ? 'PASS' : 'FAIL'} ${name} — ${detail}`);
29 if (!ok) failures++;
30};
31const log = (s: string): void => console.log(s);
33/**
34 * These checks compile MATLAB to compute shaders, so they need a GPU.
35 * `--skip-without-gpu` lets a runner that has none say so and move on; a plain
36 * local run still fails loudly, so a missing GPU is never mistaken for a pass.
37 */
38const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
40let runtime: string;
41let device: GPUDevice;
42try {
43 runtime = await installWebGpu();
44 device = await requestAcousticDevice();
45} catch (e) {
46 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
47 if (skipWithoutGpu) {
48 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
49 process.exit(0);
50 }
51 console.error(`test-node: ${detail}`);
52 process.exit(1);
54console.log(`soundbox tests — ${runtime}\n`);
56await planChecks(device, check, log);
57await codegenChecks(device, check, log);
58await sceneFileChecks(device, check, log);
59await stringChecks(device, check, log);
60await barChecks(device, check, log);
61await membraneChecks(device, check, log);
62await wallChecks(device, check, log);
63await duetChecks(device, check, log);
64await placementChecks(device, check, log);
65await spectrumChecks(device, check, log);
66await splitChecks(device, check, log);
68console.log(failures ? `\n${failures} failure(s)` : '\nall checks passed');
69process.exit(failures ? 1 : 0);
↑↓ move↵openescclose