How to use restart method in lisa

Best Python code snippet using lisa_python

es3fPrimitiveRestartTests.js

Source:es3fPrimitiveRestartTests.js Github

copy

Full Screen

1/*-------------------------------------------------------------------------2 * drawElements Quality Program OpenGL ES Utilities3 * ------------------------------------------------4 *5 * Copyright 2014 The Android Open Source Project6 *7 * Licensed under the Apache License, Version 2.0 (the "License");8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 *19 */20'use strict';21goog.provide('functional.gles3.es3fPrimitiveRestartTests');22goog.require('framework.common.tcuImageCompare');23goog.require('framework.common.tcuSurface');24goog.require('framework.common.tcuTestCase');25goog.require('framework.delibs.debase.deMath');26goog.require('framework.delibs.debase.deRandom');27goog.require('framework.delibs.debase.deString');28goog.require('framework.opengl.gluShaderProgram');29goog.require('framework.opengl.gluTextureUtil');30goog.scope(function() {31var es3fPrimitiveRestartTests = functional.gles3.es3fPrimitiveRestartTests;32var tcuTestCase = framework.common.tcuTestCase;33var gluShaderProgram = framework.opengl.gluShaderProgram;34var tcuSurface = framework.common.tcuSurface;35var deMath = framework.delibs.debase.deMath;36var deRandom = framework.delibs.debase.deRandom;37var deString = framework.delibs.debase.deString;38var tcuImageCompare = framework.common.tcuImageCompare;39var gluTextureUtil = framework.opengl.gluTextureUtil;40 /** @type {WebGL2RenderingContext} */ var gl;41 /** @const @type {number} */ es3fPrimitiveRestartTests.MAX_RENDER_WIDTH = 256;42 /** @const @type {number} */ es3fPrimitiveRestartTests.MAX_RENDER_HEIGHT = 256;43 /** @const @type {number} */ es3fPrimitiveRestartTests.MAX_UNSIGNED_BYTE = 255;44 /** @const @type {number} */ es3fPrimitiveRestartTests.MAX_UNSIGNED_SHORT = 65535;45 /** @const @type {number} */ es3fPrimitiveRestartTests.MAX_UNSIGNED_INT = 4294967295;46 /** @const @type {number} */ es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_BYTE = es3fPrimitiveRestartTests.MAX_UNSIGNED_BYTE;47 /** @const @type {number} */ es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_SHORT = es3fPrimitiveRestartTests.MAX_UNSIGNED_SHORT;48 /** @const @type {number} */ es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_INT = es3fPrimitiveRestartTests.MAX_UNSIGNED_INT;49 var DE_ASSERT = function(expression) {50 if (!expression) throw new Error('Assert failed');51 };52 /**53 * @enum54 */55 es3fPrimitiveRestartTests.PrimitiveType = {56 PRIMITIVE_POINTS: 0,57 PRIMITIVE_LINE_STRIP: 1,58 PRIMITIVE_LINE_LOOP: 2,59 PRIMITIVE_LINES: 3,60 PRIMITIVE_TRIANGLE_STRIP: 4,61 PRIMITIVE_TRIANGLE_FAN: 5,62 PRIMITIVE_TRIANGLES: 663 };64 /**65 * @enum66 */67 es3fPrimitiveRestartTests.IndexType = {68 INDEX_UNSIGNED_BYTE: 0,69 INDEX_UNSIGNED_SHORT: 1,70 INDEX_UNSIGNED_INT: 271 };72 /**73 * @enum74 */75 es3fPrimitiveRestartTests.DrawFunction = {76 FUNCTION_DRAW_ELEMENTS: 0,77 FUNCTION_DRAW_ELEMENTS_INSTANCED: 1,78 FUNCTION_DRAW_RANGE_ELEMENTS: 279 };80 /**81 * es3fPrimitiveRestartTests.PrimitiveRestartCase class, inherits from TestCase class82 * @constructor83 * @extends {tcuTestCase.DeqpTest}84 * @param {?string} name85 * @param {string} description86 * @param {es3fPrimitiveRestartTests.PrimitiveType} primType87 * @param {es3fPrimitiveRestartTests.IndexType} indexType88 * @param {es3fPrimitiveRestartTests.DrawFunction} _function89 * @param {boolean} beginWithRestart90 * @param {boolean} endWithRestart91 * @param {boolean} duplicateRestarts92 */93 es3fPrimitiveRestartTests.PrimitiveRestartCase = function(name, description, primType, indexType, _function, beginWithRestart, endWithRestart, duplicateRestarts) {94 tcuTestCase.DeqpTest.call(this, name, description);95 /** @type {es3fPrimitiveRestartTests.PrimitiveType} */ this.m_primType = primType;96 /** @type {es3fPrimitiveRestartTests.IndexType} */ this.m_indexType = indexType;97 /** @type {es3fPrimitiveRestartTests.DrawFunction} */ this.m_function = _function;98 /** @type {boolean} */ this.m_beginWithRestart = beginWithRestart; // Whether there will be restart indices at the beginning of the index array.99 /** @type {boolean} */ this.m_endWithRestart = endWithRestart; // Whether there will be restart indices at the end of the index array.100 /** @type {boolean} */ this.m_duplicateRestarts = duplicateRestarts; // Whether two consecutive restarts are used instead of one.101 /** @type {gluShaderProgram.ShaderProgram} */ this.m_program = null;102 // \note Only one of the following index vectors is used (according to m_indexType).103 /** @type {Array<number>} */ this.m_indicesUB = []; //deUint8104 /** @type {Array<number>} */ this.m_indicesUS = []; //deUint16105 /** @type {Array<number>} */ this.m_indicesUI = []; //deUint32106 /** @type {Array<number>} */ this.m_positions = [];107 };108 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);109 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.constructor = es3fPrimitiveRestartTests.PrimitiveRestartCase;110 /**111 * Draw with the appropriate GLES3 draw function.112 * @param {number} startNdx113 * @param {number} count114 */115 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.draw = function(startNdx, count) {116 /** @type {number} */ var primTypeGL;117 switch (this.m_primType) {118 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_POINTS:119 primTypeGL = gl.POINTS;120 break;121 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_STRIP:122 primTypeGL = gl.LINE_STRIP;123 break;124 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_LOOP:125 primTypeGL = gl.LINE_LOOP;126 break;127 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINES:128 primTypeGL = gl.LINES;129 break;130 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_STRIP:131 primTypeGL = gl.TRIANGLE_STRIP;132 break;133 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_FAN:134 primTypeGL = gl.TRIANGLE_FAN;135 break;136 case es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLES:137 primTypeGL = gl.TRIANGLES;138 break;139 default:140 DE_ASSERT(false);141 primTypeGL = 0;142 }143 /** @type {number} */ var indexTypeGL;144 switch (this.m_indexType) {145 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE:146 indexTypeGL = gl.UNSIGNED_BYTE;147 break;148 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT:149 indexTypeGL = gl.UNSIGNED_SHORT;150 break;151 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT:152 indexTypeGL = gl.UNSIGNED_INT;153 break;154 default:155 DE_ASSERT(false);156 indexTypeGL = 0;157 }158 /** @type {number} */ var restartIndex = this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_BYTE :159 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_SHORT :160 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_INT :161 0;162 DE_ASSERT(restartIndex != 0);163 var indexGLBuffer = gl.createBuffer();164 var bufferIndex = this.getIndexPtr(startNdx);165 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexGLBuffer);166 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, bufferIndex, gl.STATIC_DRAW);167 if (this.m_function == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_ELEMENTS) {168 gl.drawElements(primTypeGL, count, indexTypeGL, 0);169 } else if (this.m_function == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_ELEMENTS_INSTANCED) {170 gl.drawElementsInstanced(primTypeGL, count, indexTypeGL, 0, 1);171 } else {172 DE_ASSERT(this.m_function == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_RANGE_ELEMENTS);173 // Find the largest non-restart index in the index array (for glDrawRangeElements() end parameter).174 /** @type {number} */ var max = 0;175 /** @type {number} */ var numIndices = this.getNumIndices();176 for (var i = 0; i < numIndices; i++) {177 /** @type {number} */ var index = this.getIndex(i);178 if (index != restartIndex && index > max)179 max = index;180 }181 //TODO: drawRangeElements -> check getIndexPtr usage182 gl.drawRangeElements(primTypeGL, 0, max, count, indexTypeGL, 0);183 }184 };185 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.renderWithRestart = function() {186 // Primitive Restart is always on in WebGL2187 //gl.enable(gl.PRIMITIVE_RESTART_FIXED_INDEX);188 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);189 this.draw(0, this.getNumIndices());190 };191 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.renderWithoutRestart = function() {192 /** @type {number} */ var restartIndex = this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_BYTE :193 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_SHORT :194 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_INT :195 0;196 DE_ASSERT(restartIndex != 0);197 // Primitive Restart is always on in WebGL2198 //gl.disable(gl.PRIMITIVE_RESTART_FIXED_INDEX);199 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);200 // Draw, emulating primitive restart.201 /** @type {number} */ var numIndices = this.getNumIndices();202 DE_ASSERT(numIndices >= 0);203 /** @type {number} */ var indexArrayStartNdx = 0; // Keep track of the draw start index - first index after a primitive restart, or initially the first index altogether.204 for (var indexArrayNdx = 0; indexArrayNdx <= numIndices; indexArrayNdx++) { // \note Goes one "too far" in order to detect end of array as well.205 if (indexArrayNdx >= numIndices || this.getIndex(indexArrayNdx) == restartIndex) {// \note Handle end of array the same way as a restart index encounter.206 if (indexArrayStartNdx < numIndices) {207 // Draw from index indexArrayStartNdx to index indexArrayNdx-1 .208 this.draw(indexArrayStartNdx, indexArrayNdx - indexArrayStartNdx);209 }210 indexArrayStartNdx = indexArrayNdx + 1; // Next draw starts just after this restart index.211 }212 }213 };214 /**215 * @param {number} index216 */217 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.addIndex = function(index) {218 if (this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE) {219 DE_ASSERT(deMath.deInRange32(index, 0, es3fPrimitiveRestartTests.MAX_UNSIGNED_BYTE));220 this.m_indicesUB.push(index); // deUint8221 } else if (this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT) {222 DE_ASSERT(deMath.deInRange32(index, 0, es3fPrimitiveRestartTests.MAX_UNSIGNED_SHORT));223 this.m_indicesUS.push(index); // deUint16224 } else if (this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT) {225 DE_ASSERT(deMath.deInRange32(index, 0, es3fPrimitiveRestartTests.MAX_UNSIGNED_INT));226 this.m_indicesUI.push(index); // // deUint32227 } else228 DE_ASSERT(false);229 };230 /**231 * @param {number} indexNdx232 * @return {number}233 */234 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.getIndex = function(indexNdx) {235 switch (this.m_indexType) {236 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE:237 return this.m_indicesUB[indexNdx]; //deUint32238 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT:239 return this.m_indicesUS[indexNdx]; //deUint32240 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT:241 return this.m_indicesUI[indexNdx];242 default:243 DE_ASSERT(false);244 return 0;245 }246 };247 /**248 * @return {number}249 */250 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.getNumIndices = function() {251 switch (this.m_indexType) {252 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE:253 return this.m_indicesUB.length;254 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT:255 return this.m_indicesUS.length;256 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT:257 return this.m_indicesUI.length;258 default:259 DE_ASSERT(false);260 return 0;261 }262 };263 /**264 * Pointer to the index value at index indexNdx.265 * @param {number} indexNdx266 * @return {Uint8Array|Uint16Array|Uint32Array}267 */268 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.getIndexPtr = function(indexNdx) {269 //TODO: implement270 switch (this.m_indexType) {271 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE:272 return new Uint8Array(this.m_indicesUB).subarray(indexNdx);273 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT:274 return new Uint16Array(this.m_indicesUS).subarray(indexNdx);275 case es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT:276 return new Uint32Array(this.m_indicesUI).subarray(indexNdx);277 default:278 DE_ASSERT(false);279 return null;280 }281 };282 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.init = function() {283 // Clear errors from previous tests284 gl.getError();285 // Create shader program.286 /** @type {string} */ var vertShaderSource =287 '#version 300 es\n' +288 'in highp vec4 a_position;\n' +289 '\n' +290 'void main()\n' +291 ' {\n' +292 ' gl_Position = a_position;\n' +293 '}\n';294 /** @type {string} */ var fragShaderSource =295 '#version 300 es\n' +296 'layout(location = 0) out mediump vec4 o_color;\n' +297 '\n' +298 'void main()\n' +299 ' {\n' +300 ' o_color = vec4(1.0f);\n' +301 '}\n';302 DE_ASSERT(!this.m_program);303 this.m_program = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(vertShaderSource, fragShaderSource));304 if (!this.m_program.isOk()) {305 //m_testCtx.getLog() << *this.m_program;306 testFailedOptions('Failed to compile shader', true);307 }308 /** @type {number} */ var restartIndex = this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_BYTE :309 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_SHORT :310 this.m_indexType == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT ? es3fPrimitiveRestartTests.RESTART_INDEX_UNSIGNED_INT :311 0;312 DE_ASSERT(restartIndex != 0);313 DE_ASSERT(this.getNumIndices() == 0);314 // If testing a case with restart at beginning, add it there.315 if (this.m_beginWithRestart) {316 this.addIndex(restartIndex);317 if (this.m_duplicateRestarts)318 this.addIndex(restartIndex);319 }320 // Generate vertex positions and indices depending on primitive type.321 // \note At this point, restarts shall not be added to the start or the end of the index vector. Those are special cases, and are done above and after the following if-else chain, respectively.322 /** @type {number} */ var curIndex;323 /** @type {number} */ var numRows;324 /** @type {number} */ var numCols;325 /** @type {number} */ var fx;326 /** @type {number} */ var fy;327 /** @type {number} */ var centerY;328 /** @type {number} */ var centerX;329 /** @type {number} */ var numVertices;330 /** @type {number} */ var numArcVertices;331 /** @type {number} */ var numStrips;332 if (this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_POINTS) {333 // Generate rows with different numbers of points.334 curIndex = 0;335 numRows = 20;336 for (var row = 0; row < numRows; row++) {337 for (var col = 0; col < row + 1; col++) {338 fx = -1.0 + 2.0 * (col + 0.5) / numRows;339 fy = -1.0 + 2.0 * (row + 0.5) / numRows;340 this.m_positions.push(fx);341 this.m_positions.push(fy);342 this.addIndex(curIndex++);343 }344 if (row < numRows - 1) { // Add a restart after all but last row.345 this.addIndex(restartIndex);346 if (this.m_duplicateRestarts)347 this.addIndex(restartIndex);348 }349 }350 } else if (this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_STRIP || this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_LOOP || this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINES) {351 // Generate a numRows x numCols arrangement of line polygons of different vertex counts.352 curIndex = 0;353 numRows = 4;354 numCols = 4;355 for (var row = 0; row < numRows; row++) {356 centerY = -1.0 + 2.0 * (row + 0.5) / numRows;357 for (var col = 0; col < numCols; col++) {358 centerX = -1.0 + 2.0 * (col + 0.5) / numCols;359 numVertices = row * numCols + col + 1;360 for (var i = 0; i < numVertices; i++) {361 fx = centerX + 0.9 * Math.cos(i * 2.0 * Math.PI / numVertices) / numCols;362 fy = centerY + 0.9 * Math.sin(i * 2.0 * Math.PI / numVertices) / numRows;363 this.m_positions.push(fx);364 this.m_positions.push(fy);365 this.addIndex(curIndex++);366 }367 if (col < numCols - 1 || row < numRows - 1) {// Add a restart after all but last polygon.368 this.addIndex(restartIndex);369 if (this.m_duplicateRestarts)370 this.addIndex(restartIndex);371 }372 }373 }374 } else if (this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_STRIP) {375 // Generate a number of horizontal triangle strips of different lengths.376 curIndex = 0;377 numStrips = 20;378 for (var stripNdx = 0; stripNdx < numStrips; stripNdx++) {379 numVertices = stripNdx + 1;380 for (var i = 0; i < numVertices; i++) {381 fx = -0.9 + 1.8 * (i / 2 * 2) / numStrips;382 fy = -0.9 + 1.8 * (stripNdx + (i % 2 == 0 ? 0.0 : 0.8)) / numStrips;383 this.m_positions.push(fx);384 this.m_positions.push(fy);385 this.addIndex(curIndex++);386 }387 if (stripNdx < numStrips - 1) { // Add a restart after all but last strip.388 this.addIndex(restartIndex);389 if (this.m_duplicateRestarts)390 this.addIndex(restartIndex);391 }392 }393 } else if (this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_FAN) {394 // Generate a numRows x numCols arrangement of triangle fan polygons of different vertex counts.395 curIndex = 0;396 numRows = 4;397 numCols = 4;398 for (var row = 0; row < numRows; row++) {399 centerY = -1.0 + 2.0 * (row + 0.5) / numRows;400 for (var col = 0; col < numCols; col++) {401 centerX = -1.0 + 2.0 * (col + 0.5) / numCols;402 numArcVertices = row * numCols + col;403 this.m_positions.push(centerX);404 this.m_positions.push(centerY);405 this.addIndex(curIndex++);406 for (var i = 0; i < numArcVertices; i++) {407 fx = centerX + 0.9 * Math.cos(i * 2.0 * Math.PI / numArcVertices) / numCols;408 fy = centerY + 0.9 * Math.sin(i * 2.0 * Math.PI / numArcVertices) / numRows;409 this.m_positions.push(fx);410 this.m_positions.push(fy);411 this.addIndex(curIndex++);412 }413 if (col < numCols - 1 || row < numRows - 1) { // Add a restart after all but last polygon.414 this.addIndex(restartIndex);415 if (this.m_duplicateRestarts)416 this.addIndex(restartIndex);417 }418 }419 }420 } else if (this.m_primType == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLES) {421 // Generate a number of rows with (potentially incomplete) triangles.422 curIndex = 0;423 numRows = 3 * 7;424 for (var rowNdx = 0; rowNdx < numRows; rowNdx++) {425 numVertices = rowNdx + 1;426 for (var i = 0; i < numVertices; i++) {427 fx = -0.9 + 1.8 * ((i / 3) + (i % 3 == 2 ? 0.8 : 0.0)) * 3 / numRows;428 fy = -0.9 + 1.8 * (rowNdx + (i % 3 == 0 ? 0.0 : 0.8)) / numRows;429 this.m_positions.push(fx);430 this.m_positions.push(fy);431 this.addIndex(curIndex++);432 }433 if (rowNdx < numRows - 1) { // Add a restart after all but last row.434 this.addIndex(restartIndex);435 if (this.m_duplicateRestarts)436 this.addIndex(restartIndex);437 }438 }439 } else440 DE_ASSERT(false);441 // If testing a case with restart at end, add it there.442 if (this.m_endWithRestart) {443 this.addIndex(restartIndex);444 if (this.m_duplicateRestarts)445 this.addIndex(restartIndex);446 }447 // Special case assertions.448 /** @type {number} */ var numIndices = this.getNumIndices();449 DE_ASSERT(numIndices > 0);450 DE_ASSERT(this.m_beginWithRestart || this.getIndex(0) != restartIndex); // We don't want restarts at beginning unless the case is a special case.451 DE_ASSERT(this.m_endWithRestart || this.getIndex(numIndices - 1) != restartIndex); // We don't want restarts at end unless the case is a special case.452 if (!this.m_duplicateRestarts)453 for (var i = 1; i < numIndices; i++)454 DE_ASSERT(this.getIndex(i) != restartIndex || this.getIndex(i - 1) != restartIndex); // We don't want duplicate restarts unless the case is a special case.455 };456 es3fPrimitiveRestartTests.PrimitiveRestartCase.prototype.iterate = function() {457 /** @type {number} */ var width = Math.min(gl.drawingBufferWidth, es3fPrimitiveRestartTests.MAX_RENDER_WIDTH);458 /** @type {number} */ var height = Math.min(gl.drawingBufferHeight, es3fPrimitiveRestartTests.MAX_RENDER_HEIGHT);459 /** @type {number} */ var xOffsetMax = gl.drawingBufferWidth - width;460 /** @type {number} */ var yOffsetMax = gl.drawingBufferHeight - height;461 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(deString.deStringHash(this.name));462 /** @type {number} */ var xOffset = rnd.getInt(0, xOffsetMax);463 /** @type {number} */ var yOffset = rnd.getInt(0, yOffsetMax);464 /** @type {tcuSurface.Surface} */ var referenceImg = new tcuSurface.Surface(width, height);465 /** @type {tcuSurface.Surface} */ var resultImg = new tcuSurface.Surface(width, height);466 gl.viewport(xOffset, yOffset, width, height);467 gl.clearColor(0.0, 0.0, 0.0, 1.0);468 var program = this.m_program.getProgram();469 gl.useProgram(program);470 // Setup position attribute.471 /** @type {number} */ var loc = gl.getAttribLocation(program, 'a_position');472 gl.enableVertexAttribArray(loc);473 var locGlBuffer = gl.createBuffer();474 var bufferLoc = new Float32Array(this.m_positions);475 gl.bindBuffer(gl.ARRAY_BUFFER, locGlBuffer);476 gl.bufferData(gl.ARRAY_BUFFER, bufferLoc, gl.STATIC_DRAW);477 gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);478 // Render result.479 this.renderWithRestart();480 var resImg = resultImg.getAccess();481 var resImgTransferFormat = gluTextureUtil.getTransferFormat(resImg.getFormat());482 gl.readPixels(xOffset, yOffset, resImg.m_width, resImg.m_height, resImgTransferFormat.format, resImgTransferFormat.dataType, resultImg.m_pixels);483 // Render reference (same scene as the real deal, but emulate primitive restart without actually using it).484 this.renderWithoutRestart();485 var refImg = referenceImg.getAccess();486 var refImgTransferFormat = gluTextureUtil.getTransferFormat(refImg.getFormat());487 gl.readPixels(xOffset, yOffset, refImg.m_width, refImg.m_height, refImgTransferFormat.format, refImgTransferFormat.dataType, referenceImg.m_pixels);488 // Compare.489 /** @type {boolean} */ var testOk = tcuImageCompare.pixelThresholdCompare('ComparisonResult', 'Image comparison result', referenceImg, resultImg, [0, 0, 0, 0]);490 assertMsgOptions(testOk, '', true, false);491 gl.useProgram(null);492 return tcuTestCase.IterateResult.STOP;493 };494 es3fPrimitiveRestartTests.init = function() {495 var testGroup = tcuTestCase.runner.testCases;496 for (var isRestartBeginCaseI = 0; isRestartBeginCaseI <= 1; isRestartBeginCaseI++) {497 for (var isRestartEndCaseI = 0; isRestartEndCaseI <= 1; isRestartEndCaseI++) {498 for (var isDuplicateRestartCaseI = 0; isDuplicateRestartCaseI <= 1; isDuplicateRestartCaseI++) {499 /** @type {boolean} */ var isRestartBeginCase = isRestartBeginCaseI != 0;500 /** @type {boolean} */ var isRestartEndCase = isRestartEndCaseI != 0;501 /** @type {boolean} */ var isDuplicateRestartCase = isDuplicateRestartCaseI != 0;502 /** @type {string} */ var specialCaseGroupName = '';503 if (isRestartBeginCase) specialCaseGroupName = 'begin_restart';504 if (isRestartEndCase) specialCaseGroupName += (deString.deIsStringEmpty(specialCaseGroupName) ? '' : '_') + 'end_restart';505 if (isDuplicateRestartCase) specialCaseGroupName += (deString.deIsStringEmpty(specialCaseGroupName) ? '' : '_') + 'duplicate_restarts';506 if (deString.deIsStringEmpty(specialCaseGroupName))507 specialCaseGroupName = 'basic';508 /** @type {tcuTestCase.DeqpTest} */ var specialCaseGroup = tcuTestCase.newTest(specialCaseGroupName, '');509 testGroup.addChild(specialCaseGroup);510 for (var primType in es3fPrimitiveRestartTests.PrimitiveType) {511 /** @type {string} */ var primTypeName = es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_POINTS ? 'points' :512 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_STRIP ? 'line_strip' :513 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINE_LOOP ? 'line_loop' :514 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_LINES ? 'lines' :515 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_STRIP ? 'triangle_strip' :516 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLE_FAN ? 'triangle_fan' :517 es3fPrimitiveRestartTests.PrimitiveType[primType] == es3fPrimitiveRestartTests.PrimitiveType.PRIMITIVE_TRIANGLES ? 'triangles' :518 '';519 DE_ASSERT(primTypeName != null);520 /** @type {tcuTestCase.DeqpTest} */ var primTypeGroup = tcuTestCase.newTest(primTypeName, '');521 specialCaseGroup.addChild(primTypeGroup);522 for (var indexType in es3fPrimitiveRestartTests.IndexType) {523 /** @type {string} */ var indexTypeName = es3fPrimitiveRestartTests.IndexType[indexType] == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_BYTE ? 'unsigned_byte' :524 es3fPrimitiveRestartTests.IndexType[indexType] == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_SHORT ? 'unsigned_short' :525 es3fPrimitiveRestartTests.IndexType[indexType] == es3fPrimitiveRestartTests.IndexType.INDEX_UNSIGNED_INT ? 'unsigned_int' :526 '';527 DE_ASSERT(indexTypeName != null);528 /** @type {tcuTestCase.DeqpTest} */ var indexTypeGroup = tcuTestCase.newTest(indexTypeName, '');529 primTypeGroup.addChild(indexTypeGroup);530 for (var _function in es3fPrimitiveRestartTests.DrawFunction) {531 /** @type {?string} */ var functionName = es3fPrimitiveRestartTests.DrawFunction[_function] == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_ELEMENTS ? 'draw_elements' :532 es3fPrimitiveRestartTests.DrawFunction[_function] == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_ELEMENTS_INSTANCED ? 'draw_elements_instanced' :533 es3fPrimitiveRestartTests.DrawFunction[_function] == es3fPrimitiveRestartTests.DrawFunction.FUNCTION_DRAW_RANGE_ELEMENTS ? 'draw_range_elements' :534 null;535 DE_ASSERT(functionName != null);536 indexTypeGroup.addChild(new es3fPrimitiveRestartTests.PrimitiveRestartCase(functionName,537 '',538 es3fPrimitiveRestartTests.PrimitiveType[primType],539 es3fPrimitiveRestartTests.IndexType[indexType],540 es3fPrimitiveRestartTests.DrawFunction[_function],541 isRestartBeginCase,542 isRestartEndCase,543 isDuplicateRestartCase));544 }545 }546 }547 }548 }549 }550 };551 es3fPrimitiveRestartTests.run = function(context, range) {552 gl = context;553 //Set up Test Root parameters554 var testName = 'primitive_restart';555 var testDescription = 'Primitive Restart Tests';556 var state = tcuTestCase.runner;557 state.testName = testName;558 state.setRoot(tcuTestCase.newTest(testName, testDescription, null));559 //Set up name and description of this test series.560 setCurrentTestName(testName);561 description(testDescription);562 try {563 //Create test cases564 es3fPrimitiveRestartTests.init();565 if (range)566 state.setRange(range);567 //Run test cases568 tcuTestCase.runTestCases();569 }570 catch (err) {571 testFailedOptions('Failed to es3fPrimitiveRestartTests.run tests', false);572 tcuTestCase.runner.terminate();573 }574 };...

Full Screen

Full Screen

restart_strategy.py

Source:restart_strategy.py Github

copy

Full Screen

...167 j_restart_strategy=j_restart_strategy)168 else:169 raise Exception("Unsupported java RestartStrategyConfiguration: %s" % clz.getName())170 @staticmethod171 def no_restart() -> 'NoRestartStrategyConfiguration':172 """173 Generates NoRestartStrategyConfiguration.174 :return: The :class:`NoRestartStrategyConfiguration`.175 """176 return RestartStrategies.NoRestartStrategyConfiguration()177 @staticmethod178 def fall_back_restart() -> 'FallbackRestartStrategyConfiguration':179 return RestartStrategies.FallbackRestartStrategyConfiguration()180 @staticmethod181 def fixed_delay_restart(restart_attempts: int, delay_between_attempts: int) -> \182 'FixedDelayRestartStrategyConfiguration':183 """184 Generates a FixedDelayRestartStrategyConfiguration.185 :param restart_attempts: Number of restart attempts for the FixedDelayRestartStrategy.186 :param delay_between_attempts: Delay in-between restart attempts for the187 FixedDelayRestartStrategy, the input could be integer value188 in milliseconds or datetime.timedelta object.189 :return: The :class:`FixedDelayRestartStrategyConfiguration`.190 """191 return RestartStrategies.FixedDelayRestartStrategyConfiguration(restart_attempts,192 delay_between_attempts)193 @staticmethod194 def failure_rate_restart(failure_rate: int, failure_interval: int, delay_interval: int) -> \195 'FailureRateRestartStrategyConfiguration':196 """197 Generates a FailureRateRestartStrategyConfiguration.198 :param failure_rate: Maximum number of restarts in given interval ``failure_interval``199 before failing a job.200 :param failure_interval: Time interval for failures, the input could be integer value201 in milliseconds or datetime.timedelta object.202 :param delay_interval: Delay in-between restart attempts, the input could be integer value203 in milliseconds or datetime.timedelta object.204 """205 return RestartStrategies.FailureRateRestartStrategyConfiguration(failure_rate,206 failure_interval,...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import "./styles.css";2import GameBoard from "./gameboard.js";3import { BOARD_SIZES } from "./gameboard.js";4// Get game board element5const boardelem = document.getElementById("game_board");6// Get overlay7let overlay = document.getElementById("game_overlay");8// Get status area9let stats = document.getElementById("game_stats");10// Create GameBoard object11let gameboard = new GameBoard(boardelem);12// Pass the overlay element to the board13gameboard.setOverlay(overlay);14// Pass the stats element to the board15gameboard.setStats(stats);16// Start new game with some board size17gameboard.newGame(BOARD_SIZES.SMALL);18// Chosen size (toggled by size option buttons)19let chosenSize = null;20// Get size option buttons and add event listeners to them21let sizebuttons = document.getElementsByClassName("size_option_button");22for (const btn of sizebuttons) {23 btn.addEventListener("click", (e) => {24 chosenSize = getSizeFromButtonID(e.target.id);25 restartWithChosenSize();26 });27}28// Add event listener to win button (debug only)29let winbutton = document.getElementById("win_button");30winbutton.addEventListener("click", () => {31 gameboard.win();32});33// Whether user has confirmed they want to start a new game34// (required if user wants to start a new game while there is35// an ongoing game)36let restartConfirmed = false;37// Get restart confirmation notification and its yes- and no-buttons38let confirmRestartNotif = document.getElementById("confirm-restart");39let confirmRestartYesBtn = document.getElementById("confirm-restart-yes");40let confirmRestartNoBtn = document.getElementById("confirm-restart-no");41// Add event listeners to restart confirmation buttons42// The Yes button requests to restart the game with the43// currently chosen side and hides the notification44confirmRestartYesBtn.addEventListener("click", () => {45 console.log("YES-BUTTON CLICKED");46 showNotification(confirmRestartNotif, false);47 restartConfirmed = true;48 restartWithChosenSize();49});50// The No button hides the notification51confirmRestartNoBtn.addEventListener("click", () => {52 console.log("NO-BUTTON CLICKED");53 showNotification(confirmRestartNotif, false);54});55// Executable script ends here.56// TODO-LIST:57// - timer58// - color change for matching and non matching pairs?59// Function definitions begin here.60// Function to toggle the visibility of a notification element61function showNotification(notif, visible = true) {62 if (visible) {63 notif.classList.remove("hidden");64 } else {65 notif.classList.add("hidden");66 }67}68function getSizeFromButtonID(btn_id) {69 switch (btn_id) {70 case "size_option_small":71 return BOARD_SIZES.SMALL;72 case "size_option_medium":73 return BOARD_SIZES.MEDIUM;74 case "size_option_large":75 return BOARD_SIZES.LARGE;76 default:77 console.log(78 "getSizeFromButtonID WARNING: ID not recognized. Returning null."79 );80 return null;81 }82}83// Restarts the game with84// If there is an ongoing game and the user85// has not confirmed the decision to restart, ask for confirmation86function restartWithChosenSize() {87 if (chosenSize === null) {88 console.log("restartWithChosenSize ERROR: No chosen size. Returning.");89 return;90 }91 console.log(92 "Game in progress: " +93 gameboard.gameInProgress() +94 ", restart confirmed: " +95 restartConfirmed96 );97 // If the game has already been started and user has not98 // confirmed the decision, display notification99 // asking for confirmation on starting a new game.100 if (gameboard.gameInProgress() && !restartConfirmed) {101 console.log(102 "changeBoardSize DEBUG: Game in progress. Must confirm decision."103 );104 showNotification(confirmRestartNotif);105 return;106 }107 // Reset restart confirmation108 restartConfirmed = false;109 // Start new game110 gameboard.newGame(chosenSize);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful