[Piglit] [PATCH 4/15] framework: Bump JSON on disk format to version 9

Dylan Baker dylan at pnwbakers.com
Fri Sep 9 19:18:42 UTC 2016


This change makes the TestResult.pid field into a list of ints instead
of a list. This will be used by the multiple test per process tests to
ensure that all PIDs are recorded when the cherry features is invoked.

This is groundwork for later patches in the series.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/json.py                        |  18 +-
 framework/results.py                              |   2 +-
 framework/test/base.py                            |   2 +-
 unittests/framework/backends/schema/piglit-9.json | 122 +++++++++++++++-
 unittests/framework/backends/shared.py            |   4 +-
 unittests/framework/backends/test_json_update.py  |  85 ++++++++++-
 6 files changed, 228 insertions(+), 5 deletions(-)
 create mode 100644 unittests/framework/backends/schema/piglit-9.json

diff --git a/framework/backends/json.py b/framework/backends/json.py
index 7533f53..a954882 100644
--- a/framework/backends/json.py
+++ b/framework/backends/json.py
@@ -47,7 +47,7 @@ __all__ = [
 ]
 
 # The current version of the JSON results
-CURRENT_JSON_VERSION = 8
+CURRENT_JSON_VERSION = 9
 
 # The level to indent a final file
 INDENT = 4
@@ -296,6 +296,7 @@ def _update_results(results, filepath):
             5: _update_five_to_six,
             6: _update_six_to_seven,
             7: _update_seven_to_eight,
+            8: _update_eight_to_nine,
         }
 
         while results.results_version < CURRENT_JSON_VERSION:
@@ -593,6 +594,21 @@ def _update_seven_to_eight(result):
     return result
 
 
+def _update_eight_to_nine(result):
+    """Update json results from version 8 to 9.
+
+    This changes the PID feild of the TestResult object to alist of Integers or
+    null rather than a single integer or null.
+
+    """
+    for test in compat.viewvalues(result.tests):
+        test.pid = [test.pid]
+
+    result.results_version = 9
+
+    return result
+
+
 REGISTRY = Registry(
     extensions=['', '.json'],
     backend=JSONBackend,
diff --git a/framework/results.py b/framework/results.py
index 756d261..f9ddcb4 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -162,7 +162,7 @@ class TestResult(object):
         self.images = None
         self.traceback = None
         self.exception = None
-        self.pid = None
+        self.pid = []
         if result:
             self.result = result
         else:
diff --git a/framework/test/base.py b/framework/test/base.py
index 63fcaf4..b667b15 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -322,7 +322,7 @@ class Test(object):
                                     universal_newlines=True,
                                     **_EXTRA_POPEN_ARGS)
 
-            self.result.pid = proc.pid
+            self.result.pid.append(proc.pid)
             if not _SUPPRESS_TIMEOUT:
                 out, err = proc.communicate(timeout=self.timeout)
             else:
