diff options
author | maxim <maxim@FreeBSD.org> | 2006-05-31 11:13:10 +0000 |
---|---|---|
committer | maxim <maxim@FreeBSD.org> | 2006-05-31 11:13:10 +0000 |
commit | c71174382901f997548f6c2d99b587853b42f3c3 (patch) | |
tree | 53991a628d698e82a910f39be007c49a70769e3f /tools | |
parent | 9d817df889b68d471c8935500342a91c98a411f3 (diff) | |
download | FreeBSD-src-c71174382901f997548f6c2d99b587853b42f3c3.zip FreeBSD-src-c71174382901f997548f6c2d99b587853b42f3c3.tar.gz |
o Add various regression tests for execve(2) syscall.
Obtained from: NetBSD
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/execve/Makefile | 71 | ||||
-rw-r--r-- | tools/regression/execve/doexec.c | 58 | ||||
-rw-r--r-- | tools/regression/execve/execve.t | 27 | ||||
-rw-r--r-- | tools/regression/execve/tests/badinterplen | 4 | ||||
-rw-r--r-- | tools/regression/execve/tests/devnullscript | 4 | ||||
-rw-r--r-- | tools/regression/execve/tests/goodaout.c | 47 | ||||
-rw-r--r-- | tools/regression/execve/tests/goodscript | 4 | ||||
-rw-r--r-- | tools/regression/execve/tests/nonexistshell | 4 | ||||
-rw-r--r-- | tools/regression/execve/tests/scriptarg | 4 | ||||
-rw-r--r-- | tools/regression/execve/tests/scriptarg-nospace | 4 |
10 files changed, 227 insertions, 0 deletions
diff --git a/tools/regression/execve/Makefile b/tools/regression/execve/Makefile new file mode 100644 index 0000000..2c4777f --- /dev/null +++ b/tools/regression/execve/Makefile @@ -0,0 +1,71 @@ +# $FreeBSD$ + +PROG= doexec +NO_MAN= + +RP= ./${PROG} +TD= ${.CURDIR}/tests +OD= ${.CURDIR}/good + +TESTSCRIPTS= nonexistshell devnullscript badinterplen goodscript \ + scriptarg scriptarg-nospace +CLEANFILES= goodaout truncaout sparceaout empty ${TESTSCRIPTS} + +all: ${PROG} goodaout ${TESTSCRIPTS} + +.for x in ${TESTSCRIPTS} +${x}: ${TD}/${x} + cp ${TD}/${x} . + chmod +x ${x} +.endfor + +regress: test-empty test-nonexist test-nonexistshell \ + test-devnullscript test-badinterplen test-goodscript \ + test-scriptarg test-scriptarg-nospace test-goodaout \ + test-truncaout test-sparceaout + +test-empty: ${PROG} + rm -f empty + touch empty + chmod +x empty + ${RP} empty | diff ${OD}/empty - + +test-nonexist: ${PROG} + ${RP} ${TD}/nonexistent | grep 'No such file or directory' + +test-nonexistshell: ${PROG} nonexistshell + ${RP} nonexistshell | grep 'No such file or directory' + +test-devnullscript: ${PROG} devnullscript + ${RP} devnullscript | grep 'Permission denied' + +test-badinterplen: ${PROG} badinterplen + ${RP} badinterplen | grep 'No such file or directory' + +test-goodscript: ${PROG} goodscript + ${RP} goodscript | grep 'succeeded' + +test-scriptarg: ${PROG} scriptarg + ${RP} scriptarg 2>&1 | grep '+ echo succeeded' + +test-scriptarg-nospace: ${PROG} scriptarg-nospace + ${RP} scriptarg-nospace 2>&1 | grep '+ echo succeeded' + +goodaout: ${TD}/goodaout.c + ${CC} -static -o ${.TARGET} ${TD}/goodaout.c + +test-goodaout: ${PROG} goodaout + ${RP} goodaout | grep 'succeeded' + +test-truncaout: ${PROG} goodaout + truncate -s 16 truncaout + chmod a+x truncaout + ${RP} truncaout | grep 'Exec format error' + +test-sparceaout: ${PROG} + /bin/rm -rf sparceaout + truncate -s 20480 sparceaout + chmod a+x sparceaout + ${RP} sparceaout | grep 'Exec format error' + +.include <bsd.prog.mk> diff --git a/tools/regression/execve/doexec.c b/tools/regression/execve/doexec.c new file mode 100644 index 0000000..0aa82ec --- /dev/null +++ b/tools/regression/execve/doexec.c @@ -0,0 +1,58 @@ +/* $NetBSD: doexec.c,v 1.8 2003/07/26 19:38:48 salo Exp $ */ + +/* + * Copyright (c) 1993 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * NetBSD Project. See http://www.NetBSD.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +int +main(argc, argv) + int argc; + char *argv[]; +{ + if (argc != 2) { + fprintf(stderr, "usage: %s <progname>\n", argv[0]); + exit(2); + } + + unsetenv("LANG"); /* we compare C error strings */ + if (execve(argv[1], &argv[1], NULL) == -1) { + printf("%s\n", strerror(errno)); + exit(1); + } +} diff --git a/tools/regression/execve/execve.t b/tools/regression/execve/execve.t new file mode 100644 index 0000000..021987d --- /dev/null +++ b/tools/regression/execve/execve.t @@ -0,0 +1,27 @@ +#!/bin/sh +# $FreeBSD$ + +cd `dirname $0` +cmd="./`basename $0 .t`" + +make >/dev/null 2>&1 + +tests="test-empty test-nonexist test-nonexistshell \ + test-devnullscript test-badinterplen test-goodscript \ + test-scriptarg test-scriptarg-nospace test-goodaout \ + test-truncaout" + +n=0 + +echo "1..10" + +for atest in ${tests} +do + n=`expr ${n} + 1` + if make ${atest} + then + echo "ok ${n} - ${atest}" + else + echo "not ok ${n} - ${atest}" + fi +done diff --git a/tools/regression/execve/tests/badinterplen b/tools/regression/execve/tests/badinterplen new file mode 100644 index 0000000..96c049f --- /dev/null +++ b/tools/regression/execve/tests/badinterplen @@ -0,0 +1,4 @@ +#! 456789012345678 0123456789012345 789012345678 012345678901234 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 +# $FreeBSD$ + +echo succeeded diff --git a/tools/regression/execve/tests/devnullscript b/tools/regression/execve/tests/devnullscript new file mode 100644 index 0000000..73b1020 --- /dev/null +++ b/tools/regression/execve/tests/devnullscript @@ -0,0 +1,4 @@ +#! /dev/null +# $FreeBSD$ + +echo succeeded diff --git a/tools/regression/execve/tests/goodaout.c b/tools/regression/execve/tests/goodaout.c new file mode 100644 index 0000000..ebf476b --- /dev/null +++ b/tools/regression/execve/tests/goodaout.c @@ -0,0 +1,47 @@ +/* $NetBSD: goodaout.c,v 1.8 2003/07/26 19:38:49 salo Exp $ */ + +/*- + * Copyright (c) 1993 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * NetBSD Project. See http://www.NetBSD.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <stdio.h> +#include <stdlib.h> + +int +main(argc, argv) + int argc; + char *argv[]; +{ + printf("succeeded\n"); + exit(0); +} diff --git a/tools/regression/execve/tests/goodscript b/tools/regression/execve/tests/goodscript new file mode 100644 index 0000000..51270dc --- /dev/null +++ b/tools/regression/execve/tests/goodscript @@ -0,0 +1,4 @@ +#! /bin/csh +# $FreeBSD$ + +echo succeeded diff --git a/tools/regression/execve/tests/nonexistshell b/tools/regression/execve/tests/nonexistshell new file mode 100644 index 0000000..f9ee705 --- /dev/null +++ b/tools/regression/execve/tests/nonexistshell @@ -0,0 +1,4 @@ +#! /foo/bar/baz +# $FreeBSD$ + +echo foo diff --git a/tools/regression/execve/tests/scriptarg b/tools/regression/execve/tests/scriptarg new file mode 100644 index 0000000..2700f1c --- /dev/null +++ b/tools/regression/execve/tests/scriptarg @@ -0,0 +1,4 @@ +#! /bin/sh -x +# $FreeBSD$ + +echo succeeded diff --git a/tools/regression/execve/tests/scriptarg-nospace b/tools/regression/execve/tests/scriptarg-nospace new file mode 100644 index 0000000..6731ad5 --- /dev/null +++ b/tools/regression/execve/tests/scriptarg-nospace @@ -0,0 +1,4 @@ +#!/bin/sh -x +# $FreeBSD$ + +echo succeeded |