diff mbox

[2/2] tests: crc: Add CRC computation test

Message ID 20171203105554.10416-3-laurent.pinchart@ideasonboard.com (mailing list archive)
State Not Applicable
Delegated to: Geert Uytterhoeven
Headers show

Commit Message

Laurent Pinchart Dec. 3, 2017, 10:55 a.m. UTC
The test exercises the CRC API by enabling CRC computation on the
pipeline output, capturing CRC values and verifying that they all match.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 tests/kms-test-crc.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
 create mode 100755 tests/kms-test-crc.py
diff mbox

Patch

diff --git a/tests/kms-test-crc.py b/tests/kms-test-crc.py
new file mode 100755
index 000000000000..93b5d8210b4e
--- /dev/null
+++ b/tests/kms-test-crc.py
@@ -0,0 +1,103 @@ 
+#!/usr/bin/python3
+
+import kmstest
+import pykms
+
+class CRCTest(kmstest.KMSTest):
+    """Test CRC calculation on pipeline output."""
+
+    def handle_page_flip(self, frame, time):
+        self.logger.log("Page flip complete")
+
+    def main(self):
+        # Create the connectors to CRTCs map
+        connectors = {}
+        for connector in self.card.connectors:
+            # Skip disconnected connectors
+            if not connector.connected():
+                continue
+
+            # Add the connector to the map
+            for crtc in connector.get_possible_crtcs():
+                if crtc not in connectors:
+                    connectors[crtc] = connector
+
+        for crtc in self.card.crtcs:
+            self.start("CRC calculation on CRTC %u" % crtc.id)
+
+            # Get the connector and default mode
+            try:
+                connector = connectors[crtc];
+                mode = connector.get_default_mode()
+            except KeyError:
+                self.skip("no connector or mode available")
+                continue
+
+            # List planes available for the CRTC
+            planes = []
+            for plane in self.card.planes:
+                if plane.supports_crtc(crtc) and plane != crtc.primary_plane:
+                    planes.append(plane)
+
+            if len(planes) == 0:
+                self.skip("no plane available for CRTC")
+                continue
+
+            self.logger.log("Testing connector %s, CRTC %u, mode %s with %u planes" % \
+                  (connector.fullname, crtc.id, mode.name, len(planes)))
+
+            # Create a frame buffer
+            fb = pykms.DumbFramebuffer(self.card, mode.hdisplay, mode.vdisplay, "XR24")
+            pykms.draw_test_pattern(fb)
+
+            # Set the mode and add all planes
+            ret = self.atomic_crtc_mode_set(crtc, connector, mode, fb)
+            if ret < 0:
+                self.fail("atomic mode set failed with %d" % ret)
+                continue
+
+            req = pykms.AtomicReq(self.card)
+
+            offset = 100
+            for plane in planes:
+                source = kmstest.Rect(0, 0, fb.width, fb.height)
+                destination = kmstest.Rect(offset, offset, fb.width, fb.height)
+                req.add(plane, {
+                        'FB_ID': fb.id,
+                        'CRTC_ID': crtc.id,
+                        'SRC_X': int(source.left * 65536),
+                        'SRC_Y': int(source.top * 65536),
+                        'SRC_W': int(source.width * 65536),
+                        'SRC_H': int(source.height * 65536),
+                        'CRTC_X': destination.left,
+                        'CRTC_Y': destination.top,
+                        'CRTC_W': destination.width,
+                        'CRTC_H': destination.height,
+                })
+                offset += 50
+
+            ret = req.commit_sync()
+            if ret < 0:
+                self.fail("atomic plane set failed with %d" % ret)
+                continue
+
+            # Wait for one second and make sure the page flip has completed.
+            self.run(1)
+            if self.flips == 0:
+                self.fail("No page flip registered")
+                continue
+
+            crc_reader = kmstest.CRCReader(crtc)
+            crc_reader.start("auto")
+            crcs = crc_reader.read(10)
+            crc_reader.stop()
+
+            crcs = [c.crcs[0] for c in crcs]
+            if len(set(crcs)) != 1:
+                self.fail("CRC values not constant")
+                continue
+
+            self.logger.log("CRC value 0x%08x" % crcs[0])
+            self.success()
+
+CRCTest().execute()