summaryrefslogtreecommitdiff
path: root/unittests/json_tests.py
blob: 417b46a1a92e0084d2d63180f0634d34a50d8071 (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
# Copyright (c) 2014 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 the json outpt format.

This module drills the ouput of the json backend with a series of tests
designed to catch changes in the json output. This is a rather volatile set of
tests and they will change with each version of the json output.

"""

from __future__ import print_function, absolute_import
import os

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

from . import utils
from framework import results
from framework.backends.json import JSONBackend
from framework.programs.run import _create_metadata

# pylint: disable=invalid-name


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


def teardown_module():
    utils.unset_compression()


# Helpers
class Namespace(object):
    """Simple namespace object for replicating and argparse namespace."""
    pass


# Tests
# pylint: disable=too-many-public-methods
class TestJsonOutput(utils.StaticDirectory):
    """Class for testing JSON output."""
    @classmethod
    def setup_class(cls):
        super(TestJsonOutput, cls).setup_class()

        args = Namespace()
        # pylint: disable=attribute-defined-outside-init
        args.test_profile = ['fake.py']
        args.platform = 'gbm'
        args.log_level = 'verbose'

        backend = JSONBackend(cls.tdir, file_fsync=True)
        backend.initialize(_create_metadata(args, 'test'))
        with backend.write_test('result') as t:
            t(results.TestResult('pass'))
        backend.finalize({'time_elapsed': results.TimeAttribute(end=1.2)})
        with open(os.path.join(cls.tdir, 'results.json'), 'r') as f:
            cls.json = json.load(f)

    def test_root_results_version(self):
        """JSON: result_version is a root key."""
        nt.assert_in('results_version', self.json)

    def test_root_name(self):
        """JSON: name is a root key."""
        nt.assert_in('name', self.json)

    def test_root_options(self):
        """JSON: options is a root key."""
        nt.assert_in('options', self.json)

    def test_root_tests(self):
        """JSON: tests is a root key."""
        nt.assert_in('tests', self.json)

    def test_root_lspci(self):
        """JSON: lspci is a root key."""
        utils.platform_check('linux')
        utils.binary_check('lspci')
        nt.assert_in('lspci', self.json)

    def test_root_uname(self):
        """JSON: uname is a root key."""
        utils.platform_check('linux')
        utils.binary_check('uname')
        nt.assert_in('uname', self.json)

    def test_root_glxinfo(self):
        """JSON: glxinfo is a root key."""
        utils.platform_check('linux')
        utils.binary_check('glxinfo')
        nt.assert_in('glxinfo', self.json)

    def test_root_time_elapsed(self):
        """JSON: time_elapsed is a root key."""
        nt.assert_in('time_elapsed', self.json)

    def test_options_profile(self):
        """JSON: profile is an options key."""
        nt.assert_in('profile', self.json['options'])

    def test_options_dmesg(self):
        """JSON: dmesg is an options key."""
        nt.assert_in('dmesg', self.json['options'])

    def test_options_execute(self):
        """JSON: execute is an options key."""
        nt.assert_in('execute', self.json['options'])

    def test_options_log_level(self):
        """JSON: log_level is an options key."""
        nt.assert_in('log_level', self.json['options'])

    def test_options_platform(self):
        """JSON: platform is an options key."""
        nt.assert_in('platform', self.json['options'])

    def test_options_sync(self):
        """JSON: sync is an options key."""
        nt.assert_in('sync', self.json['options'])

    def test_options_valgrind(self):
        """JSON: valgrind is an options key."""
        nt.assert_in('valgrind', self.json['options'])

    def test_options_concurrent(self):
        """JSON: concurrent is an options key."""
        nt.assert_in('concurrent', self.json['options'])

    def test_options_filter(self):
        """JSON: include_filter is an options key."""
        nt.assert_in('include_filter', self.json['options'])

    def test_options_exclude_tests(self):
        """JSON: exclude_tests is an options key."""
        nt.assert_in('exclude_tests', self.json['options'])

    def test_options_exclude_filter(self):
        """JSON: exclude_filter is an options key."""
        nt.assert_in('exclude_filter', self.json['options'])