(mode)
| 4 | describe('features: to-string as file'); |
| 5 | |
| 6 | function 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'); |
no test coverage detected
searching dependent graphs…