[LTP] [PATCH v2 03/11] Refactor ptem01 test
Cyril Hrubis
chrubis@suse.cz
Tue Jan 7 17:01:48 CET 2025
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()
> - 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.
> - if (unlockpt(masterfd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "unlockpt() call failed");
> - }
> -
> - if ((slavefd[i] = open(slavename, O_RDWR)) < 0) {
> - tst_brkm(TFAIL, NULL,
> - "Iteration %d: Could not open %s", i,
> - slavename);
> - }
> -
> - }
> -
> - for (i = 0; i < NUMOPENS; ++i) {
> - if (close(slavefd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "Iteration %d: close slave", i);
> - }
> - if (close(masterfd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "close master");
> - }
> - }
> - tst_resm(TPASS, "test5");
> -
> - /** NOT REACHED **/
> - return 0;
> + SAFE_CLOSE(slavefd);
> + SAFE_CLOSE(masterfd);
And this should be done in cleanup if we do the init in the
setup.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list