/ concept-collection / dulcimer
Sign in
concept-collection / dulcimer
dulcimer / scripts / test-node.ts
63 lines · 1.9 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 planChecks,
14 pitchChecks,
15 decayChecks,
16 wallChecks,
17 holeChecks,
18 spectrumChecks,
19 bareChecks,
20 splitChecks,
21} from '../test/checks.ts';
23let failures = 0;
24const check = (name: string, ok: boolean, detail: string): void => {
25 console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail}`);
26 if (!ok) failures++;
27};
28const log = (s: string): void => console.log(s);
30/**
31 * These checks compile MATLAB to compute shaders, so they need a GPU.
32 * `--skip-without-gpu` lets a runner that has none say so and move on; a plain
33 * local run still fails loudly, so a missing GPU is never mistaken for a pass.
34 */
35const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
37let runtime: string;
38let device: GPUDevice;
39try {
40 runtime = await installWebGpu();
41 device = await requestAcousticDevice();
42} catch (e) {
43 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
44 if (skipWithoutGpu) {
45 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
46 process.exit(0);
47 }
48 console.error(`test-node: ${detail}`);
49 process.exit(1);
51console.log(`dulcimer tests — ${runtime}\n`);
53await planChecks(device, check, log);
54await pitchChecks(device, check, log);
55await decayChecks(device, check, log);
56await wallChecks(device, check, log);
57await holeChecks(device, check, log);
58await spectrumChecks(device, check, log);
59await bareChecks(device, check, log);
60await splitChecks(device, check, log);
62console.log(failures ? `\n${failures} failure(s)` : '\nall checks passed');
63process.exit(failures ? 1 : 0);
moveopenescclose