From patchwork Sun Dec 3 10:55:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10089135 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9D5B602C8 for ; Sun, 3 Dec 2017 10:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C3E290C2 for ; Sun, 3 Dec 2017 10:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4D32290C3; Sun, 3 Dec 2017 10:55:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54CA8290C1 for ; Sun, 3 Dec 2017 10:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbdLCKzs (ORCPT ); Sun, 3 Dec 2017 05:55:48 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:53665 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdLCKzr (ORCPT ); Sun, 3 Dec 2017 05:55:47 -0500 Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 37D5520226 for ; Sun, 3 Dec 2017 11:54:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1512298443; bh=KD0pDGXiLlYCKI3I6OD8I5OfEaCU5DRMzdKpYOUE+wA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XKem02aivTbhHmcbU3cajNUvUXVBmoR7tuqK5B3TScxfRRCFtPNeGUgJWQn9BBtCE pLxQYhK+lJ8GFp5zk1Y0TBY1KZsmk0j0V0CMhP+ZD0ZDTplr9LWa3A5ti0i1j0eZe7 uuTMhDx+Mvf9B/FQmvv88YRDLsmXf0g8geQ2vzag= From: Laurent Pinchart To: linux-renesas-soc@vger.kernel.org Subject: [PATCH 1/2] kmstest.py: Add CRC reader class Date: Sun, 3 Dec 2017 12:55:53 +0200 Message-Id: <20171203105554.10416-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171203105554.10416-1-laurent.pinchart@ideasonboard.com> References: <20171203105554.10416-1-laurent.pinchart@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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