From patchwork Mon Apr 8 08:45:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 10889015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 539CE1669 for ; Mon, 8 Apr 2019 08:46:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E97627FA8 for ; Mon, 8 Apr 2019 08:46:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32D4028640; Mon, 8 Apr 2019 08:46:16 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 50A32284F9 for ; Mon, 8 Apr 2019 08:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbfDHIqM (ORCPT ); Mon, 8 Apr 2019 04:46:12 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:42111 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfDHIqK (ORCPT ); Mon, 8 Apr 2019 04:46:10 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1hDPur-00075y-IS for linux-media@vger.kernel.org; Mon, 08 Apr 2019 10:46:09 +0200 From: Philipp Zabel To: linux-media@vger.kernel.org Subject: [PATCH v4l-utils 1/2] v4l2-compliance: use warn() in warn_once() Date: Mon, 8 Apr 2019 10:45:57 +0200 Message-Id: <20190408084558.2979-2-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408084558.2979-1-p.zabel@pengutronix.de> References: <20190408084558.2979-1-p.zabel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the warn() macro in warn_once() instead of duplicating its contents. Signed-off-by: Philipp Zabel --- utils/v4l2-compliance/v4l2-compliance.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/utils/v4l2-compliance/v4l2-compliance.h b/utils/v4l2-compliance/v4l2-compliance.h index ac709e94a537..f7e1ea5d7124 100644 --- a/utils/v4l2-compliance/v4l2-compliance.h +++ b/utils/v4l2-compliance/v4l2-compliance.h @@ -206,12 +206,7 @@ private: \ if (!show) { \ show = true; \ - warnings++; \ - if (show_warnings) \ - printf("\t\twarn: %s(%d): " fmt, \ - __FILE__, __LINE__, ##args); \ - if (exit_on_warn) \ - exit(1); \ + warn(fmt, ##args); \ } \ } while (0) From patchwork Mon Apr 8 08:45:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 10889017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A48A214DB for ; Mon, 8 Apr 2019 08:46:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5AF27CAF for ; Mon, 8 Apr 2019 08:46:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82FE127FA8; Mon, 8 Apr 2019 08:46:21 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 E36872863E for ; Mon, 8 Apr 2019 08:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726595AbfDHIqO (ORCPT ); Mon, 8 Apr 2019 04:46:14 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:53005 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbfDHIqL (ORCPT ); Mon, 8 Apr 2019 04:46:11 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1hDPus-00075y-1g for linux-media@vger.kernel.org; Mon, 08 Apr 2019 10:46:10 +0200 From: Philipp Zabel To: linux-media@vger.kernel.org Subject: [PATCH v4l-utils 2/2] v4l2-compliance: add colors Date: Mon, 8 Apr 2019 10:45:58 +0200 Message-Id: <20190408084558.2979-3-p.zabel@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408084558.2979-1-p.zabel@pengutronix.de> References: <20190408084558.2979-1-p.zabel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the output is a terminal, use color codes to mark OK, warn, and FAIL messages with green, bold, and bright red accents, respectively. Signed-off-by: Philipp Zabel --- utils/v4l2-compliance/v4l2-compliance.cpp | 11 ++++++++--- utils/v4l2-compliance/v4l2-compliance.h | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp index f7611d75cb1b..488e746d055d 100644 --- a/utils/v4l2-compliance/v4l2-compliance.cpp +++ b/utils/v4l2-compliance/v4l2-compliance.cpp @@ -89,6 +89,7 @@ static int grand_total, grand_ok, grand_warnings; bool show_info; bool no_progress; bool show_warnings = true; +bool show_colors; bool exit_on_fail; bool exit_on_warn; bool is_vivid; @@ -250,15 +251,17 @@ const char *ok(int res) static char buf[100]; if (res == ENOTTY) { - strcpy(buf, "OK (Not Supported)"); + strcpy(buf, show_colors ? + COLOR_GREEN("OK") " (Not Supported)" : + "OK (Not Supported)"); res = 0; } else { - strcpy(buf, "OK"); + strcpy(buf, show_colors ? COLOR_GREEN("OK") : "OK"); } tests_total++; if (res) { app_result = res; - sprintf(buf, "FAIL"); + sprintf(buf, show_colors ? COLOR_RED("FAIL") : "FAIL"); } else { tests_ok++; } @@ -1630,6 +1633,8 @@ int main(int argc, char **argv) bool direct = !options[OptUseWrapper]; int fd; + show_colors = isatty(STDOUT_FILENO); + if (type == MEDIA_TYPE_UNKNOWN) type = mi_media_detect_type(device.c_str()); if (type == MEDIA_TYPE_CANT_STAT) { diff --git a/utils/v4l2-compliance/v4l2-compliance.h b/utils/v4l2-compliance/v4l2-compliance.h index f7e1ea5d7124..7909c3822cd0 100644 --- a/utils/v4l2-compliance/v4l2-compliance.h +++ b/utils/v4l2-compliance/v4l2-compliance.h @@ -52,6 +52,7 @@ extern bool show_info; extern bool show_warnings; extern bool no_progress; +extern bool show_colors; extern bool exit_on_fail; extern bool exit_on_warn; extern bool is_vivid; // We're testing the vivid driver @@ -185,17 +186,24 @@ private: std::set fhs; }; +#define COLOR_GREEN(s) "\033[32m" s "\033[0m" +#define COLOR_RED(s) "\033[1;31m" s "\033[0m" +#define COLOR_BOLD(s) "\033[1m" s "\033[0m" + #define info(fmt, args...) \ do { \ if (show_info) \ - printf("\t\tinfo: " fmt, ##args); \ + printf("\t\tinfo: " fmt, ##args); \ } while (0) #define warn(fmt, args...) \ do { \ warnings++; \ if (show_warnings) \ - printf("\t\twarn: %s(%d): " fmt, __FILE__, __LINE__, ##args); \ + printf("\t\t%s: %s(%d): " fmt, \ + show_colors ? \ + COLOR_BOLD("warn") : "warn", \ + __FILE__, __LINE__, ##args); \ if (exit_on_warn) \ exit(1); \ } while (0) @@ -218,7 +226,8 @@ private: #define fail(fmt, args...) \ ({ \ - printf("\t\tfail: %s(%d): " fmt, __FILE__, __LINE__, ##args); \ + printf("\t\t%s: %s(%d): " fmt, show_colors ? \ + COLOR_RED("fail") : "fail", __FILE__, __LINE__, ##args); \ if (exit_on_fail) \ exit(1); \ 1; \