diff --git a/unittests/framework/backends/schema/piglit-9.json b/unittests/framework/backends/schema/piglit-9.json
new file mode 100644
index 0000000..33f7eef
--- /dev/null
+++ b/unittests/framework/backends/schema/piglit-9.json
@@ -0,0 +1,122 @@
+{
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    "title": "TestrunResult",
+    "description": "The collection of all results",
+    "type": "object",
+    "properties": {
+        "__type__": { "type": "string" },
+        "clinfo": { "type": ["string", "null"] },
+        "glxinfo": { "type": ["string", "null"] },
+        "lspci": { "type": ["string", "null"] },
+        "wglinfo": { "type": ["string", "null"] },
+        "name": { "type": "string" },
+        "results_version": { "type": "number" },
+        "uname": { "type": [ "string", "null" ] },
+        "time_elapsed": { "$ref": "#/definitions/timeAttribute" },
+        "options": {
+            "descrption": "The options that were invoked with this run. These are implementation specific and not required.",
+            "type": "object",
+            "properties": {
+                "exclude_tests": { 
+                    "type": "array",
+                    "items": { "type": "string" },
+                    "uniqueItems": true
+                },
+                "include_filter": { 
+                    "type": "array",
+                    "items": { "type": "string" }
+                },
+                "exclude_filter": { 
+                    "type": "array",
+                    "items": { "type": "string" }
+                },
+                "sync": { "type": "boolean" },
+                "valgrind": { "type": "boolean" },
+                "monitored": { "type": "boolean" },
+                "dmesg": { "type": "boolean" },
+                "execute": { "type": "boolean" },
+                "concurrent": { "enum": ["none", "all", "some"] },
+                "platform": { "type": "string" },
+                "log_level": { "type": "string" },
+                "env": {
+                    "description": "Environment variables that must be specified",
+                    "type": "object",
+                    "additionalProperties": { "type": "string" }
+                },
+                "profile": {
+                    "type": "array",
+                    "items": { "type": "string" }
+                }
+            }
+        },
+        "totals": {
+            "type": "object",
+            "description": "A calculation of the group totals.",
+            "additionalProperties": {
+                "type": "object",
+                "properties": {
+                    "crash": { "type": "number" },
+                    "dmesg-fail": { "type": "number" },
+                    "dmesg-warn": { "type": "number" },
+                    "fail": { "type": "number" },
+                    "incomplete": { "type": "number" },
+                    "notrun": { "type": "number" },
+                    "pass": { "type": "number" },
+                    "skip": { "type": "number" },
+                    "timeout": { "type": "number" },
+                    "warn": { "type": "number" }
+                },
+                "additionalProperties": false,
+                "required": [ "crash", "dmesg-fail", "dmesg-warn", "fail", "incomplete", "notrun", "pass", "skip", "timeout", "warn" ]
+            }
+        },
+        "tests": {
+            "type": "object",
+            "additionalProperties": {
+                "type": "object",
+                "properties": {
+                    "__type__": { "type": "string" },
+                    "err": { "type": "string" },
+                    "exception": { "type": ["string", "null"] },
+                    "result": {
+                        "type": "string",
+                        "enum": [ "pass", "fail", "crash", "warn", "incomplete", "notrun", "skip", "dmesg-warn", "dmesg-fail" ]
+                    },
+                    "environment": { "type": "string" },
+                    "command": { "type": "string" },
+                    "traceback": { "type": ["string", "null"] },
+                    "out": { "type": "string" },
+                    "dmesg": { "type": "string" },
+                    "pid": {
+                        "type": "array",
+                        "items": { "type": "number" }
+                    },
+                    "returncode": { "type": [ "number", "null" ] },
+                    "time": { "$ref": "#/definitions/timeAttribute" },
+                    "subtests": {
+                        "type": "object",
+                        "properties": { "__type__": { "type": "string" } },
+                        "additionalProperties": { "type": "string" },
+                        "required": [ "__type__" ]
+                    }
+                },
+                "additionalProperties": false
+            }
+        }
+    },
+    "additionalProperties": false,
+    "required": [ "__type__", "clinfo", "glxinfo", "lspci", "wglinfo", "name", "results_version", "uname", "time_elapsed", "totals", "tests" ],
+    "definitions": {
+        "timeAttribute": {
+            "type": "object",
+            "description": "An element containing a start and end time",
+            "properties": {
+                "__type__": { "type": "string" },
+                "start": { "type": "number" },
+                "end": { "type": "number" }
+            },
+            "additionalProperties": false,
+            "required": [ "__type__", "start", "end" ]
+        }
+    }
+}
diff --git a/unittests/framework/backends/shared.py b/unittests/framework/backends/shared.py
index eeffe76..9602ae2 100644
--- a/unittests/framework/backends/shared.py
+++ b/unittests/framework/backends/shared.py
@@ -39,7 +39,7 @@ INITIAL_METADATA = {
 # changes. This does not contain piglit specifc objects, only strings, floats,
 # ints, and Nones (instead of JSON's null)
 JSON = {
-    "results_version": 8,
+    "results_version": 9,
     "time_elapsed": {
         "start": 1469638791.2351687,
         "__type__": "TimeAttribute",
@@ -64,7 +64,7 @@ JSON = {
                 "__type__": "TimeAttribute",
                 "end": 1469638791.2439244
             },
-            "pid": 11768,
+            "pid": [11768],
             "__type__": "TestResult",
             "returncode": 1,
             "result": "fail",
diff --git a/unittests/framework/backends/test_json_update.py b/unittests/framework/backends/test_json_update.py
index 33b4c09..501a895 100644
--- a/unittests/framework/backends/test_json_update.py
+++ b/unittests/framework/backends/test_json_update.py
@@ -34,6 +34,7 @@ try:
 except ImportError:
     from unittest import mock
 
+import jsonschema
 import pytest
 import six
 
@@ -865,3 +866,87 @@ class TestV7toV8(object):
         """
         assert result.time_elapsed.start == 0.0
         assert result.time_elapsed.end == 1.2
+
+    def test_valid(self, result):
+        with open(os.path.join(os.path.dirname(__file__), 'schema',
+                               'piglit-8.json'),
+                  'r') as f:
+            schema = json.load(f)
+        jsonschema.validate(
+            json.loads(json.dumps(result, default=backends.json.piglit_encoder)),
+            schema)
+
+
+class TestV8toV9(object):
+    """Tests for Version 8 to version 9."""
+
+    data = {
+        "results_version": 9,
+        "name": "test",
+        "options": {
+            "profile": ['quick'],
+            "dmesg": False,
+            "verbose": False,
+            "platform": "gbm",
+            "sync": False,
+            "valgrind": False,
+            "filter": [],
+            "concurrent": "all",
+            "test_count": 0,
+            "exclude_tests": [],
+            "exclude_filter": [],
+            "env": {
+                "lspci": "stuff",
+                "uname": "more stuff",
+                "glxinfo": "and stuff",
+                "wglinfo": "stuff"
+            }
+        },
+        "tests": {
+            'a at test': {
+                "time_elapsed": {
+                    'start': 1.2,
+                    'end': 1.8,
+                    '__type__': 'TimeAttribute'
+                },
+                'dmesg': '',
+                'result': 'fail',
+                '__type__': 'TestResult',
+                'command': '/a/command',
+                'traceback': None,
+                'out': '',
+                'environment': 'A=variable',
+                'returncode': 0,
+                'err': '',
+                'pid': 5,
+                'subtests': {
+                    '__type__': 'Subtests',
+                },
+                'exception': None,
+            }
+        },
+        "time_elapsed": {
+            'start': 1.2,
+            'end': 1.8,
+            '__type__': 'TimeAttribute'
+        }
+    }
+
+    @pytest.fixture
+    def result(self, tmpdir):
+        p = tmpdir.join('result.json')
+        p.write(json.dumps(self.data, default=backends.json.piglit_encoder))
+        with p.open('r') as f:
+            return backends.json._update_eight_to_nine(backends.json._load(f))
+
+    def test_pid(self, result):
+        assert result.tests['a at test'].pid == [5]
+
+    def test_valid(self, result):
+        with open(os.path.join(os.path.dirname(__file__), 'schema',
+                               'piglit-9.json'),
+                  'r') as f:
+            schema = json.load(f)
+        jsonschema.validate(
+            json.loads(json.dumps(result, default=backends.json.piglit_encoder)),
+            schema)
-- 
git-series 0.8.10


More information about the Piglit mailing list