summaryrefslogtreecommitdiff
path: root/unittests/json_results_update_tests.py
blob: 33a30bc1400f58198737cbb9e24dad3f66e6f970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# Copyright (c) 2014, 2015 Intel Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Tests for JSON backend version updates."""

from __future__ import print_function, absolute_import, division
import os
import copy
import tempfile

try:
    import simplejson as json
except ImportError:
    import json
import nose.tools as nt

from . import utils
from framework import backends, results

# Disable some errors that cannot be fixed either because tests need to probe
# protected members, or because of nose requirements, like long lines
# pylint: disable=protected-access,invalid-name,line-too-long


def setup_module():
    utils.set_compression('none')


def teardown_module():
    utils.unset_compression()


class TestV0toV1(object):
    """Tests for version 0 -> version 1 of json results format."""
    # NOTE: It is very important to NOT use grouptools in this class.
    # The grouptools module changes and is updated from time to time, but this file
    # must remain static. It tests the update from one static version to another
    # static version.

    @classmethod
    def setup_class(cls):
        cls.DATA = {}
        cls.DATA['options'] = {
            'profile': "tests/fake.py",
            'filter': [],
            'exclude_filter': [],
        }
        cls.DATA['name'] = 'fake-tests'
        cls.DATA['lspci'] = 'fake'
        cls.DATA['glxinfo'] = 'fake'
        cls.DATA['tests'] = {}
        cls.DATA['tests'].update({
            'sometest': {
                'result': 'pass',
                'time': 0.01,
                'dmesg': ['this', 'is', 'dmesg'],
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput: stdout\n',
            },
            'group1/groupA/test/subtest 1': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1': 'pass',
                    'subtest 2': 'pass'
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
            'group1/groupA/test/subtest 2': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1': 'pass',
                    'subtest 2': 'pass'
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
            'single/test/thing': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1': 'pass',
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
            'group2/groupA/test/subtest 1/depth': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1/depth': 'pass',
                    'subtest 2/float': 'pass'
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
            'group2/groupA/test/subtest 2/float': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1/depth': 'pass',
                    'subtest 2/float': 'pass'
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
            'group3/groupA/test': {
                'info': 'Returncode: 1\n\nErrors:stderr\n\nOutput:stdout\n',
                'subtest': {
                    'subtest 1': 'pass',
                    'subtest 2': 'pass',
                    'subtest 3': 'pass',
                },
                'returncode': 0,
                'command': 'this is a command',
                'result': 'pass',
                'time': 0.1
            },
        })

        with utils.tempfile(json.dumps(cls.DATA)) as t:
            with open(t, 'r') as f:
                cls.RESULT = backends.json._update_zero_to_one(backends.json._load(f))

    def test_dmesg(self):
        """backends.json.update_results (0 -> 1): dmesg is converted from a list to a string"""
        nt.eq_(self.RESULT.tests['sometest']['dmesg'], 'this\nis\ndmesg')

    def test_subtests_remove_duplicates(self):
        """backends.json.update_results (0 -> 1): Removes duplicate entries"""
        nt.ok_('group1/groupA/test/subtest 1' not in self.RESULT.tests)
        nt.ok_('group1/groupA/test/subtest 2' not in self.RESULT.tests)

    def test_subtests_add_test(self):
        """backends.json.update_results (0 -> 1): Add an entry for the actual test"""
        nt.ok_(self.RESULT.tests.get('group1/groupA/test'))

    def test_subtests_test_is_testresult(self):
        """backends.json.update_results (0 -> 1): The result of the new test is a dict Instance"""
        nt.ok_(isinstance(self.RESULT.tests['group1/groupA/test'], dict))

    def test_info_delete(self):
        """backends.json.update_results (0 -> 1): Remove the info name from results"""
        for value in self.RESULT.tests.itervalues():
            nt.ok_('info' not in value)

    def test_returncode_from_info(self):
        """backends.json.update_results (0 -> 1): Use the returncode from info if there is no returncode"""
        nt.eq_(self.RESULT.tests['sometest']['returncode'], 1)

    def test_returncode_no_override(self):
        """backends.json.update_results (0 -> 1): Do not clobber returncode with info

        The returncode from info should not overwrite an existing returcnode
        attribute, this test only tests that the value in info isn't used when
        there is a value in returncode already

        """
        nt.ok_(self.RESULT.tests['group1/groupA/test']['returncode'] != 1)

    def test_err_from_info(self):
        """backends.json.update_results (0 -> 1): add an err attribute from info"""
        nt.eq_(self.RESULT.tests['group1/groupA/test']['err'], 'stderr')

    def test_out_from_info(self):
        """backends.json.update_results (0 -> 1): add an out attribute from info"""
        nt.eq_(self.RESULT.tests['group1/groupA/test']['out'], 'stdout')

    def test_set_version(self):
        """backends.json.update_results (0 -> 1): Set the version to 1"""
        nt.eq_(self.RESULT.results_version, 1)

    def test_dont_break_single_subtest(self):
        """backends.json.update_results (0 -> 1): Don't break single subtest entries

        A test with a single subtest was written correctly before, dont break it by
        removing the name of the test. ex:
        test/foo/bar: {
            ...
            subtest: {
                1x1: pass
            }
        }

        should remain test/foo/bar since bar is the name of the test not a subtest

        """
        nt.ok_(self.RESULT.tests['single/test/thing'])

    def test_subtests_with_slash(self):
        """backends.json.update_results (0 -> 1): Subtest names with /'s are handled correctly"""

        expected = 'group2/groupA/test/subtest 1'
        nt.assert_not_in(
            expected, self.RESULT.tests.iterkeys(),
            msg='{0} found in result, when it should not be'.format(expected))

    def test_handle_fixed_subtests(self):
        """backends.json.update_results (0 -> 1): Correctly handle new single entry subtests correctly"""
        nt.ok_('group3/groupA/test' in self.RESULT.tests.iterkeys())

    def _load_with_update(self, data=None):
        """If the file is not results.json, it will be renamed.

        This ensures that the right file is removed.

        """
        if not data:
            data = self.DATA

        try:
            with utils.tempfile(
                    json.dumps(data, default=backends.json.piglit_encoder)) as t:
                result = backends.json.load_results(t, 'none')
        except OSError as e:
            # There is the potential that the file will be renamed. In that event
            # remove the renamed files
            if e.errno == 2:
                os.unlink(os.path.join(tempfile.tempdir, 'results.json'))
                os.unlink(os.path.join(tempfile.tempdir, 'results.json.old'))
            else:
                raise

        return result

    def test_load_results_unversioned(self):
        """backends.json.load_results: Loads unversioned results and updates correctly.

        This is just a random change to show that the update path is being hit.

        """
        result = self._load_with_update()
        nt.assert_equal(result.tests['sometest'].dmesg, 'this\nis\ndmesg')

    def test_load_results_v0(self):
        """backends.json.load_results: Loads results v0 and updates correctly.

        This is just a random change to show that the update path is being hit.

        """
        data = copy.deepcopy(self.DATA)
        data['results_version'] = 0

        result = self._load_with_update(data)
        nt.assert_equal(result.tests['sometest'].dmesg, 'this\nis\ndmesg')

    def test_info_split(self):
        """backends.json.update_results (0 -> 1): info can split into any number of elements"""
        data = copy.copy(self.DATA)
        data['tests']['sometest']['info'] = \
            'Returncode: 1\n\nErrors:stderr\n\nOutput: stdout\n\nmore\n\nstuff'

        with utils.tempfile(
                json.dumps(data, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                backends.json._update_zero_to_one(backends.json._load(f))

    @utils.DocFormatter({'current': backends.json.CURRENT_JSON_VERSION})
    def test_load_results(self):
        """backends.json.update_results (1 -> {current}): load_results properly updates"""
        with utils.tempdir() as d:
            tempfile = os.path.join(d, 'results.json')
            with open(tempfile, 'w') as f:
                json.dump(self.DATA, f, default=backends.json.piglit_encoder)
            with open(tempfile, 'r') as f:
                result = backends.json.load_results(tempfile, 'none')
                nt.eq_(result.results_version,
                       backends.json.CURRENT_JSON_VERSION)


class TestV2Update(object):
    """Test V1 to V2 of results."""
    @classmethod
    def setup_class(cls):
        data = {
            "results_version": 1,
            "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": {
                "test/is/a/test": {
                    "returncode": 0,
                    "err": None,
                    "environment": None,
                    "command": "foo",
                    "result": "skip",
                    "time": 0.123,
                    "out": None,
                }
            }
        }

        with utils.tempfile(
                json.dumps(data, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_one_to_two(
                    backends.json._load(f))

    def test_version_is_two(self):
        """backends.json.update_results (1 -> 2): The result version is updated to 2"""
        nt.assert_equal(self.result.results_version, 2)

    def test_no_env(self):
        """backends.json.update_results (1 -> 2): Removes options['env']"""
        nt.ok_('env' not in self.result.options)

    def test_glxinfo(self):
        """backends.json.update_results (1 -> 2): puts glxinfo in the root"""
        nt.assert_equal(self.result.glxinfo, 'and stuff')

    def test_lspci(self):
        """backends.json.update_results (1 -> 2): puts lspci in the root"""
        nt.assert_equal(self.result.lspci, 'stuff')

    def test_uname(self):
        """backends.json.update_results (1 -> 2): puts uname in the root"""
        nt.assert_equal(self.result.uname, 'more stuff')

    def test_wglinfo(self):
        """backends.json.update_results (1 -> 2): puts wglinfo in the root"""
        nt.assert_equal(self.result.wglinfo, 'stuff')


class TestV2NoUpdate(object):
    """Test a version 1 to 2 update when version 1 was correct"""
    @classmethod
    def setup_class(cls):
        data = {
            "results_version": 1,
            "name": "test",
            "lspci": "stuff",
            "uname": "more stuff",
            "glxinfo": "and stuff",
            "wglinfo": "stuff",
            "options": {
                "profile": ['quick'],
                "dmesg": False,
                "verbose": False,
                "platform": "gbm",
                "sync": False,
                "valgrind": False,
                "filter": [],
                "concurrent": "all",
                "test_count": 0,
                "exclude_tests": [],
                "exclude_filter": [],
            },
            "tests": {
                "test/is/a/test": {
                    "returncode": 0,
                    "err": None,
                    "environment": None,
                    "command": "foo",
                    "result": "skip",
                    "time": 0.123,
                    "out": None,
                }
            }
        }

        with utils.tempfile(
                json.dumps(data, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_one_to_two(
                    backends.json._load(f))

    def test_version_is_two(self):
        """backends.json.update_results (1 -> 2) no change: The result version is updated to 2"""
        nt.assert_equal(self.result.results_version, 2)

    def test_glxinfo(self):
        """backends.json.update_results (1 -> 2) no change: doesn't clobber glxinfo"""
        nt.assert_equal(self.result.glxinfo, 'and stuff')

    def test_lspci(self):
        """backends.json.update_results (1 -> 2) no change: doesn't clobber lspci"""
        nt.assert_equal(self.result.lspci, 'stuff')

    def test_uname(self):
        """backends.json.update_results (1 -> 2) no change: doesn't clobber uname"""
        nt.assert_equal(self.result.uname, 'more stuff')

    def test_wglinfo(self):
        """backends.json.update_results (1 -> 2) no change: doesn't clobber wglinfo"""
        nt.assert_equal(self.result.wglinfo, 'stuff')


class TestV2toV3(object):
    """Tests for version 2 -> version 3 of json results"""
    # NOTE: do NOT use grouptools in this class, see v0 tests for explanation

    @classmethod
    def setup_class(cls):
        data = {
            "results_version": 2,
            "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": {
                "test/is/a/test": {
                    "returncode": 0,
                    "err": None,
                    "environment": None,
                    "command": "foo",
                    "result": "skip",
                    "time": 0.123,
                    "out": None,
                },
                "Test/Is/SomE/Other1/Test": {
                    "returncode": 0,
                    "err": None,
                    "environment": None,
                    "command": "foo",
                    "result": "skip",
                    "time": 0.123,
                    "out": None,
                }
            }
        }

        with utils.tempfile(
                json.dumps(data, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                # pylint: disable=protected-access
                cls.RESULT = backends.json._update_two_to_three(backends.json._load(f))

    def test_unchanged(self):
        """backends.json.update_results (2 -> 3): results with no caps are not mangled"""
        nt.ok_('test/is/a/test' in self.RESULT.tests)

    def test_lower(self):
        """backends.json.update_results (2 -> 3): results with caps are lowered"""
        nt.ok_('test/is/some/other1/test' in self.RESULT.tests)

    def test_removed(self):
        """backends.json.update_results (2 -> 3): results with caps are removed"""
        nt.ok_('Test/Is/SomE/Other1/Test' not in self.RESULT.tests)


class TestV3toV4(object):
    # NOTE: do NOT use grouptools in this module, see v0 tests for explanation
    TEST_DATA = {
        'returncode': 0,
        'err': None,
        'environment': None,
        'command': 'foo',
        'result': 'skip',
        'time': 0.123,
        'out': None,
    }

    DATA = {
        "results_version": 3,
        "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": {
            "spec/arb_texture_rg/fs-shadow2d-red-01": TEST_DATA,
            "spec/arb_texture_rg/fs-shadow2d-red-02": TEST_DATA,
            "spec/arb_texture_rg/fs-shadow2d-red-03": TEST_DATA,
            "spec/arb_draw_instanced/draw-non-instanced": TEST_DATA,
            "spec/arb_draw_instanced/instance-array-dereference": TEST_DATA,
            "glslparsertest/foo": TEST_DATA,
        }
    }

    @staticmethod
    def _make_result(data):
        """Write data to a file and return a result.TestrunResult object."""
        with utils.tempfile(
                json.dumps(data, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                # pylint: disable=protected-access
                return backends.json._update_three_to_four(backends.json._load(f))

    @classmethod
    def setup_class(cls):
        """Class setup. Create a TestrunResult with v3 data."""
        cls.old = cls.DATA['tests'].keys()
        cls.new = [
            "spec/arb_texture_rg/execution/fs-shadow2d-red-01",
            "spec/arb_texture_rg/execution/fs-shadow2d-red-02",
            "spec/arb_texture_rg/execution/fs-shadow2d-red-03",
            "spec/arb_draw_instanced/execution/draw-non-instanced",
            "spec/arb_draw_instanced/execution/instance-array-dereference",
        ]
        cls.result = cls._make_result(cls.DATA)

    def test_old_removed(self):
        """backends.json.update_results (3 -> 4): All old test names are removed"""
        for old in self.old:
            nt.assert_not_in(old, self.result.tests)

    def test_new_added(self):
        """backends.json.update_results (3 -> 4): All new test names are added"""
        for new in self.new:
            nt.assert_in(new, self.result.tests)

    def test_new_has_data(self):
        """backends.json.update_results (3 -> 4): All new tests have expected data"""
        for new in self.new:
            nt.assert_dict_equal(self.result.tests[new], self.TEST_DATA)

    @utils.not_raises(KeyError)
    def test_missing(self):
        """backends.json.update_results (3 -> 4): updates successfully when tests to rename are not present"""
        data = copy.copy(self.DATA)
        del data['tests']['spec/arb_draw_instanced/instance-array-dereference']
        self._make_result(data)


class TestV4toV5(object):
    TEST_DATA = {
        'returncode': 0,
        'err': None,
        'environment': None,
        'command': 'foo',
        'result': 'skip',
        'time': 0.123,
        'out': None,
    }

    DATA = {
        "results_version": 4,
        "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/test/group/of/great/length": TEST_DATA,
            "has\\windows": TEST_DATA,
        }
    }

    @classmethod
    def setup_class(cls):
        """Class setup. Create a TestrunResult with v4 data."""
        cls.old = cls.DATA['tests'].keys()
        cls.new = [
            "a@test@group@of@great@length",
            "has@windows",
        ]

        with utils.tempfile(
                json.dumps(cls.DATA, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_four_to_five(backends.json._load(f))

    def test_posix_removed(self):
        """backends.json.update_results (4 -> 5): / is replaced with @"""
        nt.assert_not_in('a/test/of/great/length', self.result.tests)

    def test_win_removed(self):
        """backends.json.update_results (4 -> 5): \\ is replaced with @"""
        nt.assert_not_in('has\\windows', self.result.tests)

    def test_new_added(self):
        """backends.json.update_results (4 -> 5): All new test names are added."""
        for new in self.new:
            nt.assert_in(new, self.result.tests)

    def test_new_has_data(self):
        """backends.json.update_results (4 -> 5): All new tests have expected data."""
        for new in self.new:
            nt.assert_dict_equal(self.result.tests[new], self.TEST_DATA)


class TestV5toV6(object):
    TEST_DATA = {
        'returncode': 0,
        'err': '',
        'environment': None,
        'command': 'foo',
        'result': 'skip',
        'time': 0.123,
        'out': '',
    }

    DATA = {
        "results_version": 4,
        "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@test': TEST_DATA,
        }
    }

    @classmethod
    def setup_class(cls):
        """Class setup. Create a TestrunResult with v4 data."""
        with utils.tempfile(
                json.dumps(cls.DATA, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_five_to_six(backends.json._load(f))

    def test_result_is_TestResult(self):
        """backends.json.update_results (5 -> 6): A test result is converted to a TestResult instance"""
        nt.ok_(isinstance(self.result.tests['a@test'], results.TestResult))


class TestV6toV7(object):
    DATA = {
        "results_version": 6,
        "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@test': results.TestResult('pass'),
            'a@nother@test': results.TestResult('fail'),
            'a@nother@thing': results.TestResult('crash'),
        }
    }

    @classmethod
    def setup_class(cls):
        """Class setup. Create a TestrunResult with v4 data."""
        with utils.tempfile(
                json.dumps(cls.DATA, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_six_to_seven(backends.json._load(f))

    def test_is_TestrunResult(self):
        """backends.json.update_results (6 -> 7): makes TestrunResult"""
        nt.ok_(isinstance(self.result, results.TestrunResult))

    def test_totals(self):
        """backends.json.update_results (6 -> 7): Totals are populated"""
        nt.ok_(self.result.totals != {})


class TestV7toV8(object):
    DATA = {
        "results_version": 7,
        "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@test': results.TestResult('pass'),
        },
        "time_elapsed": 1.2,
    }

    @classmethod
    def setup_class(cls):
        """Class setup. Create a TestrunResult with v4 data."""
        cls.DATA['tests']['a@test'] = cls.DATA['tests']['a@test'].to_json()
        cls.DATA['tests']['a@test']['time'] = 1.2

        with utils.tempfile(
                json.dumps(cls.DATA, default=backends.json.piglit_encoder)) as t:
            with open(t, 'r') as f:
                cls.result = backends.json._update_seven_to_eight(
                    backends.json._load(f))

    def test_time(self):
        """backends.json.update_results (7 -> 8): test time is stored as start and end"""
        nt.eq_(self.result.tests['a@test'].time.start, 0.0)
        nt.eq_(self.result.tests['a@test'].time.end, 1.2)

    def test_time_inst(self):
        """backends.json.update_results (7 -> 8): test time is a TimeAttribute instance"""
        nt.ok_(
            isinstance(self.result.tests['a@test'].time, results.TimeAttribute),
            msg='Testresult.time should have been TimeAttribute, '
                'but was "{}"'.format(type(self.result.tests['a@test'].time)))

    def test_time_elapsed_inst(self):
        """backends.json.update_results (7 -> 8): total time is stored as TimeAttribute"""
        nt.ok_(
            isinstance(self.result.time_elapsed, results.TimeAttribute),
            msg='TestrunResult.time_elapsed should have been TimeAttribute, '
                'but was "{}"'.format(type(self.result.time_elapsed)))

    def test_time_elapsed(self):
        """backends.json.update_results (7 -> 8): total time is stored as start and end"""
        nt.eq_(self.result.time_elapsed.start, 0.0)
        nt.eq_(self.result.time_elapsed.end, 1.2)