Skip to content

Commit

Permalink
Avoid messing with system tty in ioctl01.c
Browse files Browse the repository at this point in the history
* Use `openpty()` to create a new tty
* Remove `-D` option
* Remove requirement to run as root

Signed-off-by: Marius Kittler <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
  • Loading branch information
Martchus authored and metan-ucw committed Sep 13, 2023
1 parent de8d826 commit e6bfa42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.
4 changes: 2 additions & 2 deletions runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,11 @@ 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_02 test_ioctl
ioctl01 ioctl01
ioctl02 test_ioctl
ioctl03 ioctl03
ioctl04 ioctl04
ioctl05 ioctl05
Expand Down
24 changes: 10 additions & 14 deletions testcases/kernel/syscalls/ioctl/ioctl01.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -55,8 +57,6 @@ static struct tcase {
{"Termios is NULL", &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),
Expand All @@ -65,31 +65,27 @@ 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, NULL, 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)
};
23 changes: 0 additions & 23 deletions testcases/kernel/syscalls/ioctl/test_ioctl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit e6bfa42

Please sign in to comment.