diff options
author | anton <anton@cvs.openbsd.org> | 2018-11-20 19:37:11 +0000 |
---|---|---|
committer | anton <anton@cvs.openbsd.org> | 2018-11-20 19:37:11 +0000 |
commit | be98f1c4cb54e2ff9a9120b47c7a62808efb95bd (patch) | |
tree | adc9fc31f520f4a507f746e653ebb6d5e77ca3cf | |
parent | f56c514771569be071318dbde651be1b01f73e3d (diff) |
test getown
-rw-r--r-- | regress/sys/dev/wscons/Makefile | 4 | ||||
-rw-r--r-- | regress/sys/dev/wscons/sigio.c | 81 |
2 files changed, 82 insertions, 3 deletions
diff --git a/regress/sys/dev/wscons/Makefile b/regress/sys/dev/wscons/Makefile index 4072f5a46e8..1548d076ebf 100644 --- a/regress/sys/dev/wscons/Makefile +++ b/regress/sys/dev/wscons/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.2 2018/11/20 18:49:42 anton Exp $ +# $OpenBSD: Makefile,v 1.3 2018/11/20 19:37:10 anton Exp $ PROG= sigio WARNINGS= yes .for d in wskbd0 wsmouse0 wskbd -. for t in setown-fcntl setown-ioctl spgrp sigio +. for t in getown-fcntl getown-ioctl gpgrp setown-fcntl setown-ioctl spgrp sigio REGRESS_TARGETS+= $d-$t $d-$t: ${PROG} @echo "\n======== ${@} ========" diff --git a/regress/sys/dev/wscons/sigio.c b/regress/sys/dev/wscons/sigio.c index b4b6fd33611..40f55207de7 100644 --- a/regress/sys/dev/wscons/sigio.c +++ b/regress/sys/dev/wscons/sigio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sigio.c,v 1.2 2018/11/20 18:49:42 anton Exp $ */ +/* $OpenBSD: sigio.c,v 1.3 2018/11/20 19:37:10 anton Exp $ */ /* * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org> @@ -30,11 +30,15 @@ #include <string.h> #include <unistd.h> +static int test_getown_fcntl(int); +static int test_getown_ioctl(int); +static int test_gpgrp(int); static int test_setown_fcntl(int); static int test_setown_ioctl(int); static int test_sigio(int); static int test_spgrp(int); +static int test_common_getown(int, int); static int test_common_setown(int, int); static void sigio(int); @@ -48,6 +52,9 @@ static struct { const char *name; int (*fn)(int); } tests[] = { + { "getown-fcntl", test_getown_fcntl }, + { "getown-ioctl", test_getown_ioctl }, + { "gpgrp", test_gpgrp }, { "setown-fcntl", test_setown_fcntl }, { "setown-ioctl", test_setown_ioctl }, { "sigio", test_sigio }, @@ -99,6 +106,39 @@ main(int argc, char *argv[]) } static int +test_getown_fcntl(int fd) +{ + return test_common_getown(fd, 1); +} + +static int +test_getown_ioctl(int fd) +{ + return test_common_getown(fd, 0); +} + +static int +test_gpgrp(int fd) +{ + int arg, pgrp; + + if (ioctl(fd, TIOCGPGRP, &pgrp) == -1) + err(1, "ioctl: TIOCGPGRP"); + if (pgrp != 0) + errx(1, "ioctl: TIOCGPGRP: expected 0, got %d", pgrp); + + arg = getpgrp(); + if (ioctl(fd, TIOCSPGRP, &arg) == -1) + err(1, "ioctl: TIOCSPGRP"); + if (ioctl(fd, TIOCGPGRP, &pgrp) == -1) + err(1, "ioctl: TIOCGPGRP"); + if (pgrp != getpgrp()) + errx(1, "ioctl: TIOCGPGRP: expected %d, got %d", getpgrp(), pgrp); + + return 0; +} + +static int test_setown_fcntl(int fd) { return test_common_setown(fd, 1); @@ -208,6 +248,45 @@ test_spgrp(int fd) } static int +test_common_getown(int fd, int dofcntl) +{ + int arg, pgrp; + + if (dofcntl) { + pgrp = fcntl(fd, F_GETOWN); + if (pgrp == -1) + err(1, "fcntl: F_GETOWN"); + if (pgrp != 0) + errx(1, "fcntl: F_GETOWN: expected 0, got %d", pgrp); + } else { + if (ioctl(fd, FIOGETOWN, &pgrp) == -1) + err(1, "ioctl: FIOGETOWN"); + if (pgrp != 0) + errx(1, "ioctl: FIOGETOWN: expected 0, got %d", pgrp); + } + + arg = getpid(); + if (ioctl(fd, FIOSETOWN, &arg) == -1) + err(1, "ioctl: FIOSETOWN"); + if (dofcntl) { + pgrp = fcntl(fd, F_GETOWN); + if (pgrp == -1) + err(1, "fcntl: F_GETOWN"); + if (pgrp != -getpgrp()) + errx(1, "fcntl: F_GETOWN: expected %d, got %d", + -getpgrp(), pgrp); + } else { + if (ioctl(fd, FIOGETOWN, &pgrp) == -1) + err(1, "ioctl: FIOGETOWN"); + if (pgrp != -getpgrp()) + errx(1, "ioctl: FIOGETOWN: expected %d, got %d", + -getpgrp(), pgrp); + } + + return 0; +} + +static int test_common_setown(int fd, int dofcntl) { int arg; |