Skip to content

Commit

Permalink
stress-pty: exercise cfgetispeed and cfgetospeed on leader and follower
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Ian King <[email protected]>
  • Loading branch information
ColinIanKing committed Dec 22, 2023
1 parent e00b6a1 commit 13a7c43
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,8 @@ functions: \
BUILTIN_TAN BUILTIN_TANF BUILTIN_TANL \
INTRINSIC_ROLB INTRINSIC_ROLD INTRINSIC_ROLW INTRINSIC_ROLQ \
INTRINSIC_RORB INTRINSIC_RORD INTRINSIC_RORW INTRINSIC_RORQ \
CABSL CACHEFLUSH CCOS CCOSF CCOSL CHROOT CIMAG CIMAGF CIMAGL CLEARENV CLOCK_ADJTIME \
CABSL CACHEFLUSH CCOS CCOSF CCOSL CFGETISPEED CFGETOSPEED \
CHROOT CIMAG CIMAGF CIMAGL CLEARENV CLOCK_ADJTIME \
CLOCK_GETRES CLOCK_GETTIME CLOCK_NANOSLEEP CLOCK_SETTIME CLONE COPY_FILE_RANGE \
COSHL COSL CPOW CREAL CREALF CREALL CRYPT_R CSIN CSINF CSINL DUP3 DRAND48 DELETE_MODULE \
EIGEN ENDMNTENT ENDPWENT EPOLL_CREATE \
Expand Down Expand Up @@ -2119,6 +2120,12 @@ CCOSF:
CCOSL:
$(call check,test-mathfunc,HAVE_CCOSL,ccosl,-lm,-DMATHFUNC=ccosl)

CFGETISPEED:
$(call check,test-cfgetispeed,HAVE_CFGETISPEED,cfgetispeed)

CFGETOSPEED:
$(call check,test-cfgetospeed,HAVE_CFGETOSPEED,cfgetospeed)

CHROOT:
$(call check,test-chroot,HAVE_CHROOT,chroot)

Expand Down
21 changes: 21 additions & 0 deletions stress-pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,26 @@ static int stress_pty(stress_args_t *args)
(void)ret;
}
#endif
{
struct termios ios;

if (tcgetattr(ptys[i].follower, &ios) == 0) {
#if defined(HAVE_CFGETISPEED)
(void)cfgetispeed(&ios);
#endif
#if defined(HAVE_CFGETOSPEED)
(void)cfgetospeed(&ios);
#endif
}
if (tcgetattr(ptys[i].leader, &ios) == 0) {
#if defined(HAVE_CFGETISPEED)
(void)cfgetispeed(&ios);
#endif
#if defined(HAVE_CFGETOSPEED)
(void)cfgetospeed(&ios);
#endif
}
}
if (!stress_continue_flag())
goto clean;
}
Expand Down Expand Up @@ -437,6 +457,7 @@ static int stress_pty(stress_args_t *args)
}
}
#endif

clean:
/*
* and close
Expand Down
34 changes: 34 additions & 0 deletions test/test-cfgetispeed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <sys/termios.h>
#include <unistd.h>
#include <stdio.h>

int main(void)
{
struct termios t;
speed_t speed;
const int fd = fileno(stdin);

if (tcgetattr(fd, &t) != 0)
return 1;
speed = cfgetispeed(&t);

return (int)speed;
}
34 changes: 34 additions & 0 deletions test/test-cfgetospeed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <sys/termios.h>
#include <unistd.h>
#include <stdio.h>

int main(void)
{
struct termios t;
speed_t speed;
const int fd = fileno(stdout);

if (tcgetattr(fd, &t) != 0)
return 1;
speed = cfgetospeed(&t);

return (int)speed;
}

0 comments on commit 13a7c43

Please sign in to comment.