Avoid messing with system tty in ioctl01.c
PATCH 1/1 Avoid messing with system tty in ioctl01.c
* Use openpty() to create a new tty
* Remove -D option
* Remove requirement to run as root
--- runtest/syscalls | 2 +- testcases/kernel/syscalls/ioctl/ioctl01.c | 25 ++++++++++------------ testcases/kernel/syscalls/ioctl/test_ioctl | 23 -------------------- 3 files changed, 12 insertions(+), 38 deletions(-)
runtest/syscalls +1 -1
@@ -557,10 +557,10 @@ init_module01 init_module01 init_module02 init_module02 #Needs tty device. -#ioctl01 ioctl01 -D /dev/tty0 #ioctl02 ioctl02 -D /dev/tty0 # Introducing ioctl tests for all /dev/tty* devices +ioctl01 ioctl01 ioctl01_02 test_ioctl ioctl03 ioctl03 ioctl04 ioctl04
testcases/kernel/syscalls/ioctl/ioctl01.c +11 -14
@@ -23,11 +23,13 @@#include <fcntl.h> #include <stdio.h> #include <termios.h> +#include <pty.h> #include "tst_test.h" #include "lapi/ioctl.h" #define INVAL_IOCTL 9999999 +static int amaster, aslave;static int fd, fd_file;static int bfd =-1 ;
@@ -59,8 +61,6 @@ static struct tcase { {&fd, TCGETS, NULL, EFAULT} }; -static char *device; -static void verify_ioctl (unsigned int i) { TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tio),
@@ -69,31 +69,28 @@ static void verify_ioctl(unsigned int i)static void setup (void ) { -if (!device) -tst_brk (TBROK ,"You must specify a tty device with -D option" ); +if (openpty (&amaster, &aslave,NULL , &termios,NULL ) <0 ) { +tst_brk (TBROK |TERRNO ,"unable to open pty" ); + } - fd =SAFE_OPEN (device,O_RDWR ,0777 ); + fd = amaster; fd_file =SAFE_OPEN ("x" ,O_CREAT ,0777 ); }static void cleanup (void ) { -if (fd >0 ) -SAFE_CLOSE (fd); - +if (amaster >0 ) +SAFE_CLOSE (amaster); +if (aslave >0 ) +SAFE_CLOSE (aslave);if (fd_file >0 )SAFE_CLOSE (fd_file); }static struct tst_test test = { - .needs_root =1 , .needs_tmpdir =1 , .setup = setup, .cleanup = cleanup, .test = verify_ioctl, - .tcnt =ARRAY_SIZE (tcases), - .options = (struct tst_option []) { - {"D:" , &device,"Tty device. For example, /dev/tty[0-9]" }, - {} - } + .tcnt =ARRAY_SIZE (tcases) };
testcases/kernel/syscalls/ioctl/test_ioctl +0 -23
@@ -34,29 +34,6 @@ has_tty() return 1 } -for tttype in `ls /dev/tty*` -do -device_no=${tttype#/dev/tty} -case "$device_no" in -[0-9]|[0-9][0-9]) - has_tty $tttype - if [ $? -eq 0 ]; then - tst_resm TINFO "Skipping ioctl01 with $tttype" - continue - fi - tst_resm TINFO "Testing ioctl01 with $tttype" - ioctl01 -D $tttype - RC=$? - if [ $RC -eq 0 ] - then - tst_resm TPASS "ioctl01 Passed with $tttype" - else - tst_resm TFAIL "ioctl01 Failed with $tttype" - fi -echo;; -esac -done - for tttype in `ls /dev/tty*` do device_no=${tttype#/dev/tty}
Signature · 5 lines
2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 16 lines
* Use
openpty()to create a new tty
* Remove-Doption
* Remove requirement to run as rootSigned-off-by Marius Kittler <[email protected]>--- runtest/syscalls | 2 +- testcases/kernel/syscalls/ioctl/ioctl01.c | 25 ++++++++++------------ testcases/kernel/syscalls/ioctl/test_ioctl | 23 -------------------- 3 files changed, 12 insertions(+), 38 deletions(-)runtest/syscalls +0
-0
runtest/syscalls init_module01 init_module01 · line 564
Quoted 9 lines
runtest/syscalls +1
-1@@ -557,10 +557,10 @@ init_module01 init_module01 init_module02 init_module02 #Needs tty device. -#ioctl01 ioctl01 -D /dev/tty0 #ioctl02 ioctl02 -D /dev/tty0 # Introducing ioctl tests for all /dev/tty* devices +ioctl01 ioctl01 ioctl01_02 test_ioctl
This should be renamed to ioctl02 now I suppose.
Quoted 30 lines
runtest/syscalls +0
-0ioctl03 ioctl03 ioctl04 ioctl04testcases/kernel/syscalls/ioctl/ioctl01.c +2
-2@@ -23,11 +23,13 @@#include <fcntl.h> #include <stdio.h> #include <termios.h> +#include <pty.h> #include "tst_test.h" #include "lapi/ioctl.h" #define INVAL_IOCTL 9999999 +static int amaster, aslave;static int fd, fd_file;static int bfd =-1 ;@@ -59,8 +61,6 @@ static struct tcase { {&fd, TCGETS, NULL, EFAULT} }; -static char *device; -static void verify_ioctl (unsigned int i) { TST_EXP_FAIL(ioctl(*(tcases[i].fd), tcases[i].request, tcases[i].s_tio),
testcases/kernel/syscalls/ioctl/ioctl01.c static void verify_ioctl(unsigned int i) · line 74
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl01.c +3
-2@@ -69,31 +69,28 @@ static void verify_ioctl(unsigned int i)static void setup (void ) { -if (!device) -tst_brk (TBROK ,"You must specify a tty device with -D option" ); +if (openpty (&amaster, &aslave,NULL , &termios,NULL ) <0 ) { +tst_brk (TBROK |TERRNO ,"unable to open pty" ); + }
It's better just to pass NULL instead of the zero filled &termios here.
The rest looks good to me, if you agree I can merge the patch with the changes I've proposed.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Am Montag, 11. September 2023, 17:14:53 CEST schrieb Cyril Hrubis:
Quoted 28 lines
Hi!
Quoted 26 lines
* Use
openpty()to create a new tty
* Remove-Doption
* Remove requirement to run as rootSigned-off-by Marius Kittler <[email protected]>---
runtest/syscalls | 2 +- testcases/kernel/syscalls/ioctl/ioctl01.c | 25 ++++++++++------------ testcases/kernel/syscalls/ioctl/test_ioctl | 23 -------------------- 3 files changed, 12 insertions(+), 38 deletions(-)runtest/syscalls +0
-1@@ -557,10 +557,10 @@ init_module01 init_module01 init_module02 init_module02 #Needs tty device. -#ioctl01 ioctl01 -D /dev/tty0 #ioctl02 ioctl02 -D /dev/tty0
Quoted 8 lines
runtest/syscalls init_module01 init_module01 · line 564
Quoted 5 lines
runtest/syscalls +1
-0# Introducing ioctl tests for all /dev/tty* devices +ioctl01 ioctl01 ioctl01_02 test_ioctlThis should be renamed to ioctl02 now I suppose.
Right, this should now be the only remaining test in test_ioctl.
Quoted 3 lines
runtest/syscalls
Quoted 3 lines
runtest/syscalls +0
-2- if (!device) - tst_brk(TBROK, "You must specify a tty device with -D
option");
Quoted 6 lines
runtest/syscalls
Quoted 3 lines
runtest/syscalls +3
-0+ if (openpty(&amaster, &aslave, NULL, &termios, NULL) < 0) { + tst_brk(TBROK | TERRNO, "unable to open pty"); + }It's better just to pass NULL instead of the zero filled &termios here.
Makes sense.
Quoted 2 lines
The rest looks good to me, if you agree I can merge the patch with the changes I've proposed.
Yes, go ahead.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Applied, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp