From 73e6550d6871245c762c9afe087b8c055cc1454a Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Sun, 18 Jan 2004 20:56:23 +0000 Subject: add regression tests for /dev/ptm. ok deraadt@ --- regress/sys/kern/ptmget/Makefile | 5 ++++ regress/sys/kern/ptmget/ptmget.c | 57 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 regress/sys/kern/ptmget/Makefile create mode 100644 regress/sys/kern/ptmget/ptmget.c (limited to 'regress/sys') diff --git a/regress/sys/kern/ptmget/Makefile b/regress/sys/kern/ptmget/Makefile new file mode 100644 index 00000000000..8f495ee7f25 --- /dev/null +++ b/regress/sys/kern/ptmget/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2004/01/18 20:56:22 beck Exp $ + +PROG= ptmget + +.include diff --git a/regress/sys/kern/ptmget/ptmget.c b/regress/sys/kern/ptmget/ptmget.c new file mode 100644 index 00000000000..943e2c4f0c3 --- /dev/null +++ b/regress/sys/kern/ptmget/ptmget.c @@ -0,0 +1,57 @@ +/* $OpenBSD: ptmget.c,v 1.1 2004/01/18 20:56:22 beck Exp $ */ +/* + * Written by Bob Beck 2004 Public Domain. + * Basic test to ensure /dev/ptm works, and what it returns + * can be used via tty(4); + */ +#include +#include +#include +#include +#include + +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int fd; + struct ptmget ptm; + struct termios ti; + struct stat sb; + struct group *gr; + gid_t ttygid; + + if ((gr = getgrnam("tty")) != NULL) + ttygid = gr->gr_gid; + else + ttygid = 4; + fd = open("/dev/ptm", O_RDWR, 0); + if (fd == -1) + err(1, "Can't open /dev/ptm"); + if ((ioctl(fd, PTMGET, &ptm) == -1)) + err(1, "ioctl PTMGET failed"); + if ((tcgetattr(ptm.sfd, &ti) == -1)) + err(1, "tcgetattr failed on slave"); + if ((tcgetattr(ptm.cfd, &ti) == -1)) + err(1, "tcgetattr failed on master"); + if ((ioctl(ptm.sfd, TIOCSTOP) == -1)) + err(1, "ioctl TIOCSTOP failed on slave"); + if ((ioctl(ptm.cfd, TIOCSTOP) == -1)) + err(1, "ioctl TIOCSTOP failed on master"); + bzero(&sb, sizeof(sb)); + if ((stat(ptm.sn, &sb) == -1)) + err(1, "can't stat slave %s", ptm.sn); + if (sb.st_mode != (S_IFCHR | S_IWUSR | S_IRUSR | S_IWGRP)) + errx(1, "Bad mode %o on %s, should be %o", sb.st_mode, + ptm.sn, (S_IFCHR | S_IWUSR | S_IRUSR | S_IWGRP)); + if (sb.st_gid != ttygid) + errx(1, "%s gid is %d not the tty group(%d)", ptm.sn, + sb.st_gid, ttygid); + if (sb.st_uid != geteuid()) + errx(1, "%s owned by %d, not the current user (%d)", ptm.sn, + sb.st_uid, geteuid()); + return(0); +} -- cgit v1.2.3