From patchwork Fri Jan 23 16:08:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 5695361 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A9D91C058D for ; Fri, 23 Jan 2015 16:08:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B5F7202B8 for ; Fri, 23 Jan 2015 16:08:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 19DD82028D for ; Fri, 23 Jan 2015 16:08:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF16C6E949; Fri, 23 Jan 2015 08:08:52 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D0616E949 for ; Fri, 23 Jan 2015 08:08:52 -0800 (PST) Received: by mail-pa0-f52.google.com with SMTP id kx10so9370078pab.11 for ; Fri, 23 Jan 2015 08:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zftTslCHI3g9y+sn1I1bxzBmtVT7Fmr6hAJWqXLvkF8=; b=IGavhl+omUg+yE5f2Zy//xWMQ01Apuxi21RKh85Y9sVg5UVUsMxyYRMAZsNfyM3Bc6 CAuMcTXPX/xDmNYN2BnsYhb9kwycYGvGkUCMJcoqmz2dOeA6W1otRHgDjVzwJBcbzvPQ DlGHGkBObP3tq3eBaVKVR6t1yrk7VjdXeoCFBoYL31IGnZGJguDCBZd1yChm0b8B63tR SUA0hELrbIputiquUfOwZkELenbzVCTYJdT7ex9+XH8c2C5yvTeVwSMmLRQqbMspLhNR 0m1xtc/gfADgSOyJ7OBZ/9zntarJsVgBtY70820Sd6ntFqNerZlifI133v7E/TdHxRkb xagQ== X-Received: by 10.70.102.193 with SMTP id fq1mr12477471pdb.19.1422029331803; Fri, 23 Jan 2015 08:08:51 -0800 (PST) Received: from localhost ([216.228.120.20]) by mx.google.com with ESMTPSA id oi5sm2356442pbb.7.2015.01.23.08.08.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jan 2015 08:08:51 -0800 (PST) From: Thierry Reding To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 05/11] tests: Move name tables to libutil Date: Fri, 23 Jan 2015 17:08:18 +0100 Message-Id: <1422029304-1926-6-git-send-email-thierry.reding@gmail.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1422029304-1926-1-git-send-email-thierry.reding@gmail.com> References: <1422029304-1926-1-git-send-email-thierry.reding@gmail.com> Cc: Laurent Pinchart X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding These tables are duplicated in several places, so move them into libutil so that they can be shared. Signed-off-by: Thierry Reding Acked-by: Laurent Pinchart --- tests/modetest/modetest.c | 50 ++----------------- tests/proptest/Makefile.am | 4 +- tests/proptest/proptest.c | 40 +-------------- tests/util/Makefile.am | 2 + tests/util/kms.c | 122 +++++++++++++++++++++++++++++++++++++++++++++ tests/util/kms.h | 33 ++++++++++++ 6 files changed, 165 insertions(+), 86 deletions(-) create mode 100644 tests/util/kms.c create mode 100644 tests/util/kms.h diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index b610956adfcb..d5fd99ebe1fd 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -61,6 +61,7 @@ #include "util/common.h" #include "util/format.h" +#include "util/kms.h" #include "util/pattern.h" #include "buffers.h" @@ -123,11 +124,6 @@ static inline int64_t U642I64(uint64_t val) return (int64_t)*((int64_t *)&val); } -struct type_name { - int type; - const char *name; -}; - #define type_name_fn(res) \ const char * res##_str(int type) { \ unsigned int i; \ @@ -138,44 +134,6 @@ const char * res##_str(int type) { \ return "(invalid)"; \ } -struct type_name encoder_type_names[] = { - { DRM_MODE_ENCODER_NONE, "none" }, - { DRM_MODE_ENCODER_DAC, "DAC" }, - { DRM_MODE_ENCODER_TMDS, "TMDS" }, - { DRM_MODE_ENCODER_LVDS, "LVDS" }, - { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, -}; - -static type_name_fn(encoder_type) - -struct type_name connector_status_names[] = { - { DRM_MODE_CONNECTED, "connected" }, - { DRM_MODE_DISCONNECTED, "disconnected" }, - { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, -}; - -static type_name_fn(connector_status) - -struct type_name connector_type_names[] = { - { DRM_MODE_CONNECTOR_Unknown, "unknown" }, - { DRM_MODE_CONNECTOR_VGA, "VGA" }, - { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, - { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, - { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, - { DRM_MODE_CONNECTOR_Composite, "composite" }, - { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, - { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, - { DRM_MODE_CONNECTOR_Component, "component" }, - { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, - { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, - { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, - { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, - { DRM_MODE_CONNECTOR_TV, "TV" }, - { DRM_MODE_CONNECTOR_eDP, "eDP" }, -}; - -static type_name_fn(connector_type) - #define bit_name_fn(res) \ const char * res##_str(int type) { \ unsigned int i; \ @@ -235,7 +193,7 @@ static void dump_encoders(struct device *dev) printf("%d\t%d\t%s\t0x%08x\t0x%08x\n", encoder->encoder_id, encoder->crtc_id, - encoder_type_str(encoder->encoder_type), + util_lookup_encoder_type_name(encoder->encoder_type), encoder->possible_crtcs, encoder->possible_clones); } @@ -379,8 +337,8 @@ static void dump_connectors(struct device *dev) printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t", connector->connector_id, connector->encoder_id, - connector_status_str(connector->connection), - connector_type_str(connector->connector_type), + util_lookup_connector_status_name(connector->connection), + util_lookup_connector_type_name(connector->connector_type), connector->mmWidth, connector->mmHeight, connector->count_modes); diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am index f81a3c00846b..c615489b9a92 100644 --- a/tests/proptest/Makefile.am +++ b/tests/proptest/Makefile.am @@ -1,5 +1,6 @@ AM_CFLAGS = \ -I$(top_srcdir)/include/drm \ + -I$(top_srcdir)/tests \ -I$(top_srcdir) noinst_PROGRAMS = \ @@ -8,4 +9,5 @@ noinst_PROGRAMS = \ proptest_SOURCES = \ proptest.c proptest_LDADD = \ - $(top_builddir)/libdrm.la + $(top_builddir)/libdrm.la \ + $(top_builddir)/tests/util/libutil.la diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c index ee3fa408a310..b442d583d528 100644 --- a/tests/proptest/proptest.c +++ b/tests/proptest/proptest.c @@ -45,44 +45,6 @@ static inline int64_t U642I64(uint64_t val) int fd; drmModeResPtr res = NULL; -const char *connector_type_str(uint32_t type) -{ - switch (type) { - case DRM_MODE_CONNECTOR_Unknown: - return "Unknown"; - case DRM_MODE_CONNECTOR_VGA: - return "VGA"; - case DRM_MODE_CONNECTOR_DVII: - return "DVI-I"; - case DRM_MODE_CONNECTOR_DVID: - return "DVI-D"; - case DRM_MODE_CONNECTOR_DVIA: - return "DVI-A"; - case DRM_MODE_CONNECTOR_Composite: - return "Composite"; - case DRM_MODE_CONNECTOR_SVIDEO: - return "SVIDEO"; - case DRM_MODE_CONNECTOR_LVDS: - return "LVDS"; - case DRM_MODE_CONNECTOR_Component: - return "Component"; - case DRM_MODE_CONNECTOR_9PinDIN: - return "9PinDin"; - case DRM_MODE_CONNECTOR_DisplayPort: - return "DisplayPort"; - case DRM_MODE_CONNECTOR_HDMIA: - return "HDMI-A"; - case DRM_MODE_CONNECTOR_HDMIB: - return "HDMI-B"; - case DRM_MODE_CONNECTOR_TV: - return "TV"; - case DRM_MODE_CONNECTOR_eDP: - return "eDP"; - default: - return "Invalid"; - } -} - /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */ static void dump_blob(uint32_t blob_id) @@ -226,7 +188,7 @@ static void listConnectorProperties(void) } printf("Connector %u (%s-%u)\n", c->connector_id, - connector_type_str(c->connector_type), + util_lookup_connector_type_name(c->connector_type), c->connector_type_id); listObjectProperties(c->connector_id, diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am index 1a2519fbea89..c00574484867 100644 --- a/tests/util/Makefile.am +++ b/tests/util/Makefile.am @@ -12,6 +12,8 @@ libutil_la_SOURCES = \ common.h \ format.c \ format.h \ + kms.c \ + kms.h \ pattern.c \ pattern.h diff --git a/tests/util/kms.c b/tests/util/kms.c new file mode 100644 index 000000000000..a271ca047c4e --- /dev/null +++ b/tests/util/kms.c @@ -0,0 +1,122 @@ +/* + * Copyright 2008 Tungsten Graphics + * Jakob Bornecrantz + * Copyright 2008 Intel Corporation + * Jesse Barnes + * + * 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 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. + */ + +/* + * This fairly simple test program dumps output in a similar format to the + * "xrandr" tool everyone knows & loves. It's necessarily slightly different + * since the kernel separates outputs into encoder and connector structures, + * each with their own unique ID. The program also allows test testing of the + * memory management and mode setting APIs by allowing the user to specify a + * connector and mode to use for mode setting. If all works as expected, a + * blue background should be painted on the monitor attached to the specified + * connector after the selected mode is set. + * + * TODO: use cairo to write the mode info on the selected output once + * the mode has been programmed, along with possible test patterns. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "xf86drmMode.h" + +#include "common.h" + +struct type_name { + unsigned int type; + const char *name; +}; + +static const char *util_lookup_type_name(unsigned int type, + const struct type_name *table, + unsigned int count) +{ + unsigned int i; + + for (i = 0; i < count; i++) + if (table[i].type == type) + return table[i].name; + + return NULL; +} + +static const struct type_name encoder_type_names[] = { + { DRM_MODE_ENCODER_NONE, "none" }, + { DRM_MODE_ENCODER_DAC, "DAC" }, + { DRM_MODE_ENCODER_TMDS, "TMDS" }, + { DRM_MODE_ENCODER_LVDS, "LVDS" }, + { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, + { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, + { DRM_MODE_ENCODER_DSI, "DSI" }, + { DRM_MODE_ENCODER_DPMST, "DisplayPort MST" }, +}; + +const char *util_lookup_encoder_type_name(unsigned int type) +{ + return util_lookup_type_name(type, encoder_type_names, + ARRAY_SIZE(encoder_type_names)); +} + +static const struct type_name connector_status_names[] = { + { DRM_MODE_CONNECTED, "connected" }, + { DRM_MODE_DISCONNECTED, "disconnected" }, + { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, +}; + +const char *util_lookup_connector_status_name(unsigned int status) +{ + return util_lookup_type_name(status, connector_status_names, + ARRAY_SIZE(connector_status_names)); +} + +static const struct type_name connector_type_names[] = { + { DRM_MODE_CONNECTOR_Unknown, "unknown" }, + { DRM_MODE_CONNECTOR_VGA, "VGA" }, + { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, + { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, + { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, + { DRM_MODE_CONNECTOR_Composite, "composite" }, + { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, + { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, + { DRM_MODE_CONNECTOR_Component, "component" }, + { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, + { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, + { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, + { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, + { DRM_MODE_CONNECTOR_TV, "TV" }, + { DRM_MODE_CONNECTOR_eDP, "eDP" }, + { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, + { DRM_MODE_CONNECTOR_DSI, "DSI" }, +}; + +const char *util_lookup_connector_type_name(unsigned int type) +{ + return util_lookup_type_name(type, connector_type_names, + ARRAY_SIZE(connector_type_names)); +} diff --git a/tests/util/kms.h b/tests/util/kms.h new file mode 100644 index 000000000000..fa9ab69983ac --- /dev/null +++ b/tests/util/kms.h @@ -0,0 +1,33 @@ +/* + * Copyright 2008 Tungsten Graphics + * Jakob Bornecrantz + * Copyright 2008 Intel Corporation + * Jesse Barnes + * + * 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 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. + */ + +#ifndef UTIL_KMS_H +#define UTIL_KMS_H + +const char *util_lookup_encoder_type_name(unsigned int type); +const char *util_lookup_connector_status_name(unsigned int type); +const char *util_lookup_connector_type_name(unsigned int type); + +#endif /* UTIL_KMS_H */