public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 03/11] Refactor ptem01 test
Date: Wed, 8 Jan 2025 13:47:34 +0100	[thread overview]
Message-ID: <20250108124734.GB27248@pevik> (raw)
In-Reply-To: <Z31P7KEtbAwaCG7l@yuki.lan>

Hi Andrea, Cyril,

> Hi!
> > +	masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> > +	slavename = SAFE_PTSNAME(masterfd);

> > -	for (i = 0; i < NUMOPENS; ++i) {
> > -		masterfd[i] = open(MASTERCLONE, O_RDWR);
> > -		if (masterfd[i] < 0) {
> > -			tst_resm(TBROK, "%s", MASTERCLONE);
> > -			tst_resm(TBROK, "out of ptys");
> > -			for (i = 0; i < NUMOPENS; ++i) {
> > -				if (masterfd[i] != 0) {
> > -					(void)close(masterfd[i]);
> > -				}
> > -				if (slavefd[i] != 0) {
> > -					(void)close(slavefd[i]);
> > -				}
> > -			}
> > -			tst_exit();
> > -		}
> > +	TST_EXP_PASS(grantpt(masterfd));
> > +	TST_EXP_PASS(unlockpt(masterfd));

> > -		slavename = ptsname(masterfd[i]);
> > -		if (slavename == NULL) {
> > -			tst_brkm(TBROK | TERRNO, NULL,
> > -				 "ptsname() call failed");
> > -		}
> > +	slavefd = SAFE_OPEN(slavename, O_RDWR);

> This would be a bit better if done in setup()

Good catch. If this fails, masterfd will be left unclosest
(it would break on high -i). Also it speedup the test with high -i.

I did not catch it because I thought it's better to close fd in case of repeated
testing with -i, but obviously it should be perfectly safe to have open file
descriptors shared during repeated testing.

> > -		if (grantpt(masterfd[i]) != 0) {
> > -			tst_brkm(TBROK | TERRNO, NULL,
> > -				 "grantpt() call failed");
> > -		}
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCGETS, &termios));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETSW, &termios));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETSF, &termios));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCGETA, &termio));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETA, &termio));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETAW, &termio));
> > +	TST_EXP_POSITIVE(ioctl(slavefd, TCSETAF, &termio));

> Are you sure these shouldn't be TST_EXP_PASS() instead? The original
> code was doing != 0 for all of these.

+1

Kind regards,
Petr

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

  reply	other threads:[~2025-01-08 12:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
2025-01-07 15:26   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
2025-01-07 15:32   ` Cyril Hrubis
2025-01-08 12:01   ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
2025-01-07 16:01   ` Cyril Hrubis
2025-01-08 12:47     ` Petr Vorel [this message]
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
2025-01-07 16:14   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
2025-01-07 16:30   ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 06/11] Add ptem04 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 07/11] Add ptem05 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 08/11] Add ptem06 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
2025-01-08 12:39   ` Petr Vorel
2025-01-09  8:28     ` Andrea Cervesato via ltp
2025-01-06 10:31 ` [LTP] [PATCH v2 10/11] Add pty08 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 11/11] Add pty09 test Andrea Cervesato

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=20250108124734.GB27248@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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