All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] pty/pty07: Restore active console after the testrun
@ 2022-03-11  9:51 Cyril Hrubis
  2022-03-11  9:56 ` Martin Doucha
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2022-03-11  9:51 UTC (permalink / raw)
  To: ltp

The test, as a side effect, switches to a different console during the
run, which may confuse both users and automated test systems.

Fix that by saving the console active at the start of the test and
restore it in the test cleanup.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/pty/pty07.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/pty/pty07.c b/testcases/kernel/pty/pty07.c
index 462569c4a..af2dccb32 100644
--- a/testcases/kernel/pty/pty07.c
+++ b/testcases/kernel/pty/pty07.c
@@ -40,6 +40,8 @@ static int test_tty_port = 8;
 static int fd = -1;
 static struct tst_fzsync_pair fzp;
 
+static unsigned short vt_active;
+
 static void *open_close(void *unused)
 {
 	int i;
@@ -76,16 +78,27 @@ static void do_test(void)
 
 static void setup(void)
 {
+	struct vt_stat stat;
+
 	sprintf(tty_path, "/dev/tty%d", test_tty_port);
 	fd = SAFE_OPEN(tty_path, O_RDWR);
+	SAFE_IOCTL(fd, VT_GETSTATE, &stat);
+	vt_active = stat.v_active;
+
+	tst_res(TINFO, "Saving active console %i", vt_active);
+
 	tst_fzsync_pair_init(&fzp);
 }
 
 static void cleanup(void)
 {
-	tst_fzsync_pair_cleanup(&fzp);
-	if (fd >= 0)
+	if (fd >= 0) {
+		tst_res(TINFO, "Restoring active console");
+		SAFE_IOCTL(fd, VT_ACTIVATE, vt_active);
 		SAFE_CLOSE(fd);
+	}
+
+	tst_fzsync_pair_cleanup(&fzp);
 }
 
 static struct tst_test test = {
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-11  9:51 [LTP] [PATCH] pty/pty07: Restore active console after the testrun Cyril Hrubis
@ 2022-03-11  9:56 ` Martin Doucha
  2022-03-11 10:06   ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Doucha @ 2022-03-11  9:56 UTC (permalink / raw)
  To: Cyril Hrubis, ltp

Hi,

