[Piglit] [PATCH 2/3] framework: fix glxinfo, uname, and lspci in json output

Dylan Baker baker.dylan.c at gmail.com
Thu Oct 23 14:43:36 PDT 2014


Move the environment information back into the root of the json output
dictionary.

Also modifies two tests. One is removed because it is basically a
duplicate of the tests added in the last patch, the other is simplified
to be more robust.
---
 framework/backends/json_.py       |  8 ++------
 framework/programs/run.py         | 11 +++++++----
 framework/tests/backends_tests.py | 37 ++++---------------------------------
 3 files changed, 13 insertions(+), 43 deletions(-)

diff --git a/framework/backends/json_.py b/framework/backends/json_.py
index 4632680..f4a740f 100644
--- a/framework/backends/json_.py
+++ b/framework/backends/json_.py
@@ -79,14 +79,10 @@ class JSONBackend(FileBackend):
         """
         # If metadata is None then this is a loaded result and there is no need
         # to initialize
-        out = {
-            'results_version': CURRENT_JSON_VERSION,
-            'name': metadata['name'],
-            'options': {k: v for k, v in metadata.iteritems() if k != 'name'},
-        }
+        metadata['results_version'] = CURRENT_JSON_VERSION
 
         with open(os.path.join(self._dest, 'metadata.json'), 'w') as f:
-            json.dump(out, f, default=piglit_encoder)
+            json.dump(metadata, f, default=piglit_encoder)
 
         # make the directory for the tests
         try:
diff --git a/framework/programs/run.py b/framework/programs/run.py
index 0e0fe7f..dfa4358 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -192,15 +192,18 @@ def _run_parser(input_):
 
 def _create_metadata(args, name, opts):
     """Create and return a metadata dict for Backend.initialize()."""
-    options = {'profile': args.test_profile}
+    options = {}
+    options['profile'] = args.test_profile
     for key, value in opts:
         options[key] = value
     if args.platform:
         options['platform'] = args.platform
-    options['name'] = name
-    options['env'] = core.collect_system_info()
 
-    return options
+    metadata = {'options': options}
+    metadata['name'] = name
+    metadata.update(core.collect_system_info())
+
+    return metadata
 
 
 def run(input_):
diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py
index 177225d..dc73f2f 100644
--- a/framework/tests/backends_tests.py
+++ b/framework/tests/backends_tests.py
@@ -32,6 +32,7 @@ try:
 except ImportError:
     import json
 import nose.tools as nt
+import framework.core as core
 import framework.results as results
 import framework.backends as backends
 import framework.tests.utils as utils
@@ -39,8 +40,9 @@ import framework.tests.utils as utils
 
 BACKEND_INITIAL_META = {
     'name': 'name',
-    'env': {},
     'test_count': 0,
+    'env': {},
+    'options': {k: v for k, v in core.Options()},
 }
 
 JUNIT_SCHEMA = 'framework/tests/schema/junit-7.xsd'
@@ -164,23 +166,11 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
 
 def test_json_initialize_metadata():
     """ JSONBackend.initialize() produces a metadata.json file """
-    baseline = {
-        'name': BACKEND_INITIAL_META['name'],
-        'results_version': backends.CURRENT_JSON_VERSION,
-        'options': {
-            'test_count': BACKEND_INITIAL_META['test_count'],
-            'env': BACKEND_INITIAL_META['env'],
-        }
-    }
-
     with utils.tempdir() as f:
         test = backends.JSONBackend(f)
         test.initialize(BACKEND_INITIAL_META)
 
-        with open(os.path.join(f, 'metadata.json'), 'r') as t:
-            test = json.load(t)
-
-    nt.assert_dict_equal(baseline, test)
+        nt.ok_(os.path.exists(os.path.join(f, 'metadata.json')))
 
 
 class TestJSONTestMethod(utils.StaticDirectory):
@@ -254,25 +244,6 @@ class TestJSONTestFinalize(utils.StaticDirectory):
             except Exception as e:
                 raise AssertionError(e)
 
-    def test_results_correct(self):
-        """ JSONBackend.finalize() results are expected """
-        baseline = {
-            'name': BACKEND_INITIAL_META['name'],
-            'results_version': backends.CURRENT_JSON_VERSION,
-            'options': {
-                'test_count': BACKEND_INITIAL_META['test_count'],
-                'env': BACKEND_INITIAL_META['env'],
-            },
-            'tests': {
-                self.test_name: dict(self.result)
-            }
-        }
-
-        with open(os.path.join(self.tdir, 'results.json'), 'r') as f:
-            test = json.load(f)
-
-        nt.assert_equal(baseline, test)
-
 
 def test_junit_skips_bad_tests():
     """ backends.JUnitBackend skips illformed tests """
-- 
2.1.2



More information about the Piglit mailing list