MCPcopy Index your code
hub / github.com/gpujs/gpu.js / toStringAsFileTest

Function toStringAsFileTest

test/features/to-string/as-file.js:6–27  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

4describe('features: to-string as file');
5
6function toStringAsFileTest(mode) {
7 const path = __dirname + `/to-string-as-file-${mode}.js`;
8 const fs = require('fs');
9 if (fs.existsSync(path)) {
10 fs.unlinkSync(path);
11 }
12 const gpu = new GPU({ mode });
13 const kernel = gpu.createKernel(function(v) {
14 return v[this.thread.y][this.thread.x] + 1;
15 }, { output: [1, 1] });
16 const a = [[1]];
17 const expected = kernel(a);
18 assert.deepEqual(expected, [new Float32Array([2])]);
19 const kernelAsString = kernel.toString(a);
20 fs.writeFileSync(path, `module.exports = ${kernelAsString};`);
21 const toStringAsFile = require(path);
22 const restoredKernel = toStringAsFile({ context: kernel.context });
23 const result = restoredKernel(a);
24 assert.deepEqual(result, expected);
25 fs.unlinkSync(path);
26 gpu.destroy();
27}
28
29(GPU.isHeadlessGLSupported ? test : skip)('can save and restore function headlessgl', () => {
30 toStringAsFileTest('headlessgl');

Callers 1

as-file.jsFile · 0.85

Calls 4

createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…