framework/replay: Update simpler integrity unit tests
[piglit.git] / unittests / framework / test / test_piglit_test.py
blobcda2de76d12a16adaabb4a1002b6731ea68b76e6
1 # coding=utf-8
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
20 # SOFTWARE.
22 """Tests for the piglit_test module."""
24 import textwrap
25 from unittest import mock
27 import pytest
29 from framework import status
30 from framework.options import _Options as Options
31 from framework.test.base import TestIsSkip as _TestIsSkip
32 from framework.test.piglit_test import PiglitBaseTest, PiglitGLTest
34 # pylint: disable=no-self-use
35 # pylint: disable=protected-access
38 class TestPiglitBaseTest(object):
39 """Tests for the PiglitBaseTest class."""
41 class TestIntepretResult(object):
42 """Tests for PiglitBaseTest.interpret_results."""
44 def test_basic(self):
45 """A basic sanity test with nothing tricky."""
46 test = PiglitBaseTest(['foo'])
47 test.result.out = 'PIGLIT: {"result": "pass"}\n'
48 test.result.returncode = 0
49 test.interpret_result()
50 assert test.result.result is status.PASS
52 def test_stdout(self):
53 """Separates the actual stdout printing from the PIGLIT protocol.
54 """
55 test = PiglitBaseTest(['foo'])
56 test.result.out = textwrap.dedent("""\
57 This is output
59 more output
60 PIGLIT: {"result": "pass"}
61 and stuff""")
62 test.result.returncode = 0
63 test.interpret_result()
65 assert test.result.result is status.PASS
66 assert test.result.out == textwrap.dedent("""\
67 This is output
69 more output
70 and stuff""")
72 def test_with_subtests(self):
73 """works with one subtest."""
74 test = PiglitBaseTest(['foo'])
75 test.result.out = textwrap.dedent("""\
76 PIGLIT: {"result": "pass"}
77 PIGLIT: {"subtest": {"subtest": "pass"}}""")
78 test.result.returncode = 0
79 test.interpret_result()
80 assert test.result.subtests['subtest'] is status.PASS
82 def test_with_multiple_subtests(self):
83 """Works with multiple subtests.
85 Including that it doesn't only take the last subtest, but counts
86 all of them.
87 """
88 test = PiglitBaseTest(['a', 'command'])
89 test.result.out = textwrap.dedent("""\
90 PIGLIT: {"result": "pass"}
91 PIGLIT: {"subtest": {"test1": "pass"}}
92 PIGLIT: {"subtest": {"test2": "pass"}}""")
93 test.result.returncode = 0
94 test.interpret_result()
96 assert dict(test.result.subtests) == \
97 {'test1': 'pass', 'test2': 'pass'}
100 class TestPiglitGLTest(object):
101 """tests for the PiglitGLTest class."""
103 def test_signature(self):
104 test = PiglitGLTest(['foo'], env=None)
106 class TestCommand(object):
107 """Tests for the command getter and setter."""
109 def test_getter_serial(self):
110 """adds -auto to serial tests."""
111 test = PiglitGLTest(['foo'])
112 assert '-auto' in test.command
114 def test_getter_concurrent(self):
115 """adds -fbo and -auto to concurrent tests."""
116 test = PiglitGLTest(['foo'], run_concurrent=True)
117 assert '-auto' in test.command
118 assert '-fbo' in test.command
120 def test_setter_no_add_auto(self):
121 """Doesn't add -fbo or -auto when setting."""
122 test = PiglitGLTest(['foo'], run_concurrent=True)
123 test.command += ['bar']
124 assert '-auto' not in test._command
125 assert '-fbo' not in test._command
127 class TestIsSkip(object):
128 """Tests for the is_skip method and the constructor logic to make it
129 work.
132 @pytest.fixture()
133 def mock_options(self):
134 with mock.patch('framework.test.piglit_test.options.OPTIONS',
135 new_callable=Options) as m:
136 yield m
138 def test_include_and_exclude(self):
139 """ raises if include and exclude are given."""
140 with pytest.raises(AssertionError):
141 PiglitGLTest(['foo'],
142 require_platforms=['glx'],
143 exclude_platforms=['gbm'])
145 def test_platform_in_require(self, mock_options):
146 """does not skip if platform is in require_platforms."""
147 mock_options.env['PIGLIT_PLATFORM'] = 'glx'
148 test = PiglitGLTest(['foo'], require_platforms=['glx'])
149 test.is_skip()
151 def test_platform_not_in_require(self, mock_options):
152 """skips if platform is not in require_platforms."""
153 mock_options.env['PIGLIT_PLATFORM'] = 'gbm'
154 test = PiglitGLTest(['foo'], require_platforms=['glx'])
155 with pytest.raises(_TestIsSkip):
156 test.is_skip()
158 def test_platform_in_exclude(self, mock_options):
159 """skips if platform is in exclude_platforms."""
160 mock_options.env['PIGLIT_PLATFORM'] = 'glx'
161 test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
162 with pytest.raises(_TestIsSkip):
163 test.is_skip()
165 def test_platform_not_in_exclude(self, mock_options):
166 """does not skip if platform is in exclude_platforms."""
167 mock_options.env['PIGLIT_PLATFORM'] = 'gbm'
168 test = PiglitGLTest(['foo'], exclude_platforms=['glx'])
169 test.is_skip()