Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Hung <alex.hung@amd.com>
To: <igt-dev@lists.freedesktop.org>
Cc: <harry.wentland@amd.com>, <rodrigo.siqueira@amd.com>,
	<mark.broadworth@amd.com>, <sunpeng.li@amd.com>,
	<alex.hung@amd.com>
Subject: [PATCH 3/3][V2] tools/amd_hdmi_compliance: Add timeout option
Date: Tue, 29 Oct 2024 11:03:49 -0600	[thread overview]
Message-ID: <20241029170349.1388428-3-alex.hung@amd.com> (raw)
In-Reply-To: <20241029170349.1388428-1-alex.hung@amd.com>

From: Stylon Wang <stylon.wang@amd.com>

[WHY]
Displaying test pattern only exits by user manually pressing enter.

[HOW]
Add option -e to exit with timeout and still allows pressing enter.

Reviewed-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Stylon Wang <stylon.wang@amd.com>
---
 tools/amd_hdmi_compliance.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/tools/amd_hdmi_compliance.c b/tools/amd_hdmi_compliance.c
index 9d2a820af..d21301733 100644
--- a/tools/amd_hdmi_compliance.c
+++ b/tools/amd_hdmi_compliance.c
@@ -23,6 +23,8 @@
 #include "igt.h"
 #include "igt_sysfs.h"
 #include <fcntl.h>
+#include <signal.h>
+#include <string.h>
 
 /* Common test data */
 typedef struct data {
@@ -34,6 +36,7 @@ typedef struct data {
 	igt_pipe_t *pipe;
 	enum pipe pipe_id;
 	bool use_virtual_connector;
+	int timeout_seconds;
 } data_t;
 
 /* Video modes indexed by VIC */
@@ -370,6 +373,12 @@ static drmModeModeInfo test_modes[] = {
 	},
 };
 
+static void signal_handler(int signo)
+{
+	if (signo == SIGALRM)
+		igt_info("Timeout and exit\n");
+}
+
 /* Common test setup. */
 static void test_init(data_t *data, int conn_id)
 {
@@ -402,6 +411,19 @@ static void test_init(data_t *data, int conn_id)
 
 	igt_output_set_pipe(data->output, data->pipe_id);
 
+	if (data->timeout_seconds > 0) {
+		struct sigaction sa;
+
+		memset(&sa, 0, sizeof(struct sigaction));
+		sa.sa_handler = signal_handler;
+		/* without SA_RESTART so getchar() is not restarted on signal */
+		sa.sa_flags = 0;
+
+		if (sigaction(SIGALRM, &sa, NULL))
+			igt_info("cannot set up timeout: %s\n", strerror(errno));
+		else
+			alarm(data->timeout_seconds);
+	}
 }
 
 /* Common test cleanup. */
@@ -412,8 +434,11 @@ static void test_fini(data_t *data)
 
 static void wait_for_keypress(void)
 {
-	while (getchar() != '\n')
-		;
+	int c;
+
+	do {
+		c = getchar();
+	} while (c != '\n' && c != EOF);
 }
 
 /* Write 0 or 1 to debugfs entry "force_yuv420_output" of connector */
@@ -478,7 +503,7 @@ static void test_vic_mode(data_t *data, int vic, int conn_id)
 	test_fini(data);
 }
 
-const char *optstr = "hvt:i:b:y:";
+const char *optstr = "hvt:i:b:y:e:";
 static void usage(const char *name)
 {
 	igt_info("Usage: %s options\n", name);
@@ -488,6 +513,7 @@ static void usage(const char *name)
 	igt_info("-i conn_id	Use connector by ID\n");
 	igt_info("-b max_bpc	Set \"max bpc\" connector property\n");
 	igt_info("-y 0|1	Write 0 or 1 to connector's debugfs force_yuv420_output\n");
+	igt_info("-e seconds    number of seconds to display test pattern and exit\n");
 	igt_info("NOTE: if -i is not specified, first connected HDMI connector will be used for -t, -b and -y\n");
 }
 
@@ -519,6 +545,9 @@ int main(int argc, char **argv)
 		case 'y':
 			force_yuv_420 = atoi(optarg);
 			break;
+		case 'e':
+			data.timeout_seconds = atoi(optarg);
+			break;
 		default:
 		case 'h':
 			usage(argv[0]);
-- 
2.43.0


  parent reply	other threads:[~2024-10-29 17:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 17:03 [PATCH 1/3][V2] tools/amd_hdmi_compliance: Additional functionalities Alex Hung
2024-10-29 17:03 ` [PATCH 2/3][V2] tools/amd_hdmi_compliance: Fix atomic commit failure Alex Hung
2024-10-29 17:03 ` Alex Hung [this message]
2024-10-29 22:17 ` [PATCH 1/3][V2] tools/amd_hdmi_compliance: Additional functionalities Rodrigo Siqueira Jordao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241029170349.1388428-3-alex.hung@amd.com \
    --to=alex.hung@amd.com \
    --cc=harry.wentland@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=mark.broadworth@amd.com \
    --cc=rodrigo.siqueira@amd.com \
    --cc=sunpeng.li@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox