1/**
2 * The whole suite on desktop WebGPU (Google Dawn), against the real pipeline:
3 * MATLAB source -> numbl lowering -> generated WGSL -> GPU.
4 *
5 * The same four check modules run in the browser (test.html), so both GPU
6 * stacks get the same guarantees. Run through vite-node, which is what resolves
7 * numbl's compiler sources and the `?raw` model imports:
8 *
9 * npm run test:node
10 */
11import { tmpdir } from 'node:os';
12import { join } from 'node:path';
13import * as h5wasm from 'h5wasm/node';
14import { requestShtDevice } from '../src/sht/sht.ts';
15import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts';
16import { transformChecks } from '../test/transformChecks.ts';
17import { analyticChecks } from '../test/analyticChecks.ts';
18import { modelChecks } from '../test/modelChecks.ts';
19import { geometryChecks } from '../test/geometryChecks.ts';
20import { fluxChecks } from '../test/fluxChecks.ts';
21import { compareChecks } from '../test/compareChecks.ts';
22import { referenceChecks, type H5Rt } from '../test/referenceChecks.ts';
23import { matlabExportChecks } from '../test/matlabExportChecks.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 unlike the old CPU-solver
34 * suite they need a GPU. `--skip-without-gpu` lets a runner that has none say so
35 * and move on — CI uses it, because the browser suite runs the very same check
36 * modules on SwiftShader. A plain local run still fails loudly, so a missing GPU
37 * is never mistaken for a pass.
38 */
39const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
41let runtime: string;
42let device: GPUDevice;
43try {
44 runtime = await installWebGpu();
45 device = await requestShtDevice();
46} catch (e) {
47 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
48 if (skipWithoutGpu) {
49 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
50 process.exit(0);
51 }
52 console.error(`test-node: ${detail}`);
53 process.exit(1);
54}
55console.log(`turing-surface tests — ${runtime}\n`);
57await transformChecks(device, check, log);
58await analyticChecks(device, check, log);
59await modelChecks(device, check, log);
60await geometryChecks(device, check, log);
61await fluxChecks(device, check, log);
62await compareChecks(device, check, log);
63matlabExportChecks(check, log);
64await referenceChecks(
65 h5wasm as unknown as H5Rt,
66 (name) => join(tmpdir(), `turing-surface-${process.pid}-${name}`),
67 check,
68 log,
69);
71console.log(failures === 0 ? '\nAll tests passed.' : `\n${failures} failed.`);
72process.exit(failures === 0 ? 0 : 1);