2 # Copyright (c) 2014-2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Tests for JSON backend version updates."""
26 import simplejson
as json
32 from unittest
import mock
37 from framework
import backends
39 # pylint: disable=protected-access,no-self-use
42 @pytest.fixture(autouse
=True, scope
='module')
44 with mock
.patch
.dict(backends
.json
.compression
.os
.environ
,
45 {'PIGLIT_COMPRESSION': 'none'}):
49 class TestV7toV8(object):
50 """Tests for Version 7 to version 8."""
70 "uname": "more stuff",
71 "glxinfo": "and stuff",
79 '__type__': 'TestResult',
80 'command': '/a/command',
83 'environment': 'A=variable',
88 '__type__': 'Subtests',
94 '__type__': 'TestrunResult',
98 def result(self
, tmpdir
):
99 p
= tmpdir
.join('result.json')
100 p
.write(json
.dumps(self
.data
, default
=backends
.json
.piglit_encoder
))
101 with p
.open('r') as f
:
102 return backends
.json
._update
_seven
_to
_eight
(backends
.json
._load
(f
))
104 def test_time(self
, result
):
105 """backends.json.update_results (7 -> 8): test time is stored as start
108 assert result
['tests']['a@test']['time']['start'] == 0.0
109 assert result
['tests']['a@test']['time']['end'] == 1.2
111 def test_time_elapsed(self
, result
):
112 """backends.json.update_results (7 -> 8): total time is stored as start
115 assert result
['time_elapsed']['start'] == 0.0
116 assert result
['time_elapsed']['end'] == 1.2
118 def test_valid(self
, result
):
119 with
open(os
.path
.join(os
.path
.dirname(__file__
), 'schema',
122 schema
= json
.load(f
)
124 json
.loads(json
.dumps(result
, default
=backends
.json
.piglit_encoder
)),
128 class TestV8toV9(object):
129 """Tests for Version 8 to version 9."""
132 "results_version": 8,
135 "profile": ['quick'],
145 "exclude_filter": [],
149 "uname": "more stuff",
150 "glxinfo": "and stuff",
158 '__type__': 'TimeAttribute'
162 '__type__': 'TestResult',
163 'command': '/a/command',
166 'environment': 'A=variable',
171 '__type__': 'Subtests',
179 '__type__': 'TimeAttribute'
183 '__type__': 'TestResult',
184 'command': '/a/command',
187 'environment': 'A=variable',
191 '__type__': 'Subtests',
199 '__type__': 'TimeAttribute'
201 '__type__': 'TestrunResult',
205 def result(self
, tmpdir
):
206 p
= tmpdir
.join('result.json')
207 p
.write(json
.dumps(self
.data
, default
=backends
.json
.piglit_encoder
))
208 with p
.open('r') as f
:
209 return backends
.json
._update
_eight
_to
_nine
(backends
.json
._load
(f
))
211 def test_pid(self
, result
):
212 assert result
['tests']['a@test']['pid'] == [5]
214 def test_no_pid(self
, result
):
215 assert result
['tests']['b@test']['pid'] == []
217 def test_valid(self
, result
):
218 with
open(os
.path
.join(os
.path
.dirname(__file__
), 'schema',
221 schema
= json
.load(f
)
223 json
.loads(json
.dumps(result
, default
=backends
.json
.piglit_encoder
)),
227 class TestV9toV10(object):
228 """Tests for Version 8 to version 9."""
231 "results_version": 9,
234 "profile": ['quick'],
244 "exclude_filter": [],
248 "uname": "more stuff",
249 "glxinfo": "and stuff",
257 '__type__': 'TimeAttribute'
261 '__type__': 'TestResult',
262 'command': '/a/command',
265 'environment': 'A=variable',
270 '__type__': 'Subtests',
278 '__type__': 'TimeAttribute'
280 '__type__': 'TestrunResult',
284 def result(self
, tmpdir
):
285 p
= tmpdir
.join('result.json')
286 p
.write(json
.dumps(self
.data
, default
=backends
.json
.piglit_encoder
))
287 with p
.open('r') as f
:
288 return backends
.json
._update
_nine
_to
_ten
(backends
.json
._load
(f
))
290 @pytest.mark
.parametrize("key", ['glxinfo', 'wglinfo', 'clinfo', 'uname', 'lspci'])
291 def test(self
, key
, result
):
292 assert key
not in result
, 'Root key/value not removed'
293 assert key
in result
['info']['system'], 'Key not added to info/system'
294 assert result
['info']['system'][key
] == self
.data
[key
], \
295 'Value not set properly.'
297 def test_valid(self
, result
):
298 with
open(os
.path
.join(os
.path
.dirname(__file__
), 'schema',
301 schema
= json
.load(f
)
303 json
.loads(json
.dumps(result
, default
=backends
.json
.piglit_encoder
)),