[LTP] [PATCH v2 03/11] Refactor ptem01 test
Petr Vorel
pvorel@suse.cz
Wed Jan 8 13:47:34 CET 2025
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
More information about the ltp
mailing list