[LTP] [PATCH v4 10/12] Refactor pty01 test

Cyril Hrubis chrubis@suse.cz
Thu Jan 16 15:57:41 CET 2025


Hi!
> +	tst_res(TINFO, "Send message to master and read it from slave");
>  
> -	errno = 0;
> -	if ((i = read(slavefd, &c, 1)) == 1) {
> -		tst_brkm(TFAIL, NULL,
> -			 "reading from slave fd should have failed, but didn't"
> -			 "(read '%c')", c);
> -	}
> +	memset(buf, 0, BUFSIZ);
> +	SAFE_WRITE(SAFE_WRITE_ALL, masterfd, STRING, string_len);

I guess that we can read and check the exact lenght here because no
conversions happne when we write to the master.

> +	SAFE_READ(0, slavefd, buf, string_len + 1);
> +	TST_EXP_EQ_STRN(STRING, buf, string_len - 1);
>  
> -	if ((i = write(slavefd, &c, 1)) == 1) {
> -		tst_brkm(TFAIL, NULL,
> -			 "writing to slave fd should have failed, but didn't");
> -	}
> +	tst_res(TINFO, "Send message to slave and read it from master");
>  
> -	if (ioctl(slavefd, TIOCGWINSZ, NULL) == 0) {
> -		tst_brkm(TFAIL, NULL,
> -			 "trying TIOCGWINSZ on slave fd should have failed, "
> -			 "but didn't");
> -	}
> -
> -	if (close(slavefd) != 0) {
> -		tst_brkm(TBROK, NULL, "close");
> -	}
> -	tst_resm(TPASS, "test2");
> +	memset(buf, 0, BUFSIZ);
> +	SAFE_WRITE(SAFE_WRITE_ALL, slavefd, STRING, string_len);

Maybe a note that we need to read string_len + 1 here because kernel
converts the newline into carriage return + newline in this case.

> +	SAFE_READ(0, masterfd, buf, string_len + 1);
> +	TST_EXP_EQ_STRN(STRING, buf, string_len - 1);
>  }

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list