On 11. 03. 22 10:51, Cyril Hrubis wrote:
> The test, as a side effect, switches to a different console during the
> run, which may confuse both users and automated test systems.
> 
> Fix that by saving the console active at the start of the test and
> restore it in the test cleanup.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/pty/pty07.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/testcases/kernel/pty/pty07.c b/testcases/kernel/pty/pty07.c
> index 462569c4a..af2dccb32 100644
> --- a/testcases/kernel/pty/pty07.c
> +++ b/testcases/kernel/pty/pty07.c
> @@ -40,6 +40,8 @@ static int test_tty_port = 8;
>  static int fd = -1;
>  static struct tst_fzsync_pair fzp;
>  
> +static unsigned short vt_active;
> +
>  static void *open_close(void *unused)
>  {
>  	int i;
> @@ -76,16 +78,27 @@ static void do_test(void)
>  
>  static void setup(void)
>  {
> +	struct vt_stat stat;
> +
>  	sprintf(tty_path, "/dev/tty%d", test_tty_port);
>  	fd = SAFE_OPEN(tty_path, O_RDWR);
> +	SAFE_IOCTL(fd, VT_GETSTATE, &stat);
> +	vt_active = stat.v_active;
> +
> +	tst_res(TINFO, "Saving active console %i", vt_active);
> +
>  	tst_fzsync_pair_init(&fzp);
>  }
>  
>  static void cleanup(void)
>  {
> -	tst_fzsync_pair_cleanup(&fzp);
> -	if (fd >= 0)
> +	if (fd >= 0) {
> +		tst_res(TINFO, "Restoring active console");
> +		SAFE_IOCTL(fd, VT_ACTIVATE, vt_active);
>  		SAFE_CLOSE(fd);
> +	}
> +
> +	tst_fzsync_pair_cleanup(&fzp);

If you move the fzsync cleanup to the end of cleanup(), you can end up
with the open_close() thread racing against fd cleanup.

>  }
>  
>  static struct tst_test test = {


-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-11  9:56 ` Martin Doucha
@ 2022-03-11 10:06   ` Cyril Hrubis
  2022-03-22  8:13     ` Richard Palethorpe
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2022-03-11 10:06 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Hi!
> >  static void cleanup(void)
> >  {
> > -	tst_fzsync_pair_cleanup(&fzp);
> > -	if (fd >= 0)
> > +	if (fd >= 0) {
> > +		tst_res(TINFO, "Restoring active console");
> > +		SAFE_IOCTL(fd, VT_ACTIVATE, vt_active);
> >  		SAFE_CLOSE(fd);
> > +	}
> > +
> > +	tst_fzsync_pair_cleanup(&fzp);
> 
> If you move the fzsync cleanup to the end of cleanup(), you can end up
> with the open_close() thread racing against fd cleanup.

Ah, right, looking closely at the fzsync, the thread B may be racing
against the restoration in the case that something caused premature exit
in the thread A.

Will move the call back to the start of the cleanup().

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-11 10:06   ` Cyril Hrubis
@ 2022-03-22  8:13     ` Richard Palethorpe
  2022-03-22  9:34       ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Palethorpe @ 2022-03-22  8:13 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
>> >  static void cleanup(void)
>> >  {
>> > -	tst_fzsync_pair_cleanup(&fzp);
>> > -	if (fd >= 0)
>> > +	if (fd >= 0) {
>> > +		tst_res(TINFO, "Restoring active console");
>> > +		SAFE_IOCTL(fd, VT_ACTIVATE, vt_active);
>> >  		SAFE_CLOSE(fd);
>> > +	}
>> > +
>> > +	tst_fzsync_pair_cleanup(&fzp);
>> 
>> If you move the fzsync cleanup to the end of cleanup(), you can end up
>> with the open_close() thread racing against fd cleanup.
>
> Ah, right, looking closely at the fzsync, the thread B may be racing
> against the restoration in the case that something caused premature exit
> in the thread A.
>
> Will move the call back to the start of the cleanup().
>
> -- 
> Cyril Hrubis
> chrubis@suse.cz

Why are we using /dev/tty8 instead of allocating a pty with /dev/ptmx?

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-22  8:13     ` Richard Palethorpe
@ 2022-03-22  9:34       ` Cyril Hrubis
  2022-03-22 11:41         ` Richard Palethorpe
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2022-03-22  9:34 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi!
> > Ah, right, looking closely at the fzsync, the thread B may be racing
> > against the restoration in the case that something caused premature exit
> > in the thread A.
> >
> > Will move the call back to the start of the cleanup().
> >
> > -- 
> > Cyril Hrubis
> > chrubis@suse.cz
> 
> Why are we using /dev/tty8 instead of allocating a pty with /dev/ptmx?

I do not think that we can VT_ACTIVATE on pseudoterminals, as far as I
can tell we have to have real console for that.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-22  9:34       ` Cyril Hrubis
@ 2022-03-22 11:41         ` Richard Palethorpe
  2022-03-22 12:05           ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Palethorpe @ 2022-03-22 11:41 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp


Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
>> > Ah, right, looking closely at the fzsync, the thread B may be racing
>> > against the restoration in the case that something caused premature exit
>> > in the thread A.
>> >
>> > Will move the call back to the start of the cleanup().
>> >
>> > -- 
>> > Cyril Hrubis
>> > chrubis@suse.cz
>> 
>> Why are we using /dev/tty8 instead of allocating a pty with /dev/ptmx?
>
> I do not think that we can VT_ACTIVATE on pseudoterminals, as far as I
> can tell we have to have real console for that.

OK, this looks good then.

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH] pty/pty07: Restore active console after the testrun
  2022-03-22 11:41         ` Richard Palethorpe
@ 2022-03-22 12:05           ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2022-03-22 12:05 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi!
Applied with the change requested by Martin.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-22 12:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11  9:51 [LTP] [PATCH] pty/pty07: Restore active console after the testrun Cyril Hrubis
2022-03-11  9:56 ` Martin Doucha
2022-03-11 10:06   ` Cyril Hrubis
2022-03-22  8:13     ` Richard Palethorpe
2022-03-22  9:34       ` Cyril Hrubis
2022-03-22 11:41         ` Richard Palethorpe
2022-03-22 12:05           ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.