diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-02-24 06:58:37 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-02-24 06:58:37 +0000 |
commit | a93add44d60bfdf5e479dc5a5d5803e32591e398 (patch) | |
tree | 4d9791e55df511df6cf3c48ab6c310a4a72e467e | |
parent | a9467fe33110b5632193a8cb3376d8b891d62909 (diff) |
Add tedu's copy* test, turned into a regress test by me.
-rw-r--r-- | regress/sys/Makefile | 4 | ||||
-rw-r--r-- | regress/sys/copy/Makefile | 6 | ||||
-rw-r--r-- | regress/sys/copy/copy.c | 102 |
3 files changed, 110 insertions, 2 deletions
diff --git a/regress/sys/Makefile b/regress/sys/Makefile index 2443ff36071..8cd4d4aa051 100644 --- a/regress/sys/Makefile +++ b/regress/sys/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.15 2004/04/24 13:19:12 miod Exp $ +# $OpenBSD: Makefile,v 1.16 2005/02/24 06:58:36 otto Exp $ # $NetBSD: Makefile,v 1.4 1995/04/20 22:41:08 cgd Exp $ -SUBDIR+= crypto ddb fdescfs fifofs kern ptrace sys uvm dev +SUBDIR+= copy crypto ddb fdescfs fifofs kern ptrace sys uvm dev .if exists(arch/${MACHINE}) SUBDIR+= arch/${MACHINE} .endif diff --git a/regress/sys/copy/Makefile b/regress/sys/copy/Makefile new file mode 100644 index 00000000000..ce6e2f8f172 --- /dev/null +++ b/regress/sys/copy/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 2005/02/24 06:58:36 otto Exp $ + +PROG=copy +CFLAGS+= -Wall + +.include <bsd.regress.mk> diff --git a/regress/sys/copy/copy.c b/regress/sys/copy/copy.c new file mode 100644 index 00000000000..6125c050bc1 --- /dev/null +++ b/regress/sys/copy/copy.c @@ -0,0 +1,102 @@ +/* $OpenBSD: copy.c,v 1.1 2005/02/24 06:58:36 otto Exp $ */ + +/* Written by Ted Unangst 2004 Public Domain */ + +#include <sys/param.h> +#include <sys/mount.h> +#include <sys/sysctl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <net/if.h> +#include <strings.h> + +#include <stdio.h> +#include <err.h> +#include <unistd.h> + +int failure; + +static void +fail(const char *str) +{ + fprintf(stderr, "%s\n", str); + failure++; +} + +int +main(int argc, char **argv) +{ + char buf[4096]; + void *goodbuf; + void *badbuf; + int mib[6]; + struct kinfo_proc2 kinfo; + size_t kinfosize = sizeof(kinfo); + int s; + struct ifreq ifrdesc; + + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) + err(1, "socket"); + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC2; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + mib[4] = sizeof(struct kinfo_proc2); + mib[5] = 1; + + if (sysctl(mib, 6, &kinfo, &kinfosize, 0, 0)) + err(1, "sysctl"); + + + goodbuf = buf; + badbuf = (void*)(long)kinfo.p_paddr; + + /* printf("goodbuf %p badbuf %p\n", goodbuf, badbuf); */ + + /* copyin */ + if (!syscall(202, 0, 6, &kinfo, &kinfosize, 0, 0)) + fail("copyin did not fail on 0 buf\n"); + if (!syscall(202, badbuf, 6, &kinfo, &kinfosize, 0, 0)) + fail("copyin did not fail on bad buf\n"); + + /* copyout */ + if (statfs("/", goodbuf)) + fail("copyout failed on a good buf\n"); + if (!statfs("/", 0)) + fail("copyout didn't fail on 0 buf\n"); + if (!statfs("/", badbuf)) + fail("copyout didn't fail on bad buf\n"); + + /* copyoutstr */ + memset(&ifrdesc, 0, sizeof(ifrdesc)); + strlcpy(ifrdesc.ifr_name, "lo0", sizeof(ifrdesc.ifr_name)); + ifrdesc.ifr_data = goodbuf; + if (ioctl(s, SIOCGIFDESCR, &ifrdesc)) + fail("SIOCIFDESCR ioctl failed\n"); + memset(&ifrdesc, 0, sizeof(ifrdesc)); + strlcpy(ifrdesc.ifr_name, "lo0", sizeof(ifrdesc.ifr_name)); + ifrdesc.ifr_data = 0; + if (!ioctl(s, SIOCGIFDESCR, &ifrdesc)) + fail("copyoutstr didn't fail on 0 buf\n"); + memset(&ifrdesc, 0, sizeof(ifrdesc)); + strlcpy(ifrdesc.ifr_name, "lo0", sizeof(ifrdesc.ifr_name)); + ifrdesc.ifr_data = badbuf; + if (!ioctl(s, SIOCGIFDESCR, &ifrdesc)) + fail("copyoutstr didn't fail on badbuf\n"); + + /* copyinstr */ + if (statfs("/", goodbuf)) + fail("copyinstr failed on a good buf\n"); + if (!statfs(0, goodbuf)) + fail("copyinstr didn't fail on 0 buf\n"); + if (!statfs(badbuf, goodbuf)) + fail("copyinstr didn't fail on bad buf\n"); + + if (failure) + errx(1, "%d failures", failure); + return 0; +} |