[LTP] [PATCH 02/10] Refactor ptem01 test

Petr Vorel pvorel@suse.cz
Mon Dec 16 22:22:21 CET 2024


Hi Andrea,

> Fix test failure when running inside a new session via setsid() and
> start spliting its internal tests cases implementations into multiple
> files.

+1

> Fixes: https://github.com/linux-test-project/kirk/issues/28

+1

...
> -	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
> +	masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);

>  	slavename = ptsname(masterfd);
> -	if (slavename == NULL) {
> -		tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
> -	}
> -
> -	if (grantpt(masterfd) != 0) {
> -		tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
> -	}
> -
> -	if (unlockpt(masterfd) != 0) {
> -		tst_brkm(TBROK, NULL, "unlockpt() call failed");
> -	}
> -
> -	if ((slavefd = open(slavename, O_RDWR)) < 0) {
> -		tst_brkm(TFAIL, NULL, "Could not open %s", slavename);
> -	}
> -
> -	if (ioctl(slavefd, TCGETS, &termios) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCGETS");
> -	}
> -
> -	if (ioctl(slavefd, TCSETS, &termios) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETS");
> -	}
> -
> -	if (ioctl(slavefd, TCSETSW, &termios) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETSW");
> -	}
> -
> -	if (ioctl(slavefd, TCSETSF, &termios) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETSF");
> -	}
> -
> -	if (ioctl(slavefd, TCSETS, &termios) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETS");
> -	}
> -
> -	if (ioctl(slavefd, TCGETA, &termio) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCGETA");
> -	}
> -
> -	if (ioctl(slavefd, TCSETA, &termio) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETA");
> -	}
> -
> -	if (ioctl(slavefd, TCSETAW, &termio) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETAW");
> -	}
> -
> -	if (ioctl(slavefd, TCSETAF, &termio) != 0) {
> -		tst_brkm(TFAIL, NULL, "TCSETAF");
> -	}
> -
> -	if (close(slavefd) != 0) {
> -		tst_brkm(TBROK, NULL, "close slave");
> -	}
> -
> -	if (close(masterfd) != 0) {
> -		tst_brkm(TBROK, NULL, "close master");
> -	}
> -	tst_resm(TPASS, "test1");
...

> +	if (slavename == NULL)
> +		tst_res(TFAIL, "Can't get slave device location");
The old test uses tst_brkm() for all tests, which is IMHO necessary, but I this
one should be tst_brk() because slavename is later used with open/SAFE_OPEN().

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> +	else
> +		tst_res(TPASS, "pts device location is %s", slavename);
> +
> +	TST_EXP_PASS(grantpt(masterfd));
> +	TST_EXP_PASS(unlockpt(masterfd));
> +
> +	slavefd = SAFE_OPEN(slavename, O_RDWR);
> +
> +	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));
> +
> +	SAFE_CLOSE(slavefd);
> +	SAFE_CLOSE(masterfd);
>  }


More information about the ltp mailing list