pty04: Remove unnecessary volatile and style fix
PATCH 1/2 pty04: Remove unnecessary volatile and style fix
--- testcases/kernel/pty/pty04.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
testcases/kernel/pty/pty04.c +5 -3
@@ -92,7 +92,7 @@ static struct ldisc_info ldiscs[] = { {N_SLCAN, "N_SLCAN", CAN_MTU}, }; -static volatile int ptmx, pts, sk, mtu, no_check; +static int ptmx, pts, sk, mtu, no_check;static int set_ldisc (int tty,const struct ldisc_info *ldisc) {
@@ -173,13 +173,15 @@ static void write_pty(const struct ldisc_info *ldisc) written =0 ; - ret =TST_RETRY_FUNC (try_write (ptmx, data, len, &written),TST_RETVAL_NOTNULL ); + ret =TST_RETRY_FUNC (try_write (ptmx, data, len, &written), +TST_RETVAL_NOTNULL );if (ret <0 )tst_brk (TBROK |TERRNO ,"Failed 1st write to PTY" );tst_res (TPASS ,"Wrote PTY 1" ); written =0 ; - ret =TST_RETRY_FUNC (try_write (ptmx, data, len, &written),TST_RETVAL_NOTNULL ); + ret =TST_RETRY_FUNC (try_write (ptmx, data, len, &written), +TST_RETVAL_NOTNULL );if (ret <0 )tst_brk (TBROK |TERRNO ,"Failed 2nd write to PTY" );
Signature · 1 line
2.26.1
PATCH 2/2 pty04: Retry reads when short
Even though reads are blocking and packets are flipped into the netdevice buffer whole, it seems read may return before a full packet is read into user land. Retrying read should prevent timeouts and read failures on some machines.
---
NOTE: When running this test repeatedly and in parallel; strange things still happen, see:
https://github.com/linux-test-project/ltp/issues/674#issuecomment-625181783
However this hopefully will fix the timeout issues and read failures reported by some testers.
testcases/kernel/pty/pty04.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
testcases/kernel/pty/pty04.c +23 -4
@@ -288,9 +288,20 @@ static void check_data(const struct ldisc_info *ldisc,tst_res (TINFO ,"Will continue test without data checking" ); } +static ssize_t try_read (int fd,char *data,ssize_t size,ssize_t *n) +{ +ssize_t ret =read (fd, data, size); + +if (ret <0 ) +return -(errno !=EAGAIN ); + +return (*n += ret) >= size; +} +static void read_netdev (const struct ldisc_info *ldisc) { -int rlen, plen =0 ; +int ret, rlen, plen =0 ; +ssize_t n;char *data;switch (ldisc->n) {
@@ -305,20 +316,27 @@ static void read_netdev(const struct ldisc_info *ldisc)tst_res (TINFO ,"Reading from socket %d" , sk); -SAFE_READ (1 , sk, data, plen); + n =0 ; + ret =TST_RETRY_FUNC (try_read (sk, data, plen, &n),TST_RETVAL_NOTNULL ); +if (ret <0 ) +tst_brk (TBROK |TERRNO ,"Read %zd of %d bytes" , n, plen);check_data (ldisc, data, plen);tst_res (TPASS ,"Read netdev 1" ); -SAFE_READ (1 , sk, data, plen); + n =0 ; + ret =TST_RETRY_FUNC (try_read (sk, data, plen, &n),TST_RETVAL_NOTNULL ); +if (ret <0 ) +tst_brk (TBROK |TERRNO ,"Read %zd of %d bytes" , n, plen);check_data (ldisc, data, plen);tst_res (TPASS ,"Read netdev 2" );TST_CHECKPOINT_WAKE (0 ); -while ((rlen =read (sk, data, plen)) >0 ) +while ((rlen =read (sk, data, plen)) >0 )check_data (ldisc, data, rlen);tst_res (TPASS ,"Reading data from netdev interrupted by hangup" ); +close (sk);tst_free_all (); }
@@ -357,6 +375,7 @@ static void cleanup(void) {ioctl (pts,TIOCVHANGUP );ioctl (ptmx,TIOCVHANGUP ); +close (sk);tst_reap_children (); }
Signature · 1 line
2.26.1
PATCH 2/2 pty04: Retry reads when short
Hi!
testcases/kernel/pty/pty04.c static void check_data(const struct ldisc_info *ldisc, · line 299
Quoted 9 lines
testcases/kernel/pty/pty04.c +9
-0+static ssize_t try_read (int fd,char *data,ssize_t size,ssize_t *n) +{ +ssize_t ret =read (fd, data, size); + +if (ret <0 ) +return -(errno !=EAGAIN ); + +return (*n += ret) >= size; +}
I had to read this piece twice, but I think it's correct.
Quoted 9 lines
static void
read_netdev(const struct ldisc_info *ldisc){testcases/kernel/pty/pty04.c +2
-1-int rlen, plen =0 ; +int ret, rlen, plen =0 ; +ssize_t n;char *data;switch (ldisc->n) {
testcases/kernel/pty/pty04.c static void read_netdev(const struct ldisc_info *ldisc) · line 322
Quoted 8 lines
testcases/kernel/pty/pty04.c +4
-1@@ -305,20 +316,27 @@ static void read_netdev(const struct ldisc_info *ldisc)tst_res (TINFO ,"Reading from socket %d" , sk); -SAFE_READ (1 , sk, data, plen); + n =0 ; + ret =TST_RETRY_FUNC (try_read (sk, data, plen, &n),TST_RETVAL_NOTNULL ); +if (ret <0 ) +tst_brk (TBROK |TERRNO ,"Read %zd of %d bytes" , n, plen);
I wonder if a simple loop without exponential backoff would suffice here. A least the code would probably be more readable.
Quoted 5 lines
testcases/kernel/pty/pty04.c +1
-1check_data (ldisc, data, plen);tst_res (TPASS ,"Read netdev 1" ); -SAFE_READ (1 , sk, data, plen); + n =0 ;
testcases/kernel/pty/pty04.c static void read_netdev(const struct ldisc_info *ldisc) · line 335
Quoted 10 lines
testcases/kernel/pty/pty04.c +4
-1+ ret =TST_RETRY_FUNC (try_read (sk, data, plen, &n),TST_RETVAL_NOTNULL ); +if (ret <0 ) +tst_brk (TBROK |TERRNO ,"Read %zd of %d bytes" , n, plen);check_data (ldisc, data, plen);tst_res (TPASS ,"Read netdev 2" );TST_CHECKPOINT_WAKE (0 ); -while ((rlen =read (sk, data, plen)) >0 ) +while ((rlen =read (sk, data, plen)) >0 )check_data (ldisc, data, rlen);
This should have been part of the previous cleanup patch.
Quoted 20 lines
testcases/kernel/pty/pty04.c +2
-0tst_res (TPASS ,"Reading data from netdev interrupted by hangup" ); +close (sk);tst_free_all (); }@@ -357,6 +375,7 @@ static void cleanup(void) {ioctl (pts,TIOCVHANGUP );ioctl (ptmx,TIOCVHANGUP ); +close (sk);tst_reap_children (); }Signature · 5 lines
2.26.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 pty04: Retry reads when short
In reply to Richard PalethorpeHi Richard,
Quoted 8 lines
Even though reads are blocking and packets are flipped into the netdevice buffer whole, it seems read may return before a full packet is read into user land. Retrying read should prevent timeouts and read failures on some machines.
Signed-off-by Richard Palethorpe <[email protected]>Reported-by Jan Stancek <[email protected]>Cc Petr Vorel <[email protected]>
Thanks for taking care of this.
It's still possible to reproduce timeout just with higher -i (-i10), but it's an improvement.
Kind regards,
Petr
PATCH 2/2 pty04: Retry reads when short
----- Original Message -----
Quoted 8 lines
Hi Richard,
Quoted 5 lines
Even though reads are blocking and packets are flipped into the netdevice buffer whole, it seems read may return before a full packet is read into user
land. Retrying read should prevent timeouts and read failures on some machines.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Richard Palethorpe <[email protected]>Reported-by Jan Stancek <[email protected]>Cc Petr Vorel <[email protected]>Reviewed-by Petr Vorel <[email protected]>Thanks for taking care of this.
ACK, I'll update github issue when this runs for a while with recent upstream kernels.
Quoted 7 lines
It's still possible to reproduce timeout just with higher -i (-i10), but it's an improvement.
Kind regards,
Petr
PATCH 1/2 pty04: Remove unnecessary volatile and style fix
In reply to Richard PalethorpeHi Richard,
Merged (with while from 2nd patch).
Thanks!
Kind regards,
Petr