docs: Fix README link
[piglit.git] / tests / crucible.py
blob45dfd8e8f7a9c13e150655bc40b83ad427c8efc8
1 # coding=utf-8
2 # Copyright 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 """Piglit integrations for Crucible Test Suite.
24 upstream: https://gitlab.freedesktop.org/mesa/crucible/
26 """
28 import os
29 import subprocess
30 import tempfile
32 try:
33 from lxml import etree
34 except ImportError:
35 import xml.etree.ElementTree as etree
37 from framework import grouptools, backends, core, exceptions
38 from framework import status
39 from framework.profile import TestProfile, Test
41 __all__ = ['profile']
43 crucible_bin = core.get_option('PIGLIT_CRUCIBLE_BIN',
44 ('crucible', 'bin'),
45 required=True)
48 class CrucibleTest(Test):
49 """Test representation for Crucible"""
50 def __init__(self, case_name):
51 self.__out_xml = tempfile.NamedTemporaryFile(delete=True).name
52 command = [crucible_bin, 'run',
53 '--junit-xml={}'.format(self.__out_xml), case_name]
54 self._case = case_name
55 super(CrucibleTest, self).__init__(command)
57 def interpret_result(self):
58 try:
59 test = backends.junit.REGISTRY.load(self.__out_xml, 'none')
60 result = test.get_result(next(test.tests.keys()))
61 self.result.result = result.name
62 super(CrucibleTest, self).interpret_result()
63 except etree.ParseError:
64 # This error is what ElementTree will generate, and is the parent
65 # of what lxml will generate.
66 self.result.result = status.CRASH
67 finally:
68 os.remove(self.__out_xml)
70 def gen_caselist_txt(bin_):
71 with open('crucible.txt', 'w') as d:
72 subprocess.check_call(
73 [bin_, 'ls-tests'],
74 stdout=d, stderr=d)
75 assert os.path.exists('crucible.txt')
76 return 'crucible.txt'
78 def _populate_profile():
79 profile = TestProfile()
80 case_file = gen_caselist_txt(crucible_bin)
81 with open(case_file, 'r') as caselist_file:
82 for i, line in enumerate(caselist_file):
83 case = line.rstrip()
84 piglit_name = case.replace('.', grouptools.SEPARATOR)
85 profile.test_list[piglit_name] = CrucibleTest(case)
86 os.remove('crucible.txt')
87 return profile
89 profile = _populate_profile()