[Piglit] [PATCH v2 35/35] profile: use gz to compress profiles

Dylan Baker dylan at pnwbakers.com
Wed Apr 4 22:50:18 UTC 2018


This results in substantially smaller profiles and doesn't seem to
affect runtime.

v2: - install xml and xml.gz files. This is needed so that meta profiles
      will be installed.
---
 CMakeLists.txt              |  4 ++--
 framework/profile.py        | 10 +++++-----
 tests/CMakeLists.no_api.txt |  6 +++---
 tests/serializer.py         |  4 +++-
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index db047b4b2..8c7d16270 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -533,14 +533,14 @@ install (
 install (
 	DIRECTORY tests
 	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
-	FILES_MATCHING REGEX ".*\\.(xml|py|program_test|shader_test|frag|vert|geom|tesc|tese|comp|ktx|cl|txt|inc)$"
+	FILES_MATCHING REGEX ".*\\.(xml|xml.gz|py|program_test|shader_test|frag|vert|geom|tesc|tese|comp|ktx|cl|txt|inc)$"
 	REGEX "CMakeFiles|CMakeLists|serializer.py|opengl.py|cl.py|quick_gl.py|glslparser.py|shader.py|quick_shader.py|no_error.py|llvmpipe_gl.py|sanity.py" EXCLUDE
 )
 
 install (
 	DIRECTORY ${CMAKE_BINARY_DIR}/tests
 	DESTINATION ${PIGLIT_INSTALL_LIBDIR}
-	FILES_MATCHING REGEX ".*\\.xml"
+	FILES_MATCHING REGEX ".*\\.xml.gz"
 )
 
 install (
diff --git a/framework/profile.py b/framework/profile.py
index 3975d0606..1c75025b3 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -34,8 +34,8 @@ import ast
 import collections
 import contextlib
 import copy
+import gzip
 import importlib
-import io
 import itertools
 import multiprocessing
 import multiprocessing.dummy
@@ -318,7 +318,7 @@ class XMLProfile(object):
 
     def __len__(self):
         if not (self.filters or self.forced_test_list):
-            with io.open(self.filename, 'rt') as f:
+            with gzip.open(self.filename, 'rt') as f:
                 iter_ = et.iterparse(f, events=(b'start', ))
                 for _, elem in iter_:
                     if elem.tag == 'PiglitTestList':
@@ -333,7 +333,7 @@ class XMLProfile(object):
 
     def _itertests(self):
         """Always iterates tests instead of using the forced test_list."""
-        with io.open(self.filename, 'rt') as f:
+        with gzip.open(self.filename, 'rt') as f:
             doc = et.iterparse(f, events=(b'end', ))
             _, root = next(doc)  # get the root so we can keep clearing it
             for _, e in doc:
@@ -517,13 +517,13 @@ def load_test_profile(filename, python=None):
         if os.path.exists(meta):
             return MetaProfile(meta)
 
-        xml = os.path.join(ROOT_DIR, 'tests', name + '.xml')
+        xml = os.path.join(ROOT_DIR, 'tests', name + '.xml.gz')
         if os.path.exists(xml):
             return XMLProfile(xml)
 
     if python is False:
         raise exceptions.PiglitFatalError(
-            'Cannot open "tests/{0}.xml" or "tests/{0}.meta.xml"'.format(name))
+            'Cannot open "tests/{0}.xml.gz" or "tests/{0}.meta.xml"'.format(name))
 
     try:
         mod = importlib.import_module('tests.{0}'.format(name))
diff --git a/tests/CMakeLists.no_api.txt b/tests/CMakeLists.no_api.txt
index d7f95af0e..3ffba74b0 100644
--- a/tests/CMakeLists.no_api.txt
+++ b/tests/CMakeLists.no_api.txt
@@ -45,14 +45,14 @@ add_custom_target(
 
 function(piglit_generate_xml name profile meta_target extra_args)
 	add_custom_command(
-		OUTPUT ${CMAKE_BINARY_DIR}/tests/${name}.xml
-		COMMAND ${CMAKE_COMMAND} -E env PIGLIT_BUILD_TREE=${CMAKE_BINARY_DIR} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/serializer.py ${name} ${CMAKE_CURRENT_SOURCE_DIR}/${profile}.py ${CMAKE_BINARY_DIR}/tests/${name}.xml  ${extra_args}
+		OUTPUT ${CMAKE_BINARY_DIR}/tests/${name}.xml.gz
+		COMMAND ${CMAKE_COMMAND} -E env PIGLIT_BUILD_TREE=${CMAKE_BINARY_DIR} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/serializer.py ${name} ${CMAKE_CURRENT_SOURCE_DIR}/${profile}.py ${CMAKE_BINARY_DIR}/tests/${name}.xml.gz  ${extra_args}
 		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${profile}.py ${CMAKE_CURRENT_SOURCE_DIR}/serializer.py ${ARGN}
 		VERBATIM
 	)
 	add_custom_target(
 		generate-${name}-xml
-		DEPENDS ${CMAKE_BINARY_DIR}/tests/${name}.xml
+		DEPENDS ${CMAKE_BINARY_DIR}/tests/${name}.xml.gz
 	)
 	add_dependencies(${meta_target} generate-${name}-xml)
 endfunction()
diff --git a/tests/serializer.py b/tests/serializer.py
index 58b3a14e9..32beb428c 100644
--- a/tests/serializer.py
+++ b/tests/serializer.py
@@ -22,6 +22,7 @@
 """Script for taking profiles in python format and serializing them to XML."""
 
 import argparse
+import gzip
 import os
 import sys
 import xml.etree.cElementTree as et
@@ -133,7 +134,8 @@ def serializer(name, profile, outfile):
                 et.SubElement(env, 'env', name=k, value=v)
 
     tree = et.ElementTree(root)
-    tree.write(outfile, encoding='utf-8', xml_declaration=True)
+    with gzip.open(outfile, 'wb') as f:
+        tree.write(f, encoding='utf-8', xml_declaration=True)
 
 
 def main():
-- 
2.16.3



More information about the Piglit mailing list