summaryrefslogtreecommitdiff
path: root/unittests/framework/test/test_deqp.py
blob: 1dc5c97de3b6563f9f97ded58c290a49bbb7c83b (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
# coding=utf-8
# Copyright (c) 2015-2016, 2019 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 dEQP integration in framework.

This tests the core framework shared code, and not the individual packages in
tests

"""

import textwrap

import pytest

from framework import exceptions
from framework import grouptools
from framework import profile
from framework import status
from framework.test import deqp

# pylint:disable=invalid-name,no-self-use


class _DEQPTestTest(deqp.DEQPBaseTest):
    deqp_bin = 'deqp.bin'
    extra_args = ['extra']


class TestMakeProfile(object):
    """Test deqp.make_profile."""

    @classmethod
    def setup_class(cls):
        cls.profile = deqp.make_profile(['this.is.a.deqp.test'], _DEQPTestTest)

    def test_returns_profile(self):
        """deqp.make_profile: returns a TestProfile."""
        assert isinstance(self.profile, profile.TestProfile)

    def test_replaces_separator(self):
        """deqp.make_profile: replaces '.' with grouptools.separator"""
        expected = grouptools.join('this', 'is', 'a', 'deqp', 'test')
        assert expected in self.profile.test_list


class TestIterDeqpTestCases(object):
    """Tests for iter_deqp_test_cases."""

    def _do_test(self, write, expect, tmpdir):
        """Run the actual test."""
        p = tmpdir.join('foo')
        p.write(write)
        gen = deqp.iter_deqp_test_cases(str(p))
        assert next(gen) == expect

    def test_test_cases(self, tmpdir):
        """Correctly detects a test line."""
        self._do_test('TEST: a.deqp.test', 'a.deqp.test', tmpdir)

    def test_test_group(self, tmpdir):
        """Correctly detects a group line."""
        self._do_test('GROUP: a group\nTEST: a.deqp.test', 'a.deqp.test',
                      tmpdir)

    def test_bad_entry(self, tmpdir):
        """A PiglitFatalException is raised if a line is not a TEST or GROUP.
        """
        with pytest.raises(exceptions.PiglitFatalError):
            self._do_test('this will fail', None, tmpdir)


class TestDEQPBaseTest(object):
    """Test the DEQPBaseTest class."""

    @classmethod
    def setup_class(cls):
        cls.test = _DEQPTestTest('a.deqp.test')

    def test_command_adds_extra_args(self):
        assert self.test.command[-1] == 'extra'

    class TestInterpretResultReturncodes(object):
        """Test the interpret_result method's returncode handling."""

        @classmethod
        def setup_class(cls):
            cls.test = _DEQPTestTest('a.deqp.test')

        def test_crash(self):
            """deqp.DEQPBaseTest.interpret_result: if returncode is < 0 stauts
            is crash.
            """
            self.test.result.returncode = -9
            self.test.interpret_result()
            assert self.test.result.result is status.CRASH

        def test_returncode_fail(self):
            """deqp.DEQPBaseTest.interpret_result: if returncode is > 0 result
            is fail.
            """
            self.test.result.returncode = 1
            self.test.interpret_result()
            assert self.test.result.result is status.FAIL

        def test_fallthrough(self):
            """deqp.DEQPBaseTest.interpret_result: if no case is hit set to
            fail.
            """
            self.test.result.returncode = 0
            self.test.result.out = ''
            self.test.interpret_result()
            assert self.test.result.result is status.FAIL

        def test_windows_returncode_3(self, mocker):
            """deqp.DEQPBaseTest.interpret_result: on windows returncode 3 is
            crash.
            """
            mocker.patch('framework.test.base.sys.platform', 'win32')
            self.test.result.returncode = 3
            self.test.interpret_result()
            assert self.test.result.result is status.CRASH

    class TestDEQPBaseTestIntepretResultOutput(object):
        """Tests for DEQPBaseTest.__find_map."""

        inst = None
        __OUT = textwrap.dedent("""\
            dEQP Core 2014.x (0xcafebabe) starting..
              target implementation = 'DRM'

            Test case 'dEQP-GLES2.functional.shaders.conversions.vector_to_vector.vec3_to_ivec3_fragment'..
            Vertex shader compile time = 0.129000 ms
            Fragment shader compile time = 0.264000 ms
            Link time = 0.814000 ms
            Test case duration in microseconds = 487155 us
              {stat} ({stat})

            DONE!

            Test run totals:
              Passed:        {pass_}/1 (100.0%)
              Failed:        {fail}/1 (0.0%)
              Not supported: {supp}/1 (0.0%)
              Warnings:      {warn}/1 (0.0%)
            Test run was ABORTED!
        """)

        def __gen_stdout(self, stat):
            """Make a string that looks like DEQP output."""
            assert stat in ['Fail', 'NotSupported', 'Pass', 'QualityWarning',
                            'InternalError', 'Crash', 'ResourceError']

            return self.__OUT.format(
                stat=stat,
                pass_=1 if stat == 'Pass' else 0,
                fail=1 if stat in ['Crash', 'Fail', 'ResourceError'] else 0,
                supp=1 if stat == 'InternalError' else 0,
                warn=1 if stat == 'QualityWarning' else 0,
            )

        def setup(self):
            self.inst = _DEQPTestTest('a.deqp.test')
            self.inst.result.returncode = 0

        def test_fail(self):
            """test.deqp.DEQPBaseTest.interpret_result: when Fail in result the
            result is 'fail'.
            """
            self.inst.result.out = self.__gen_stdout('Fail')
            self.inst.interpret_result()
            assert self.inst.result.result is status.FAIL

        def test_pass(self):
            """test.deqp.DEQPBaseTest.interpret_result: when Pass in result the
            result is 'Pass'.
            """
            self.inst.result.out = self.__gen_stdout('Pass')
            self.inst.interpret_result()
            assert self.inst.result.result is status.PASS

        def test_warn(self):
            """test.deqp.DEQPBaseTest.interpret_result: when QualityWarning in
            result the result is 'warn'.
            """
            self.inst.result.out = self.__gen_stdout('QualityWarning')
            self.inst.interpret_result()
            assert self.inst.result.result is status.WARN

        def test_error(self):
            """test.deqp.DEQPBaseTest.interpret_result: when InternalError in
            result the result is 'fail'.
            """
            self.inst.result.out = self.__gen_stdout('InternalError')
            self.inst.interpret_result()
            assert self.inst.result.result is status.FAIL

        def test_crash(self):
            """test.deqp.DEQPBaseTest.interpret_result: when InternalError in
            result the result is 'crash'.
            """
            self.inst.result.out = self.__gen_stdout('Crash')
            self.inst.interpret_result()
            assert self.inst.result.result is status.CRASH

        def test_skip(self):
            """test.deqp.DEQPBaseTest.interpret_result: when NotSupported in
            result the result is 'skip'.
            """
            self.inst.result.out = self.__gen_stdout('NotSupported')
            self.inst.interpret_result()
            assert self.inst.result.result is status.SKIP

        def test_resourceerror(self):
            """test.deqp.DEQPBaseTest.interpret_result: when ResourceError in
            result the result is 'crash'.
            """
            self.inst.result.out = self.__gen_stdout('ResourceError')
            self.inst.interpret_result()
            assert self.inst.result.result is status.CRASH


class TestGenMustpassTests(object):
    """Tests for the gen_mustpass_tests function."""

    _txt = """\
dEQP.piglit.group1.test1
dEQP.piglit.group1.test2
dEQP.piglit.nested.group2.test3
dEQP.piglit.nested.group2.test4
    """

    def test_basic(self, tmpdir):
        p = tmpdir.join('foo.txt')
        p.write(self._txt)
        tests = set(deqp.gen_mustpass_tests(str(p)))
        print(tests)
        assert tests == {
            'dEQP.piglit.group1.test1',
            'dEQP.piglit.group1.test2',
            'dEQP.piglit.nested.group2.test3',
            'dEQP.piglit.nested.group2.test4',
        }