diff options
author | ngie <ngie@FreeBSD.org> | 2015-04-12 12:29:34 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-04-12 12:29:34 +0000 |
commit | bf56b0293159b2fe85c3d2595798953ba35f1148 (patch) | |
tree | 9472f7b79416ca4976e81e5cd4a73227062c1fa1 | |
parent | 66cc740ed9057725932ec1479cb42919d01336bd (diff) | |
download | FreeBSD-src-bf56b0293159b2fe85c3d2595798953ba35f1148.zip FreeBSD-src-bf56b0293159b2fe85c3d2595798953ba35f1148.tar.gz |
Integrate tools/regression/execve into the FreeBSD test suite as tests/sys/kern/execve
-rw-r--r-- | etc/mtree/BSD.tests.dist | 2 | ||||
-rw-r--r-- | tests/sys/kern/Makefile | 2 | ||||
-rw-r--r-- | tests/sys/kern/execve/Makefile | 37 | ||||
-rw-r--r-- | tests/sys/kern/execve/bad_interp_len (renamed from tools/regression/execve/tests/badinterplen) | 0 | ||||
-rw-r--r-- | tests/sys/kern/execve/devnullscript (renamed from tools/regression/execve/tests/devnullscript) | 0 | ||||
-rw-r--r-- | tests/sys/kern/execve/execve_helper.c (renamed from tools/regression/execve/doexec.c) | 14 | ||||
-rw-r--r-- | tests/sys/kern/execve/execve_test.sh | 115 | ||||
-rw-r--r-- | tests/sys/kern/execve/good_aout.c (renamed from tools/regression/execve/tests/goodaout.c) | 4 | ||||
-rw-r--r-- | tests/sys/kern/execve/good_script (renamed from tools/regression/execve/tests/goodscript) | 2 | ||||
-rw-r--r-- | tests/sys/kern/execve/non_exist_shell (renamed from tools/regression/execve/tests/nonexistshell) | 0 | ||||
-rw-r--r-- | tests/sys/kern/execve/scriptarg (renamed from tools/regression/execve/tests/scriptarg) | 0 | ||||
-rw-r--r-- | tests/sys/kern/execve/scriptarg-nospace (renamed from tools/regression/execve/tests/scriptarg-nospace) | 0 | ||||
-rw-r--r-- | tools/regression/execve/Makefile | 70 | ||||
-rw-r--r-- | tools/regression/execve/execve.t | 27 |
14 files changed, 163 insertions, 110 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 8fd59c5..0009932 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -359,6 +359,8 @@ file .. kern + execve + .. .. kqueue .. diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 4a1e671..d366aa1 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -10,4 +10,6 @@ LDADD.unix_seqpacket_test+= -lpthread WARNS?= 5 +TESTS_SUBDIRS+= execve + .include <bsd.test.mk> diff --git a/tests/sys/kern/execve/Makefile b/tests/sys/kern/execve/Makefile new file mode 100644 index 0000000..8ed6f63 --- /dev/null +++ b/tests/sys/kern/execve/Makefile @@ -0,0 +1,37 @@ +TESTSDIR= ${TESTSBASE}/sys/kern/execve + +BINDIR= ${TESTSDIR} + +MAN= + +ATF_TESTS_SH+= execve_test + +PROGS+= good_aout +PROGS+= execve_helper + +LDFLAGS.goodaout+= -static + +CLEANFILES+= empty +CLEANFILES+= sparse_aout +CLEANFILES+= trunc_aout + +SCRIPTS+= bad_interp_len +SCRIPTS+= dev_null_script +SCRIPTS+= empty +SCRIPTS+= good_script +SCRIPTS+= non_exist_shell +SCRIPTS+= script_arg +SCRIPTS+= script_arg_nospace +SCRIPTS+= sparse_aout +SCRIPTS+= trunc_aout + +empty: + @touch $@ + +sparse_aout: + @truncate -s 20480 $@ + +trunc_aout: + @truncate -s 16 $@ + +.include <bsd.test.mk> diff --git a/tools/regression/execve/tests/badinterplen b/tests/sys/kern/execve/bad_interp_len index 96c049f..96c049f 100644 --- a/tools/regression/execve/tests/badinterplen +++ b/tests/sys/kern/execve/bad_interp_len diff --git a/tools/regression/execve/tests/devnullscript b/tests/sys/kern/execve/devnullscript index 73b1020..73b1020 100644 --- a/tools/regression/execve/tests/devnullscript +++ b/tests/sys/kern/execve/devnullscript diff --git a/tools/regression/execve/doexec.c b/tests/sys/kern/execve/execve_helper.c index 0aa82ec..164a8f3 100644 --- a/tools/regression/execve/doexec.c +++ b/tests/sys/kern/execve/execve_helper.c @@ -34,25 +34,21 @@ * $FreeBSD$ */ +#include <err.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> int -main(argc, argv) - int argc; - char *argv[]; +main(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); - } + execve(argv[1], &argv[1], NULL); + err(1, ""); } diff --git a/tests/sys/kern/execve/execve_test.sh b/tests/sys/kern/execve/execve_test.sh new file mode 100644 index 0000000..ef803a1 --- /dev/null +++ b/tests/sys/kern/execve/execve_test.sh @@ -0,0 +1,115 @@ + +bad_interp_len_head() +{ + atf_set "descr" "Bad interpreter length" +} +bad_interp_len_body() +{ + atf_check -s exit:1 -e 'match:No such file or directory' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper bad_interp_len" +} + +empty_head() +{ + atf_set "descr" "Empty file" +} +empty_body() +{ + atf_check -s exit:1 -e 'match:Exec format error' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper empty" +} + +good_aout_head() +{ + atf_set "descr" "Good a.out" +} +good_aout_body() +{ + atf_check -s exit:0 -e empty -o 'match:succeeded' \ + -x "cd $(atf_get_srcdir) && ./execve_helper ./good_aout" +} + +good_script_head() +{ + atf_set "descr" "Good script" +} +good_script_body() +{ + atf_check -s exit:0 -e empty -o 'match:succeeded' \ + -x "cd $(atf_get_srcdir) && ./execve_helper good_script" +} + +non_exist_head() +{ + atf_set "descr" "Non-existent file" +} +non_exist_body() +{ + atf_check -s exit:1 -e 'match:No such file or directory' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper non_exist" +} + +non_exist_shell_head() +{ + atf_set "descr" "Non-existent shell" +} +non_exist_shell_body() +{ + atf_check -s exit:1 -e 'match:No such file or directory' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper non_exist_shell" +} + +script_arg_head() +{ + atf_set "descr" "-x in the shebang" +} +script_arg_body() +{ + atf_check -s exit:0 -e 'match:\+ echo succeeded' -o 'match:succeeded' \ + -x "cd $(atf_get_srcdir) && ./execve_helper script_arg" +} + +script_arg_nospace_head() +{ + atf_set "descr" '-x in the shebang; no space between #! and /bin/sh' +} +script_arg_nospace_body() +{ + atf_check -s exit:0 -e 'match:\+ echo succeeded' -o 'match:succeeded' \ + -x "cd $(atf_get_srcdir) && ./execve_helper script_arg_nospace" +} + +sparse_aout_head() +{ + atf_set "descr" 'Sparse file' +} +sparse_aout_body() +{ + atf_check -s exit:1 -e 'match:Exec format error' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper sparse_aout" +} + +trunc_aout_head() +{ + atf_set "descr" 'Truncated file' +} +trunc_aout_body() +{ + atf_check -s exit:1 -e 'match:Exec format error' -o empty \ + -x "cd $(atf_get_srcdir) && ./execve_helper trunc_aout" +} + +atf_init_test_cases() +{ + atf_add_test_case bad_interp_len + atf_add_test_case empty + atf_add_test_case good_aout + atf_add_test_case good_script + atf_add_test_case non_exist + atf_add_test_case non_exist_shell + atf_add_test_case script_arg + atf_add_test_case script_arg_nospace + atf_add_test_case sparse_aout + atf_add_test_case trunc_aout + +} diff --git a/tools/regression/execve/tests/goodaout.c b/tests/sys/kern/execve/good_aout.c index ebf476b..39e9867 100644 --- a/tools/regression/execve/tests/goodaout.c +++ b/tests/sys/kern/execve/good_aout.c @@ -38,9 +38,7 @@ #include <stdlib.h> int -main(argc, argv) - int argc; - char *argv[]; +main(void) { printf("succeeded\n"); exit(0); diff --git a/tools/regression/execve/tests/goodscript b/tests/sys/kern/execve/good_script index 51270dc..11c7689 100644 --- a/tools/regression/execve/tests/goodscript +++ b/tests/sys/kern/execve/good_script @@ -1,4 +1,4 @@ -#! /bin/csh +#!/bin/sh # $FreeBSD$ echo succeeded diff --git a/tools/regression/execve/tests/nonexistshell b/tests/sys/kern/execve/non_exist_shell index f9ee705..f9ee705 100644 --- a/tools/regression/execve/tests/nonexistshell +++ b/tests/sys/kern/execve/non_exist_shell diff --git a/tools/regression/execve/tests/scriptarg b/tests/sys/kern/execve/scriptarg index 2700f1c..2700f1c 100644 --- a/tools/regression/execve/tests/scriptarg +++ b/tests/sys/kern/execve/scriptarg diff --git a/tools/regression/execve/tests/scriptarg-nospace b/tests/sys/kern/execve/scriptarg-nospace index 6731ad5..6731ad5 100644 --- a/tools/regression/execve/tests/scriptarg-nospace +++ b/tests/sys/kern/execve/scriptarg-nospace diff --git a/tools/regression/execve/Makefile b/tools/regression/execve/Makefile deleted file mode 100644 index 018678c..0000000 --- a/tools/regression/execve/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# $FreeBSD$ - -PROG= doexec -MAN= - -RP= ./${PROG} -TD= ${.CURDIR}/tests - -TESTSCRIPTS= nonexistshell devnullscript badinterplen goodscript \ - scriptarg scriptarg-nospace -CLEANFILES= goodaout truncaout sparseaout 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-sparseaout - -test-empty: ${PROG} - rm -f empty - touch empty - chmod +x empty - ${RP} empty | grep 'Exec format error' - -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-sparseaout: ${PROG} - /bin/rm -rf sparseaout - truncate -s 20480 sparseaout - chmod a+x sparseaout - ${RP} sparseaout | grep 'Exec format error' - -.include <bsd.prog.mk> diff --git a/tools/regression/execve/execve.t b/tools/regression/execve/execve.t deleted file mode 100644 index dd2be9a..0000000 --- a/tools/regression/execve/execve.t +++ /dev/null @@ -1,27 +0,0 @@ -#!/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 test-sparseaout" - -n=0 - -echo "1..11" - -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 |