summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gallium/state_trackers/python/tests/base.py87
-rw-r--r--src/gallium/state_trackers/python/tests/texture.py72
2 files changed, 116 insertions, 43 deletions
diff --git a/src/gallium/state_trackers/python/tests/base.py b/src/gallium/state_trackers/python/tests/base.py
index d83abdfa76..c50abf7f69 100644
--- a/src/gallium/state_trackers/python/tests/base.py
+++ b/src/gallium/state_trackers/python/tests/base.py
@@ -27,6 +27,12 @@
##########################################################################
+"""Base classes for tests.
+
+Loosely inspired on Python's unittest module.
+"""
+
+
from gallium import *
@@ -87,17 +93,54 @@ def show_image(width, height, **rgbas):
root.mainloop()
+class TestFailure(Exception):
-class Test:
+ pass
+
+class TestSkip(Exception):
+ pass
+
+
+class Test:
+
def __init__(self):
pass
+
+ def _run(self, result):
+ raise NotImplementedError
+ def run(self):
+ result = TestResult()
+ self._run(result)
+ result.summary()
+
+
+class TestCase(Test):
+
+ def __init__(self, dev, **kargs):
+ Test.__init__(self)
+ self.dev = dev
+ self.__dict__.update(kargs)
+
def description(self):
raise NotImplementedError
- def run(self):
+ def test(self):
raise NotImplementedError
+
+ def _run(self, result):
+ result.test_start(self)
+ try:
+ self.test()
+ except KeyboardInterrupt:
+ raise
+ except TestSkip:
+ result.test_skipped(self)
+ except TestFailure:
+ result.test_failed(self)
+ else:
+ result.test_passed(self)
class TestSuite(Test):
@@ -112,21 +155,35 @@ class TestSuite(Test):
def add_test(self, test):
self.tests.append(test)
- def run(self):
+ def _run(self, result):
for test in self.tests:
- print "Running %s..." % test.description()
- test.run()
+ test._run(result)
-class TextureTemplate:
+class TestResult:
- def __init__(self, format=PIPE_FORMAT_R8G8B8A8_UNORM, width=1, height=1, depth=1, last_level=0, target=PIPE_TEXTURE_2D):
- self.format = format
- self.width = width
- self.height = height
- self.depth = depth
- self.last_level = last_level
- self.target = target
-
-
+ def __init__(self):
+ self.tests = 0
+ self.passed = 0
+ self.skipped = 0
+ self.failed = 0
+
+ def test_start(self, test):
+ self.tests += 1
+ print "Running %s..." % test.description()
+
+ def test_passed(self, test):
+ self.passed += 1
+ print "PASS"
+
+ def test_skipped(self, test):
+ self.skipped += 1
+ print "SKIP"
+
+ def test_failed(self):
+ self.failed += 1
+ print "FAIL"
+ def summary(self):
+ print "%u tests, %u passed, %u skipped, %u failed" % (self.tests, self.passed, self.skipped, self.failed)
+ \ No newline at end of file
diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py
index 7812d8aebf..7c7245e65c 100644
--- a/src/gallium/state_trackers/python/tests/texture.py
+++ b/src/gallium/state_trackers/python/tests/texture.py
@@ -52,30 +52,39 @@ def compare_rgba(width, height, rgba1, rgba2, tol=4.0/256):
return errors == 0
-class TextureTest(Test):
-
- def __init__(self, **kargs):
- Test.__init__(self)
- self.__dict__.update(kargs)
+def lods(*dims):
+ size = max(dims)
+ lods = 0
+ while size:
+ lods += 1
+ size >>= 1
+ return lods
+
+
+def minify(dims, level = 1):
+ return [max(dim>>level, 1) for dim in dims]
+
+class TextureTest(TestCase):
+
def description(self):
- return "%s %ux%u" % (formats[self.format], self.width, self.height)
-
- def run(self):
+ return "%s %ux%u level=%u" % (formats[self.format], self.width, self.height, self.level)
+
+ def test(self):
dev = self.dev
format = self.format
width = self.width
height = self.height
+ level = self.level
+
+ levels = lods(width, height)
+
if not dev.is_format_supported(format, PIPE_TEXTURE):
- print "SKIP"
- return
- if not dev.is_format_supported(format, PIPE_SURFACE):
- print "SKIP"
- return
+ raise TestSkip
- ctx = dev.context_create()
+ ctx = self.dev.context_create()
# disabled blending/masking
blend = Blend()
@@ -123,15 +132,20 @@ class TextureTest(Test):
sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST
sampler.normalized_coords = 1
+ sampler.min_lod = level
+ sampler.max_lod = level
ctx.set_sampler(0, sampler)
# texture
texture = dev.texture_create(format,
width,
- height)
+ height,
+ last_level = levels - 1)
ctx.set_sampler_texture(0, texture)
- expected_rgba = generate_data(texture.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE))
+ expected_rgba = generate_data(texture.get_surface(
+ usage = PIPE_BUFFER_USAGE_CPU_READ|PIPE_BUFFER_USAGE_CPU_WRITE,
+ level = level))
# framebuffer
cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM,
@@ -181,8 +195,7 @@ class TextureTest(Test):
x = 0
y = 0
- w = width
- h = height
+ w, h = minify((width, height), level)
verts[ 0] = x # x1
verts[ 1] = y # y1
@@ -223,32 +236,35 @@ class TextureTest(Test):
verts)
ctx.flush()
-
- del ctx
-
- rgba = FloatArray(height*width*4)
+
+ rgba = FloatArray(h*w*4)
cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_CPU_READ).get_tile_rgba(x, y, w, h, rgba)
- if compare_rgba(width, height, rgba, expected_rgba):
- print "OK"
- else:
- print "FAIL"
+ if not compare_rgba(w, h, rgba, expected_rgba):
- show_image(width, height, Result=rgba, Expected=expected_rgba)
+ show_image(w, h, Result=rgba, Expected=expected_rgba)
#save_image(width, height, rgba, "result.png")
#save_image(width, height, expected_rgba, "expected.png")
sys.exit(0)
+
+ raise TestFailure
+
+ del ctx
+
def main():
dev = Device()
suite = TestSuite()
formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_DXT1_RGB]
+ #formats = [PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_DXT1_RGB]
sizes = [64, 32, 16, 8, 4, 2]
for format in formats:
for size in sizes:
- suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size))
+ levels = lods(size)
+ for level in range(levels):
+ suite.add_test(TextureTest(dev=dev, format=format, width=size, height=size, level=level))
suite.run()