From patchwork Thu Mar 30 08:09:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Abdiel Janulgue X-Patchwork-Id: 9653163 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 F0B95602C8 for ; Thu, 30 Mar 2017 08:10:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E234428552 for ; Thu, 30 Mar 2017 08:10:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6CF22857D; Thu, 30 Mar 2017 08:10:37 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 50F6E28552 for ; Thu, 30 Mar 2017 08:10:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0480E6E859; Thu, 30 Mar 2017 08:10:37 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1DBAB6E859 for ; Thu, 30 Mar 2017 08:10:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490861435; x=1522397435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iP7vxhHL5kuX7mCQ8uVh+CjLJreQwPFJZXCxduv+63c=; b=uU5IkzP2IFXCw7iGW+H/pYVCKFWAHVK20B4jV5imXgj1pTZ7XH/V34Xs hm76r6vWnVCd1IHdYNfjklr1A9nwew==; Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Mar 2017 01:10:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,245,1486454400"; d="scan'208";a="839958886" Received: from skylake-nuc.fi.intel.com ([10.237.72.145]) by FMSMGA003.fm.intel.com with ESMTP; 30 Mar 2017 01:10:33 -0700 From: Abdiel Janulgue To: intel-gfx@lists.freedesktop.org Date: Thu, 30 Mar 2017 11:09:22 +0300 Message-Id: <1490861362-4991-2-git-send-email-abdiel.janulgue@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490861362-4991-1-git-send-email-abdiel.janulgue@linux.intel.com> References: <1490610492-18649-1-git-send-email-abdiel.janulgue@linux.intel.com> <1490861362-4991-1-git-send-email-abdiel.janulgue@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [i-g-t PATCH 2/2] lib/tests: Add kmstest_edid_add_* selftests X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Sanity check the edid block generation capabilities. Cc: Petri Latvala Signed-off-by: Abdiel Janulgue --- lib/tests/Makefile.sources | 1 + lib/tests/igt_hdmi_inject.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 lib/tests/igt_hdmi_inject.c diff --git a/lib/tests/Makefile.sources b/lib/tests/Makefile.sources index 3fcfe14..4cfc0a5 100644 --- a/lib/tests/Makefile.sources +++ b/lib/tests/Makefile.sources @@ -13,6 +13,7 @@ check_prog_list = \ igt_subtest_group \ igt_assert \ igt_exit_handler \ + igt_hdmi_inject \ $(NULL) TESTS = \ diff --git a/lib/tests/igt_hdmi_inject.c b/lib/tests/igt_hdmi_inject.c new file mode 100644 index 0000000..9b6780a --- /dev/null +++ b/lib/tests/igt_hdmi_inject.c @@ -0,0 +1,96 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#include "igt.h" + +static const unsigned char edid_header[] = { + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 +}; + +/** + * Sanity check the header of the base EDID block. + * + * Return: 8 if the header is perfect, down to 0 if it's totally wrong. + */ +static int edid_header_is_valid(const unsigned char *raw_edid) +{ + int i, score = 0; + + for (i = 0; i < sizeof(edid_header); i++) + if (raw_edid[i] == edid_header[i]) + score++; + + return score; +} + +/** + * Sanity check the checksum of the EDID block. + * + * Return: 0 if the block is perfect. + * See byte 127 of spec + * https://en.wikipedia.org/wiki/Extended_Display_Identification_Data#EDID_1.3_data_format + */ +static int edid_block_checksum(const unsigned char *raw_edid) +{ + int i; + unsigned char csum = 0; + for (i = 0; i < EDID_LENGTH; i++) { + csum += raw_edid[i]; + } + + return csum; +} + +typedef void (*hdmi_inject_func)(const unsigned char *edid, size_t length, + unsigned char *new_edid_ptr[], size_t *new_length); + +igt_simple_main +{ + const struct { + const char *desc; + hdmi_inject_func inject; + } funcs[] = { + { "3D", kmstest_edid_add_3d }, + { "4k", kmstest_edid_add_4k }, + { "audio", kmstest_edid_add_audio }, + { NULL, NULL }, + }, *f; + + for (f = funcs; f->inject; f++) { + unsigned char *edid; + size_t length; + + f->inject(igt_kms_get_base_edid(), EDID_LENGTH, &edid, + &length); + + igt_assert_f(edid_header_is_valid(edid) == 8, + "invalid header on HDMI %s", f->desc); + /* check base edid block */ + igt_assert_f(edid_block_checksum(edid) == 0, + "checksum failed on HDMI %s", f->desc); + /* check extension block */ + igt_assert_f(edid_block_checksum(edid + EDID_LENGTH) == 0, + "CEA block checksum failed on HDMI %s", f->desc); + } +}