From 62f3a53608f093ccf0fa5ace8568a95d557ec65f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 2 Dec 2017 15:34:32 +0200 Subject: 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 --- tests/kmstest.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) 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 -- cgit v1.2.3