summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2017-12-02 15:34:32 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-04-23 01:37:23 +0300
commit62f3a53608f093ccf0fa5ace8568a95d557ec65f (patch)
tree37664182b1415770dab41aa8ee377ed8aa8b1855
parent8d2da273b18e8be9af82692f23d0b9da91c5a45d (diff)
kmstest.py: Add CRC reader class
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@ideasonboard.com>
-rwxr-xr-xtests/kmstest.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/kmstest.py b/tests/kmstest.py
index e528b90..12454df 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