Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/more/conformance/quickCheckAPI.js

Issue 9373009: Check in webgl conformance tests r16844 from khronos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 QuickCheck tests for WebGL:
3
4 1. Write a valid arg generator for each function
5 1.1. Write valid arg predicates to use with random generator:
6 if value passes generator, accept it as valid.
7 1.2. Often needs initializing and cleanup:
8 setup - generate - cleanup
9 gl.createBuffer - test(bindBufferGenerator) - gl.deleteBuffer
10
11 2. Write an invalid arg generator
12 2.1. Take valid args, modify an arg until the args no longer pass
13 checkArgValidity.
14 2.2. Repeat for all args.
15
16 3. Test functions using the generators
17 3.1. Args generated with the valid arg generator should pass
18 assertOk(f(args))
19 3.2. Args generated with the invalid arg generator should pass
20 assertFail(f(args))
21 */
22 var GLcanvas = document.createElement('canvas');
23 var canvas2D = document.createElement('canvas');
24 GLcanvas.width = GLcanvas.height = 256;
25 GL = GLcanvas.getContext(GL_CONTEXT_ID);
26 Array.from = function(o) {
27 var a = [];
28 for (var i=0; i<o.length; i++)
29 a.push(o[i]);
30 return a;
31 }
32 Array.prototype.has = function(v) { return this.indexOf(v) != -1; }
33 Array.prototype.random = function() { return this[randomInt(this.length)]; }
34
35 castToInt = function(o) {
36 if (typeof o == 'number')
37 return isNaN(o) ? 0 : Math.floor(o);
38 if (o == true) return 1;
39 return 0;
40 };
41
42 // Creates a constant checker / generator from its arguments.
43 //
44 // E.g. if you want a constant checker for the constants 1, 2, and 3, you
45 // would do the following:
46 //
47 // var cc = constCheck(1,2,3);
48 // var randomConst = cc.random();
49 // if (cc.has(randomConst))
50 // console.log("randomConst is included in cc's constants");
51 //
52 constCheck = function() {
53 var a = Array.from(arguments);
54 a.has = function(v) { return this.indexOf(castToInt(v)) != -1; };
55 return a;
56 }
57
58 bindTextureTarget = constCheck(GL.TEXTURE_2D, GL.TEXTURE_CUBE_MAP);
59 blendEquationMode = constCheck(GL.FUNC_ADD, GL.FUNC_SUBTRACT, GL.FUNC_REVERSE_SU BTRACT);
60 blendFuncSfactor = constCheck(
61 GL.ZERO, GL.ONE, GL.SRC_COLOR, GL.ONE_MINUS_SRC_COLOR, GL.DST_COLOR,
62 GL.ONE_MINUS_DST_COLOR, GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.DST_ALPHA,
63 GL.ONE_MINUS_DST_ALPHA, GL.CONSTANT_COLOR, GL.ONE_MINUS_CONSTANT_COLOR,
64 GL.CONSTANT_ALPHA, GL.ONE_MINUS_CONSTANT_ALPHA, GL.SRC_ALPHA_SATURATE
65 );
66 blendFuncDfactor = constCheck(
67 GL.ZERO, GL.ONE, GL.SRC_COLOR, GL.ONE_MINUS_SRC_COLOR, GL.DST_COLOR,
68 GL.ONE_MINUS_DST_COLOR, GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.DST_ALPHA,
69 GL.ONE_MINUS_DST_ALPHA, GL.CONSTANT_COLOR, GL.ONE_MINUS_CONSTANT_COLOR,
70 GL.CONSTANT_ALPHA, GL.ONE_MINUS_CONSTANT_ALPHA
71 );
72 bufferTarget = constCheck(GL.ARRAY_BUFFER, GL.ELEMENT_ARRAY_BUFFER);
73 bufferMode = constCheck(GL.STREAM_DRAW, GL.STATIC_DRAW, GL.DYNAMIC_DRAW);
74 clearMask = constCheck(
75 GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT | GL.STENCIL_BUFFER_BIT,
76 GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT,
77 GL.COLOR_BUFFER_BIT | GL.STENCIL_BUFFER_BIT,
78 GL.DEPTH_BUFFER_BIT | GL.STENCIL_BUFFER_BIT,
79 GL.COLOR_BUFFER_BIT, GL.DEPTH_BUFFER_BIT, GL.STENCIL_BUFFER_BIT, 0
80 );
81 cullFace = constCheck(GL.FRONT, GL.BACK, GL.FRONT_AND_BACK);
82 depthFuncFunc = constCheck(
83 GL.NEVER, GL.LESS, GL.EQUAL, GL.LEQUAL, GL.GREATER, GL.NOTEQUAL,
84 GL.GEQUAL, GL.ALWAYS
85 );
86 stencilFuncFunc = depthFuncFunc;
87 enableCap = constCheck(
88 GL.BLEND, GL.CULL_FACE, GL.DEPTH_TEST, GL.DITHER, GL.POLYGON_OFFSET_FILL,
89 GL.SAMPLE_ALPHA_TO_COVERAGE, GL.SAMPLE_COVERAGE, GL.SCISSOR_TEST,
90 GL.STENCIL_TEST
91 );
92 frontFaceMode = constCheck(GL.CCW, GL.CW);
93 getParameterPname = constCheck(
94 GL.ACTIVE_TEXTURE || "GL.ACTIVE_TEXTURE",
95 GL.ALIASED_LINE_WIDTH_RANGE || "GL.ALIASED_LINE_WIDTH_RANGE",
96 GL.ALIASED_POINT_SIZE_RANGE || "GL.ALIASED_POINT_SIZE_RANGE",
97 GL.ALPHA_BITS || "GL.ALPHA_BITS",
98 GL.ARRAY_BUFFER_BINDING || "GL.ARRAY_BUFFER_BINDING",
99 GL.BLEND || "GL.BLEND",
100 GL.BLEND_COLOR || "GL.BLEND_COLOR",
101 GL.BLEND_DST_ALPHA || "GL.BLEND_DST_ALPHA",
102 GL.BLEND_DST_RGB || "GL.BLEND_DST_RGB",
103 GL.BLEND_EQUATION_ALPHA || "GL.BLEND_EQUATION_ALPHA",
104 GL.BLEND_EQUATION_RGB || "GL.BLEND_EQUATION_RGB",
105 GL.BLEND_SRC_ALPHA || "GL.BLEND_SRC_ALPHA",
106 GL.BLEND_SRC_RGB || "GL.BLEND_SRC_RGB",
107 GL.BLUE_BITS || "GL.BLUE_BITS",
108 GL.COLOR_CLEAR_VALUE || "GL.COLOR_CLEAR_VALUE",
109 GL.COLOR_WRITEMASK || "GL.COLOR_WRITEMASK",
110 GL.COMPRESSED_TEXTURE_FORMATS || "GL.COMPRESSED_TEXTURE_FORMATS",
111 GL.CULL_FACE || "GL.CULL_FACE",
112 GL.CULL_FACE_MODE || "GL.CULL_FACE_MODE",
113 GL.CURRENT_PROGRAM || "GL.CURRENT_PROGRAM",
114 GL.DEPTH_BITS || "GL.DEPTH_BITS",
115 GL.DEPTH_CLEAR_VALUE || "GL.DEPTH_CLEAR_VALUE",
116 GL.DEPTH_FUNC || "GL.DEPTH_FUNC",
117 GL.DEPTH_RANGE || "GL.DEPTH_RANGE",
118 GL.DEPTH_TEST || "GL.DEPTH_TEST",
119 GL.DEPTH_WRITEMASK || "GL.DEPTH_WRITEMASK",
120 GL.DITHER || "GL.DITHER",
121 GL.ELEMENT_ARRAY_BUFFER_BINDING || "GL.ELEMENT_ARRAY_BUFFER_BINDING",
122 GL.FRAMEBUFFER_BINDING || "GL.FRAMEBUFFER_BINDING",
123 GL.FRONT_FACE || "GL.FRONT_FACE",
124 GL.GENERATE_MIPMAP_HINT || "GL.GENERATE_MIPMAP_HINT",
125 GL.GREEN_BITS || "GL.GREEN_BITS",
126 GL.LINE_WIDTH || "GL.LINE_WIDTH",
127 GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS || "GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS",
128 GL.MAX_CUBE_MAP_TEXTURE_SIZE || "GL.MAX_CUBE_MAP_TEXTURE_SIZE",
129 GL.MAX_FRAGMENT_UNIFORM_VECTORS || "GL.MAX_FRAGMENT_UNIFORM_VECTORS",
130 GL.MAX_RENDERBUFFER_SIZE || "GL.MAX_RENDERBUFFER_SIZE",
131 GL.MAX_TEXTURE_IMAGE_UNITS || "GL.MAX_TEXTURE_IMAGE_UNITS",
132 GL.MAX_TEXTURE_SIZE || "GL.MAX_TEXTURE_SIZE",
133 GL.MAX_VARYING_VECTORS || "GL.MAX_VARYING_VECTORS",
134 GL.MAX_VERTEX_ATTRIBS || "GL.MAX_VERTEX_ATTRIBS",
135 GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS || "GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS",
136 GL.MAX_VERTEX_UNIFORM_VECTORS || "GL.MAX_VERTEX_UNIFORM_VECTORS",
137 GL.MAX_VIEWPORT_DIMS || "GL.MAX_VIEWPORT_DIMS",
138 GL.PACK_ALIGNMENT || "GL.PACK_ALIGNMENT",
139 GL.POLYGON_OFFSET_FACTOR || "GL.POLYGON_OFFSET_FACTOR",
140 GL.POLYGON_OFFSET_FILL || "GL.POLYGON_OFFSET_FILL",
141 GL.POLYGON_OFFSET_UNITS || "GL.POLYGON_OFFSET_UNITS",
142 GL.RED_BITS || "GL.RED_BITS",
143 GL.RENDERBUFFER_BINDING || "GL.RENDERBUFFER_BINDING",
144 GL.SAMPLE_BUFFERS || "GL.SAMPLE_BUFFERS",
145 GL.SAMPLE_COVERAGE_INVERT || "GL.SAMPLE_COVERAGE_INVERT",
146 GL.SAMPLE_COVERAGE_VALUE || "GL.SAMPLE_COVERAGE_VALUE",
147 GL.SAMPLES || "GL.SAMPLES",
148 GL.SCISSOR_BOX || "GL.SCISSOR_BOX",
149 GL.SCISSOR_TEST || "GL.SCISSOR_TEST",
150 GL.STENCIL_BACK_FAIL || "GL.STENCIL_BACK_FAIL",
151 GL.STENCIL_BACK_FUNC || "GL.STENCIL_BACK_FUNC",
152 GL.STENCIL_BACK_PASS_DEPTH_FAIL || "GL.STENCIL_BACK_PASS_DEPTH_FAIL",
153 GL.STENCIL_BACK_PASS_DEPTH_PASS || "GL.STENCIL_BACK_PASS_DEPTH_PASS",
154 GL.STENCIL_BACK_REF || "GL.STENCIL_BACK_REF",
155 GL.STENCIL_BACK_VALUE_MASK || "GL.STENCIL_BACK_VALUE_MASK",
156 GL.STENCIL_BACK_WRITEMASK || "GL.STENCIL_BACK_WRITEMASK",
157 GL.STENCIL_BITS || "GL.STENCIL_BITS",
158 GL.STENCIL_CLEAR_VALUE || "GL.STENCIL_CLEAR_VALUE",
159 GL.STENCIL_FAIL || "GL.STENCIL_FAIL",
160 GL.STENCIL_FUNC || "GL.STENCIL_FUNC",
161 GL.STENCIL_PASS_DEPTH_FAIL || "GL.STENCIL_PASS_DEPTH_FAIL",
162 GL.STENCIL_PASS_DEPTH_PASS || "GL.STENCIL_PASS_DEPTH_PASS",
163 GL.STENCIL_REF || "GL.STENCIL_REF",
164 GL.STENCIL_TEST || "GL.STENCIL_TEST",
165 GL.STENCIL_VALUE_MASK || "GL.STENCIL_VALUE_MASK",
166 GL.STENCIL_WRITEMASK || "GL.STENCIL_WRITEMASK",
167 GL.SUBPIXEL_BITS || "GL.SUBPIXEL_BITS",
168 GL.TEXTURE_BINDING_2D || "GL.TEXTURE_BINDING_2D",
169 GL.TEXTURE_BINDING_CUBE_MAP || "GL.TEXTURE_BINDING_CUBE_MAP",
170 GL.UNPACK_ALIGNMENT || "GL.UNPACK_ALIGNMENT",
171 GL.VIEWPORT || "GL.VIEWPORT"
172 );
173 mipmapHint = constCheck(GL.FASTEST, GL.NICEST, GL.DONT_CARE);
174 pixelStoreiPname = constCheck(GL.PACK_ALIGNMENT, GL.UNPACK_ALIGNMENT);
175 pixelStoreiParam = constCheck(1,2,4,8);
176 shaderType = constCheck(GL.VERTEX_SHADER, GL.FRAGMENT_SHADER);
177 stencilOp = constCheck(GL.KEEP, GL.ZERO, GL.REPLACE, GL.INCR, GL.INCR_WRAP,
178 GL.DECR, GL.DECR_WRAP, GL.INVERT);
179 texImageTarget = constCheck(
180 GL.TEXTURE_2D,
181 GL.TEXTURE_CUBE_MAP_POSITIVE_X,
182 GL.TEXTURE_CUBE_MAP_NEGATIVE_X,
183 GL.TEXTURE_CUBE_MAP_POSITIVE_Y,
184 GL.TEXTURE_CUBE_MAP_NEGATIVE_Y,
185 GL.TEXTURE_CUBE_MAP_POSITIVE_Z,
186 GL.TEXTURE_CUBE_MAP_NEGATIVE_Z
187 );
188 texImageInternalFormat = constCheck(
189 GL.ALPHA,
190 GL.LUMINANCE,
191 GL.LUMINANCE_ALPHA,
192 GL.RGB,
193 GL.RGBA
194 );
195 texImageFormat = constCheck(
196 GL.ALPHA,
197 GL.LUMINANCE,
198 GL.LUMINANCE_ALPHA,
199 GL.RGB,
200 GL.RGBA
201 );
202 texImageType = constCheck(GL.UNSIGNED_BYTE);
203 texParameterPname = constCheck(
204 GL.TEXTURE_MIN_FILTER, GL.TEXTURE_MAG_FILTER,
205 GL.TEXTURE_WRAP_S, GL.TEXTURE_WRAP_T);
206 texParameterParam = {};
207 texParameterParam[GL.TEXTURE_MIN_FILTER] = constCheck(
208 GL.NEAREST, GL.LINEAR, GL.NEAREST_MIPMAP_NEAREST, GL.LINEAR_MIPMAP_NEAREST,
209 GL.NEAREST_MIPMAP_LINEAR, GL.LINEAR_MIPMAP_LINEAR);
210 texParameterParam[GL.TEXTURE_MAG_FILTER] = constCheck(GL.NEAREST, GL.LINEAR);
211 texParameterParam[GL.TEXTURE_WRAP_S] = constCheck(
212 GL.CLAMP_TO_EDGE, GL.MIRRORED_REPEAT, GL.REPEAT);
213 texParameterParam[GL.TEXTURE_WRAP_T] = texParameterParam[GL.TEXTURE_WRAP_S];
214 textureUnit = constCheck.apply(this, (function(){
215 var textureUnits = [];
216 var texUnits = GL.getParameter(GL.MAX_TEXTURE_IMAGE_UNITS);
217 for (var i=0; i<texUnits; i++) textureUnits.push(GL['TEXTURE'+i]);
218 return textureUnits;
219 })());
220
221 var StencilBits = GL.getParameter(GL.STENCIL_BITS);
222 var MaxStencilValue = 1 << StencilBits;
223
224 var MaxVertexAttribs = GL.getParameter(GL.MAX_VERTEX_ATTRIBS);
225 var LineWidthRange = GL.getParameter(GL.ALIASED_LINE_WIDTH_RANGE);
226
227 // Returns true if bufData can be passed to GL.bufferData
228 isBufferData = function(bufData) {
229 if (typeof bufData == 'number')
230 return bufData >= 0;
231 if (bufData instanceof ArrayBuffer)
232 return true;
233 return WebGLArrayTypes.some(function(t) {
234 return bufData instanceof t;
235 });
236 };
237
238 isVertexAttribute = function(idx) {
239 if (typeof idx != 'number') return false;
240 return idx >= 0 && idx < MaxVertexAttribs;
241 };
242
243 isValidName = function(name) {
244 if (typeof name != 'string') return false;
245 for (var i=0; i<name.length; i++) {
246 var c = name.charCodeAt(i);
247 if (c & 0x00FF == 0 || c & 0xFF00 == 0) {
248 return false;
249 }
250 }
251 return true;
252 };
253
254 WebGLArrayTypes = [
255 Float32Array,
256 Int32Array,
257 Int16Array,
258 Int8Array,
259 Uint32Array,
260 Uint16Array,
261 Uint8Array
262 ];
263 webGLArrayContentGenerators = [randomLength, randomSmallIntArray];
264 randomWebGLArray = function() {
265 var t = WebGLArrayTypes.random();
266 return new t(webGLArrayContentGenerators.random()());
267 };
268
269 randomArrayBuffer = function(buflen) {
270 if (buflen == null) buflen = 256;
271 var len = randomInt(buflen)+1;
272 var rv;
273 try {
274 rv = new ArrayBuffer(len);
275 } catch(e) {
276 log("Error creating ArrayBuffer with length " + len);
277 throw(e);
278 }
279 return rv;
280 };
281
282 bufferDataGenerators = [randomLength, randomWebGLArray, randomArrayBuffer];
283 randomBufferData = function() {
284 return bufferDataGenerators.random()();
285 };
286
287 randomSmallWebGLArray = function(buflen) {
288 var t = WebGLArrayTypes.random();
289 return new t(randomInt(buflen/4)+1);
290 };
291
292 bufferSubDataGenerators = [randomSmallWebGLArray, randomArrayBuffer];
293 randomBufferSubData = function(buflen) {
294 var data = bufferSubDataGenerators.random()(buflen);
295 var offset = randomInt(buflen - data.byteLength);
296 return {data:data, offset:offset};
297 };
298
299 randomColor = function() {
300 return [Math.random(), Math.random(), Math.random(), Math.random()];
301 };
302
303 randomName = function() {
304 var arr = [];
305 var len = randomLength()+1;
306 for (var i=0; i<len; i++) {
307 var l = randomInt(255)+1;
308 var h = randomInt(255)+1;
309 var c = (h << 8) | l;
310 arr.push(String.fromCharCode(c));
311 }
312 return arr.join('');
313 };
314 randomVertexAttribute = function() {
315 return randomInt(MaxVertexAttribs);
316 };
317
318 randomBool = function() { return Math.random() > 0.5; };
319
320 randomStencil = function() {
321 return randomInt(MaxStencilValue);
322 };
323
324 randomLineWidth = function() {
325 var lo = LineWidthRange[0],
326 hi = LineWidthRange[1];
327 return randomFloatFromRange(lo, hi);
328 };
329
330 randomImage = function(w,h) {
331 var img;
332 var r = Math.random();
333 if (r < 0.5) {
334 img = document.createElement('canvas');
335 img.width = w; img.height = h;
336 img.getContext('2d').fillRect(0,0,w,h);
337 } else if (r < 0.5) {
338 img = document.createElement('video');
339 img.width = w; img.height = h;
340 } else if (r < 0.75) {
341 img = document.createElement('img');
342 img.width = w; img.height = h;
343 } else {
344 img = canvas2D.getContext('2d').createImageData(w,h);
345 }
346 return img
347 };
348
349 mutateArgs = function(args) {
350 var mutateCount = randomIntFromRange(1, args.length);
351 var newArgs = Array.from(args);
352 for (var i=0; i<mutateCount; i++) {
353 var idx = randomInt(args.length);
354 newArgs[idx] = generateRandomArg(idx, args.length);
355 }
356 return newArgs;
357 };
358
359 // Calls testFunction numberOfTests times with arguments generated by
360 // argGen.generate() (or empty arguments if no generate present).
361 //
362 // The arguments testFunction is called with are the generated args,
363 // the argGen, and what argGen.setup() returned or [] if argGen has not setup
364 // method. I.e. testFunction(generatedArgs, argGen, setupVars).
365 //
366 argGeneratorTestRunner = function(argGen, testFunction, numberOfTests) {
367 // do argument generator setup if needed
368 var setupVars = argGen.setup ? argGen.setup() : [];
369 var error;
370 for (var i=0; i<numberOfTests; i++) {
371 var failed = false;
372 // generate arguments if argGen has a generate method
373 var generatedArgs = argGen.generate ? argGen.generate.apply(argGen, setupVar s) : [];
374 try {
375 // call testFunction with the generated args
376 testFunction.call(this, generatedArgs, argGen, setupVars);
377 } catch (e) {
378 failed = true;
379 error = e;
380 }
381 // if argGen needs cleanup for generated args, do it here
382 if (argGen.cleanup)
383 argGen.cleanup.apply(argGen, generatedArgs);
384 if (failed) break;
385 }
386 // if argGen needs to do a final cleanup for setupVars, do it here
387 if (argGen.teardown)
388 argGen.teardown.apply(argGen, setupVars);
389 if (error) throw(error);
390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698