[PATCH 1/2] kmstest.py: Add CRC reader class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The CRCReader class uses the DRM/KMS debugfs-based CRC API to configure
CRC computation on a CRTC and read the computed CRC values.

Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
---
 tests/kmstest.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/tests/kmstest.py b/tests/kmstest.py
index cb0d9a7546d8..45d619c7a9be 100755
--- a/tests/kmstest.py
+++ b/tests/kmstest.py
@@ -145,6 +145,61 @@ class Logger(object):
         self.logfile.flush()
 
 
+class CRC(object):
+    def __init__(self, crc):
+        if crc.startswith("XXXXXXXXXX"):
+            self.frame = None
+        else:
+            self.frame = int(crc[:10], 16)
+
+        crc = crc[11:].strip('\n\0').split(' ')
+        self.crcs = [int(c, 16) for c in crc]
+
+
+class CRCReader(object):
+
+    MAX_CRC_ENTRIES = 10
+    MAX_LINE_LEN  = 10 + 11 * MAX_CRC_ENTRIES + 1
+
+    def __init__(self, crtc):
+        self.pipe = crtc.idx
+
+        # Hardcode the device minor to 0 as the KMSTest constructor opens the
+        # default card object.
+        self.dir = os.open("/sys/kernel/debug/dri/0/crtc-%u/crc" % self.pipe, 0)
+        self.ctrl = os.open("control", os.O_WRONLY, dir_fd = self.dir)
+        self.data = -1
+
+    def __del__(self):
+        self.stop()
+        os.close(self.ctrl)
+        os.close(self.dir)
+
+    def start(self, source):
+        os.write(self.ctrl, source.encode("ascii"))
+        self.data = os.open("data", os.O_RDONLY, dir_fd = self.dir)
+
+    def stop(self):
+        if self.data != -1:
+            os.close(self.data)
+            self.data = -1
+
+    def read(self, num_entries=1):
+        crcs = []
+        while len(crcs) < num_entries:
+            try:
+                crc = os.read(self.data, CRCReader.MAX_LINE_LEN)
+                crc = crc.decode("ascii")
+            except OSError as e:
+                if e.errno == errno.EAGAIN:
+                    break
+                else:
+                    raise e
+            crcs.append(CRC(crc))
+
+        return crcs
+
+
 class Rect(object):
     def __init__(self, left, top, width, height):
         self.left = left
-- 
Regards,

Laurent Pinchart




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux