Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('.validateSettings() checks output texture size - too large', () => {
const mockContext = {
constructor: {
features: {
maxTextureSize: 1,
},
},
checkOutput: () => {},
output: [2],
validate: true,
checkTextureSize: WebGL2Kernel.prototype.checkTextureSize,
};
assert.throws(() => {
WebGL2Kernel.prototype.validateSettings.apply(mockContext, []);
}, new Error('Texture size [1,2] generated by kernel is larger than supported size [1,1]'));
});
test('binary expression divide', () => {
assert.throws(() => {
run('value[0] / value[0]');
});
});
test('setOutput() throws when not dynamicOutput and already compiled', () => {
assert.throws(() => {
GLKernel.prototype.setOutput.call({
program: {},
toKernelOutput: () => {},
dynamicOutput: false
});
}, new Error('Resizing a kernel with dynamicOutput: false is not possible'));
});
test('.validateSettings() checks output texture size - too large', () => {
const mockContext = {
constructor: {
features: {
maxTextureSize: 1,
},
},
checkOutput: () => {},
output: [2],
validate: true,
checkTextureSize: WebGLKernel.prototype.checkTextureSize,
};
assert.throws(() => {
WebGLKernel.prototype.validateSettings.apply(mockContext, []);
}, new Error('Texture size [1,2] generated by kernel is larger than supported size [1,1]'));
});
test('colorSyntaxTest (cpu) throws', () => {
assert.throws(() => {
colorSyntaxTest('cpu');
});
});
(GPU.isWebGLSupported && typeof Image !== 'undefined' ? test : skip)('webgl', t => {
assert.throws(() => {
feature('webgl')
}, 'imageArray are not compatible with webgl');
});
function outputGraphicalArray(mode) {
const gpu = new GPU({ mode });
const mockContext = {
getExtension: () => {}
};
const mockCanvas = {
getContext: () => mockContext,
};
assert.throws(() => {
const kernel = gpu.createKernel(function(input) {
return input[this.thread.x];
}, {
canvas: mockCanvas,
output: [5],
graphical: true
});
kernel([1]);
}, new Error('Output must have 2 dimensions on graphical mode'));
gpu.destroy();
}
if (!kernel.hasPrependString(string1)) {
kernel.prependString(string1);
}
const string2 = '__coverage__();\n';
if (!kernel.hasPrependString(string2)) {
kernel.prependString(string2);
}
}
});
const kernel = gpu.createKernel(`function() {
mockGlobalValue.f[100]++;
return (mockGlobalValue.f[100]++, 1);
}`, { output: [1] });
assert.deepEqual(kernel(), new Float32Array([1]));
assert.throws(() => {
kernel.prependString('null');
}, new Error('Kernel already built'));
gpu.destroy();
}
function outputGraphicalCube(mode) {
const gpu = new GPU({ mode });
const mockContext = {
getExtension: () => {}
};
const mockCanvas = {
getContext: () => mockContext
};
assert.throws(() => {
const kernel = gpu.createKernel(function(input) {
return input[this.thread.x];
}, {
canvas: mockCanvas,
output: [5,5,5],
graphical: true
});
kernel([1]);
}, new Error('Output must have 2 dimensions on graphical mode'));
gpu.destroy();
}
features: { maxTextureSize: 1 },
},
validate: true,
};
const v = new webGLKernelValueMaps.unsigned.dynamic.MemoryOptimizedNumberTexture({ size: [1, 1] }, {
kernel: mockKernel,
name: 'test',
type: 'MemoryOptimizedNumberTexture',
origin: 'user',
tactic: 'speed',
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});
assert.throws(() => {
v.updateValue({
size: [2,1]
})
}, new Error('Argument width of 2 larger than maximum size of 1 for your GPU'));
});