[Piglit] [PATCH 3/6] framework/test/deqp: generalize mustpass list handling

Dylan Baker dylan at pnwbakers.com
Sat Aug 6 00:19:16 UTC 2016


This patch generalizes the mustpass list functionality in deqp_gles3.py.
While the idea is the same, this implementation is considerably
different than the version in deqp_gles3, since it bypasses calling the
binary to generate a test list altogether, and simply replaces the
iter_deqp_test_cases function by providing output that the make_profile
function can consume.

The end result is that this is simpler (though more LOC are added since
this actually has tests), and can be applied to gles2 and gles31.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/deqp.py                | 32 ++++++++++++++++++++-
 tests/deqp_gles3.py                   | 44 +---------------------------
 unittests/framework/test/test_deqp.py | 33 +++++++++++++++++++++-
 3 files changed, 67 insertions(+), 42 deletions(-)

diff --git a/framework/test/deqp.py b/framework/test/deqp.py
index 4f9bf14..cd094c9 100644
--- a/framework/test/deqp.py
+++ b/framework/test/deqp.py
@@ -24,6 +24,10 @@ from __future__ import (
 import abc
 import os
 import subprocess
+try:
+    from lxml import etree as et
+except ImportError:
+    from xml.etree import cElementTree as et
 
 import six
 from six.moves import range
@@ -65,6 +69,15 @@ _EXTRA_ARGS = get_option('PIGLIT_DEQP_EXTRA_ARGS',
                          default='').split()
 
 
+def select_source(bin_, filename, mustpass, extra_args):
+    """Return either the mustpass list or the generated list."""
+    if mustpass is not None:
+        return gen_mustpass_tests(mustpass)
+    else:
+        return iter_deqp_test_cases(
+            gen_caselist_txt(bin_, filename, extra_args))
+
+
 def make_profile(test_list, test_class):
     """Create a TestProfile instance."""
     profile = TestProfile()
@@ -76,6 +89,25 @@ def make_profile(test_list, test_class):
     return profile
 
 
+def gen_mustpass_tests(mp_list):
+    """Return a testlist from the mustpass list."""
+    root = et.parse(mp_list).getroot()
+    group = []
+
+    def gen(base):
+        for elem in base:
+            if elem.tag == 'Test':
+                yield '{}.{}'.format('.'.join(group), elem.get('name'))
+            else:
+                group.append(elem.get('name'))
+                for test in gen(elem):
+                    yield test
+                del group[-1]
+
+    for test in gen(root):
+        yield test
+
+
 def gen_caselist_txt(bin_, caselist, extra_args):
     """Generate a caselist.txt and return its path.
 
diff --git a/tests/deqp_gles3.py b/tests/deqp_gles3.py
index 9bfc7a9..bfee344 100644
--- a/tests/deqp_gles3.py
+++ b/tests/deqp_gles3.py
@@ -24,8 +24,6 @@ from __future__ import (
     absolute_import, division, print_function, unicode_literals
 )
 
-import xml.etree.cElementTree as ET
-
 from framework.test import deqp
 
 __all__ = ['profile']
@@ -35,8 +33,6 @@ _DEQP_GLES3_EXE = deqp.get_option('PIGLIT_DEQP_GLES3_EXE',
                                   ('deqp-gles3', 'exe'),
                                   required=True)
 
-# Path to the xml file which contained the case list of the subset of dEQP
-# and marked as must pass in CTS.
 _DEQP_MUSTPASS = deqp.get_option('PIGLIT_DEQP_MUSTPASS',
                                  ('deqp-gles3', 'mustpasslist'))
 
@@ -45,41 +41,6 @@ _EXTRA_ARGS = deqp.get_option('PIGLIT_DEQP_GLES3_EXTRA_ARGS',
                               default='').split()
 
 
-def _get_test_case(root, root_group, outputfile):
-    """Parser the test case list of Google Android CTS,
-    and store the test case list to dEQP-GLES3-cases.txt
-    """
-    for child in root:
-        root_group.append(child.get('name'))
-        if child.tag == "Test":
-            outputfile.write('TEST: {}\n'.format('.'.join(root_group)))
-            del root_group[-1]
-        else:
-            _get_test_case(child, root_group, outputfile)
-            del root_group[-1]
-
-
-def _load_test_hierarchy(mustpass, case_list):
-    """Google have added a subset of dEQP to CTS test, the case list is stored
-    at some xml files. Such as: com.drawelements.deqp.gles3.xml This function
-    is used to parser the file, and generate a new dEQP-GLES3-cases.txt which
-    only contain the subset of dEQP.
-    """
-    tree = ET.parse(mustpass)
-    root = tree.getroot()
-    root_group = []
-    with open(case_list, 'w') as f:
-        _get_test_case(root, root_group, f)
-
-
-def filter_mustpass(caselist_path):
-    """Filter tests that are not in the DEQP_MUSTPASS profile."""
-    if _DEQP_MUSTPASS is not None:
-        _load_test_hierarchy(_DEQP_MUSTPASS, caselist_path)
-
-    return caselist_path
-
-
 class DEQPGLES3Test(deqp.DEQPBaseTest):
     deqp_bin = _DEQP_GLES3_EXE
 
@@ -94,7 +55,6 @@ class DEQPGLES3Test(deqp.DEQPBaseTest):
 
 
 profile = deqp.make_profile(  # pylint: disable=invalid-name
-    deqp.iter_deqp_test_cases(filter_mustpass(
-        deqp.gen_caselist_txt(_DEQP_GLES3_EXE, 'dEQP-GLES3-cases.txt',
-                              _EXTRA_ARGS))),
+    deqp.select_source(_DEQP_MUSTPASS, _DEQP_GLES3_EXE, 'dEQP-GLES3-cases.txt',
+                       _EXTRA_ARGS),
     DEQPGLES3Test)
diff --git a/unittests/framework/test/test_deqp.py b/unittests/framework/test/test_deqp.py
index 8e7579a..1eb84b1 100644
--- a/unittests/framework/test/test_deqp.py
+++ b/unittests/framework/test/test_deqp.py
@@ -294,3 +294,36 @@ class TestDEQPBaseTest(object):
             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."""
+
+    _xml = textwrap.dedent("""\
+        <?xml version="1.0" encoding="UTF-8"?>
+        <TestPackage name="dEQP-piglit-test" appPackageName="com.freedesktop.org.piglit.deqp" testType="deqpTest" xmlns:deqp="http://drawelements.com/deqp" deqp:glesVersion="196608">
+            <TestSuite name="dEQP.piglit">
+                <TestCase name="group1">
+                    <Test name="test1" />
+                    <Test name="test2" />
+                </TestCase>
+                <TestSuite name="nested">
+                    <TestCase name="group2">
+                        <Test name="test3" />
+                        <Test name="test4" />
+                    </TestCase>
+                </TestSuite>
+            </TestSuite>
+        </TestPackage>
+    """)
+
+    def test_basic(self, tmpdir):
+        p = tmpdir.join('foo.xml')
+        p.write(self._xml)
+        tests = set(deqp.gen_mustpass_tests(six.text_type(p)))
+        assert tests == {
+            'dEQP.piglit.group1.test1',
+            'dEQP.piglit.group1.test2',
+            'dEQP.piglit.nested.group2.test3',
+            'dEQP.piglit.nested.group2.test4',
+        }
-- 
git-series 0.8.7


More information about the Piglit mailing list