Pārlūkot izejas kodu

tests-repeating from config

Raanan Weber 7 gadi atpakaļ
vecāks
revīzija
cdd17f587f

+ 30 - 15
Viewer/tests/validation/config.json

@@ -5,7 +5,7 @@
             "title": "Control",
             "createMesh": true,
             "configuration": {
-                "extends": "extended"
+                "extends": "extended, shadowDirectionalLight"
             },
             "referenceImage": "Control.png"
         },
@@ -14,7 +14,7 @@
             "createMesh": true,
             "createMaterial": true,
             "configuration": {
-                "extends": "extended",
+                "extends": "extended, shadowDirectionalLight",
                 "castShadow": true,
                 "model": {
                     "material": {
@@ -35,23 +35,44 @@
             "referenceImage": "Diffuse.png"
         },
         {
-            "title": "BrainStem",
+            "title": "Specular {{glos * 20}} - {{spec * 20}}",
+            "createMesh": true,
+            "createMaterial": true,
+            "repeatVariables": "glos,spec",
+            "repeatTimes": "6,6",
             "configuration": {
-                "extends": "extended",
-                "skybox": {
-                    "cubeTexture": {
-                        "url": "/dist/assets/environment/DefaultSkybox_cube_radiance_256.dds",
-                        "gammaSpace": false
+                "extends": "extended, shadowDirectionalLight",
+                "castShadow": true,
+                "model": {
+                    "material": {
+                        "albedoColor": {
+                            "r": 0,
+                            "g": 0,
+                            "b": 1
+                        },
+                        "reflectivityColor": {
+                            "r": "{{spec / 5}}",
+                            "g": "{{spec / 5}}",
+                            "b": "{{spec / 5}}"
+                        },
+                        "microSurface": "{{glos / 5}}"
                     }
                 }
             },
+            "referenceImage": "Specular{{glos * 20}}-{{spec * 20}}.png"
+        },
+        {
+            "title": "BrainStem",
+            "configuration": {
+                "extends": "extended, shadowDirectionalLight"
+            },
             "model": "/dist/assets/BrainStem/BrainStem.gltf",
             "referenceImage": "BrainStem.png"
         },
         {
             "title": "BrainStem transformation",
             "configuration": {
-                "extends": "extended",
+                "extends": "extended, shadowDirectionalLight",
                 "camera": {
                     "disableAutoFocus": true
                 },
@@ -63,12 +84,6 @@
                     "rotation": {
                         "y": 0.9
                     }
-                },
-                "skybox": {
-                    "cubeTexture": {
-                        "url": "/dist/assets/environment/DefaultSkybox_cube_radiance_256.dds",
-                        "gammaSpace": false
-                    }
                 }
             },
             "model": "/dist/assets/BrainStem/BrainStem.gltf",

+ 70 - 5
Viewer/tests/validation/integration.js

@@ -13,16 +13,45 @@ window.onload = function () {
 
             config = JSON.parse(xhr.responseText);
 
+            config.tests.forEach(function (test, index) {
+                if (test.repeatVariables) {
+                    let paramsArray = [];
+                    var variables = test.repeatVariables.split(",");
+                    var repeatTimes = test.repeatTimes.split(",").map(s => +s);
+
+                    for (var i = 0; i < repeatTimes[0]; ++i) {
+                        if (repeatTimes[1]) {
+                            for (var j = 0; j < repeatTimes[1]; ++j) {
+                                var obj = {};
+                                obj[variables[0]] = i;
+                                obj[variables[1]] = j;
+                                paramsArray.push(obj);
+                            }
+                        } else {
+                            var obj = {};
+                            obj[variables[0]] = i;
+                            paramsArray.push(obj);
+                        }
+                    }
+                    paramsArray.forEach(function (params) {
+
+                        let newTest = processTest(test, "", params);
+                        delete newTest.repeatVariables;
+                        config.tests.push(newTest);
+                    });
+                }
+            });
+
             describe("Validation Tests", function () {
                 // Run tests
-                for (let index = 0; index < config.tests.length; index++) {
-                    var test = config.tests[index];
-                    if (test.onlyVisual || test.excludeFromAutomaticTesting) {
-                        continue;
+                config.tests.forEach(function (test, index) {
+                    if (test.repeatVariables || test.onlyVisual || test.excludeFromAutomaticTesting) {
+                        return;
                     }
 
                     it(test.title, function (done) {
                         this.timeout(60000);
+                        var self = this;
 
                         var deferredDone = function (err) {
                             setTimeout(function () {
@@ -43,12 +72,13 @@ window.onload = function () {
                                     deferredDone(e);
                                 }
                             });
+
                         }
                         catch (e) {
                             deferredDone(e);
                         }
                     });
-                };
+                });
             });
 
             window.__karma__.start();
@@ -58,3 +88,38 @@ window.onload = function () {
 
     xhr.send();
 }
+
+function processTest(test, key, params) {
+    if (!key) {
+        let testCopy = Object.assign({}, test);
+        Object.keys(testCopy).forEach(testKey => {
+            testCopy[testKey] = processTest(testCopy, testKey, params);
+        });
+        return testCopy;
+    } else {
+        if (typeof test[key] === "object") {
+            let testCopy = Object.assign({}, test[key]);
+            Object.keys(testCopy).forEach(testKey => {
+                testCopy[testKey] = processTest(testCopy, testKey, params);
+            });
+            return testCopy;
+        } else if (typeof test[key] === "string") {
+            let evals = test[key].match(/{{\s*([^{}]+)\s*}}/g);
+            if (evals) {
+                let clean = evals.map(function (x) { var s = x.replace(/}/g, "").replace(/{/g, ""); return s; });
+                evals.forEach((ev, idx) => {
+                    var valuated = clean[idx];
+                    Object.keys(params).forEach(p => {
+                        valuated = valuated.replace(p, "" + params[p]);
+                    });
+                    valuated = eval(valuated);
+                    test[key] = test[key].replace(ev, valuated);
+                });
+                test[key] = parseFloat(test[key]) || test[key];
+            }
+
+            return test[key];
+        }
+        else return test[key];
+    }
+}

+ 10 - 4
Viewer/tests/validation/validation.js

@@ -7,7 +7,7 @@ var config;
 var justOnce;
 
 var threshold = 25;
-var errorRatio = 2.5;
+var errorRatio = 1.5;
 
 // Overload the random to make it deterministic
 var seed = 100000,
@@ -131,7 +131,14 @@ function runTest(index, done) {
         done(false);
     }
 
-    var test = config.tests[index];
+
+    var test = Object.assign({}, config.tests[index]);
+
+    //process params
+    /*if (params) {
+        processTest(test, "", params);
+    }*/
+
     var container = document.createElement("div");
     container.id = "container#" + index;
     container.className = "container";
@@ -204,7 +211,6 @@ function runTest(index, done) {
     configuration.model = configuration.model || {};
     configuration.model.castShadow = !test.createMesh
 
-
     // create a new viewer
     currentViewer && currentViewer.dispose();
     currentViewer = null;
@@ -215,7 +221,7 @@ function runTest(index, done) {
     currentViewer.onInitDoneObservable.add(() => {
 
         var currentFrame = 0;
-        var waitForFrame = test.waitForFrame || 0;
+        var waitForFrame = test.waitForFrame || 1;
 
         if (test.model) {
             currentViewer.initModel(test.model);