From patchwork Tue Apr 9 14:49:55 2019
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Philipp Zabel
X-Patchwork-Id: 10891395
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 2663B18B7
for ;
Tue, 9 Apr 2019 14:50:07 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14556285A7
for ;
Tue, 9 Apr 2019 14:50:07 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id 07487288F4; Tue, 9 Apr 2019 14:50:07 +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 AE42A285A7
for ;
Tue, 9 Apr 2019 14:50:06 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1726599AbfDIOuF (ORCPT
);
Tue, 9 Apr 2019 10:50:05 -0400
Received: from metis.ext.pengutronix.de ([85.220.165.71]:37637 "EHLO
metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1726460AbfDIOuF (ORCPT
); Tue, 9 Apr 2019 10:50:05 -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 1hDs4Z-0005vk-CR
for linux-media@vger.kernel.org; Tue, 09 Apr 2019 16:50:03 +0200
From: Philipp Zabel
To: linux-media@vger.kernel.org
Subject: [PATCH v4l-utils v2 1/4] v4l2-compliance: use warn() in warn_once()
Date: Tue, 9 Apr 2019 16:49:55 +0200
Message-Id: <20190409144958.31233-2-p.zabel@pengutronix.de>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190409144958.31233-1-p.zabel@pengutronix.de>
References: <20190409144958.31233-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 Tue Apr 9 14:49:56 2019
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Philipp Zabel
X-Patchwork-Id: 10891399
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 20CFE1805
for ;
Tue, 9 Apr 2019 14:50:09 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D456285A7
for ;
Tue, 9 Apr 2019 14:50:09 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id F1BE9288F4; Tue, 9 Apr 2019 14:50:08 +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 62EB5285A7
for ;
Tue, 9 Apr 2019 14:50:08 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1726535AbfDIOuH (ORCPT
);
Tue, 9 Apr 2019 10:50:07 -0400
Received: from metis.ext.pengutronix.de ([85.220.165.71]:59137 "EHLO
metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1726515AbfDIOuF (ORCPT
); Tue, 9 Apr 2019 10:50:05 -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 1hDs4Z-0005vk-EP
for linux-media@vger.kernel.org; Tue, 09 Apr 2019 16:50:03 +0200
From: Philipp Zabel
To: linux-media@vger.kernel.org
Subject: [PATCH v4l-utils v2 2/4] v4l2-compliance: add colors
Date: Tue, 9 Apr 2019 16:49:56 +0200
Message-Id: <20190409144958.31233-3-p.zabel@pengutronix.de>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190409144958.31233-1-p.zabel@pengutronix.de>
References: <20190409144958.31233-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 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.1.in | 5 +++
utils/v4l2-compliance/v4l2-compliance.cpp | 37 ++++++++++++++++++++--
utils/v4l2-compliance/v4l2-compliance.h | 15 +++++++--
3 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/utils/v4l2-compliance/v4l2-compliance.1.in b/utils/v4l2-compliance/v4l2-compliance.1.in
index 77b84ba6022f..39f0229d7af1 100644
--- a/utils/v4l2-compliance/v4l2-compliance.1.in
+++ b/utils/v4l2-compliance/v4l2-compliance.1.in
@@ -167,6 +167,11 @@ signal is present on all inputs or that all outputs are hooked up.
Exit this application when the first failure occurs instead of continuing
with a possible inconsistent state.
.TP
+\fB\-C\fR, \fB\-\-color\fR \fI\fR
+Highlight OK/warn/fail/FAIL strings with colors. OK is marked green, warn is
+marked bold, and fail/FAIL are marked bright red if enabled. \fI\fR can
+be \fIalways\fR, \fInever\fR, or \fIauto\fR (the default).
+.TP
\fB\-n\fR, \fB\-\-no\-warnings\fR
Turn off warning messages. They are still counted in the summary, but you won't see them.
.TP
diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp
index f7611d75cb1b..e5bafc0738ea 100644
--- a/utils/v4l2-compliance/v4l2-compliance.cpp
+++ b/utils/v4l2-compliance/v4l2-compliance.cpp
@@ -54,6 +54,7 @@
enum Option {
OptStreamAllIO = 'a',
OptStreamAllColorTest = 'c',
+ OptColor = 'C',
OptSetDevice = 'd',
OptSetExpBufDevice = 'e',
OptExitOnFail = 'E',
@@ -89,6 +90,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;
@@ -135,6 +137,7 @@ static struct option long_options[] = {
{"media-bus-info", required_argument, 0, OptMediaBusInfo},
{"help", no_argument, 0, OptHelp},
{"verbose", no_argument, 0, OptVerbose},
+ {"color", required_argument, 0, OptColor},
{"no-warnings", no_argument, 0, OptNoWarnings},
{"no-progress", no_argument, 0, OptNoProgress},
{"exit-on-fail", no_argument, 0, OptExitOnFail},
@@ -234,6 +237,8 @@ static void usage(void)
printf(" then this defaults to 90%%.\n");
printf(" -E, --exit-on-fail Exit on the first fail.\n");
printf(" -h, --help Display this help message.\n");
+ printf(" -C, --color Highlight OK/warn/fail/FAIL strings with colors\n");
+ printf(" can be set to always, never, or auto (the default)\n");
printf(" -n, --no-warnings Turn off warning messages.\n");
printf(" -P, --no-progress Turn off progress messages.\n");
printf(" -T, --trace Trace all called ioctls.\n");
@@ -250,15 +255,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++;
}
@@ -1432,6 +1439,7 @@ int main(int argc, char **argv)
media_type type = MEDIA_TYPE_UNKNOWN;
struct node expbuf_node;
std::string media_bus_info;
+ const char *env_media_apps_color = getenv("MEDIA_APPS_COLOR");
/* command args */
int ch;
@@ -1461,6 +1469,17 @@ int main(int argc, char **argv)
printf("Running on 2.6.%d\n", kernel_version);
printf("\n");
+ if (!env_media_apps_color || !strcmp(env_media_apps_color, "auto"))
+ show_colors = isatty(STDOUT_FILENO);
+ else if (!strcmp(env_media_apps_color, "always"))
+ show_colors = true;
+ else if (!strcmp(env_media_apps_color, "never"))
+ show_colors = false;
+ else {
+ fprintf(stderr,
+ "v4l2-compliance: invalid value for MEDIA_APPS_COLOR environment variable\n");
+ }
+
for (i = 0; long_options[i].name; i++) {
if (!isalpha(long_options[i].val))
continue;
@@ -1591,6 +1610,18 @@ int main(int argc, char **argv)
}
}
break;
+ case OptColor:
+ if (!strcmp(optarg, "always"))
+ show_colors = true;
+ else if (!strcmp(optarg, "never"))
+ show_colors = false;
+ else if (!strcmp(optarg, "auto"))
+ show_colors = isatty(STDOUT_FILENO);
+ else {
+ usage();
+ exit(1);
+ }
+ break;
case OptNoWarnings:
show_warnings = false;
break;
diff --git a/utils/v4l2-compliance/v4l2-compliance.h b/utils/v4l2-compliance/v4l2-compliance.h
index f7e1ea5d7124..152a6c6d9c76 100644
--- a/utils/v4l2-compliance/v4l2-compliance.h
+++ b/utils/v4l2-compliance/v4l2-compliance.h
@@ -50,6 +50,7 @@
#endif
extern bool show_info;
+extern bool show_colors;
extern bool show_warnings;
extern bool no_progress;
extern bool exit_on_fail;
@@ -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; \
From patchwork Tue Apr 9 14:49: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: 10891393
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 A2BD117EF
for ;
Tue, 9 Apr 2019 14:50:06 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 905ED285A7
for ;
Tue, 9 Apr 2019 14:50:06 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id 84B192861C; Tue, 9 Apr 2019 14:50:06 +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 340F9285A9
for ;
Tue, 9 Apr 2019 14:50:06 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1726591AbfDIOuF (ORCPT
);
Tue, 9 Apr 2019 10:50:05 -0400
Received: from metis.ext.pengutronix.de ([85.220.165.71]:55759 "EHLO
metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1726577AbfDIOuE (ORCPT
); Tue, 9 Apr 2019 10:50:04 -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 1hDs4Z-0005vk-Et
for linux-media@vger.kernel.org; Tue, 09 Apr 2019 16:50:03 +0200
From: Philipp Zabel
To: linux-media@vger.kernel.org
Subject: [PATCH v4l-utils v2 3/4] cec-compliance: use warn() in warn_once()
Date: Tue, 9 Apr 2019 16:49:57 +0200
Message-Id: <20190409144958.31233-4-p.zabel@pengutronix.de>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190409144958.31233-1-p.zabel@pengutronix.de>
References: <20190409144958.31233-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/cec-compliance/cec-compliance.h | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/utils/cec-compliance/cec-compliance.h b/utils/cec-compliance/cec-compliance.h
index 0a890311665e..2ebf2d5d9027 100644
--- a/utils/cec-compliance/cec-compliance.h
+++ b/utils/cec-compliance/cec-compliance.h
@@ -230,12 +230,7 @@ struct remote_subtest {
\
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 Tue Apr 9 14:49: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: 10891397
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 E8A181805
for ;
Tue, 9 Apr 2019 14:50:07 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5980285A7
for ;
Tue, 9 Apr 2019 14:50:07 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id C79D8288F4; Tue, 9 Apr 2019 14:50:07 +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 3E187285A7
for ;
Tue, 9 Apr 2019 14:50:07 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1726595AbfDIOuF (ORCPT
);
Tue, 9 Apr 2019 10:50:05 -0400
Received: from metis.ext.pengutronix.de ([85.220.165.71]:58419 "EHLO
metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1726568AbfDIOuF (ORCPT
); Tue, 9 Apr 2019 10:50:05 -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 1hDs4Z-0005vk-Gm
for linux-media@vger.kernel.org; Tue, 09 Apr 2019 16:50:03 +0200
From: Philipp Zabel
To: linux-media@vger.kernel.org
Subject: [PATCH v4l-utils v2 4/4] cec-compliance: add colors
Date: Tue, 9 Apr 2019 16:49:58 +0200
Message-Id: <20190409144958.31233-5-p.zabel@pengutronix.de>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20190409144958.31233-1-p.zabel@pengutronix.de>
References: <20190409144958.31233-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 color codes to mark OK, warn, and FAIL messages with green, bold,
and bright red accents, respectively.
Signed-off-by: Philipp Zabel
---
utils/cec-compliance/cec-compliance.1.in | 5 +++
utils/cec-compliance/cec-compliance.cpp | 42 +++++++++++++++++++++---
utils/cec-compliance/cec-compliance.h | 12 +++++--
3 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/utils/cec-compliance/cec-compliance.1.in b/utils/cec-compliance/cec-compliance.1.in
index 205561f186e1..fa96fb01b1e9 100644
--- a/utils/cec-compliance/cec-compliance.1.in
+++ b/utils/cec-compliance/cec-compliance.1.in
@@ -106,6 +106,11 @@ Exit this application when the first warning occurs instead of continuing.
\fB\-s\fR, \fB\-\-skip\-info\fR
Skip the Driver Info output section.
.TP
+\fB\-C\fR, \fB\-\-color\fR \fI\fR
+Highlight OK/warn/fail/FAIL strings with colors. OK is marked green, warn is
+marked bold, and fail/FAIL are marked bright red if enabled. \fI\fR can
+be \fIalways\fR, \fInever\fR, or \fIauto\fR (the default).
+.TP
\fB\-n\fR, \fB\-\-no\-warnings\fR
Turn off warning messages.
.TP
diff --git a/utils/cec-compliance/cec-compliance.cpp b/utils/cec-compliance/cec-compliance.cpp
index 1f70adef0d3f..3818ce583d0f 100644
--- a/utils/cec-compliance/cec-compliance.cpp
+++ b/utils/cec-compliance/cec-compliance.cpp
@@ -36,6 +36,7 @@
enum Option {
OptSetAdapter = 'a',
OptTestAdapter = 'A',
+ OptColor = 'C',
OptSetDevice = 'd',
OptSetDriver = 'D',
OptExitOnFail = 'E',
@@ -101,6 +102,7 @@ static int app_result;
static int tests_total, tests_ok;
bool show_info;
+bool show_colors;
bool show_warnings = true;
bool exit_on_fail;
bool exit_on_warn;
@@ -120,6 +122,7 @@ static struct option long_options[] = {
{"timeout", required_argument, 0, OptTimeout},
{"trace", no_argument, 0, OptTrace},
{"verbose", no_argument, 0, OptVerbose},
+ {"color", required_argument, 0, OptColor},
{"skip-info", no_argument, 0, OptSkipInfo},
{"wall-clock", no_argument, 0, OptWallClock},
{"interactive", no_argument, 0, OptInteractive},
@@ -211,6 +214,8 @@ static void usage(void)
"\n"
" -E, --exit-on-fail Exit on the first fail.\n"
" -h, --help Display this help message\n"
+ " -C, --color Highlight OK/warn/fail/FAIL strings with colors\n"
+ " can be set to always, never, or auto (the default)\n"
" -n, --no-warnings Turn off warning messages\n"
" -s, --skip-info Skip Driver Info output\n"
" -T, --trace Trace all called ioctls\n"
@@ -726,20 +731,23 @@ const char *ok(int res)
static char buf[100];
if (res == NOTSUPPORTED) {
- strcpy(buf, "OK (Not Supported)");
+ strcpy(buf, show_colors ? COLOR_GREEN("OK") " (Not Supported)" :
+ "OK (Not Supported)");
res = 0;
} else if (res == PRESUMED_OK) {
- strcpy(buf, "OK (Presumed)");
+ strcpy(buf, show_colors ? COLOR_GREEN("OK") " (Presumed)" :
+ "OK (Presumed)");
res = 0;
} else if (res == REFUSED) {
- strcpy(buf, "OK (Refused)");
+ strcpy(buf, show_colors ? COLOR_GREEN("OK") " (Refused)" :
+ "OK (Refused)");
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++;
}
@@ -1056,6 +1064,18 @@ int main(int argc, char **argv)
int fd = -1;
int ch;
int i;
+ const char *env_media_apps_color = getenv("MEDIA_APPS_COLOR");
+
+ if (!env_media_apps_color || !strcmp(env_media_apps_color, "auto"))
+ show_colors = isatty(STDOUT_FILENO);
+ else if (!strcmp(env_media_apps_color, "always"))
+ show_colors = true;
+ else if (!strcmp(env_media_apps_color, "never"))
+ show_colors = false;
+ else {
+ fprintf(stderr,
+ "cec-compliance: invalid value for MEDIA_APPS_COLOR environment variable\n");
+ }
for (i = 0; long_options[i].name; i++) {
if (!isalpha(long_options[i].val))
@@ -1115,6 +1135,18 @@ int main(int argc, char **argv)
case OptTimeout:
long_timeout = strtoul(optarg, NULL, 0);
break;
+ case OptColor:
+ if (!strcmp(optarg, "always"))
+ show_colors = true;
+ else if (!strcmp(optarg, "never"))
+ show_colors = false;
+ else if (!strcmp(optarg, "auto"))
+ show_colors = isatty(STDOUT_FILENO);
+ else {
+ usage();
+ exit(1);
+ }
+ break;
case OptNoWarnings:
show_warnings = false;
break;
diff --git a/utils/cec-compliance/cec-compliance.h b/utils/cec-compliance/cec-compliance.h
index 2ebf2d5d9027..d7460b6244e2 100644
--- a/utils/cec-compliance/cec-compliance.h
+++ b/utils/cec-compliance/cec-compliance.h
@@ -111,6 +111,7 @@ struct short_audio_desc {
#define SAD_EXT_TYPE_LPCM_3D_AUDIO 13
extern bool show_info;
+extern bool show_colors;
extern bool show_warnings;
extern bool exit_on_fail;
extern bool exit_on_warn;
@@ -192,6 +193,10 @@ struct remote_subtest {
#define cec_phys_addr_exp(pa) \
((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
+#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) \
@@ -218,7 +223,9 @@ struct remote_subtest {
({ \
warnings++; \
if (show_warnings) \
- printf("\t\twarn: %s(%d): " fmt, __FILE__, __LINE__, ##args); \
+ printf("\t\%s: %s(%d): " fmt, \
+ show_colors ? COLOR_BOLD("warn") : "warn", \
+ __FILE__, __LINE__, ##args); \
if (exit_on_warn) \
exit(1); \
0; \
@@ -236,7 +243,8 @@ struct remote_subtest {
#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); \
FAIL; \