You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
(16) |
Apr
(25) |
May
(8) |
Jun
(22) |
Jul
(71) |
Aug
(36) |
Sep
(22) |
Oct
(31) |
Nov
(88) |
Dec
(40) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(128) |
Feb
(35) |
Mar
(28) |
Apr
(33) |
May
(18) |
Jun
(8) |
Jul
(21) |
Aug
(18) |
Sep
(6) |
Oct
(19) |
Nov
(12) |
Dec
(44) |
2012 |
Jan
(31) |
Feb
(48) |
Mar
(31) |
Apr
(11) |
May
(13) |
Jun
(15) |
Jul
(13) |
Aug
(18) |
Sep
(7) |
Oct
(25) |
Nov
(21) |
Dec
(13) |
2013 |
Jan
(17) |
Feb
(18) |
Mar
(21) |
Apr
(35) |
May
(30) |
Jun
(4) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(30) |
Nov
(13) |
Dec
|
From: Cyril H. <su...@li...> - 2013-11-14 15:51:10
|
The branch, master, has been updated via 1eb440c2b5fe43a3e5023015a16aa5d7d3385b1e (commit) from b185f2281d0e8767db4c1270280ec160b9fa097b (commit) - Log ----------------------------------------------------------------- commit 1eb440c2b5fe43a3e5023015a16aa5d7d3385b1e Author: Cyril Hrubis <ch...@su...> Date: Wed Nov 13 18:25:50 2013 +0100 Fix 743f2fcd5744744d649496d8f0524cf5ca7d3859. The gethost is called from multicast testcases too, which I failed to find, apologies everyone. This commit moves the gethost to muticast directory and renames it to mc_gethost and fixes all usages accordingly. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/network/multicast/mc_cmds/mc_cmds | 11 +---------- testcases/network/multicast/mc_commo/mc_commo | 8 +++----- .../multicast/mc_gethost}/Makefile | 9 +++------ .../mc_gethost/mc_gethost.c} | 0 testcases/network/multicast/mc_member/mc_member | 3 +-- testcases/network/multicast/mc_opts/mc_opts | 2 +- testcases/network/tcp_cmds/sendfile/Makefile | 4 ++-- testcases/network/tcp_cmds/sendfile/sendfile01 | 4 ++-- 8 files changed, 13 insertions(+), 28 deletions(-) copy testcases/{kernel/fs/ext4-new-features/ext4-nsec-timestamps => network/multicast/mc_gethost}/Makefile (87%) rename testcases/network/{tcp_cmds/sendfile/sendfile01_gethost.c => multicast/mc_gethost/mc_gethost.c} (100%) diff --git a/testcases/network/multicast/mc_cmds/mc_cmds b/testcases/network/multicast/mc_cmds/mc_cmds index d27f669..fda26a3 100755 --- a/testcases/network/multicast/mc_cmds/mc_cmds +++ b/testcases/network/multicast/mc_cmds/mc_cmds @@ -36,15 +36,6 @@ $trace_logic TC=mc_cmds PING_OUT=/tmp/${TC}_out -# Set the LTPROOT variable to the correct path -# from the ltp/testcases/bin directory or the -# /ltp/testcases/network/multicast/mc_cmds directory -pwd | grep -q bin -if [ $? -eq 0 ]; then - LTPROOT=${LTPROOT:-../..} -else - LTPROOT=${LTPROOT:-../../../..} -fi HOSTNAME=`hostname` CLEANUP=${CLEANUP:-ON} #******************************************************************************* @@ -63,7 +54,7 @@ do_test() IFNAME=${IFNAME:-$(netstat -i -n | grep "^[b-z]\{2,4\}[0-9][^*]"|\ awk '{print $1}')} - INTERFACE=${INTERFACE:-$("$LTPROOT/bin/gethost" `hostname` | grep addresses: | awk '{print $2}')} + INTERFACE=${INTERFACE:-$(mc_gethost `hostname` | grep addresses: | awk '{print $2}')} echo "Testing ifconfig and netstat" diff --git a/testcases/network/multicast/mc_commo/mc_commo b/testcases/network/multicast/mc_commo/mc_commo index 50fa6b9..87609b9 100755 --- a/testcases/network/multicast/mc_commo/mc_commo +++ b/testcases/network/multicast/mc_commo/mc_commo @@ -41,15 +41,13 @@ $trace_logic TC=mc_commo TCtmp=${TCtmp:-"/tmp/mc_commo.$$"} CLEANUP=${CLEANUP:-ON} -EXECUTABLES="mc_recv" -REMOTE_EXEC="mc_send" LTPROOT=${LTPROOT:-../../../..} TTL=10 PORT=3333 RHOST=${RHOST:-`hostname`} OUTFILE=$TCtmp/mc_commo_out NUMLOOPS=${NUMLOOPS:-2} -INTERFACE=${INTERFACE:-$("$LTPROOT/bin/gethost" `hostname` | grep addresses: | awk '{print $2}')} +INTERFACE=${INTERFACE:-$(mc_gethost `hostname` | grep addresses: | awk '{print $2}')} this_file=${0##*/} trap "interrupt_test" 2 @@ -85,7 +83,7 @@ do_test () # Start up the recv on local host echo "Starting mc_recv on $GROUP_ADDR $INTERFACE $PORT" - "$LTPROOT/testcases/bin/$EXECUTABLES" $GROUP_ADDR $INTERFACE $PORT \ + mc_recv $GROUP_ADDR $INTERFACE $PORT \ >> $OUTFILE & SERVER_PID=$! sleep 5 @@ -128,7 +126,7 @@ do_test () do echo "Running on $HOST mc_send $GROUP_ADDR $HOST $PORT $TTL" - rsh -n -l root $HOST "$LTPROOT/testcases/bin/$REMOTE_EXEC" $GROUP_ADDR \ + rsh -n -l root $HOST "$LTPROOT/testcases/bin/mc_send" $GROUP_ADDR \ $HOST $PORT $TTL >/dev/null & sleep 10 rsh -n -l root $HOST "ps -ewf | grep mc_send | grep -v grep" diff --git a/testcases/kernel/fs/ext4-new-features/ext4-nsec-timestamps/Makefile b/testcases/network/multicast/mc_gethost/Makefile similarity index 87% copy from testcases/kernel/fs/ext4-new-features/ext4-nsec-timestamps/Makefile copy to testcases/network/multicast/mc_gethost/Makefile index 6b8aabb..d5eaf84 100644 --- a/testcases/kernel/fs/ext4-new-features/ext4-nsec-timestamps/Makefile +++ b/testcases/network/multicast/mc_gethost/Makefile @@ -1,4 +1,5 @@ -# Copyright (C) 2009, FUJITSU LIMITED +# +# Copyright (C) 2013, Linux Test Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,11 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -top_srcdir ?= ../../../../.. +top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk - -LDLIBS += -lm -INSTALL_TARGETS ?= *.sh - include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c b/testcases/network/multicast/mc_gethost/mc_gethost.c similarity index 100% rename from testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c rename to testcases/network/multicast/mc_gethost/mc_gethost.c diff --git a/testcases/network/multicast/mc_member/mc_member b/testcases/network/multicast/mc_member/mc_member index 0e79cdb..ee0ca07 100755 --- a/testcases/network/multicast/mc_member/mc_member +++ b/testcases/network/multicast/mc_member/mc_member @@ -42,10 +42,9 @@ TCsrc=${TCsrc:-`pwd`} TCtmp=${TCtmp:-$TCsrc/$TC$$} CLEANUP=${CLEANUP:-ON} -LTPROOT=${LTPROOT:-"../../../../"} EXECUTABLES=${EXECUTABLES:-"member"} NUMLOOPS=${NUMLOOPS:-2} -INTERFACE=${INTERFACE:-$("$LTPROOT/bin/gethost" `hostname`| grep address |awk '{ print $2 }')} +INTERFACE=${INTERFACE:-$(mc_gethost `hostname`| grep address |awk '{ print $2 }')} GLIST=${GLIST:-$TCsrc/ManyGroups} TooManyGLIST=${TooManyGLIST:-$TCsrc/TooManyGroups} ERRFILE=${ERRFILE:-$TCtmp/errors} diff --git a/testcases/network/multicast/mc_opts/mc_opts b/testcases/network/multicast/mc_opts/mc_opts index 41e1d68..6f36c26 100755 --- a/testcases/network/multicast/mc_opts/mc_opts +++ b/testcases/network/multicast/mc_opts/mc_opts @@ -47,7 +47,7 @@ TCtmp=${TCtmp:-$LTPROOT/bin/$TC$$} CLEANUP=${CLEANUP:-ON} EXECUTABLES=${EXECUTABLES:-"opts opts_e"} NUMLOOPS=${NUMLOOPS:-10} -IPADDR=${IPADDR:-$("$LTPROOT/bin/gethost" `hostname`| grep address |awk '{ print $2 }')} +IPADDR=${IPADDR:-$(mc_gethost `hostname`| grep address |awk '{ print $2 }')} this_file=${0##*/} trap "interrupt_test" 2 diff --git a/testcases/network/tcp_cmds/sendfile/Makefile b/testcases/network/tcp_cmds/sendfile/Makefile index 7ba2d7a..a8b0736 100644 --- a/testcases/network/tcp_cmds/sendfile/Makefile +++ b/testcases/network/tcp_cmds/sendfile/Makefile @@ -27,9 +27,9 @@ include $(abs_srcdir)/../Makefile.inc CPPFLAGS += -I$(abs_srcdir)/../include -INSTALL_TARGETS := sendfile01 sendfile01_server sendfile01_gethost +INSTALL_TARGETS := sendfile01 sendfile01_server -MAKE_TARGETS += testsf_c testsf_s testsf_c6 testsf_s6 sendfile01_gethost +MAKE_TARGETS += testsf_c testsf_s testsf_c6 testsf_s6 testsf_c6.o testsf_s6.o: CPPFLAGS += -DINET6 diff --git a/testcases/network/tcp_cmds/sendfile/sendfile01 b/testcases/network/tcp_cmds/sendfile/sendfile01 index ebeb182..1598106 100755 --- a/testcases/network/tcp_cmds/sendfile/sendfile01 +++ b/testcases/network/tcp_cmds/sendfile/sendfile01 @@ -59,9 +59,9 @@ do_setup() tst_setup - exists awk diff sendfile01_gethost grep rsh stat + exists awk diff mc_gethost grep rsh stat - if ! IPADDR=$(sendfile01_gethost ${EXEC_SUFFIX:+6} $RHOST | awk 'BEGIN { ec=1 } /addresses:/ {print $2; ec=0 } END { exit ec }'); then + if ! IPADDR=$(mc_gethost ${EXEC_SUFFIX:+6} $RHOST | awk 'BEGIN { ec=1 } /addresses:/ {print $2; ec=0 } END { exit ec }'); then # XXX (garrcoop): || exit 1 is there to prevent the test from hanging in the event of an install error. end_testcase "Failed to determine the appropriate IP address for the machine." || exit 1 fi hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-14 14:51:16
|
The branch, master, has been updated via b185f2281d0e8767db4c1270280ec160b9fa097b (commit) via cb80f404615db93b9486c88de186dcb729133727 (commit) via 7b20026fd2d8766735b2adf78fe76ad1fc19b56a (commit) from 9b48608091e0b82620e4b35df768b1aeaae7ca0e (commit) - Log ----------------------------------------------------------------- commit b185f2281d0e8767db4c1270280ec160b9fa097b Author: Jan Stancek <jst...@re...> Date: Thu Nov 14 10:05:51 2013 +0100 add test for tst_checkpoint_signal_child timing out This is simple test for patch which adds timeout to tst_checkpoint_signal_child(). The test is expected to end with: Failed to open fifo 'tst_checkpoint_fifo' at tst_checkpoint_no_child.c:43: errno=ETIMEDOUT(110): Connection timed out Signed-off-by: Jan Stancek <jst...@re...> Signed-off-by: Cyril Hrubis <ch...@su...> commit cb80f404615db93b9486c88de186dcb729133727 Author: Stanislav Kholmanskikh <sta...@or...> Date: Thu Nov 14 10:37:57 2013 +0400 tst_checkpoint_signal_child: implemented timeout If a child exits before opening TST_CHECKPOINT_FIFO for reading, tst_checkpoint_signal_child() issued from the parent will block forever. To handle such situations added timeout logic to tst_checkpoint_signal_child(); Signed-off-by: Stanislav Kholmanskikh <sta...@or...> Reviewed-by: Jan Stancek <jst...@re...> Acked-by: Cyril Hrubis <ch...@su...> commit 7b20026fd2d8766735b2adf78fe76ad1fc19b56a Author: Cyril Hrubis <ch...@su...> Date: Thu Nov 14 14:38:26 2013 +0100 lib: tst_res: Add more errnos. Add all known Linux errnos. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: .gitignore | 1 + lib/errnos.h | 171 ++++++++++++++++++++ ...int_child_exits.c => tst_checkpoint_no_child.c} | 30 +--- lib/tst_checkpoint.c | 36 ++++- lib/tst_res.c | 84 +++-------- 5 files changed, 236 insertions(+), 86 deletions(-) create mode 100644 lib/errnos.h copy lib/tests/{tst_checkpoint_child_exits.c => tst_checkpoint_no_child.c} (74%) diff --git a/.gitignore b/.gitignore index 140f5f4..5f7f200 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ logfile.* /lib/tests/tst_tmpdir_test /lib/tests/tst_checkpoint_child /lib/tests/tst_checkpoint_child_exits +/lib/tests/tst_checkpoint_no_child /lib/tests/tst_checkpoint_parent /lib/tests/tst_checkpoint_parent_exits /lib/tests/tst_process_state diff --git a/lib/errnos.h b/lib/errnos.h new file mode 100644 index 0000000..797aed4 --- /dev/null +++ b/lib/errnos.h @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * Copyright (c) 2009-2013 Cyril Hrubis <ch...@su...> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, + * Mountain View, CA 94043, or: + */ + +static const char *strerrnodef(int err) +{ + struct pair errno_pairs[] = { + /* asm-generic/errno-base.h */ + PAIR(EPERM) + PAIR(ENOENT) + PAIR(ESRCH) + PAIR(EINTR) + PAIR(EIO) + PAIR(ENXIO) + PAIR(E2BIG) + PAIR(ENOEXEC) + PAIR(EBADF) + PAIR(ECHILD) + PAIR(EAGAIN) + PAIR(ENOMEM) + PAIR(EACCES) + PAIR(EFAULT) + PAIR(ENOTBLK) + PAIR(EBUSY) + PAIR(EEXIST) + PAIR(EXDEV) + PAIR(ENODEV) + PAIR(ENOTDIR) + PAIR(EISDIR) + PAIR(EINVAL) + PAIR(ENFILE) + PAIR(EMFILE) + PAIR(ENOTTY) + PAIR(ETXTBSY) + PAIR(EFBIG) + PAIR(ENOSPC) + PAIR(ESPIPE) + PAIR(EROFS) + PAIR(EMLINK) + PAIR(EPIPE) + PAIR(EDOM) + PAIR(ERANGE) + /* asm-generic/errno.h */ + PAIR(EDEADLK) + PAIR(ENAMETOOLONG) + PAIR(ENOLCK) + PAIR(ENOSYS) + PAIR(ENOTEMPTY) + PAIR(ELOOP) + /* EWOULDBLOCK == EAGAIN skipped */ + PAIR(ENOMSG) + PAIR(EIDRM) + PAIR(ECHRNG) + PAIR(EL2NSYNC) + PAIR(EL3HLT) + PAIR(EL3RST) + PAIR(ELNRNG) + PAIR(EUNATCH) + PAIR(ENOCSI) + PAIR(EL2HLT) + PAIR(EBADE) + PAIR(EBADR) + PAIR(EXFULL) + PAIR(ENOANO) + PAIR(EBADRQC) + PAIR(EBADSLT) + /* EDEADLOCK == EDEADLK skipped */ + PAIR(EBFONT) + PAIR(ENOSTR) + PAIR(ENODATA) + PAIR(ETIME) + PAIR(ENOSR) + PAIR(ENONET) + PAIR(ENOPKG) + PAIR(EREMOTE) + PAIR(ENOLINK) + PAIR(EADV) + PAIR(ESRMNT) + PAIR(ECOMM) + PAIR(EPROTO) + PAIR(EMULTIHOP) + PAIR(EDOTDOT) + PAIR(EBADMSG) + PAIR(EOVERFLOW) + PAIR(ENOTUNIQ) + PAIR(EBADFD) + PAIR(EREMCHG) + PAIR(ELIBACC) + PAIR(ELIBBAD) + PAIR(ELIBSCN) + PAIR(ELIBMAX) + PAIR(ELIBEXEC) + PAIR(EILSEQ) + PAIR(ERESTART) + PAIR(ESTRPIPE) + PAIR(EUSERS) + PAIR(ENOTSOCK) + PAIR(EDESTADDRREQ) + PAIR(EMSGSIZE) + PAIR(EPROTOTYPE) + PAIR(ENOPROTOOPT) + PAIR(EPROTONOSUPPORT) + PAIR(ESOCKTNOSUPPORT) + PAIR(EOPNOTSUPP) + PAIR(EPFNOSUPPORT) + PAIR(EAFNOSUPPORT) + PAIR(EADDRINUSE) + PAIR(EADDRNOTAVAIL) + PAIR(ENETDOWN) + PAIR(ENETUNREACH) + PAIR(ENETRESET) + PAIR(ECONNABORTED) + PAIR(ECONNRESET) + PAIR(ENOBUFS) + PAIR(EISCONN) + PAIR(ENOTCONN) + PAIR(ESHUTDOWN) + PAIR(ETOOMANYREFS) + PAIR(ETIMEDOUT) + PAIR(ECONNREFUSED) + PAIR(EHOSTDOWN) + PAIR(EHOSTUNREACH) + PAIR(EALREADY) + PAIR(EINPROGRESS) + PAIR(ESTALE) + PAIR(EUCLEAN) + PAIR(ENOTNAM) + PAIR(ENAVAIL) + PAIR(EISNAM) + PAIR(EREMOTEIO) + PAIR(EDQUOT) + PAIR(ENOMEDIUM) + PAIR(EMEDIUMTYPE) + PAIR(ECANCELED) + PAIR(ENOKEY) + PAIR(EKEYEXPIRED) + PAIR(EKEYREVOKED) + PAIR(EKEYREJECTED) + PAIR(EOWNERDEAD) + PAIR(ENOTRECOVERABLE) + PAIR(ERFKILL) +#ifdef EHWPOISON + PAIR(EHWPOISON) +#endif + }; + + PAIR_LOOKUP(errno_pairs, err); +} diff --git a/lib/tests/tst_checkpoint_child_exits.c b/lib/tests/tst_checkpoint_no_child.c similarity index 74% copy from lib/tests/tst_checkpoint_child_exits.c copy to lib/tests/tst_checkpoint_no_child.c index 3488ba2..fcf2745 100644 --- a/lib/tests/tst_checkpoint_child_exits.c +++ b/lib/tests/tst_checkpoint_no_child.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Cyril Hrubis <ch...@su...> + * Copyright (C) 2013 Linux Test Project * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -25,35 +25,23 @@ #include "test.h" -char *TCID = "tst_checkpoint_child_exits"; +char *TCID = "tst_checkpoint_no_child"; int TST_TOTAL = 1; +static void cleanup(void) +{ + tst_rmdir(); +} + int main(void) { - int pid; struct tst_checkpoint checkpoint; tst_tmpdir(); TST_CHECKPOINT_INIT(&checkpoint); + TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint); + fprintf(stderr, "Parent: checkpoint reached\n"); - pid = fork(); - - switch (pid) { - case -1: - tst_brkm(TBROK | TERRNO, NULL, "Fork failed"); - break; - case 0: - fprintf(stderr, "Child: exiting without signaling\n"); - exit(0); - break; - default: - TST_CHECKPOINT_PARENT_WAIT(NULL, &checkpoint); - fprintf(stderr, "Parent: checkpoint reached\n"); - break; - } - - wait(NULL); - tst_rmdir(); return 0; } diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c index 56c86b5..a581c36 100644 --- a/lib/tst_checkpoint.c +++ b/lib/tst_checkpoint.c @@ -33,6 +33,40 @@ #include "tst_checkpoint.h" +/* + * Issue open() on 'path' fifo with O_WRONLY flag and wait for + * a reader up to 'timeout' ms. + * + * Returns: + * >= 0 - file descriptor + * -1 - an error has occurred (errno is set accordingly) + * + */ +int open_wronly_timed(const char *path, unsigned int timeout) +{ + int fd; + int i; + int interval = 1; /* how often issue open(O_NONBLOCK), in ms */ + + for (i = 0; i < timeout; i += interval) { + fd = open(path, O_WRONLY | O_NONBLOCK); + if (fd < 0) { + if ((errno == ENXIO) || (errno == EINTR)) { + usleep(interval * 1000); + + continue; + } + + return -1; + } + + return fd; + } + + errno = ETIMEDOUT; + return -1; +} + void tst_checkpoint_init(const char *file, const int lineno, struct tst_checkpoint *self) { @@ -195,7 +229,7 @@ void tst_checkpoint_signal_child(const char *file, const int lineno, { int ret, fd; - fd = open(TST_CHECKPOINT_FIFO, O_WRONLY); + fd = open_wronly_timed(TST_CHECKPOINT_FIFO, self->timeout); if (fd < 0) { tst_brkm(TBROK | TERRNO, cleanup_fn, diff --git a/lib/tst_res.c b/lib/tst_res.c index f73022b..a24982e 100644 --- a/lib/tst_res.c +++ b/lib/tst_res.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * Copyright (c) 2009, 2012 Cyril Hrubis <ch...@su...> + * Copyright (c) 2009-2013 Cyril Hrubis <ch...@su...> * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -176,21 +176,21 @@ int tst_count = 0; /* current count of test cases executed; NOTE: */ */ extern char *TCID; /* Test case identifier from the test source */ extern int TST_TOTAL; /* Total number of test cases from the test */ - /* source */ + struct pair { const char *name; int val; }; -#define PAIR(def) [def] = { .name = #def, .val = def, }, -const char *pair_lookup(struct pair *pair, int pair_size, int idx) -{ - if (idx < 0 || idx >= pair_size || pair[idx].name == NULL) - return "???"; - return pair[idx].name; -} -#define pair_lookup(pair, idx) pair_lookup(pair, ARRAY_SIZE(pair), idx) +#define PAIR(def) [def] = {.name = #def, .val = def}, + +#define PAIR_LOOKUP(pair_arr, idx) do { \ + if (idx < 0 || idx >= ARRAY_SIZE(pair_arr) || \ + pair_arr[idx].name == NULL) \ + return "???"; \ + return pair_arr[idx].name; \ +} while (0) /* * strttype() - convert a type result to the human readable string @@ -199,65 +199,21 @@ const char *strttype(int ttype) { struct pair ttype_pairs[] = { PAIR(TPASS) - PAIR(TFAIL) - PAIR(TBROK) - PAIR(TRETR) - PAIR(TCONF) - PAIR(TWARN) - PAIR(TINFO) + PAIR(TFAIL) + PAIR(TBROK) + PAIR(TRETR) + PAIR(TCONF) + PAIR(TWARN) + PAIR(TINFO) }; - return pair_lookup(ttype_pairs, TTYPE_RESULT(ttype)); + + PAIR_LOOKUP(ttype_pairs, TTYPE_RESULT(ttype)); } /* - * strerrnodef() - convert an errno value to its C define + * Include table of errnos and strerrnodef() function. */ -static const char *strerrnodef(int err) -{ - struct pair errno_pairs[] = { - PAIR(EPERM) - PAIR(ENOENT) - PAIR(ESRCH) - PAIR(EINTR) - PAIR(EIO) - PAIR(ENXIO) - PAIR(E2BIG) - PAIR(ENOEXEC) - PAIR(EBADF) - PAIR(ECHILD) - PAIR(EAGAIN) - PAIR(ENOMEM) - PAIR(EACCES) - PAIR(EFAULT) - PAIR(ENOTBLK) - PAIR(EBUSY) - PAIR(EEXIST) - PAIR(EXDEV) - PAIR(ENODEV) - PAIR(ENOTDIR) - PAIR(EISDIR) - PAIR(EINVAL) - PAIR(ENFILE) - PAIR(EMFILE) - PAIR(ENOTTY) - PAIR(ETXTBSY) - PAIR(EFBIG) - PAIR(ENOSPC) - PAIR(ESPIPE) - PAIR(EROFS) - PAIR(EMLINK) - PAIR(EPIPE) - PAIR(EDOM) - PAIR(ERANGE) - PAIR(EDEADLK) - PAIR(ENAMETOOLONG) - PAIR(ENOLCK) - PAIR(ENOSYS) - PAIR(ENOTEMPTY) - PAIR(ELOOP) - }; - return pair_lookup(errno_pairs, err); -} +#include "errnos.h" /* * tst_res() - Main result reporting function. Handle test information hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-13 16:51:07
|
The branch, master, has been updated via 9b48608091e0b82620e4b35df768b1aeaae7ca0e (commit) from 119cf4a626d0a96dd106546987dff276c0e53acb (commit) - Log ----------------------------------------------------------------- commit 9b48608091e0b82620e4b35df768b1aeaae7ca0e Author: Siva Padhy <siv...@lg...> Date: Mon Nov 11 10:51:25 2013 +0900 BindMounts: fix to properly unmount during cleanup The fs_bind testcases creates the mount directories for testing. When the testcase exits, those directories were not properly unmounted. The reason of the issues are: 1. Some directories were kept mounted, even after the cleanup() routine, as the unmount code is missing. 2. Some "umount" command execution fails, as they are dependent on some other mounted directories. Error Report ------------ rbind/test02 1 TPASS : rbind/test02: PASSED /kvt.new/ltp/testscripts/test_fs_bind.sh 0 TWARN : rbind/test02 did not properly clean up "/tmp/ltp-XXXX9qdYqG/sandbox" rbind/test38 1 TPASS : rbind/test38: PASSED /kvt.new/ltp/testscripts/test_fs_bind.sh 0 TWARN : rbind/test38 did not properly clean up "/tmp/ltp-XXXX9qdYqG/sandbox" This patch add/reorder the unmount code to fix the above TWARN messages. Modified-by: Jan Stancek <jst...@re...> Signed-off-by: Siva <siv...@lg...> Tested-by: Jan Stancek <jst...@re...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/fs/fs_bind/rbind/test02 | 18 +++++++----------- testcases/kernel/fs/fs_bind/rbind/test38 | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/testcases/kernel/fs/fs_bind/rbind/test02 b/testcases/kernel/fs/fs_bind/rbind/test02 index 3ab7b6c..f68f691 100755 --- a/testcases/kernel/fs/fs_bind/rbind/test02 +++ b/testcases/kernel/fs/fs_bind/rbind/test02 @@ -1,5 +1,4 @@ #!/bin/bash - # # Copyright (c) International Business Machines Corp., 2005 # Author: Avantika Mathur (mat...@us...) @@ -38,9 +37,6 @@ trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LI while /bin/true ; do # This loop is for error recovery purposes only - - - "${FS_BIND_ROOT}/bin/makedir" share parent1 "${FS_BIND_ROOT}/bin/makedir" priv parent2 "${FS_BIND_ROOT}/bin/makedir" share share1 @@ -74,10 +70,10 @@ if [ -n "${ERR_MSG}" ]; then fi trap '' ERR { + umount parent2/child2/b umount parent1/child1/a - umount parent1/child1/b - umount parent1/child1 - umount parent1/child1 + umount parent2/child2 + umount share1 umount parent1/child1 umount parent1/child1 umount share1 @@ -90,11 +86,11 @@ trap '' ERR if [ $result -ne 0 ] then - tst_resm TFAIL "rbind/test02: FAILED: rbind: shared child to private parent." - exit 1 + tst_resm TFAIL "rbind/test02: FAILED: rbind: shared child to private parent." + exit 1 else - tst_resm TPASS "rbind/test02: PASSED" - exit 0 + tst_resm TPASS "rbind/test02: PASSED" + exit 0 fi diff --git a/testcases/kernel/fs/fs_bind/rbind/test38 b/testcases/kernel/fs/fs_bind/rbind/test38 index c9cf3e1..ae7477e 100755 --- a/testcases/kernel/fs/fs_bind/rbind/test38 +++ b/testcases/kernel/fs/fs_bind/rbind/test38 @@ -1,5 +1,4 @@ #!/bin/bash - # # Copyright (c) International Business Machines Corp., 2005 # Author: Avantika Mathur (mat...@us...) @@ -82,10 +81,11 @@ trap '' ERR umount parent1/child1 umount parent2/child1 umount parent2/child1 - umount parent2/child2 umount parent2 umount share1 umount share1 + umount share2 + umount parent2/child2 rm -rf parent* share* cleanup hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-13 15:51:20
|
The branch, master, has been updated via 119cf4a626d0a96dd106546987dff276c0e53acb (commit) via b6e703296d90dc094a780d7ad1435c968359e931 (commit) from 09bd9333e950d25c084c9c1c46ab0736e7fa9a86 (commit) - Log ----------------------------------------------------------------- commit 119cf4a626d0a96dd106546987dff276c0e53acb Author: Stanislav Kholmanskikh <sta...@or...> Date: Fri Nov 8 16:16:18 2013 +0400 msgctl{08, 09, 10, 11}: cleanup * Moved common functions, definitions to libmsgctl.h, libmsgctl.c. * Changed tst_* in the children with printf + exit (or return). * Some cleanup. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit b6e703296d90dc094a780d7ad1435c968359e931 Author: Stanislav Kholmanskikh <sta...@or...> Date: Fri Nov 8 16:16:17 2013 +0400 syscalls/ipc/Makefile.inc: changed LIB to LIBIPC Both lib.mk and testcases/kernel/syscalls/ipc/Makefile.inc set LIB. It confuses make when both failes are included into a leaf Makefile. Renamed LIB to LIBIPC in Makefile.inc. The idea is by Cyril Hrubis <ch...@su...> Signed-off-by: Stanislav Kholmanskikh <sta...@or...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/ipc/Makefile.inc | 6 +- testcases/kernel/syscalls/ipc/msgctl/Makefile | 15 + testcases/kernel/syscalls/ipc/msgctl/libmsgctl.c | 148 +++++++++ .../{swapon/libswapon.h => ipc/msgctl/libmsgctl.h} | 31 +- testcases/kernel/syscalls/ipc/msgctl/msgctl08.c | 282 ++++------------ testcases/kernel/syscalls/ipc/msgctl/msgctl09.c | 348 +++++--------------- testcases/kernel/syscalls/ipc/msgctl/msgctl10.c | 282 ++++------------ testcases/kernel/syscalls/ipc/msgctl/msgctl11.c | 339 +++++-------------- 8 files changed, 500 insertions(+), 951 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/msgctl/libmsgctl.c copy testcases/kernel/syscalls/{swapon/libswapon.h => ipc/msgctl/libmsgctl.h} (62%) diff --git a/testcases/kernel/syscalls/ipc/Makefile.inc b/testcases/kernel/syscalls/ipc/Makefile.inc index a468e93..c7890a9 100644 --- a/testcases/kernel/syscalls/ipc/Makefile.inc +++ b/testcases/kernel/syscalls/ipc/Makefile.inc @@ -25,15 +25,15 @@ LDLIBS += -lipc LIBDIR := ../lib -LIB := $(LIBDIR)/libipc.a +LIBIPC := $(LIBDIR)/libipc.a $(LIBDIR): mkdir -p "$@" -$(LIB): $(LIBDIR) +$(LIBIPC): $(LIBDIR) $(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all -MAKE_DEPS := $(LIB) +MAKE_DEPS := $(LIBIPC) CPPFLAGS += -I$(abs_srcdir)/$(LIBDIR) diff --git a/testcases/kernel/syscalls/ipc/msgctl/Makefile b/testcases/kernel/syscalls/ipc/msgctl/Makefile index f467389..aedfda6 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/Makefile +++ b/testcases/kernel/syscalls/ipc/msgctl/Makefile @@ -19,5 +19,20 @@ top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk + +LIBSRCS := libmsgctl.c +INTERNAL_LIB := libmsgctl.a + +LDFLAGS += -L$(abs_builddir) +LDLIBS += -lmsgctl + +MAKE_TARGETS := $(patsubst %.c,%,$(wildcard msgctl??.c)) +MAKE_TARGET_OBJS := $(addsuffix .o,$(MAKE_TARGETS)) + +$(MAKE_TARGET_OBJS): $(INTERNAL_LIB) + +.INTERMEDIATE: $(MAKE_TARGET_OBJS) + include $(abs_srcdir)/../Makefile.inc +include $(top_srcdir)/include/mk/lib.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/msgctl/libmsgctl.c b/testcases/kernel/syscalls/ipc/msgctl/libmsgctl.c new file mode 100644 index 0000000..fa77b56 --- /dev/null +++ b/testcases/kernel/syscalls/ipc/msgctl/libmsgctl.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) International Business Machines Corp., 2002 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include "libmsgctl.h" + +int doreader(long key, int tid, long type, int child, int nreps) +{ + int i, size; + int id; + struct mbuffer buffer; + + id = msgget(key, 0); + if (id < 0) { + printf("msgget() error in the reader of child group %d: %s\n", + child, strerror(errno)); + + return FAIL; + } + if (id != tid) { + printf("Message queue mismatch in the reader of child group %d for message queue id %d\n", + child, id); + + return FAIL; + } + for (i = 0; i < nreps; i++) { + memset(&buffer, 0, sizeof(buffer)); + + size = msgrcv(id, &buffer, 100, type, 0); + if (size < 0) { + printf("msgrcv() error in child %d, read # = %d: %s\n", + child, (i + 1), strerror(errno)); + + return FAIL; + } + if (buffer.type != type) { + printf("Type mismatch in child %d, read #d = %d: ", + child, (i + 1)); + printf("for message got %ld, expected - %ld\n", + buffer.type, type); + + return FAIL; + } + if (buffer.data.len + 1 != size) { + printf("Size mismatch in child %d, read # = %d: ", + child, (i + 1)); + printf("for message got %d, expected - %d\n", + buffer.data.len + 1, size); + + return FAIL; + } + if (verify(buffer.data.pbytes, (key % 255), size - 1, child)) { + printf("Verify failed in child %d read # = %d, key = %lx\n", + child, (i + 1), key); + + return FAIL; + } + key++; + } + return PASS; +} + +int dowriter(long key, int tid, long type, int child, int nreps) +{ + int i, size; + int id; + struct mbuffer buffer; + + id = msgget(key, 0); + if (id < 0) { + printf("msgget() error in the writer of child group %d: %s\n", + child, strerror(errno)); + + return FAIL; + } + if (id != tid) { + printf("Message queue mismatch in the reader of child group %d for message queue id %d\n", + child, id); + + return FAIL; + } + + for (i = 0; i < nreps; i++) { + memset(&buffer, 0, sizeof(buffer)); + + do { + size = (lrand48() % 99); + } while (size == 0); + fill_buffer(buffer.data.pbytes, (key % 255), size); + buffer.data.len = size; + buffer.type = type; + if (msgsnd(id, &buffer, size + 1, 0) < 0) { + printf("msgsnd() error in child %d, write # = %d, key = %lx: %s\n", + child, nreps, key, strerror(errno)); + + return FAIL; + } + key++; + } + return PASS; +} + +int fill_buffer(char *buf, char val, int size) +{ + int i; + + for (i = 0; i < size; i++) + buf[i] = val; + return 0; +} + +/* Check a buffer for correct values */ +int verify(char *buf, char val, int size, int child) +{ + while (size-- > 0) { + if (*buf++ != val) { + printf("Verify error in child %d, *buf = %x, val = %x, size = %d\n", + child, *buf, val, size); + + return FAIL; + } + } + return PASS; +} + diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/ipc/msgctl/libmsgctl.h similarity index 62% copy from testcases/kernel/syscalls/swapon/libswapon.h copy to testcases/kernel/syscalls/ipc/msgctl/libmsgctl.h index 7f7211e..e1afeab 100644 --- a/testcases/kernel/syscalls/swapon/libswapon.h +++ b/testcases/kernel/syscalls/ipc/msgctl/libmsgctl.h @@ -1,4 +1,5 @@ /* + * Copyright (c) International Business Machines Corp., 2002 * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. * * This program is free software; you can redistribute it and/or @@ -14,21 +15,25 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: Stanislav Kholmanskikh <sta...@or...> - * */ -/* - * Contains common content for all swapon tests - */ +#ifndef __LIBMSGCTL_H__ +#define __LIBMSGCTL_H__ -#ifndef __LIBSWAPON_H__ -#define __LIBSWAPON_H__ +#define FAIL 1 +#define PASS 0 -/* - * Make a swap file - */ -void make_swapfile(void (cleanup)(void), const char *swapfile); +struct mbuffer { + long type; + struct { + char len; + char pbytes[99]; + } data; +}; + +int doreader(long key, int tid, long type, int child, int nreps); +int dowriter(long key, int tid, long type, int child, int nreps); +int fill_buffer(char *buf, char val, int size); +int verify(char *buf, char val, int size, int child); -#endif /* __LIBSWAPON_H__ */ +#endif /*__LIBMSGCTL_H__ */ diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c index f733946..0999059 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl08.c @@ -1,37 +1,26 @@ /* + * Copyright (c) International Business Machines Corp., 2002 * - * Copyright (c) International Business Machines Corp., 2002 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 06/30/2001 Port to Linux nsh...@us... + * 11/06/2002 Port to LTP dba...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ -/* 11/06/2002 Port to LTP dba...@us... */ - /* - * NAME - * msgctl08 - * - * CALLS - * msgget(2) msgctl(2) - * - * ALGORITHM - * Get and manipulate a message queue. - * - * RESTRICTIONS - * + * Get and manipulate a message queue. */ #define _XOPEN_SOURCE 500 @@ -51,17 +40,10 @@ #include "test.h" #include "usctest.h" #include "ipcmsg.h" +#include "libmsgctl.h" -void setup(); -void cleanup(); -/* - * * * * These globals must be defined in the test. - * * * */ - -char *TCID = "msgctl08"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ - -int exp_enos[] = { 0 }; /* List must end with 0 */ +char *TCID = "msgctl08"; +int TST_TOTAL = 1; #ifndef CONFIG_COLDFIRE #define MAXNPROCS 1000000 /* This value is set to an arbitrary high limit. */ @@ -69,48 +51,34 @@ int exp_enos[] = { 0 }; /* List must end with 0 */ #define MAXNPROCS 100000 /* Coldfire can't deal with 1000000 */ #endif #define MAXNREPS 100000 -#define FAIL 1 -#define PASS 0 - -key_t keyarray[MAXNPROCS]; - -struct { - long type; - struct { - char len; - char pbytes[99]; - } data; -} buffer; - -int pidarray[MAXNPROCS]; -int tid; -int MSGMNI, nprocs, nreps; -int procstat; -int dotest(key_t key, int child_process); -int doreader(int id, long key, int child); -int dowriter(int id, long key, int child); -int fill_buffer(register char *buf, char val, register int size); -int verify(register char *buf, char val, register int size, int child); -void sig_handler(); /* signal catching function */ -int mykid; + +static key_t keyarray[MAXNPROCS]; +static int pidarray[MAXNPROCS]; +static int tid; +static int MSGMNI, nprocs, nreps; +static int procstat; +static int mykid; + +void setup(void); +void cleanup(void); + +static int dotest(key_t key, int child_process); +static void sig_handler(); + #ifdef UCLINUX static char *argv0; - -void do_child_1_uclinux(); static key_t key_uclinux; static int i_uclinux; - -void do_child_2_uclinux(); static int id_uclinux; static int child_process_uclinux; + +static void do_child_1_uclinux(void); +static void do_child_2_uclinux(void); #endif -/*-----------------------------------------------------------------*/ -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char **argv) { - register int i, j, ok, pid; + int i, j, ok, pid; int count, status; struct sigaction act; @@ -162,7 +130,7 @@ char *argv[]; srand(getpid()); tid = -1; - /* Setup signal handleing routine */ + /* Setup signal handling routine */ memset(&act, 0, sizeof(act)); act.sa_handler = sig_handler; sigemptyset(&act.sa_mask); @@ -255,190 +223,94 @@ char *argv[]; } -/*--------------------------------------------------------------------*/ - #ifdef UCLINUX -void do_child_1_uclinux() +static void do_child_1_uclinux(void) { procstat = 1; exit(dotest(key_uclinux, i_uclinux)); } -void do_child_2_uclinux() +static void do_child_2_uclinux(void) { - exit(doreader(id_uclinux, key_uclinux % 255, child_process_uclinux)); + exit(doreader(key_uclinux, id_uclinux, 1, + child_process_uclinux, nreps)); } #endif -int dotest(key, child_process) -key_t key; -int child_process; +static int dotest(key_t key, int child_process) { int id, pid; + int ret, status; sighold(SIGTERM); TEST(msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, "Msgget error in child %d", - child_process); - tst_exit(); + printf("msgget() error in child %d: %s\n", + child_process, strerror(TEST_ERRNO)); + + return FAIL; } tid = id = TEST_RETURN; sigrelse(SIGTERM); fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, "\tFork failed (may be OK if under stress)"); + printf("\tFork failed (may be OK if under stress)\n"); TEST(msgctl(tid, IPC_RMID, 0)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, "Msgctl error in cleanup"); + printf("mscgtl() error in cleanup: %s\n", + strerror(TEST_ERRNO)); } - tst_exit(); + return FAIL; } /* Child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 2, id, key, child_process) < 0) { - tst_resm(TWARN, "self_exec failed"); + printf("self_exec failed\n"); TEST(msgctl(tid, IPC_RMID, 0)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, - "Msgctl error in cleanup"); + printf("msgctl() error in cleanup: %s\n", + strerror(errno)); } - tst_exit(); + return FAIL; } #else - exit(doreader(id, key % 255, child_process)); + exit(doreader(key, id, 1, child_process, nreps)); #endif } /* Parent does this */ mykid = pid; procstat = 2; - dowriter(id, key % 255, child_process); - wait(0); - TEST(msgctl(id, IPC_RMID, 0)); - if (TEST_RETURN < 0) { - tst_resm(TFAIL, "msgctl errno %d", TEST_ERRNO); - tst_exit(); - } - exit(PASS); -} + ret = dowriter(key, id, 1, child_process, nreps); + wait(&status); -int doreader(id, key, child) -int id, child; -long key; -{ - int i, size; + if (ret != PASS) + exit(FAIL); - for (i = 0; i < nreps; i++) { - if ((size = msgrcv(id, &buffer, 100, 0, 0)) < 0) { - tst_brkm(TBROK | TERRNO, cleanup, - "Msgrcv error in child %d, read # = %d", - (i + 1), child); - tst_exit(); - } - if (buffer.data.len + 1 != size) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d", - child, (i + 1)); - tst_resm(TFAIL, - "for message size got %d expected %d", - size, buffer.data.len); - tst_exit(); - } - if (verify(buffer.data.pbytes, key, size - 1, child)) { - tst_resm(TFAIL, "in child %d read # = %d,key = %lx", - child, (i + 1), key); - tst_exit(); - } - key++; - } - return (0); -} - -int dowriter(id, key, child) -int id, child; -long key; -{ - int i, size; - - for (i = 0; i < nreps; i++) { - do { - size = (rand() % 99); - } while (size == 0); - fill_buffer(buffer.data.pbytes, key, size); - buffer.data.len = size; - buffer.type = 1; - TEST(msgsnd(id, &buffer, size + 1, 0)); - if (TEST_RETURN < 0) { - tst_brkm(TBROK | TTERRNO, cleanup, - "Msgsnd error in child %d, key = %lx", - child, key); - } - key++; - } - return (0); -} - -int fill_buffer(buf, val, size) -register char *buf; -char val; -register int size; -{ - register int i; - - for (i = 0; i < size; i++) { - buf[i] = val; - } - - return (0); -} + if ((!WIFEXITED(status) || (WEXITSTATUS(status) != PASS))) + exit(FAIL); -/* - * verify() - * Check a buffer for correct values. - */ + TEST(msgctl(id, IPC_RMID, 0)); + if (TEST_RETURN < 0) { + printf("msgctl() errno %d: %s\n", + TEST_ERRNO, strerror(TEST_ERRNO)); -int verify(buf, val, size, child) -register char *buf; -char val; -register int size; -int child; -{ - while (size-- > 0) { - if (*buf++ != val) { - tst_resm(TWARN, - "Verify error in child %d, *buf = %x, val = %x, size = %d", - child, *buf, val, size); - return (FAIL); - } + return FAIL; } - return (PASS); + return PASS; } -/* - * * void - * * sig_handler() - signal catching function for 'SIGUSR1' signal. - * * - * * This is a null function and used only to catch the above signal - * * generated in parent process. - * */ -void sig_handler() +static void sig_handler(void) { } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - *****************************************************************/ -void setup() +void setup(void) { int nr_msgqs; tst_tmpdir(); - /* You will want to enable some signal handling so you can capture - * unexpected signals like SIGSEGV. - */ tst_sig(FORK, DEF_HANDLER, cleanup); /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to @@ -466,11 +338,7 @@ void setup() MSGMNI = min(nr_msgqs, NR_MSGQUEUES); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ****************************************************************/ -void cleanup() +void cleanup(void) { int status; /* @@ -488,11 +356,7 @@ void cleanup() } fflush(stdout); - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ + TEST_CLEANUP; tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c index bec852a..c019226 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl09.c @@ -1,37 +1,26 @@ /* + * Copyright (c) International Business Machines Corp., 2002 * - * Copyright (c) International Business Machines Corp., 2002 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 06/30/2001 Port to Linux nsh...@us... + * 11/11/2002 Port to LTP dba...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ -/* 11/11/2002 Port to LTP dba...@us... */ - /* - * NAME - * msgctl09 - * - * CALLS - * msgget(2) msgctl(2) msgop(2) - * - * ALGORITHM - * Get and manipulate a message queue. - * - * RESTRICTIONS - * + * Get and manipulate a message queue. */ #define _XOPEN_SOURCE 500 @@ -49,6 +38,10 @@ #include "test.h" #include "usctest.h" #include "ipcmsg.h" +#include "libmsgctl.h" + +char *TCID = "msgctl09"; +int TST_TOTAL = 1; #define MAXNREPS 1000 #ifndef CONFIG_COLDFIRE @@ -57,65 +50,39 @@ #define MAXNPROCS 100000 /* Coldfire can't deal with 1000000 */ #endif #define MAXNKIDS 10 -#define FAIL 1 -#define PASS 0 -int dotest(key_t, int); -int doreader(long, int, int); -int dowriter(long, int, int); -int fill_buffer(char *, char, int); -int verify(char *, char, int, int); -void setup(); -void cleanup(); +static key_t keyarray[MAXNPROCS]; +static int pidarray[MAXNPROCS]; +static int rkidarray[MAXNKIDS]; +static int wkidarray[MAXNKIDS]; +static int tid; +static int nprocs, nreps, nkids, MSGMNI; +static int procstat; + +void setup(void); +void cleanup(void); + +static void term(int); +static int dotest(key_t, int); +static void cleanup_msgqueue(int i, int tid); -/* - * These globals must be defined in the test. - * */ - -char *TCID = "msgctl09"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ - -int exp_enos[] = { 0 }; /* List must end with 0 */ - -key_t keyarray[MAXNPROCS]; - -struct { - long type; - struct { - char len; - char pbytes[99]; - } data; -} buffer; - -int pidarray[MAXNPROCS]; -int rkidarray[MAXNKIDS]; -int wkidarray[MAXNKIDS]; -int tid; -int nprocs, nreps, nkids, MSGMNI; -int procstat; -void term(int); #ifdef UCLINUX static char *argv0; - -void do_child_1_uclinux(); static key_t key_uclinux; static int i_uclinux; - -void do_child_2_uclinux(); static int pid_uclinux; static int child_process_uclinux; - -void do_child_3_uclinux(); static int rkid_uclinux; + + +static void do_child_1_uclinux(void); +static void do_child_2_uclinux(void); +static void do_child_3_uclinux(void); #endif -void cleanup_msgqueue(int i, int tid); -/*-----------------------------------------------------------------*/ -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char **argv) { - register int i, j, ok, pid; + int i, j, ok, pid; int count, status; #ifdef UCLINUX @@ -205,7 +172,6 @@ char *argv[]; } } while (ok == 0); } -/*-----------------------------------------------------------------*/ /* Fork a number of processes (nprocs), each of which will * create a message queue with several (nkids) reader/writer * pairs which will read and write a number (iterations) @@ -268,29 +234,29 @@ char *argv[]; } -/*--------------------------------------------------------------------*/ - #ifdef UCLINUX -void do_child_1_uclinux() +static void do_child_1_uclinux(void) { procstat = 1; exit(dotest(key_uclinux, i_uclinux)); } -void do_child_2_uclinux() +static void do_child_2_uclinux(void) { procstat = 2; - exit(doreader(key_uclinux, pid_uclinux, child_process_uclinux)); + exit(doreader(key_uclinux, tid, pid_uclinux, + child_process_uclinux, nreps)); } -void do_child_3_uclinux() +static void do_child_3_uclinux(void) { procstat = 2; - exit(dowriter(key_uclinux, rkid_uclinux, child_process_uclinux)); + exit(dowriter(key_uclinux, tid, rkid_uclinux, + child_process_uclinux, nreps)); } #endif -void cleanup_msgqueue(int i, int tid) +static void cleanup_msgqueue(int i, int tid) { /* * Decrease the value of i by 1 because it @@ -313,18 +279,16 @@ void cleanup_msgqueue(int i, int tid) } } -int dotest(key, child_process) -key_t key; -int child_process; +static int dotest(key_t key, int child_process) { int id, pid; int i, count, status, exit_status; sighold(SIGTERM); if ((id = msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0) { - tst_resm(TFAIL | TERRNO, "Msgget error in child %d", - child_process); - tst_exit(); + printf("msgget() error in child %d: %s\n", + child_process, strerror(errno)); + return FAIL; } tid = id; sigrelse(SIGTERM); @@ -334,58 +298,58 @@ int child_process; for (i = 0; i < nkids; i++) { fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, - "Fork failure in first child of child group %d", - child_process); + printf("Fork failure in the first child of child group %d\n", + child_process); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } /* First child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 2, key, getpid(), child_process) < 0) { - tst_resm(TWARN, "self_exec failed"); + printf("self_exec failed\n"); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } #else procstat = 2; - exit(doreader(key, getpid(), child_process)); + exit(doreader(key, tid, getpid(), + child_process, nreps)); #endif } rkidarray[i] = pid; fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, - "Fork failure in first child of child group %d", - child_process); + printf("Fork failure in the second child of child group %d\n", + child_process); /* * Kill the reader child process */ (void)kill(rkidarray[i], SIGKILL); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } /* Second child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 3, key, rkidarray[i], child_process) < 0) { - tst_resm(TWARN, "\tFork failure in first child " - "of child group %d \n", child_process); + printf("\tFork failure in the first child of child group %d\n", + child_process); /* * Kill the reader child process */ (void)kill(rkidarray[i], SIGKILL); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } #else procstat = 2; - exit(dowriter(key, rkidarray[i], child_process)); + exit(dowriter(key, tid, rkidarray[i], + child_process, nreps)); #endif } wkidarray[i] = pid; @@ -395,18 +359,17 @@ int child_process; while (1) { if ((wait(&status)) > 0) { if (status >> 8 != PASS) { - tst_resm(TFAIL, - "Child exit status = %d from child group %d", - status >> 8, child_process); + printf("Child exit status = %d from child group %d\n", + status >> 8, child_process); for (i = 0; i < nkids; i++) { kill(rkidarray[i], SIGTERM); kill(wkidarray[i], SIGTERM); } if (msgctl(tid, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgctl error"); + printf("msgctl() error: %s\n", + strerror(errno)); } - tst_exit(); + return FAIL; } count++; } else { @@ -417,146 +380,23 @@ int child_process; } /* Make sure proper number of children exited */ if (count != (nkids * 2)) { - tst_resm(TFAIL, - "Wrong number of children exited in child group %d, Saw %d Expected %d", - child_process, count, (nkids * 2)); + printf("Wrong number of children exited in child group %d, saw %d, expected %d\n", + child_process, count, (nkids * 2)); if (msgctl(tid, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, "Msgctl error"); + printf("msgctl() error: %s\n", strerror(errno)); } - tst_exit(); + return FAIL; } if (msgctl(id, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, "Msgctl failure in child group %d", - child_process); - tst_exit(); - } - exit(exit_status); -} - -int doreader(key, type, child) -int type, child; -long key; -{ - int i, size; - int id; - - if ((id = msgget(key, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgget error in reader of child group %d", child); - tst_exit(); - } - if (id != tid) { - tst_resm(TFAIL, - "Message queue mismatch in reader of child group %d for message queue id %d", - child, id); - tst_exit(); - } - for (i = 0; i < nreps; i++) { - if ((size = msgrcv(id, &buffer, 100, type, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgrcv error in child %d, read # = %d", - (i + 1), child); - tst_exit(); - } - if (buffer.type != type) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d", - child, (i + 1)); - tst_resm(TFAIL, - "\tfor message size got %d expected %d", - size, buffer.data.len); - tst_exit(); - } - if (buffer.data.len + 1 != size) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d, size = %d, expected = %d", - child, (i + 1), buffer.data.len, size); - tst_exit(); - } - if (verify(buffer.data.pbytes, (key % 255), size - 1, child)) { - tst_resm(TFAIL, "in child %d read # = %d,key = %lx", - child, (i + 1), key); - tst_exit(); - } - key++; - } - exit(PASS); -} - -int dowriter(key, type, child) -int type, child; -long key; -{ - int i, size; - int id; - - if ((id = msgget(key, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgget error in writer of child group %d", child); - tst_exit(); - } - if (id != tid) { - tst_resm(TFAIL, - "Message queue mismatch in writer of child group %d", - child); - tst_resm(TFAIL, "\tfor message queue id %d expected %d", id, - tid); - tst_exit(); - } - - for (i = 0; i < nreps; i++) { - do { - size = (lrand48() % 99); - } while (size == 0); - fill_buffer(buffer.data.pbytes, (key % 255), size); - buffer.data.len = size; - buffer.type = type; - if (msgsnd(id, &buffer, size + 1, 0) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgsnd error in child %d, key = %lx", - child, key); - tst_exit(); - } - key++; + printf("msgctl() failure in child group %d: %s\n", + child_process, strerror(errno)); + return FAIL; } - exit(PASS); -} - -int fill_buffer(buf, val, size) -register char *buf; -char val; -register int size; -{ - register int i; - - for (i = 0; i < size; i++) - buf[i] = val; - return 0; -} - -/* - * verify() - * Check a buffer for correct values. - */ - -int verify(buf, val, size, child) -register char *buf; -char val; -register int size; -int child; -{ - while (size-- > 0) - if (*buf++ != val) { - tst_resm(TWARN, - "Verify error in child %d, *buf = %x, val = %x, size = %d", - child, *buf, val, size); - return (FAIL); - } - return (PASS); + return exit_status; } /* ARGSUSED */ -void term(int sig) +static void term(int sig) { int i; @@ -567,9 +407,8 @@ void term(int sig) for (i = 0; i < nprocs; i++) { if (pidarray[i] > 0) { if (kill(pidarray[i], SIGTERM) < 0) { - tst_resm(TBROK, - "Kill failed to kill child %d", - i); + printf("Kill failed to kill child %d", + i); exit(FAIL); } } @@ -593,17 +432,12 @@ void term(int sig) } } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - *****************************************************************/ -void setup() +void setup(void) { int nr_msgqs; tst_tmpdir(); - /* You will want to enable some signal handling so you can capture - * unexpected signals like SIGSEGV. - */ + tst_sig(FORK, DEF_HANDLER, cleanup); /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to @@ -631,17 +465,10 @@ void setup() MSGMNI = min(nr_msgqs, NR_MSGQUEUES); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ****************************************************************/ -void cleanup() +void cleanup(void) { int status; - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ + TEST_CLEANUP; /* @@ -660,5 +487,4 @@ void cleanup() fflush(stdout); tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl10.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl10.c index 895a319..860419f 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl10.c +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl10.c @@ -1,38 +1,27 @@ /* + * Copyright (c) International Business Machines Corp., 2002 * - * Copyright (c) International Business Machines Corp., 2002 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 06/30/2001 Port to Linux nsh...@us... + * 11/06/2002 Port to LTP dba...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ -/* 11/06/2002 Port to LTP dba...@us... */ - /* - * NAME - * msgctl10 - * - * CALLS - * msgget(2) msgctl(2) - * - * ALGORITHM - * Get and manipulate a message queue. - * Same as msgctl08 but gets the actual msgmni value under procfs. - * - * RESTRICTIONS - * + * Get and manipulate a message queue. + * Same as msgctl08 but gets the actual msgmni value under procfs. */ #define _XOPEN_SOURCE 500 @@ -52,62 +41,41 @@ #include "test.h" #include "usctest.h" #include "ipcmsg.h" +#include "libmsgctl.h" -void setup(); -void cleanup(); -/* - * * * * These globals must be defined in the test. - * * * */ - -char *TCID = "msgctl10"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ - -int exp_enos[] = { 0 }; /* List must end with 0 */ +char *TCID = "msgctl10"; +int TST_TOTAL = 1; #define MAXNPROCS 10000 /*These should be sufficient */ #define MAXNREPS 10000 /*Else they srewup the system un-necessarily */ -#define FAIL 1 -#define PASS 0 - -key_t keyarray[MAXNPROCS]; - -struct { - long type; - struct { - char len; - char pbytes[99]; - } data; -} buffer; - -int pidarray[MAXNPROCS]; -int tid; -int MSGMNI, nprocs, nreps; -int procstat; -int dotest(key_t key, int child_process); -int doreader(int id, long key, int child); -int dowriter(int id, long key, int child); -int fill_buffer(register char *buf, char val, register int size); -int verify(register char *buf, char val, register int size, int child); -void sig_handler(); /* signal catching function */ -int mykid; + +static key_t keyarray[MAXNPROCS]; +static int pidarray[MAXNPROCS]; +static int tid; +static int MSGMNI, nprocs, nreps; +static int procstat; +static int mykid; + +void setup(void); +void cleanup(void); + +static int dotest(key_t key, int child_process); +static void sig_handler(int signo); + #ifdef UCLINUX static char *argv0; - -void do_child_1_uclinux(); static key_t key_uclinux; static int i_uclinux; - -void do_child_2_uclinux(); static int id_uclinux; static int child_process_uclinux; + +static void do_child_1_uclinux(void); +static void do_child_2_uclinux(void); #endif -/*-----------------------------------------------------------------*/ -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char **argv) { - register int i, j, ok, pid; + int i, j, ok, pid; int count, status; struct sigaction act; @@ -159,7 +127,7 @@ char *argv[]; srand(getpid()); tid = -1; - /* Setup signal handleing routine */ + /* Setup signal handling routine */ memset(&act, 0, sizeof(act)); act.sa_handler = sig_handler; sigemptyset(&act.sa_mask); @@ -249,188 +217,92 @@ char *argv[]; } -/*--------------------------------------------------------------------*/ - #ifdef UCLINUX -void do_child_1_uclinux() +static void do_child_1_uclinux(void) { procstat = 1; exit(dotest(key_uclinux, i_uclinux)); } -void do_child_2_uclinux() +static void do_child_2_uclinux(void) { - exit(doreader(id_uclinux, key_uclinux % 255, child_process_uclinux)); + exit(doreader(key_uclinux, id_uclinux, 1, + child_process_uclinux, nreps)); } #endif -int dotest(key, child_process) -key_t key; -int child_process; +static int dotest(key_t key, int child_process) { int id, pid; + int ret, status; sighold(SIGTERM); TEST(msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, "Msgget error in child %d", - child_process); - tst_exit(); + printf("msgget() error in child %d: %s\n", + child_process, strerror(TEST_ERRNO)); + return FAIL; } tid = id = TEST_RETURN; sigrelse(SIGTERM); fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, "\tFork failed (may be OK if under stress)"); + printf("Fork failed (may be OK if under stress)\n"); TEST(msgctl(tid, IPC_RMID, 0)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, "Msgctl error in cleanup"); + printf("msgctl() error in cleanup: %s\n", + strerror(TEST_ERRNO)); } - tst_exit(); + return FAIL; } /* Child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 2, id, key, child_process) < 0) { - tst_resm(TWARN, "self_exec failed"); + printf("self_exec failed\n"); TEST(msgctl(tid, IPC_RMID, 0)); if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, - "Msgctl error in cleanup"); + printf("msgctl() error in cleanup: %s\n", + strerror(TEST_ERRNO)); } - tst_exit(); + return FAIL; } #else - exit(doreader(id, key % 255, child_process)); + exit(doreader(key, id, 1, child_process, nreps)); #endif } /* Parent does this */ mykid = pid; procstat = 2; - dowriter(id, key % 255, child_process); - wait(0); - TEST(msgctl(id, IPC_RMID, 0)); - if (TEST_RETURN < 0) { - tst_resm(TFAIL | TTERRNO, "msgctl failed"); - tst_exit(); - } - exit(PASS); -} + ret = dowriter(key, id, 1, child_process, nreps); + wait(&status); -int doreader(int id, long key, int child) -{ - int i, size; + if (ret != PASS) + exit(FAIL); - for (i = 0; i < nreps; i++) { - if ((size = msgrcv(id, &buffer, 100, 0, 0)) < 0) { - tst_brkm(TBROK | TERRNO, cleanup, - "Msgrcv error in child %d, read # = %d", - (i + 1), child); - tst_exit(); - } - if (buffer.data.len + 1 != size) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d", - child, (i + 1)); - tst_resm(TFAIL, - "for message size got %d expected %d", - size, buffer.data.len); - tst_exit(); - } - if (verify(buffer.data.pbytes, key, size - 1, child)) { - tst_resm(TFAIL, "in child %d read # = %d,key = %lx", - child, (i + 1), key); - tst_exit(); - } - key++; - } - return (0); -} - -int dowriter(id, key, child) -int id, child; -long key; -{ - int i, size; - - for (i = 0; i < nreps; i++) { - do { - size = (rand() % 99); - } while (size == 0); - fill_buffer(buffer.data.pbytes, key, size); - buffer.data.len = size; - buffer.type = 1; - TEST(msgsnd(id, &buffer, size + 1, 0)); - if (TEST_RETURN < 0) { - tst_brkm(TBROK | TTERRNO, cleanup, - "Msgsnd error in child %d, key = %lx", - child, key); - } - key++; - } - return (0); -} - -int fill_buffer(buf, val, size) -register char *buf; -char val; -register int size; -{ - register int i; - - for (i = 0; i < size; i++) { - buf[i] = val; - } + if ((!WIFEXITED(status) || (WEXITSTATUS(status) != PASS))) + exit(FAIL); - return (0); -} - -/* - * verify() - * Check a buffer for correct values. - */ - -int verify(buf, val, size, child) -register char *buf; -char val; -register int size; -int child; -{ - while (size-- > 0) { - if (*buf++ != val) { - tst_resm(TWARN, - "Verify error in child %d, *buf = %x, val = %x, size = %d", - child, *buf, val, size); - return (FAIL); - } + TEST(msgctl(id, IPC_RMID, 0)); + if (TEST_RETURN < 0) { + printf("msgctl() failed: %s\n", + strerror(TEST_ERRNO)); + return FAIL; } - return (PASS); + return PASS; } -/* - * * void - * * sig_handler() - signal catching function for 'SIGUSR1' signal. - * * - * * This is a null function and used only to catch the above signal - * * generated in parent process. - * */ -void sig_handler() +static void sig_handler(int signo) { } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - *****************************************************************/ -void setup() +void setup(void) { int nr_msgqs; tst_tmpdir(); - /* You will want to enable some signal handling so you can capture - * unexpected signals like SIGSEGV. - */ tst_sig(FORK, DEF_HANDLER, cleanup); /* One cavet that hasn't been fixed yet. TEST_PAUSE contains the code to @@ -453,11 +325,7 @@ void setup() } } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ****************************************************************/ -void cleanup() +void cleanup(void) { int status; /* @@ -475,11 +343,7 @@ void cleanup() } fflush(stdout); - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ + TEST_CLEANUP; tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c index 82ad2d3..9b21df8 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl11.c @@ -1,38 +1,27 @@ /* + * Copyright (c) International Business Machines Corp., 2002 * - * Copyright (c) International Business Machines Corp., 2002 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 06/30/2001 Port to Linux nsh...@us... + * 11/11/2002 Port to LTP dba...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ -/* 11/11/2002 Port to LTP dba...@us... */ - /* - * NAME - * msgctl11 - * - * CALLS - * msgget(2) msgctl(2) msgop(2) - * - * ALGORITHM - * Get and manipulate a message queue. - * Same as msgctl09 but gets the actual msgmni value under procfs. - * - * RESTRICTIONS - * + * Get and manipulate a message queue. + * Same as msgctl09 but gets the actual msgmni value under procfs. */ #define _XOPEN_SOURCE 500 @@ -50,8 +39,12 @@ #include "test.h" #include "usctest.h" #include "ipcmsg.h" +#include "libmsgctl.h" #include "system_specific_process_info.h" +char *TCID = "msgctl11"; +int TST_TOTAL = 1; + #define MAXNREPS 1000 #ifndef CONFIG_COLDFIRE #define MAXNPROCS 1000000 /* This value is set to an arbitrary high limit. */ @@ -59,67 +52,39 @@ #define MAXNPROCS 100000 /* Coldfire can't deal with 1000000 */ #endif #define MAXNKIDS 10 -#define FAIL 1 -#define PASS 0 - -int dotest(key_t, int); -int doreader(long, int, int); -int dowriter(long, int, int); -int fill_buffer(char *, char, int); -int verify(char *, char, int, int); -void setup(); -void cleanup(); - -/* - * These globals must be defined in the test. - * */ - -char *TCID = "msgctl11"; /* Test program identifier. */ -int TST_TOTAL = 1; /* Total number of test cases. */ -int exp_enos[] = { 0 }; /* List must end with 0 */ +static int maxnkids = MAXNKIDS; /* Used if pid_max is exceeded */ +static key_t keyarray[MAXNPROCS]; +static int pidarray[MAXNPROCS]; +static int rkidarray[MAXNKIDS]; +static int wkidarray[MAXNKIDS]; +static int tid; +static int nprocs, nreps, nkids, MSGMNI; +static int procstat; -int maxnkids = MAXNKIDS; /* Used if pid_max is exceeded */ +void setup(void); +void cleanup(void); -key_t keyarray[MAXNPROCS]; +static void term(int); +static int dotest(key_t, int); +static void cleanup_msgqueue(int i, int tid); -struct { - long type; - struct { - char len; - char pbytes[99]; - } data; -} buffer; - -int pidarray[MAXNPROCS]; -int rkidarray[MAXNKIDS]; -int wkidarray[MAXNKIDS]; -int tid; -int nprocs, nreps, nkids, MSGMNI; -int procstat; -void term(int); #ifdef UCLINUX static char *argv0; - -void do_child_1_uclinux(); static key_t key_uclinux; static int i_uclinux; - -void do_child_2_uclinux(); static int pid_uclinux; static int child_process_uclinux; - -void do_child_3_uclinux(); static int rkid_uclinux; + +static void do_child_1_uclinux(); +static void do_child_2_uclinux(); +static void do_child_3_uclinux(); #endif -void cleanup_msgqueue(int i, int tid); -/*-----------------------------------------------------------------*/ -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char **argv) { - register int i, j, ok, pid; + int i, j, ok, pid; int count, status; #ifdef UCLINUX @@ -209,7 +174,6 @@ char *argv[]; } } while (ok == 0); } -/*-----------------------------------------------------------------*/ /* Fork a number of processes (nprocs), each of which will * create a message queue with several (nkids) reader/writer * pairs which will read and write a number (iterations) @@ -272,29 +236,29 @@ char *argv[]; } -/*--------------------------------------------------------------------*/ - #ifdef UCLINUX -void do_child_1_uclinux() +static void do_child_1_uclinux(void) { procstat = 1; exit(dotest(key_uclinux, i_uclinux)); } -void do_child_2_uclinux() +static void do_child_2_uclinux(void) { procstat = 2; - exit(doreader(key_uclinux, pid_uclinux, child_process_uclinux)); + exit(doreader(key_uclinux, tid, pid_uclinux, + child_process_uclinux, nreps)); } -void do_child_3_uclinux() +static void do_child_3_uclinux(void) { procstat = 2; - exit(dowriter(key_uclinux, rkid_uclinux, child_process_uclinux)); + exit(dowriter(key_uclinux, tid, rkid_uclinux, + child_process_uclinux, nreps)); } #endif -void cleanup_msgqueue(int i, int tid) +static void cleanup_msgqueue(int i, int tid) { /* * Decrease the value of i by 1 because it @@ -317,18 +281,16 @@ void cleanup_msgqueue(int i, int tid) } } -int dotest(key, child_process) -key_t key; -int child_process; +static int dotest(key_t key, int child_process) { int id, pid; int i, count, status, exit_status; sighold(SIGTERM); if ((id = msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0) { - tst_resm(TFAIL | TERRNO, "Msgget error in child %d", - child_process); - tst_exit(); + printf("msgget() error in child %d: %s\n", + child_process, strerror(errno)); + return FAIL; } tid = id; sigrelse(SIGTERM); @@ -338,58 +300,58 @@ int child_process; for (i = 0; i < nkids; i++) { fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, - "Fork failure in first child of child group %d", - child_process); + printf("Fork failure in the first child of child group %d\n", + child_process); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } /* First child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 2, key, getpid(), child_process) < 0) { - tst_resm(TWARN, "self_exec failed"); + printf("self_exec failed\n"); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } #else procstat = 2; - exit(doreader(key, getpid(), child_process)); + exit(doreader(key, tid, getpid(), + child_process, nreps)); #endif } rkidarray[i] = pid; fflush(stdout); if ((pid = FORK_OR_VFORK()) < 0) { - tst_resm(TWARN, - "Fork failure in first child of child group %d", - child_process); + printf("Fork failure in the second child of child group %d\n", + child_process); /* * Kill the reader child process */ (void)kill(rkidarray[i], SIGKILL); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } /* Second child does this */ if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "nddd", 3, key, rkidarray[i], child_process) < 0) { - tst_resm(TWARN, "\tFork failure in first child " - "of child group %d \n", child_process); + printf("\tFork failure in the first child of child group %d\n", + child_process); /* * Kill the reader child process */ (void)kill(rkidarray[i], SIGKILL); cleanup_msgqueue(i, tid); - tst_exit(); + return FAIL; } #else procstat = 2; - exit(dowriter(key, rkidarray[i], child_process)); + exit(dowriter(key, tid, rkidarray[i], + child_process, nreps)); #endif } wkidarray[i] = pid; @@ -399,18 +361,17 @@ int child_process; while (1) { if ((wait(&status)) > 0) { if (status >> 8 != PASS) { - tst_resm(TFAIL, - "Child exit status = %d from child group %d", - status >> 8, child_process); + printf("Child exit status = %d from child group %d\n", + status >> 8, child_process); for (i = 0; i < nkids; i++) { kill(rkidarray[i], SIGTERM); kill(wkidarray[i], SIGTERM); } if (msgctl(tid, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgctl error"); + printf("msgctl() error: %s\n", + strerror(errno)); } - tst_exit(); + return FAIL; } count++; } else { @@ -421,146 +382,23 @@ int child_process; } /* Make sure proper number of children exited */ if (count != (nkids * 2)) { - tst_resm(TFAIL, - "Wrong number of children exited in child group %d, Saw %d Expected %d", - child_process, count, (nkids * 2)); + printf("Wrong number of children exited in child group %d, saw %d, expected %d\n", + child_process, count, (nkids * 2)); if (msgctl(tid, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, "Msgctl error"); + printf("msgctl() error: %s\n", strerror(errno)); } - tst_exit(); + return FAIL; } if (msgctl(id, IPC_RMID, 0) < 0) { - tst_resm(TFAIL | TERRNO, "Msgctl failure in child group %d", - child_process); - tst_exit(); + printf("msgctl() failure in child group %d: %s\n", + child_process, strerror(errno)); + return FAIL; } - exit(exit_status); -} - -int doreader(key, type, child) -int type, child; -long key; -{ - int i, size; - int id; - - if ((id = msgget(key, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgget error in reader of child group %d", child); - tst_exit(); - } - if (id != tid) { - tst_resm(TFAIL, - "Message queue mismatch in reader of child group %d for message queue id %d", - child, id); - tst_exit(); - } - for (i = 0; i < nreps; i++) { - if ((size = msgrcv(id, &buffer, 100, type, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgrcv error in child %d, read # = %d", - (i + 1), child); - tst_exit(); - } - if (buffer.type != type) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d", - child, (i + 1)); - tst_resm(TFAIL, - "\tfor message size got %d expected %d", - size, buffer.data.len); - tst_exit(); - } - if (buffer.data.len + 1 != size) { - tst_resm(TFAIL, - "Size mismatch in child %d, read # = %d, size = %d, expected = %d", - child, (i + 1), buffer.data.len, size); - tst_exit(); - } - if (verify(buffer.data.pbytes, (key % 255), size - 1, child)) { - tst_resm(TFAIL, "in child %d read # = %d,key = %lx", - child, (i + 1), key); - tst_exit(); - } - key++; - } - exit(PASS); -} - -int dowriter(key, type, child) -int type, child; -long key; -{ - int i, size; - int id; - - if ((id = msgget(key, 0)) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgget error in writer of child group %d", child); - tst_exit(); - } - if (id != tid) { - tst_resm(TFAIL, - "Message queue mismatch in writer of child group %d", - child); - tst_resm(TFAIL, "\tfor message queue id %d expected %d", id, - tid); - tst_exit(); - } - - for (i = 0; i < nreps; i++) { - do { - size = (lrand48() % 99); - } while (size == 0); - fill_buffer(buffer.data.pbytes, (key % 255), size); - buffer.data.len = size; - buffer.type = type; - if (msgsnd(id, &buffer, size + 1, 0) < 0) { - tst_resm(TFAIL | TERRNO, - "Msgsnd error in child %d, key = %lx", - child, key); - tst_exit(); - } - key++; - } - exit(PASS); -} - -int fill_buffer(buf, val, size) -register char *buf; -char val; -register int size; -{ - register int i; - - for (i = 0; i < size; i++) - buf[i] = val; - return 0; -} - -/* - * verify() - * Check a buffer for correct values. - */ - -int verify(buf, val, size, child) -register char *buf; -char val; -register int size; -int child; -{ - while (size-- > 0) - if (*buf++ != val) { - tst_resm(TWARN, - "Verify error in child %d, *buf = %x, val = %x, size = %d", - child, *buf, val, size); - return (FAIL); - } - return (PASS); + return exit_status; } /* ARGSUSED */ -void term(int sig) +static void term(int sig) { int i; @@ -597,10 +435,7 @@ void term(int sig) } } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - *****************************************************************/ -void setup() +void setup(void) { int nr_msgqs, free_pids; @@ -649,17 +484,10 @@ void setup() tst_resm(TINFO, "Using upto %d pids", free_pids / 2); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ****************************************************************/ -void cleanup() +void cleanup(void) { int status; - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ + TEST_CLEANUP; /* @@ -678,5 +506,4 @@ void cleanup() fflush(stdout); tst_rmdir(); - } hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-13 12:51:11
|
The branch, master, has been updated via 09bd9333e950d25c084c9c1c46ab0736e7fa9a86 (commit) from 743f2fcd5744744d649496d8f0524cf5ca7d3859 (commit) - Log ----------------------------------------------------------------- commit 09bd9333e950d25c084c9c1c46ab0736e7fa9a86 Author: Stanislav Kholmanskikh <sta...@or...> Date: Fri Nov 8 12:37:37 2013 +0400 setregid02: invalid user value fix Commit 705926d096f7a64c9d53efeb789288e25457d68f introduced a bug that the value for inval_user was treated as '-1' when passed to 16-bit version of setregid(). Fixed it the same way as it's done for setreuid test cases. Reported-by: Honggyu Kim <hon...@lg...> Signed-off-by: Stanislav Kholmanskikh <sta...@or...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/setregid/setregid02.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index e67a7df..ccbaa3e 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -39,7 +39,7 @@ TCID_DEFINE(setregid02); static gid_t neg_one = -1; -static gid_t inval_user = (USHRT_MAX); +static gid_t inval_user = USHRT_MAX - 2; static struct passwd *ltpuser; static struct group nobody, root, bin; hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-12 12:51:13
|
The branch, master, has been updated via 743f2fcd5744744d649496d8f0524cf5ca7d3859 (commit) from a4f5e23bb7dbbe71a52bc89b43edea35e2567382 (commit) - Log ----------------------------------------------------------------- commit 743f2fcd5744744d649496d8f0524cf5ca7d3859 Author: Simon Xu <xu....@or...> Date: Tue Nov 12 18:59:57 2013 +0800 move gethost from tools to sendfile01 Move tools/gethost.c to testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c since sendfile01 is the only test that requires gethost. Signed-off-by: Simon Xu <xu....@or...> Acked-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: testcases/network/tcp_cmds/sendfile/Makefile | 4 ++-- testcases/network/tcp_cmds/sendfile/sendfile01 | 4 ++-- .../network/tcp_cmds/sendfile/sendfile01_gethost.c | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename tools/gethost.c => testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c (100%) diff --git a/testcases/network/tcp_cmds/sendfile/Makefile b/testcases/network/tcp_cmds/sendfile/Makefile index a8b0736..7ba2d7a 100644 --- a/testcases/network/tcp_cmds/sendfile/Makefile +++ b/testcases/network/tcp_cmds/sendfile/Makefile @@ -27,9 +27,9 @@ include $(abs_srcdir)/../Makefile.inc CPPFLAGS += -I$(abs_srcdir)/../include -INSTALL_TARGETS := sendfile01 sendfile01_server +INSTALL_TARGETS := sendfile01 sendfile01_server sendfile01_gethost -MAKE_TARGETS += testsf_c testsf_s testsf_c6 testsf_s6 +MAKE_TARGETS += testsf_c testsf_s testsf_c6 testsf_s6 sendfile01_gethost testsf_c6.o testsf_s6.o: CPPFLAGS += -DINET6 diff --git a/testcases/network/tcp_cmds/sendfile/sendfile01 b/testcases/network/tcp_cmds/sendfile/sendfile01 index ba61873..ebeb182 100755 --- a/testcases/network/tcp_cmds/sendfile/sendfile01 +++ b/testcases/network/tcp_cmds/sendfile/sendfile01 @@ -59,9 +59,9 @@ do_setup() tst_setup - exists awk diff gethost grep rsh stat + exists awk diff sendfile01_gethost grep rsh stat - if ! IPADDR=$(gethost ${EXEC_SUFFIX:+6} $RHOST | awk 'BEGIN { ec=1 } /addresses:/ {print $2; ec=0 } END { exit ec }'); then + if ! IPADDR=$(sendfile01_gethost ${EXEC_SUFFIX:+6} $RHOST | awk 'BEGIN { ec=1 } /addresses:/ {print $2; ec=0 } END { exit ec }'); then # XXX (garrcoop): || exit 1 is there to prevent the test from hanging in the event of an install error. end_testcase "Failed to determine the appropriate IP address for the machine." || exit 1 fi diff --git a/tools/gethost.c b/testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c similarity index 100% rename from tools/gethost.c rename to testcases/network/tcp_cmds/sendfile/sendfile01_gethost.c hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-11 17:51:08
|
The branch, master, has been updated via a4f5e23bb7dbbe71a52bc89b43edea35e2567382 (commit) via 4716af77488c50bb0bf929d68e105a0b619c541d (commit) from bfd9860c64e9b0c7bcb0cc149fae00ef3311574e (commit) - Log ----------------------------------------------------------------- commit a4f5e23bb7dbbe71a52bc89b43edea35e2567382 Author: Simon Xu <xu....@or...> Date: Fri Nov 8 11:18:47 2013 +0800 xinetd_tests.sh: remove RECORD and eliminate "|| RC=$?" 1) In xinetd.conf, `RECORD' is not a valid value for entry `log_on_failure' (I couldn't find a distro in which it's valid), and it makes xinetd successfully starts and promptly exit with error message: "Bad log_on_failure flag: RECORD [file=/etc/xinetd.conf] [line=6]", but the test will pass because telnet service is not started and that's what it expect. 2) Eliminate '|| RC=$?' because because it may not be excecuted and the original value in RC can mess things up. Also remove the RC=0 initializations that are now unnecessary. Signed-off-by: Simon Xu <xu....@or...> commit 4716af77488c50bb0bf929d68e105a0b619c541d Author: Simon Xu <xu....@or...> Date: Fri Nov 8 10:47:42 2013 +0800 sendfile01: rename SF_Server to sendfile01_server and add it into Makefile 1) Rename SF_Server to sendfile01_server to avoid collisions 2) The test always fails because SF_Server is not installed, add sendfile01_server into sendfile01 makefile to install it. Signed-off-by: Simon Xu <xu....@or...> ----------------------------------------------------------------------- Summary of changes: testcases/network/tcp_cmds/sendfile/Makefile | 2 +- testcases/network/tcp_cmds/sendfile/sendfile01 | 2 +- .../sendfile/{SF_Server => sendfile01_server} | 0 testcases/network/xinetd/xinetd_tests.sh | 74 +++++++++++-------- 4 files changed, 45 insertions(+), 33 deletions(-) rename testcases/network/tcp_cmds/sendfile/{SF_Server => sendfile01_server} (100%) diff --git a/testcases/network/tcp_cmds/sendfile/Makefile b/testcases/network/tcp_cmds/sendfile/Makefile index 124ce5d..a8b0736 100644 --- a/testcases/network/tcp_cmds/sendfile/Makefile +++ b/testcases/network/tcp_cmds/sendfile/Makefile @@ -27,7 +27,7 @@ include $(abs_srcdir)/../Makefile.inc CPPFLAGS += -I$(abs_srcdir)/../include -INSTALL_TARGETS := sendfile01 +INSTALL_TARGETS := sendfile01 sendfile01_server MAKE_TARGETS += testsf_c testsf_s testsf_c6 testsf_s6 diff --git a/testcases/network/tcp_cmds/sendfile/sendfile01 b/testcases/network/tcp_cmds/sendfile/sendfile01 index 46b90e2..ba61873 100755 --- a/testcases/network/tcp_cmds/sendfile/sendfile01 +++ b/testcases/network/tcp_cmds/sendfile/sendfile01 @@ -84,7 +84,7 @@ do_test() mkdir -p $TCtmp PORT=$$ - if ! rsh -l root $IPADDR "$LTPROOT/testcases/bin/SF_Server $IPADDR $PORT $LTPROOT/testcases/bin $SERVER"; then + if ! rsh -l root $IPADDR "$LTPROOT/testcases/bin/sendfile01_server $IPADDR $PORT $LTPROOT/testcases/bin $SERVER"; then end_testcase "rsh failed to $IPADDR as root failed" fi sleep 10 diff --git a/testcases/network/tcp_cmds/sendfile/SF_Server b/testcases/network/tcp_cmds/sendfile/sendfile01_server similarity index 100% rename from testcases/network/tcp_cmds/sendfile/SF_Server rename to testcases/network/tcp_cmds/sendfile/sendfile01_server diff --git a/testcases/network/xinetd/xinetd_tests.sh b/testcases/network/xinetd/xinetd_tests.sh index a607d32..5024280 100755 --- a/testcases/network/xinetd/xinetd_tests.sh +++ b/testcases/network/xinetd/xinetd_tests.sh @@ -39,9 +39,8 @@ # - non-zero on failure. chk_ifexists() { - RC=0 - - which $2 > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + which $2 > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_brkm TBROK NULL "$1: command $2 not found." @@ -61,7 +60,6 @@ chk_ifexists() init() { # Initialize global variables. - export RC=0 export TST_TOTAL=2 export TCID="xinetd" export TST_COUNT=0 @@ -77,7 +75,8 @@ init() LTPTMP=$TMP/tst_xinetd.$$ fi - mkdir -p $LTPTMP > /dev/null 2>&1 || RC=$? + mkdir -p $LTPTMP > /dev/null 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_brkm TBROK NULL "INIT: Unable to create temporary directory" @@ -103,19 +102,20 @@ init() # Create custom xinetd.conf file. # tst_xinetd.conf.1 config file has telnet service disabled. - cat > $LTPTMP/tst_xinetd.conf.1 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.conf.1 <<-EOF defaults { instances = 25 log_type = FILE /var/log/servicelog log_on_success = HOST PID - log_on_failure = HOST RECORD + log_on_failure = HOST disabled = telnet } EOF +RC=$? # tst_xinetd.conf.2 config file has telnet enabled. - cat > $LTPTMP/tst_xinetd.conf.2 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.conf.2 <<-EOF defaults { instances = 25 @@ -136,11 +136,13 @@ service telnet no_access = } EOF +RC=$? # Create expected file with telnet disabled. - cat > $LTPTMP/tst_xinetd.exp.1 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.exp.1 <<-EOF telnet: connect to address 127.0.0.1: Connection refused EOF +RC=$? if [ $RC -ne 0 ] then @@ -151,9 +153,10 @@ EOF if [ $IPV6_ENABLED -eq 1 ] then - cat > $LTPTMP/tst_xinetd.exp.1.ipv6 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.exp.1.ipv6 <<-EOF telnet: connect to address ::1: Connection refused EOF +RC=$? if [ $RC -ne 0 ] then @@ -163,12 +166,13 @@ EOF fi # Create expected file with telnet enabled. - cat > $LTPTMP/tst_xinetd.exp.2 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.exp.2 <<-EOF Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. Connection closed by foreign host. EOF +RC=$? if [ $RC -ne 0 ] then @@ -179,12 +183,13 @@ EOF if [ $IPV6_ENABLED -eq 1 ] then - cat > $LTPTMP/tst_xinetd.exp.2.ipv6 <<-EOF || RC=$? + cat > $LTPTMP/tst_xinetd.exp.2.ipv6 <<-EOF Trying ::1... Connected to ::1. Escape character is '^]'. Connection closed by foreign host. EOF +RC=$? if [ $RC -ne 0 ] then @@ -205,12 +210,12 @@ EOF # - non-zero on failure. cleanup() { - RC=0 # restore the original xinetd.conf if a back up exits. if [ -f /etc/xinetd.conf.orig ] then mv /etc/xinetd.conf.orig /etc/xinetd.conf \ - > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TINFO $LTPTMP/tst_xinetd.err \ @@ -220,7 +225,8 @@ cleanup() sleep 1s # restoring original services - /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TINFO $LTPTMP/tst_xinetd.err \ @@ -250,13 +256,12 @@ test01() TCID=xinetd01 TST_COUNT=1 nhops=0 # Number of hops required to get to host. - RC=0 # Return value from commands. tst_resm TINFO "Test #1: restart xinetd with telnet disabled." # create a backup of the original xinetd.conf file. - mv /etc/xinetd.conf /etc/xinetd.conf.orig > $LTPTMP/tst_xinetd.err 2>&1 \ - || RC=$? + mv /etc/xinetd.conf /etc/xinetd.conf.orig > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_brk TBROK $LTPTMP/tst_xinetd.err NULL \ @@ -265,8 +270,8 @@ test01() fi # install the new config file with telnet disabled. - mv $LTPTMP/tst_xinetd.conf.1 /etc/xinetd.conf > $LTPTMP/tst_xinetd.err 2>&1 \ - || RC=$? + mv $LTPTMP/tst_xinetd.conf.1 /etc/xinetd.conf > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_brk TBROK $LTPTMP/tst_xinetd.err NULL \ @@ -279,7 +284,8 @@ test01() sleep 1s # restart xinetd to re-start the services - /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.out 2>&1 || RC=$? + /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.out 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.out \ @@ -288,7 +294,8 @@ test01() else # even if xinetd restart has zero exit value, # make certain there was no failure. - grep -i "fail" $LTPTMP/tst_xinetd.out > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + grep -i "fail" $LTPTMP/tst_xinetd.out > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -eq 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err \ @@ -307,7 +314,8 @@ test01() then echo "" | $TELNET_COMM ::1 2>$LTPTMP/tst_xinetd.out.ipv6 1>/dev/null diff -iwB $LTPTMP/tst_xinetd.out.ipv6 $LTPTMP/tst_xinetd.exp.1.ipv6 \ - > $LTPTMP/tst_xinetd.err.ipv6 2>&1 || RC=$? + > $LTPTMP/tst_xinetd.err.ipv6 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err.ipv6 \ @@ -318,7 +326,8 @@ test01() echo "" | $TELNET_COMM 127.0.0.1 2>$LTPTMP/tst_xinetd.out 1>/dev/null diff -iwB $LTPTMP/tst_xinetd.out $LTPTMP/tst_xinetd.exp.1 \ - > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err \ @@ -328,8 +337,8 @@ test01() tst_resm TINFO "Test #1: restart xinetd with telnet enabled." # install the xinetd config file with telnet enabled. - mv $LTPTMP/tst_xinetd.conf.2 /etc/xinetd.conf > $LTPTMP/tst_xinetd.err 2>&1 \ - || RC=$? + mv $LTPTMP/tst_xinetd.conf.2 /etc/xinetd.conf > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_brk TBROK $LTPTMP/tst_xinetd.err NULL \ @@ -342,7 +351,8 @@ test01() sleep 1s # restart services. - /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.out 2>&1 || RC=$? + /etc/init.d/xinetd restart > $LTPTMP/tst_xinetd.out 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.out \ @@ -350,7 +360,8 @@ test01() return $RC else # even if restart has a zero exit value double check for failure. - grep -i "fail" $LTPTMP/tst_xinetd.out > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + grep -i "fail" $LTPTMP/tst_xinetd.out > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -eq 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err \ @@ -369,7 +380,8 @@ test01() then echo "" | $TELNET_COMM ::1 >$LTPTMP/tst_xinetd.out.ipv6 2>&1 diff -iwB $LTPTMP/tst_xinetd.out.ipv6 $LTPTMP/tst_xinetd.exp.2.ipv6 \ - > $LTPTMP/tst_xinetd.err.ipv6 2>&1 || RC=$? + > $LTPTMP/tst_xinetd.err.ipv6 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err.ipv6 \ @@ -384,7 +396,8 @@ test01() echo "" | $TELNET_COMM 127.0.0.1 > $LTPTMP/tst_xinetd.out 2>&1 diff -iwB $LTPTMP/tst_xinetd.out $LTPTMP/tst_xinetd.exp.2 \ - > $LTPTMP/tst_xinetd.err 2>&1 || RC=$? + > $LTPTMP/tst_xinetd.err 2>&1 + RC=$? if [ $RC -ne 0 ] then tst_res TFAIL $LTPTMP/tst_xinetd.err \ @@ -406,7 +419,6 @@ test01() # Exit: - zero on success # - non-zero on failure. -RC=0 init || exit $? test01 || RC=$? hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-11 16:51:07
|
The branch, master, has been updated via bfd9860c64e9b0c7bcb0cc149fae00ef3311574e (commit) via 021494d2512abdc30234dba4079c9435a81a24ec (commit) from 87f593c16f80c3f204c87de276c426aeb65c3527 (commit) - Log ----------------------------------------------------------------- commit bfd9860c64e9b0c7bcb0cc149fae00ef3311574e Author: Simon Xu <xu....@or...> Date: Fri Nov 8 09:52:15 2013 +0800 mc_cmds: Multicast ping being disabled should not fail the test Signed-off-by: Simon Xu <xu....@or...> commit 021494d2512abdc30234dba4079c9435a81a24ec Author: Simon Xu <xu....@or...> Date: Fri Nov 8 11:39:08 2013 +0800 rdist01: fix mistakes Fix the following mistakes in the script: 1) the way it gets dirname and basename of files is broken 2) ${FILES} and ${HOSTS} get substituted when generating distfile 3) the way it calculates sum of files on RHOST is broken 4) there is no $DIRECTORIES variable Signed-off-by: Simon Xu <xu....@or...> ----------------------------------------------------------------------- Summary of changes: testcases/network/multicast/mc_cmds/mc_cmds | 3 ++- testcases/network/tcp_cmds/rdist/rdist01 | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/testcases/network/multicast/mc_cmds/mc_cmds b/testcases/network/multicast/mc_cmds/mc_cmds index e9b7bb5..d27f669 100755 --- a/testcases/network/multicast/mc_cmds/mc_cmds +++ b/testcases/network/multicast/mc_cmds/mc_cmds @@ -127,7 +127,8 @@ for eth in $IFNAME cat /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts | grep 1 > /dev/null if [ $? -eq 0 ] then - end_testcase "Multicast ping disabled on this system (this is normal on post year:2005 kernels)" + tst_resm TCONF "Multicast ping disabled on this system (this is normal on post year:2005 kernels)" + exit 0 fi # Do the ping tests: Execute ping 224.0.0.1 - Verify that the proper diff --git a/testcases/network/tcp_cmds/rdist/rdist01 b/testcases/network/tcp_cmds/rdist/rdist01 index 9e30492..4bc239f 100755 --- a/testcases/network/tcp_cmds/rdist/rdist01 +++ b/testcases/network/tcp_cmds/rdist/rdist01 @@ -63,8 +63,8 @@ do_setup() done for i in $FILES; do - BASE=${i##*/} - DIR=${%%/*} + BASE=$(basename "$i") + DIR=$(dirname "$i") test -d "$DIR" || mkdir -p "$DIR" if [ $? -ne 0 ] ; then end_testcase "failed to create $DIR" @@ -94,7 +94,7 @@ create_distfile() { T_FILES="FILES = ( " for i in $FILES; do - if [ "${i%%*/}" = "." ]; then + if [ $(dirname "$i") == "." ]; then T_FILES="$T_FILES $i" else T_FILES="$T_FILES $DIR" @@ -105,7 +105,7 @@ create_distfile() T_HOST="HOSTS = (" for c_ruser in $RUSERS; do for c_rhost in $HOSTS; do - T_HOST=$T_HOST"$c_ruser@$c_rhost " + T_HOST=$T_HOST" $c_ruser@$c_rhost" done done @@ -113,7 +113,7 @@ create_distfile() cat <<EOF > "$TCtmp/distfile" $T_HOST $T_FILES -${FILES} -> ${HOSTS} +\${FILES} -> \${HOSTS} EOF } @@ -130,17 +130,15 @@ check_result() cd $TCtmp for c_rhost in $HOSTS; do for c_ruser in $RUSERS; do - TOTAL_SUM=`rsh -n -l $c_ruser $c_rhost \ - x=0; SUM=\$(sum -s $FILES|awk '{ print \$1 }') - for i in \$SUM; do - x=\$(( \$x + \$i )) + TOTAL_SUM=0 + for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do + TOTAL_SUM=$(( $TOTAL_SUM + $i )) done - echo \$x` - if [ $TOTAL_SUM = $LSUM ]; then + if [ $TOTAL_SUM -eq $LSUM ]; then tst_resm TINFO "Success rdist in $c_ruser@$c_rhost " - rsh -n -l $c_ruser $c_rhost "rm -rf $FILES $DIRECTORIES" + rsh -n -l $c_ruser $c_rhost "rm -rf $FILES" else - end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost" + end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost" fi done done hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-09 00:51:20
|
The branch, master, has been updated via 87f593c16f80c3f204c87de276c426aeb65c3527 (commit) via b87a83c8803dc8cf57bbe29f0d3b8600cd3b3b47 (commit) via d97f51dc8278ac024bccac7c64bc30f3b3f7bbbe (commit) via 840aa557b026c08b8d8b975e62175dfd6157ef3b (commit) via e533f082d3351ab1abc774d80d02195650a8594f (commit) via c7b23c28e50c77e8d4c1887c00d765f2963b2a01 (commit) via 90d19015631841c2b32c4f5d71e4d75cc9ffcda8 (commit) via abf28b20fe787b96bb6cd4ac95fff5de1fa3a1ef (commit) via 36531d536b405718b2520ae8ddd6b33d01b019df (commit) via ba3bf0e3486581abe0fd6ffb4a86d376060b91ef (commit) via aba5c50b7be4e522bb46acc92f71adb347540033 (commit) from 508c3038734488b0e818a7442d4c52bd51a2fa7b (commit) - Log ----------------------------------------------------------------- commit 87f593c16f80c3f204c87de276c426aeb65c3527 Author: Simon Xu <xu....@or...> Date: Mon Nov 4 17:36:41 2013 +0800 tcpdump01: fix the way to identify network interface The script tries to identify network interface that can communicate with RHOST by searching for the IP of RHOST in ifconfig output on localhost, which doesn't make any sense when RHOST is not localhost. This patch changes the script to indetify the network interface by ping RHOST. Signed-off-by: Simon Xu <xu....@or...> commit b87a83c8803dc8cf57bbe29f0d3b8600cd3b3b47 Author: Cyril Hrubis <ch...@su...> Date: Thu Nov 7 12:05:25 2013 +0100 fcntl16: Fix incorrect flock strucure The fcntl16 testcase is being compiled twice, once normal, and the other time with the _FILE_OFFSET_BITS=64 define set. When compiled with 64bit file functions (as fcntl16_64) all file functions will automatically use their 64bit variants, e.g. struct flock64" instead of "struct flock". So, when in the code e.g. fcntl(fd, F_SETLK, thislock) is called, this will automatically be translated into fcntl64(fd, F_SETLK64, thislock) and "thislock" needs to be of type "struct flock64". We need to make sure that thislock is of the correct type, with the start and len fields being of type "off_t" which then will be translated into "loff_t" during compilation when _FILE_OFFSET_BITS=64 is set. In orded to do that we make use of struct flock instead of the incorrect version that was defined in the test source. This fixes the fcntl16_64 testcase on hppa64-linux-gnu with 32bit userspace running on 64bit kernel. Signed-off-by: Helge Deller <de...@gm...> Signed-off-by: Cyril Hrubis <ch...@su...> commit d97f51dc8278ac024bccac7c64bc30f3b3f7bbbe Author: Jeff Layton <jl...@re...> Date: Wed Nov 6 11:39:11 2013 -0500 diotest3: fix -f argument The '-f' argument to diotest3 is currently ignored. During options processing it's copied to the buffer, then subsequently overwritten by the default in a later sprintf() call. Move the setting of the default prior to the options processing. Signed-off-by: Jeff Layton <jl...@re...> Signed-off-by: Jan Stancek <jst...@re...> commit 840aa557b026c08b8d8b975e62175dfd6157ef3b Author: Helge Deller <de...@gm...> Date: Wed Nov 6 20:41:11 2013 +0100 sendfile08: fix buf comparison The sendfile08 testcase uses the sendfile() syscall to write the strings "hello" and "world" to a file descriptor and then reads them back in through another file descriptor. The length of the strings written are determined by strlen(), so that in total 10 bytes are written. When reading the strings back in, again 10 bytes are read, but the problem is, that those are read back into a *local* string buffer array (buf[]) which hasn't been initialized. Afterwards, strcmp(buf, "helloworld") is called to compare input and output. This strcmp() is wrong, because basically "helloworld\0" (with the trailing string zero terminator) is compared to "helloworld" (likely without a trailing zero in the buf[] array). So, if buf[] hasn't been initialized, it's not guaranteed that the byte in buf[10] equals to '\0'. This problem was found on hppa64-linux-gnu architecture, most likely, because it's a stack-grows-up architecture. Fix this by using strncmp(). Signed-off-by: Helge Deller <de...@gm...> Signed-off-by: Jan Stancek <jst...@re...> commit e533f082d3351ab1abc774d80d02195650a8594f Author: Stanislav Kholmanskikh <sta...@or...> Date: Wed Nov 6 14:32:03 2013 +0400 fsync02: SIGFPE fix It may happen that stat_buf.f_frsize is greater than BLOCKSIZE (for example, if we use "non-default" FS block sizes or NFS) and because on (BLOCKSIZE / stat_buf.f_frsize) is 0. Moved stat_buf.f_frsize to the dividend. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit c7b23c28e50c77e8d4c1887c00d765f2963b2a01 Author: Wang, Xiaoguang/ç å°å <wan...@cn...> Date: Tue Nov 5 13:51:47 2013 +0800 access(2): add ELOOP, ENOTDIR, EROFS error number test access/access05.c: add ELOOP, ENOTDIR error number test new access/access06.c: add EROFS error number test Signed-off-by: Xiaoguang Wang <wan...@cn...> commit 90d19015631841c2b32c4f5d71e4d75cc9ffcda8 Author: Stanislav Kholmanskikh <sta...@or...> Date: Wed Nov 6 12:23:07 2013 +0400 prot_hsymlinks: use SAFE_TOUCH This test case does not need to keep the file descriptors open after doing creat() on them. So we use SAFE_TOUCH instead of SAFE_CREAT. Otherwise on NFS it outputs: TWARN : tst_rmdir: rmobj(/tmpdir/ltp-vdIWJBmrkz/provfaUSg) failed: remove(/tmpdir/ltp-vdIWJBmrkz/provfaUSg/tmp_root/hsym) failed; errno=66: Directory not empty or: TWARN : tst_rmdir: rmobj(/mnt/proXZmq0T) failed: unlink(/mnt/proXZmq0T/root/.nfs00000000000008470000015e) failed; errno=16: Device or resource busy The same idea as for 8c200cb8e843724afb49fa6617fceec09ac826a5. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit abf28b20fe787b96bb6cd4ac95fff5de1fa3a1ef Author: Stanislav Kholmanskikh <sta...@or...> Date: Wed Nov 6 12:23:06 2013 +0400 Implemented SAFE_TOUCH macro Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit 36531d536b405718b2520ae8ddd6b33d01b019df Author: Simon Xu <xu....@or...> Date: Mon Nov 4 16:58:58 2013 +0800 rwho01: fix getting hostnames from command output and $COUNT Fix the way the script gets hostnames from rwho/ruptime command output, and the mistake that $COUNT is used instead of $TST_COUNT in do_test(). Signed-off-by: Simon Xu <xu....@or...> commit ba3bf0e3486581abe0fd6ffb4a86d376060b91ef Author: Honggyu Kim <hon...@lg...> Date: Wed Nov 6 10:55:56 2013 +0900 acct01: add a check routine for acct implementation A check routine for acct implementation is added at the beginning of the test. check_acct_in_kernel function calls acct(NULL) and checks if errno is ENOSYS. It means that acct system call is not implemented in kernel. The other ENOSYS check routines in setup are removed. This patch prevents from unintentional calling acct again in cleanup, which makes TCONF to TBROK and helps configuration problems stay as TCONF. Previous test output: (becomes TBROK in the end) acct01 1 TCONF : BSD process accounting is not configured in this kernel acct01 2 TCONF : Remaining cases not appropriate for configuration acct01 3 TBROK : acct(NULL) failed: errno=ENOSYS(38): Function not implemented Fixed test output: (stays as TCONF) acct01 1 TCONF : BSD process accounting is not configured in this kernel Signed-off-by: Honggyu Kim <hon...@lg...> Reviewed-by: Wanlong Gao <gao...@cn...> commit aba5c50b7be4e522bb46acc92f71adb347540033 Author: Alexey Kodanev <ale...@or...> Date: Tue Nov 5 14:51:36 2013 +0400 device-drivers: pci: remove bus_slot file on exit Signed-off-by: Alexey Kodanev <ale...@or...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: include/safe_file_ops.h | 21 +++ lib/safe_file_ops.c | 41 +++++ runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 1 + .../device-drivers/pci/tpci_kernel/ltp_tpci.c | 1 + testcases/kernel/io/direct_io/diotest3.c | 2 +- .../security/prot_hsymlinks/prot_hsymlinks.c | 3 +- testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/access/access05.c | 21 +++- testcases/kernel/syscalls/access/access06.c | 171 ++++++++++++++++++++ testcases/kernel/syscalls/acct/acct01.c | 38 +++-- testcases/kernel/syscalls/fcntl/fcntl16.c | 30 ++--- testcases/kernel/syscalls/fsync/fsync02.c | 2 +- testcases/kernel/syscalls/sendfile/sendfile08.c | 3 +- testcases/network/tcp_cmds/rwho/rwho01 | 10 +- testcases/network/tcp_cmds/tcpdump/tcpdump01 | 20 +-- 17 files changed, 305 insertions(+), 62 deletions(-) create mode 100644 testcases/kernel/syscalls/access/access06.c diff --git a/include/safe_file_ops.h b/include/safe_file_ops.h index 7ff5baa..77ad594 100644 --- a/include/safe_file_ops.h +++ b/include/safe_file_ops.h @@ -72,4 +72,25 @@ void safe_cp(const char *file, const int lineno, #define SAFE_CP(cleanup_fn, src, dst) \ safe_cp(__FILE__, __LINE__, (cleanup_fn), (src), (dst)) +/* + * Safe function to touch a file. + * + * If the file (pathname) does not exist It will be created with + * the specified permission (mode) and the access/modification times (times). + * + * If mode is 0 then the file is created with (0666 & ~umask) + * permission or (if the file exists) the permission is not changed. + * + * times is a timespec[2] (as for utimensat(2)). If times is NULL then + * the access/modification times of the file is set to the current time. + */ +void safe_touch(const char *file, const int lineno, + void (*cleanup_fn)(void), + const char *pathname, + mode_t mode, const struct timespec times[2]); + +#define SAFE_TOUCH(cleanup_fn, pathname, mode, times) \ + safe_touch(__FILE__, __LINE__, (cleanup_fn), \ + (pathname), (mode), (times)) + #endif /* SAFE_FILE_OPS */ diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c index b602345..8cfd264 100644 --- a/lib/safe_file_ops.c +++ b/lib/safe_file_ops.c @@ -23,6 +23,9 @@ #include <stdarg.h> #include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include "safe_file_ops.h" @@ -152,3 +155,41 @@ void safe_cp(const char *file, const int lineno, src, dst, file, lineno); } } + +void safe_touch(const char *file, const int lineno, + void (*cleanup_fn)(void), + const char *pathname, + mode_t mode, const struct timespec times[2]) +{ + int ret; + mode_t defmode; + + defmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + + ret = open(pathname, O_CREAT | O_WRONLY, defmode); + if (ret == -1) + tst_brkm(TBROK | TERRNO, cleanup_fn, + "Failed to open file '%s' at %s:%d", + pathname, file, lineno); + + ret = close(ret); + if (ret == -1) + tst_brkm(TBROK | TERRNO, cleanup_fn, + "Failed to close file '%s' at %s:%d", + pathname, file, lineno); + + if (mode != 0) { + ret = chmod(pathname, mode); + if (ret == -1) + tst_brkm(TBROK | TERRNO, cleanup_fn, + "Failed to chmod file '%s' at %s:%d", + pathname, file, lineno); + } + + ret = utimensat(AT_FDCWD, pathname, times, 0); + if (ret == -1) + tst_brkm(TBROK | TERRNO, cleanup_fn, + "Failed to do utimensat() on file '%s' at %s:%d", + pathname, file, lineno); +} + diff --git a/runtest/ltplite b/runtest/ltplite index f0738c7..2382dec 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -66,6 +66,7 @@ access02 access02 access03 access03 access04 access04 access05 access05 +access06 access06 -D DEVICE -T DEVICE_FS_TYPE acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 951b00e..16247e9 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -8,6 +8,7 @@ access02 access02 access03 access03 access04 access04 access05 access05 +access06 access06 -D DEVICE -T DEVICE_FS_TYPE acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE diff --git a/runtest/syscalls b/runtest/syscalls index e5a5508..fa01ff7 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -9,6 +9,7 @@ access02 access02 access03 access03 access04 access04 access05 access05 +access06 access06 -D DEVICE -T DEVICE_FS_TYPE acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c index 4cfcc30..2cf8cef 100644 --- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c +++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c @@ -755,6 +755,7 @@ static void tpci_exit_module(void) device_remove_file(&tdev, &dev_attr_result); device_remove_file(&tdev, &dev_attr_tcase); + device_remove_file(&tdev, &dev_attr_bus_slot); device_unregister(&tdev); } module_exit(tpci_exit_module) diff --git a/testcases/kernel/io/direct_io/diotest3.c b/testcases/kernel/io/direct_io/diotest3.c index ac460ed..d38c71c 100644 --- a/testcases/kernel/io/direct_io/diotest3.c +++ b/testcases/kernel/io/direct_io/diotest3.c @@ -239,6 +239,7 @@ int main(int argc, char *argv[]) int i, fail_count = 0, failed = 0, total = 0; /* Options */ + sprintf(filename, "testdata-3.%ld", syscall(__NR_gettid)); while ((i = getopt(argc, argv, "b:o:i:n:f:")) != -1) { switch (i) { case 'b': @@ -277,7 +278,6 @@ int main(int argc, char *argv[]) prg_usage(); } } - sprintf(filename, "testdata-3.%ld", syscall(__NR_gettid)); setup(); diff --git a/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c b/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c index 558681a..e9948e3 100644 --- a/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c +++ b/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c @@ -45,6 +45,7 @@ #include "test.h" #include "usctest.h" #include "safe_macros.h" +#include "safe_file_ops.h" char *TCID = "prot_hsymlinks"; int TST_TOTAL = 396; @@ -414,7 +415,7 @@ static void ufiles_add(int usr, char *path, int type) struct user_file *ufile = &users[usr].file[file]; if (type == IS_FILE) - SAFE_CREAT(cleanup, path, 0644); + SAFE_TOUCH(cleanup, path, 0644, NULL); else SAFE_MKDIR(cleanup, path, 0755); diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 0effa6b..0130a53 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -6,6 +6,7 @@ /access/access03 /access/access04 /access/access05 +/access/access06 /acct/acct01 /add_key/add_key01 /add_key/add_key02 diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c index 739b4b2..4105e32 100644 --- a/testcases/kernel/syscalls/access/access05.c +++ b/testcases/kernel/syscalls/access/access05.c @@ -32,6 +32,10 @@ * if the specified file doesn't exist (or pathname is NULL). * 5. access() fails with -1 return value and sets errno to ENAMETOOLONG * if the pathname size is > PATH_MAX characters. + * 6. access() fails with -1 return value and sets errno to ENOTDIR + * if a component used as a directory in pathname is not a directory. + * 7. access() fails with -1 return value and sets errno to ELOOP + * if too many symbolic links were encountered in resolving pathname. * * 07/2001 Ported by Wayne Boyer */ @@ -56,6 +60,8 @@ #define TEST_FILE2 "test_file2" #define TEST_FILE3 "test_file3" #define TEST_FILE4 "test_file4" +#define TEST_FILE5 "test_file5/test_file5" +#define TEST_FILE6 "test_file6" #if !defined(UCLINUX) @@ -79,12 +85,15 @@ static struct test_case_t { #endif {"", W_OK, ENOENT}, {longpathname, R_OK, ENAMETOOLONG}, + {TEST_FILE5, R_OK, ENOTDIR}, + {TEST_FILE6, R_OK, ELOOP}, }; char *TCID = "access05"; int TST_TOTAL = ARRAY_SIZE(test_cases); -static int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, 0 }; +static int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, + ENOTDIR, ELOOP, 0 }; static const char nobody_uid[] = "nobody"; static struct passwd *ltpuser; @@ -172,6 +181,16 @@ static void setup(void) *the MAX length of PATH_MAX. */ memset(longpathname, 'a', sizeof(longpathname) - 1); + + /* create test_file5 for test ENOTDIR. */ + SAFE_TOUCH(cleanup, "test_file5", 0644, NULL); + + /* + * create two symbolic links who point to each other for + * test ELOOP. + */ + SAFE_SYMLINK(cleanup, "test_file6", "test_file7"); + SAFE_SYMLINK(cleanup, "test_file7", "test_file6"); } static void access_verify(int i) diff --git a/testcases/kernel/syscalls/access/access06.c b/testcases/kernel/syscalls/access/access06.c new file mode 100644 index 0000000..5c00a9b --- /dev/null +++ b/testcases/kernel/syscalls/access/access06.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2013 Fujitsu Ltd. + * Author: Xiaoguang Wang <wan...@cn...> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * Description: + * Verify that, + * 1. access() fails with -1 return value and sets errno to EROFS + * if write permission was requested for files on a read-only file system. + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/mount.h> +#include <pwd.h> + +#include "test.h" +#include "usctest.h" +#include "safe_macros.h" + + +static void setup(void); +static void access_verify(int i); +static void cleanup(void); +static void help(void); + +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) +#define MNT_POINT "mntpoint" + +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; + +static struct test_case_t { + char *pathname; + int a_mode; + int exp_errno; +} test_cases[] = { + {MNT_POINT, W_OK, EROFS} +}; + +char *TCID = "access06"; +int TST_TOTAL = ARRAY_SIZE(test_cases); +static int exp_enos[] = { EROFS, 0 }; + +int main(int ac, char **av) +{ + int lc; + char *msg; + int i; + + msg = parse_opts(ac, av, options, help); + if (msg != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + + /* Check for mandatory option of the testcase */ + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device " + "used for mounting with -D option"); + } + + setup(); + + TEST_EXP_ENOS(exp_enos); + + for (lc = 0; TEST_LOOPING(lc); lc++) { + tst_count = 0; + + for (i = 0; i < TST_TOTAL; i++) + access_verify(i); + } + + cleanup(); + tst_exit(); +} + +static void setup(void) +{ + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + tst_require_root(NULL); + + tst_mkfs(NULL, device, fstype, NULL); + + tst_tmpdir(); + + SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); + + TEST_PAUSE; + + /* + * mount a read-only file system for test EROFS + */ + if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; +} + +static void access_verify(int i) +{ + char *file_name; + int access_mode; + + file_name = test_cases[i].pathname; + access_mode = test_cases[i].a_mode; + + TEST(access(file_name, access_mode)); + + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "access(%s, %#o) succeeded unexpectedly", + file_name, access_mode); + return; + } + + if (TEST_ERRNO == test_cases[i].exp_errno) { + tst_resm(TPASS | TTERRNO, "access failed as expected"); + } else { + tst_resm(TFAIL | TTERRNO, + "access failed unexpectedly; expected: " + "%d - %s", test_cases[i].exp_errno, + strerror(test_cases[i].exp_errno)); + } +} + +static void cleanup(void) +{ + TEST_CLEANUP; + + if (mount_flag && umount(MNT_POINT) < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } + tst_rmdir(); +} + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index 8236042..312051a 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -124,12 +124,28 @@ int main(int argc, char *argv[]) tst_exit(); } +static void check_acct_in_kernel(void) +{ + /* check if acct is implemented in kernel */ + if (acct(NULL) == -1) { + if (errno == ENOSYS) { + tst_resm(TCONF, + "BSD process accounting is not configured in " + "this kernel"); + + tst_exit(); + } + } +} + static void setup(void) { int fd; tst_require_root(NULL); + check_acct_in_kernel(); + tst_tmpdir(); ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); @@ -137,26 +153,12 @@ static void setup(void) fd = SAFE_CREAT(cleanup, TEST_FILE5, 0777); SAFE_CLOSE(cleanup, fd); - if (acct(TEST_FILE5) == -1) { - if (errno == ENOSYS) { - tst_brkm(TCONF, cleanup, - "BSD process accounting is not configured in " - "this kernel"); - } else { - tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); - } - } + if (acct(TEST_FILE5) == -1) + tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); /* turn off acct, so we are in a known state */ - if (acct(NULL) == -1) { - if (errno == ENOSYS) { - tst_brkm(TCONF, cleanup, - "BSD process accounting is not configured in " - "this kernel"); - } else { - tst_brkm(TBROK | TERRNO, cleanup, "acct(NULL) failed"); - } - } + if (acct(NULL) == -1) + tst_brkm(TBROK | TERRNO, cleanup, "acct(NULL) failed"); /* ELOOP SETTING */ SAFE_SYMLINK(cleanup, TEST_FILE6, "test_file_eloop2"); diff --git a/testcases/kernel/syscalls/fcntl/fcntl16.c b/testcases/kernel/syscalls/fcntl/fcntl16.c index 12696a8..8baae20 100644 --- a/testcases/kernel/syscalls/fcntl/fcntl16.c +++ b/testcases/kernel/syscalls/fcntl/fcntl16.c @@ -64,20 +64,12 @@ #define TIME_OUT 10 typedef struct { - short type; - short whence; - long start; - long len; - short flag; -} lock; - -typedef struct { - lock parent_a; - lock parent_b; - lock child_a; - lock child_b; - lock parent_c; - lock parent_d; + struct flock parent_a; + struct flock parent_b; + struct flock child_a; + struct flock child_b; + struct flock parent_c; + struct flock parent_d; } testcase; static testcase testcases[] = { @@ -267,7 +259,7 @@ static testcase testcases[] = { }; static testcase *thiscase; -static lock *thislock; +static struct flock *thislock; static int parent; static int child_flag1 = 0; static int child_flag2 = 0; @@ -484,7 +476,7 @@ int run_test(int file_flag, int file_mode, int start, int end) /* Initialize second parent lock structure */ thislock = &thiscase->parent_b; - if ((thislock->type) != IGNORED) { /*SKIPVAL */ + if ((thislock->l_type) != IGNORED) { /*SKIPVAL */ /* set the second parent lock */ if ((fcntl(fd, F_SETLK, thislock)) < 0) { tst_resm(TFAIL, "Second parent lock failed"); @@ -506,7 +498,7 @@ int run_test(int file_flag, int file_mode, int start, int end) /* spawn child processes */ for (i = 0; i < 2; i++) { - if (thislock->type != IGNORED) { + if (thislock->l_type != IGNORED) { if ((child = FORK_OR_VFORK()) == 0) { #ifdef UCLINUX if (self_exec(argv0, "ddddd", i, parent, @@ -524,7 +516,7 @@ int run_test(int file_flag, int file_mode, int start, int end) } child_count++; child_pid[i] = child; - flag[i] = thislock->flag; + flag[i] = thislock->l_pid; } /* Initialize second child lock structure */ thislock = &thiscase->child_b; @@ -569,7 +561,7 @@ int run_test(int file_flag, int file_mode, int start, int end) /* Initialize fourth parent lock structure */ thislock = &thiscase->parent_d; - if ((thislock->type) != IGNORED) { /*SKIPVAL */ + if ((thislock->l_type) != IGNORED) { /*SKIPVAL */ /* set the fourth parent lock */ if ((fcntl(fd, F_SETLK, thislock)) < 0) { tst_resm(TINFO, "Fourth parent lock failed"); diff --git a/testcases/kernel/syscalls/fsync/fsync02.c b/testcases/kernel/syscalls/fsync/fsync02.c index 564f5c6..ffd2e7a 100644 --- a/testcases/kernel/syscalls/fsync/fsync02.c +++ b/testcases/kernel/syscalls/fsync/fsync02.c @@ -177,7 +177,7 @@ void setup() if (fstatvfs(fd, &stat_buf) != 0) tst_brkm(TBROK, cleanup, "fstatvfs failed"); - f_bavail = stat_buf.f_bavail / (BLOCKSIZE / stat_buf.f_frsize); + f_bavail = (stat_buf.f_bavail * stat_buf.f_frsize) / BLOCKSIZE; if (f_bavail && (f_bavail < MAXBLKS)) max_blks = f_bavail; diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c index 72bcdf7..9e85631 100644 --- a/testcases/kernel/syscalls/sendfile/sendfile08.c +++ b/testcases/kernel/syscalls/sendfile/sendfile08.c @@ -39,6 +39,7 @@ #define TEST_MSG_IN "world" #define TEST_MSG_OUT "hello" +#define TEST_MSG_ALL (TEST_MSG_OUT TEST_MSG_IN) TCID_DEFINE(sendfile08); int TST_TOTAL = 1; @@ -79,7 +80,7 @@ int main(int argc, char *argv[]) tst_brkm(TBROK | TERRNO, cleanup, "read %s failed", out_file); - if (!strcmp(buf, TEST_MSG_OUT TEST_MSG_IN)) + if (!strncmp(buf, TEST_MSG_ALL, strlen(TEST_MSG_ALL))) tst_resm(TPASS, "sendfile(2) copies data correctly"); else tst_resm(TFAIL, "sendfile(2) copies data incorrectly." diff --git a/testcases/network/tcp_cmds/rwho/rwho01 b/testcases/network/tcp_cmds/rwho/rwho01 index 2c82ef1..eb31642 100755 --- a/testcases/network/tcp_cmds/rwho/rwho01 +++ b/testcases/network/tcp_cmds/rwho/rwho01 @@ -106,18 +106,18 @@ do_test() while [ $TST_COUNT -le $NUMLOOPS ]; do rwho -a > $OUTFILE - HOST=`awk "\\$2 ~ /$LHOST>/" $OUTFILE | cut -f1 -d: | sort -u` + HOST=`grep $LHOST $OUTFILE | sed 's/[^ ]* *//; s/:.*//' | uniq` [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in rwho outfile" - HOST=`awk "\\$2 ~ /$RHOSTNAME>/" $OUTFILE | cut -f1 -d: | sort -u` + HOST=`grep $RHOSTNAME $OUTFILE | sed 's/[^ ]* *//; s/:.*//' | uniq` [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in rwho outfile" ruptime -a > $OUTFILE - HOST=`awk "\\$1 ~ /$LHOST>/" $OUTFILE | sort -u` + HOST=`grep $LHOST $OUTFILE | sed 's/ .*//' | uniq` [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in ruptime outfile" - HOST=`awk "\\$1 ~ /$RHOSTNAME>/" $OUTFILE | sort -u` + HOST=`grep $RHOSTNAME $OUTFILE | sed 's/ .*//' | uniq` [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in ruptime outfile" - tst_resm TINFO "Test $COUNT of $NUMLOOPS complete" + tst_resm TINFO "Test $TST_COUNT of $NUMLOOPS complete" incr_tst_count done } diff --git a/testcases/network/tcp_cmds/tcpdump/tcpdump01 b/testcases/network/tcp_cmds/tcpdump/tcpdump01 index 4866720..6d6d399 100755 --- a/testcases/network/tcp_cmds/tcpdump/tcpdump01 +++ b/testcases/network/tcp_cmds/tcpdump/tcpdump01 @@ -48,22 +48,12 @@ do_setup() exists awk grep host hostname ifconfig netstat ping tail tcpdump RHOST=${RHOST:-`hostname`} - IP=`host ${RHOST} 2>/dev/null | awk '{print $4}'` - IFNUMS=`netstat -i|wc -l` - IFNUMS=$(( $IFNUMS - 2 )) - IFNAME=${IFNAME:-$(netstat -i | awk '{print $1}' | tail -n ${IFNUMS})} - - for i in ${IFNAME}; do - if ifconfig ${i} | grep $IP; then - IF=$i - break - fi + # Find the first interface that can ping RHOST + IF="" + for i in $(netstat -i | tail -n+3 | sed '/^lo/d' | cut -f1 -d' '); do + ping -I $i -c 3 $RHOST && { IF="$i"; break; } done - # Default to empty string if unset, to avoid errors caused by set -u, which we use (see cmdlib.sh) - if [ -z "${IF:-}" ]; then - end_testcase "Could not identify interface" - exit 1 - fi + test -z $IF && end_testcase "Could not find an interface that can ping remote host $RHOST" IFNAME=${IF} NUMLOOPS=${NUMLOOPS:-20} OUTFILE=$TCtmp/tcpdump_out hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-04 13:51:15
|
The branch, master, has been updated via 508c3038734488b0e818a7442d4c52bd51a2fa7b (commit) via e052e107bef9ff2b32a79d636d14ae5cf4194f23 (commit) from bf30042a0362d03fbada0332e7e22191bf1525ee (commit) - Log ----------------------------------------------------------------- commit 508c3038734488b0e818a7442d4c52bd51a2fa7b Author: Cyril Hrubis <ch...@su...> Date: Mon Nov 4 14:37:09 2013 +0100 acct01: Fix runtest files. I've missed these when I was rebasing the acct01 patch. Signed-off-by: Cyril Hrubis <ch...@su...> commit e052e107bef9ff2b32a79d636d14ae5cf4194f23 Author: Zeng Linggang <zen...@cn...> Date: Thu Oct 31 16:47:28 2013 +0800 acct/acct01.c: Add ELOOP ENAMETOOLONG EROFS Add ELOOP, ENAMETOOLONG, EROFS error number test in acct01.c for acct(2) Signed-off-by: Zeng Linggang <zen...@cn...> ----------------------------------------------------------------------- Summary of changes: runtest/ltplite | 2 +- runtest/stress.part3 | 2 +- runtest/syscalls | 2 +- testcases/kernel/syscalls/acct/acct01.c | 73 ++++++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/runtest/ltplite b/runtest/ltplite index a6f57e2..f0738c7 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -67,7 +67,7 @@ access03 access03 access04 access04 access05 access05 -acct01 acct01 +acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE adjtimex01 adjtimex01 adjtimex02 adjtimex02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 2962cc4..951b00e 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -9,7 +9,7 @@ access03 access03 access04 access04 access05 access05 -acct01 acct01 +acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE adjtimex01 adjtimex01 adjtimex02 adjtimex02 diff --git a/runtest/syscalls b/runtest/syscalls index b4bb201..e5a5508 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -10,7 +10,7 @@ access03 access03 access04 access04 access05 access05 -acct01 acct01 +acct01 acct01 -D DEVICE -T DEVICE_FS_TYPE add_key01 add_key01 add_key02 add_key02 diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index 0fe973b..8236042 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -34,22 +34,41 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/mount.h> #include "test.h" #include "usctest.h" #include "safe_macros.h" +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) #define TEST_FILE1 "/" #define TEST_FILE2 "/dev/null" #define TEST_FILE3 "/tmp/does/not/exist" #define TEST_FILE4 "/etc/fstab/" #define TEST_FILE5 "./tmpfile" +#define TEST_FILE6 "test_file_eloop1" +#define TEST_FILE7 nametoolong +#define TEST_FILE8 "mntpoint/tmp" + +static char nametoolong[PATH_MAX+2]; +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; static void setup(void); static void cleanup(void); static void setup2(void); static void cleanup2(void); static void acct_verify(int); +static void help(void); + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; static struct test_case_t { char *filename; @@ -64,18 +83,33 @@ static struct test_case_t { {TEST_FILE4, "ENOTDIR", ENOTDIR, NULL, NULL}, {TEST_FILE5, "EPERM", EPERM, setup2, cleanup2}, {NULL, "EPERM", EPERM, setup2, cleanup2}, + {TEST_FILE6, "ELOOP", ELOOP, NULL, NULL}, + {TEST_FILE7, "ENAMETOOLONG", ENAMETOOLONG, NULL, NULL}, + {TEST_FILE8, "EROFS", EROFS, NULL, NULL}, }; char *TCID = "acct01"; int TST_TOTAL = ARRAY_SIZE(test_cases); static struct passwd *ltpuser; -static int exp_enos[] = { EISDIR, EACCES, ENOENT, ENOTDIR, EPERM, 0 }; +static int exp_enos[] = { EISDIR, EACCES, ENOENT, ENOTDIR, EPERM, + ELOOP, ENAMETOOLONG, EROFS, 0 }; int main(int argc, char *argv[]) { int lc; + char *msg; int i; + msg = parse_opts(argc, argv, options, help); + if (msg != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + + /* Check for mandatory option of the testcase */ + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device used for " + "mounting with -D option"); + } + setup(); TEST_EXP_ENOS(exp_enos); @@ -123,6 +157,31 @@ static void setup(void) tst_brkm(TBROK | TERRNO, cleanup, "acct(NULL) failed"); } } + + /* ELOOP SETTING */ + SAFE_SYMLINK(cleanup, TEST_FILE6, "test_file_eloop2"); + SAFE_SYMLINK(cleanup, "test_file_eloop2", TEST_FILE6); + + /* ENAMETOOLONG SETTING */ + memset(nametoolong, 'a', PATH_MAX+1); + + /* EROFS SETTING */ + tst_mkfs(NULL, device, fstype, NULL); + SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE); + if (mount(device, "mntpoint", fstype, 0, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; + /* Create a file in the file system, then remount it as read-only */ + fd = SAFE_CREAT(cleanup, TEST_FILE8, 0644); + SAFE_CLOSE(cleanup, fd); + if (mount(device, "mntpoint", fstype, + MS_REMOUNT | MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; } static void acct_verify(int i) @@ -141,6 +200,7 @@ static void acct_verify(int i) test_cases[i].filename); return; } + if (TEST_ERRNO == test_cases[i].exp_errno) { tst_resm(TPASS | TTERRNO, "acct failed as expected"); } else { @@ -167,6 +227,17 @@ static void cleanup(void) if (acct(NULL) == -1) tst_resm(TBROK | TERRNO, "acct(NULL) failed"); + if (mount_flag && umount("mntpoint") < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } tst_rmdir(); } + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-04 08:51:13
|
The branch, master, has been updated via bf30042a0362d03fbada0332e7e22191bf1525ee (commit) from 591c992a07fce81eb6d0f4ba712c1b0768e03aab (commit) - Log ----------------------------------------------------------------- commit bf30042a0362d03fbada0332e7e22191bf1525ee Author: Simon Xu <xu....@or...> Date: Mon Nov 4 13:28:15 2013 +0800 sctp: enlarge SO_RCVBUF option value When using setsockopt() with recent Linux kernels, it doesn't make sense to use a value smaller than SOCK_MIN_RCVBUF/2 for SO_RCVBUF and expect getting a SO_RCVBUF value by getsockopt() which is doubled. See the following code in linux/net/core/sock.c: if ((val * 2) < SOCK_MIN_RCVBUF) sk->sk_rcvbuf = SOCK_MIN_RCVBUF; else sk->sk_rcvbuf = val * 2; break; SOCK_MIN_RCVBUF is defined as (2048 + sizeof(struct sk_buff)) which is 2240. Signed-off-by: Simon Xu <xu....@or...> Reviewed-by: Jan Stancek <jst...@re...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: .../network/sctp/func_tests/test_1_to_1_sockopt.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testcases/network/sctp/func_tests/test_1_to_1_sockopt.c b/testcases/network/sctp/func_tests/test_1_to_1_sockopt.c index b12313b..c36f502 100644 --- a/testcases/network/sctp/func_tests/test_1_to_1_sockopt.c +++ b/testcases/network/sctp/func_tests/test_1_to_1_sockopt.c @@ -299,9 +299,9 @@ int main(void) tst_resm(TPASS, "getsockopt() SCTP_STATUS - SUCCESS"); /* Reducing the SO_RCVBUF value using setsockopt() */ - /*Minimum value is 128 and hence I am using it */ len = sizeof(int); - rcvbuf_val_set = 128; + /* (rcvbuf len)*2 should be no less than SOCK_MIN_RCVBUF in kernel */ + rcvbuf_val_set = 1500; /* TEST16: Test case for setsockopt SO_RCVBUF */ error = setsockopt(sk2, SOL_SOCKET, SO_RCVBUF, &rcvbuf_val_set, len); if (error < 0) hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-04 02:51:12
|
The branch, master, has been updated via 591c992a07fce81eb6d0f4ba712c1b0768e03aab (commit) from 01f01828681dbf8b5820b9494ead278e4678e5de (commit) - Log ----------------------------------------------------------------- commit 591c992a07fce81eb6d0f4ba712c1b0768e03aab Author: Honggyu Kim <nex...@gm...> Date: Sun Nov 3 17:14:42 2013 +0900 acct01: fix TBROK to TCONF if acct not implemented acct system call is avaliable only when the kernel option is on. When it fails, acct returns -1 and sets errno correspondingly. ENOSYS is set when the system call is not implemented. Currently, ENOSYS is not checked when the TEST_FILE5 argument is passed. It just goes to TBROK regardless of the implementation in kernel. This patch modifies to check errno ENOSYS, and marks as TCONF in that case. Signed-off-by: Honggyu Kim <nex...@gm...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/acct/acct01.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index c38d4db..0fe973b 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -103,8 +103,15 @@ static void setup(void) fd = SAFE_CREAT(cleanup, TEST_FILE5, 0777); SAFE_CLOSE(cleanup, fd); - if (acct(TEST_FILE5) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); + if (acct(TEST_FILE5) == -1) { + if (errno == ENOSYS) { + tst_brkm(TCONF, cleanup, + "BSD process accounting is not configured in " + "this kernel"); + } else { + tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); + } + } /* turn off acct, so we are in a known state */ if (acct(NULL) == -1) { hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-11-01 03:51:14
|
The branch, master, has been updated via 01f01828681dbf8b5820b9494ead278e4678e5de (commit) from abaa460b225ac40cc2f1f5f1052cd9ce44036111 (commit) - Log ----------------------------------------------------------------- commit 01f01828681dbf8b5820b9494ead278e4678e5de Author: Alexey Kodanev <ale...@or...> Date: Wed Oct 30 15:21:33 2013 +0400 device-drivers: pci: fix PCI_EXP_CAP_CONFIG test-case There is another way to check that PCI Express config space of pci devices can be read successfully. Firstly, find out if a device has a PCI Express Capability: we should get a correct config address offset from the dev's structure (dev->pcie_cap). Using the offset, read a PCI Express header. Check if we can get the right PCI Express CAP ID from the header (it must match the PCI_CAP_ID_EXP macro). Signed-off-by: Alexey Kodanev <ale...@or...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: .../device-drivers/pci/tpci_kernel/ltp_tpci.c | 54 ++++++-------------- .../kernel/device-drivers/pci/tpci_kernel/tpci.h | 1 - 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c index d2ffacd..4cfcc30 100644 --- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c +++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c @@ -541,28 +541,6 @@ static int test_find_cap(void) } /* - * test_find_pci_exp_cap - * make call to pci_find_capability, which will - * determine if a device has PCI-EXPRESS capability, - * use second parameter to specify which capability - * you are looking for - */ -static int test_find_pci_exp_cap(void) -{ - struct pci_dev *dev = ltp_pci.dev; - - prk_info("find PCIe capability"); - - if (pci_find_capability(dev, PCI_CAP_ID_EXP)) { - prk_info("device has PCI-EXP capability"); - return TPASS; - } - - prk_info("device doesn't have PCI-EXP capability"); - return TFAIL; -} - -/* * test_read_pci_exp_config * make call to pci_config_read and determine if * the PCI-Express enhanced config space of this @@ -570,37 +548,35 @@ static int test_find_pci_exp_cap(void) */ static int test_read_pci_exp_config(void) { - /* PCI-Exp enhanced config register 0x100, 4 implies dword access */ - int reg = 100; + int pos; + u32 header; struct pci_dev *dev = ltp_pci.dev; - u32 data; /* skip the test if device doesn't have PCIe capability */ - if (test_find_pci_exp_cap() == TFAIL) + pos = pci_pcie_cap(dev); + if (!pos) { + prk_info("device doesn't have PCI-EXP capability"); return TSKIP; + } + prk_info("read the PCI Express configuration registers at 0x%x", pos); - prk_info("dev on bus(%d) & slot (%d)", dev->bus->number, dev->devfn); - prk_info("reading the PCI Express configuration registers---"); - prk_info("reading PCI-Express AER CAP-ID REGISTER at Enh-Cfg AddrSpace 0x100"); - - if (pci_read_config_dword(dev, reg, &data)) { - prk_err("failed to read config word"); + if (pci_read_config_dword(dev, pos, &header)) { + prk_err("failed to read config dword"); return TFAIL; } - /* comparing the value read with AER_CAP_ID_VALUE macro */ - if (data == AER_CAP_ID_VALUE) { - prk_info("correct val read using PCIE driver installed: '%u'", - data); + /* comparing the value read with PCI_CAP_ID_EXP macro */ + if ((header & 0x000000ff) == PCI_CAP_ID_EXP) { + prk_info("correct val read using PCIE driver installed: 0x%x", + header); return TPASS; } - prk_err("incorrect val read. PCIE driver/device not installed: '%u'", - data); + prk_err("incorrect val read. PCIE driver/device not installed: 0x%x", + header); return TFAIL; } - static int test_case(unsigned int cmd) { int rc = TSKIP; diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/tpci.h b/testcases/kernel/device-drivers/pci/tpci_kernel/tpci.h index d5ee669..f65c6fc 100644 --- a/testcases/kernel/device-drivers/pci/tpci_kernel/tpci.h +++ b/testcases/kernel/device-drivers/pci/tpci_kernel/tpci.h @@ -20,7 +20,6 @@ #define PCI_DEVICE_NAME "ltp_tpci" #define MAX_DEVFN 256 #define MAX_BUS 256 -#define AER_CAP_ID_VALUE 0x14011 enum PCI_TCASES { PCI_DISABLE = 0, hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-31 11:51:06
|
The branch, master, has been updated via abaa460b225ac40cc2f1f5f1052cd9ce44036111 (commit) from 8c200cb8e843724afb49fa6617fceec09ac826a5 (commit) - Log ----------------------------------------------------------------- commit abaa460b225ac40cc2f1f5f1052cd9ce44036111 Author: Cyril Hrubis <ch...@su...> Date: Thu Oct 31 12:26:04 2013 +0100 build: Change MAKE_TARGETS in include/mk/lib.mk Currently the lib.mk sets the MAKE_TARGETS to $(LIB) which does not allow any other targets to be added before the lib.mk is included. This commit changes the := to += so that the $(LIB) target is added to the list instead. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: include/mk/lib.mk | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/include/mk/lib.mk b/include/mk/lib.mk index 96c08eb..456db24 100644 --- a/include/mk/lib.mk +++ b/include/mk/lib.mk @@ -46,7 +46,7 @@ ifneq ($(MAKECMDGOALS),install) LIB ?= $(INTERNAL_LIB) endif -MAKE_TARGETS := $(LIB) +MAKE_TARGETS += $(LIB) LIBSRCS ?= $(wildcard $(abs_srcdir)/*.c) hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-31 09:51:05
|
The branch, master, has been updated via 8c200cb8e843724afb49fa6617fceec09ac826a5 (commit) from 278743a7938096197436148f265d7a9c2a98697d (commit) - Log ----------------------------------------------------------------- commit 8c200cb8e843724afb49fa6617fceec09ac826a5 Author: Stanislav Kholmanskikh <sta...@or...> Date: Thu Oct 31 12:41:47 2013 +0400 fcntl/fcntl16: close fd before unlink This testcase fails on NFS but doesn't remove its working directory on exit (NFS silly rename): TWARN : tst_rmdir: rmobj(/mnt/fcn1GHJ8g) failed: unlink(/mnt/fcn1GHJ8g/.nfs0000000000000c4200000001) failed; errno=16: Device or resource busy Fixed. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> Acked-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/fcntl/fcntl16.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/testcases/kernel/syscalls/fcntl/fcntl16.c b/testcases/kernel/syscalls/fcntl/fcntl16.c index 8bdb6b5..12696a8 100644 --- a/testcases/kernel/syscalls/fcntl/fcntl16.c +++ b/testcases/kernel/syscalls/fcntl/fcntl16.c @@ -476,6 +476,7 @@ int run_test(int file_flag, int file_mode, int start, int end) tst_resm(TFAIL, "First parent lock failed"); tst_resm(TFAIL, "Test case %d, errno = %d", test + 1, errno); + close(fd); unlink(tmpname); return 1; } @@ -489,6 +490,7 @@ int run_test(int file_flag, int file_mode, int start, int end) tst_resm(TFAIL, "Second parent lock failed"); tst_resm(TFAIL, "Test case %d, errno = %d", test + 1, errno); + close(fd); unlink(tmpname); return 1; } @@ -559,6 +561,7 @@ int run_test(int file_flag, int file_mode, int start, int end) tst_resm(TFAIL, "Third parent lock failed"); tst_resm(TFAIL, "Test case %d, errno = %d", test + 1, errno); + close(fd); unlink(tmpname); return 1; } @@ -572,6 +575,7 @@ int run_test(int file_flag, int file_mode, int start, int end) tst_resm(TINFO, "Fourth parent lock failed"); tst_resm(TINFO, "Test case %d, errno = %d", test + 1, errno); + close(fd); unlink(tmpname); return 1; } hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-31 08:51:16
|
The branch, master, has been updated via 278743a7938096197436148f265d7a9c2a98697d (commit) via 2edca2f697cbd337d9e73338202171b39e821331 (commit) via 1237969a0e91a18e566124300f242e3fdd525782 (commit) via 792fcce8ae68436c8963c6a51f1f98c66c575494 (commit) from 2d127a3fcdbe19b892e3a3ee348c95f4a4fde374 (commit) - Log ----------------------------------------------------------------- commit 278743a7938096197436148f265d7a9c2a98697d Author: Wanlong Gao <gao...@cn...> Date: Thu Oct 31 16:37:47 2013 +0800 chroot03: code clean up Clean up the code. Signed-off-by: Wanlong Gao <gao...@cn...> commit 2edca2f697cbd337d9e73338202171b39e821331 Author: Xiaoguang Wang <wan...@cn...> Date: Thu Oct 31 10:15:05 2013 +0800 chroot/chroot03.c: add ELOOP error value test for chroot(2) Signed-off-by: Xiaoguang Wang <wan...@cn...> Reviewed-by: Wanlong Gao <gao...@cn...> commit 1237969a0e91a18e566124300f242e3fdd525782 Author: Simon Xu <xu....@or...> Date: Thu Oct 31 13:44:12 2013 +0800 dhcpd_tests.sh: fix dhcpd.conf file paths dhcpd_tests.sh only checks for /etc/dhcpd.conf, while in some distros the path is /etc/dhcp/dhcpd.conf. Signed-off-by: Simon Xu <xu....@or...> Reviewed-by: Wanlong Gao <gao...@cn...> commit 792fcce8ae68436c8963c6a51f1f98c66c575494 Author: Simon Xu <xu....@or...> Date: Thu Oct 31 14:13:38 2013 +0800 iptables_tests.sh: nat table can have 4 chains It is considered by iptables_tests.sh a failure When nat table chain count is not 3, while recent kernels can have 4 built-in chains in nat table, namely PREROUTING, OUTPUT, POSTROUTING and INPUT. Signed-off-by: Simon Xu <xu....@or...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/chroot/chroot03.c | 93 ++++++++----------------- testcases/network/dhcpd/dhcpd_tests.sh | 23 ++++-- testcases/network/iptables/iptables_tests.sh | 2 +- 3 files changed, 46 insertions(+), 72 deletions(-) diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c index c34d8ea..3d295f7 100644 --- a/testcases/kernel/syscalls/chroot/chroot03.c +++ b/testcases/kernel/syscalls/chroot/chroot03.c @@ -1,5 +1,4 @@ /* - * * Copyright (c) International Business Machines Corp., 2001 * * This program is free software; you can redistribute it and/or modify @@ -18,16 +17,8 @@ */ /* - * NAME - * chroot03.c - * - * DESCRIPTION * Testcase to test whether chroot(2) sets errno correctly. * - * CALLS - * chroot(2) - * - * ALGORITHM * 1. Test for ENAMETOOLONG: * Create a bad directory name with length more than * VFS_MAXNAMELEN (Linux kernel variable), and pass it as the @@ -43,20 +34,11 @@ * The pathname parameter to chroot() points to an invalid address, * chroot(2) fails with EPERM. * - * USAGE: <for command-line> - * chroot03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * 5. Test for ELOOP: + * Too many symbolic links were encountered When resolving the + * pathname parameter. * - * HISTORY * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None */ #include <stdio.h> @@ -66,16 +48,17 @@ #include "test.h" #include "usctest.h" #include <fcntl.h> +#include "safe_macros.h" char *TCID = "chroot03"; -int fd = 0; -char fname[255]; -char good_dir[100] = "/tmp/testdir"; -char bad_dir[] = - "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; +static int fd; +static char fname[255]; +static char good_dir[100] = "/tmp/testdir"; +static char bad_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz"; +static char symbolic_dir[] = "sym_dir1"; -int exp_enos[] = { ENAMETOOLONG, ENOENT, ENOTDIR, EFAULT, 0 }; +static int exp_enos[] = { ENAMETOOLONG, ENOENT, ENOTDIR, EFAULT, ELOOP, 0 }; struct test_case_t { char *dir; @@ -105,16 +88,17 @@ struct test_case_t { * and expect EFAULT as errno */ { - (char *)-1, EFAULT} + (char *)-1, EFAULT}, #endif + {symbolic_dir, ELOOP} }; int TST_TOTAL = (sizeof(TC) / sizeof(*TC)); -char *bad_addr = 0; +static char *bad_addr; -void setup(void); -void cleanup(void); +static void setup(void); +static void cleanup(void); int main(int ac, char **av) { @@ -122,22 +106,18 @@ int main(int ac, char **av) int i; char *msg; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } setup(); - /* set up the expected errnos */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ tst_count = 0; - /* loop through the test cases */ for (i = 0; i < TST_TOTAL; i++) { - TEST(chroot(TC[i].dir)); if (TEST_RETURN != -1) { @@ -155,22 +135,15 @@ int main(int ac, char **av) } } } - cleanup(); + cleanup(); tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); - TEST_PAUSE; - - /* make a temporary directory and cd to it */ tst_tmpdir(); /* @@ -178,9 +151,9 @@ void setup() * ENOTDIR if the argument is not a directory. */ (void)sprintf(fname, "tfile_%d", getpid()); - if ((fd = creat(fname, 0777)) == -1) { + fd = creat(fname, 0777); + if (fd == -1) tst_brkm(TBROK, cleanup, "Failed to creat a temp file"); - } /* * set up good_dir to test whether chroot() is setting ENOENT if the @@ -191,28 +164,22 @@ void setup() #if !defined(UCLINUX) bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); - if (bad_addr == MAP_FAILED) { + if (bad_addr == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap failed"); - } + TC[3].dir = bad_addr; #endif + /* + * create two symbolic directory who point to each other to + * test ELOOP. + */ + SAFE_SYMLINK(cleanup, "sym_dir1/", "sym_dir2"); + SAFE_SYMLINK(cleanup, "sym_dir2/", "sym_dir1"); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ close(fd); - TEST_CLEANUP; - - /* delete the test directory created in setup() */ tst_rmdir(); - } diff --git a/testcases/network/dhcpd/dhcpd_tests.sh b/testcases/network/dhcpd/dhcpd_tests.sh index 64c64e8..c00e549 100755 --- a/testcases/network/dhcpd/dhcpd_tests.sh +++ b/testcases/network/dhcpd/dhcpd_tests.sh @@ -42,7 +42,7 @@ # Function: init # # Description: - Check if command dhcpd is available. -# - Check if /etc/dhcpd.conf is available. +# - Check if dhcpd.conf file is available. # - Create temporary config file, for dhcpd. # - alias ethX to ethX:1 with IP 10.1.1.12 # @@ -141,11 +141,18 @@ init() return $RC fi - if [ -f /etc/dhcpd.conf ] + if [ -f /etc/dhcpd.conf ]; then + DHCPD_CONF="/etc/dhcpd.conf" + elif [ -f /etc/dhcp/dhcpd.conf ]; then + DHCPD_CONF="/etc/dhcp/dhcpd.conf" + else + DHCPD_CONF="" + fi + if [ -n $DHCPD_CONF ] then RC1=0 - mv /etc/dhcpd.conf $LTPTMP/dhcpd.conf > $LTPTMP/tst_dhcpd.err 2>&1 || RC=$? - mv $LTPTMP/tst_dhcpd.conf /etc/dhcpd.conf > $LTPTMP/tst_dhcpd.err 2>&1 \ + mv $DHCPD_CONF $LTPTMP/dhcpd.conf > $LTPTMP/tst_dhcpd.err 2>&1 || RC=$? + mv $LTPTMP/tst_dhcpd.conf $DHCPD_CONF > $LTPTMP/tst_dhcpd.err 2>&1 \ || RC1=$? if [ $RC -ne 0 -o $RC1 -ne 0 ] then @@ -155,7 +162,7 @@ init() fi else tst_brkm TBROK NULL \ - "INIT: No /etc/dhcpd.conf file found." + "INIT: No dhcpd.conf file found." return $(($RC+1)) fi @@ -204,7 +211,7 @@ cleanup() if [ -f $LTPTMP/dhcpd.conf ] then - mv $LTPTMP/dhcpd.conf /etc/dhcpd.conf > $LTPTMP/tst_dhcpd.err 2>&1 + mv $LTPTMP/dhcpd.conf $DHCPD_CONF > $LTPTMP/tst_dhcpd.err 2>&1 fi /sbin/ifconfig | grep "${ETH_INTERFACE}:1" > $LTPTMP/tst_dhcpd.err 2>&1 || RC=$? @@ -225,7 +232,7 @@ cleanup() # # Description - Test basic functionality of dhcpd. # - Test #1: dhcpd will serve IP addresses based on rules in -# /etc/dhcpd.conf file. +# dhcpd.conf file. # - create dhcpd.conf file, server to listen to ethX/.../10.1.1.0 # - start dhcpd server # - create expected output @@ -241,7 +248,7 @@ test01() TST_COUNT=1 # Test number. tst_resm TINFO \ - "Test #1: dhcpd will serve IPaddr, rules in /etc/dhcpd.conf file." + "Test #1: dhcpd will serve IPaddr, rules in dhcpd.conf file." hwaddr=`ifconfig ${ETH_INTERFACE} | grep HWaddr | awk '{print $5}'` || RC=$? if [ $RC -ne 0 ] diff --git a/testcases/network/iptables/iptables_tests.sh b/testcases/network/iptables/iptables_tests.sh index 028d54e..77ee29b 100755 --- a/testcases/network/iptables/iptables_tests.sh +++ b/testcases/network/iptables/iptables_tests.sh @@ -165,7 +165,7 @@ test01() return $RC else chaincnt=$(grep -c Chain $LTPTMP/tst_iptables.out) - if [ $chaincnt -ne 3 ]; then + if [ $chaincnt -ne 3 ] && [ $chaincnt -ne 4 ]; then tst_res TFAIL $LTPTMP/tst_iptables.out \ "$TCID: $cmd failed to list rules. Reason:" return $chaincnt hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-31 02:51:09
|
The branch, master, has been updated via 2d127a3fcdbe19b892e3a3ee348c95f4a4fde374 (commit) via 3aa27d974dcf44e16228fd2d649c842ca667de2a (commit) via 4f305454e656739f609bc90a8118fd2c270ee1f2 (commit) from b3c1c0fc2373b27227f268c88945ead56eedb067 (commit) - Log ----------------------------------------------------------------- commit 2d127a3fcdbe19b892e3a3ee348c95f4a4fde374 Author: Zeng Linggang <zen...@cn...> Date: Fri Oct 25 18:43:16 2013 +0800 chown/chown04.c: Add ELOOP EROFS Add ELOOP, EROFS error number test in chown04.c for chown(2) Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> commit 3aa27d974dcf44e16228fd2d649c842ca667de2a Author: Wang, Xiaoguang <wan...@cn...> Date: Fri Oct 25 16:13:40 2013 +0800 chmod/chmod06.c: add ELOOP, EROFS error number test for chmod(2) Signed-off-by: Xiaoguang Wang <wan...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> commit 4f305454e656739f609bc90a8118fd2c270ee1f2 Author: Zeng Linggang <zen...@cn...> Date: Mon Oct 28 09:32:06 2013 +0800 chdir/chdir01.c: Add ELOOP error number test Add ELOOP error number test in chdir01.c for chdir(2) Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: runtest/ltplite | 2 +- runtest/stress.part3 | 2 +- runtest/syscalls | 6 +- testcases/kernel/syscalls/chdir/chdir01.c | 21 ++++++++- testcases/kernel/syscalls/chmod/chmod06.c | 65 +++++++++++++++++++++++++++- testcases/kernel/syscalls/chown/chown04.c | 58 ++++++++++++++++++++++++- 6 files changed, 141 insertions(+), 13 deletions(-) diff --git a/runtest/ltplite b/runtest/ltplite index 60140e2..a6f57e2 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -110,7 +110,7 @@ chmod07 chmod07 chown01 chown01 chown02 chown02 chown03 export change_owner=$LTPROOT/testcases/bin/change_owner;chown03 -chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 +chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chroot01 chroot01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 7e7f1b7..2962cc4 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -52,7 +52,7 @@ chmod07 chmod07 chown01 chown01 chown02 chown02 chown03 export change_owner=$LTPROOT/testcases/bin/change_owner;chown03 -chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 +chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chroot01 chroot01 diff --git a/runtest/syscalls b/runtest/syscalls index 0486b95..b4bb201 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -54,7 +54,7 @@ chmod02 chmod02 chmod03 chmod03 chmod04 chmod04 chmod05 chmod05 -chmod06 chmod06 +chmod06 chmod06 -D DEVICE -T DEVICE_FS_TYPE chmod07 chmod07 chown01 chown01 @@ -63,8 +63,8 @@ chown02 chown02 chown02_16 chown02_16 chown03 chown03 chown03_16 chown03_16 -chown04 chown04 -chown04_16 chown04_16 +chown04 chown04 -D DEVICE -T DEVICE_FS_TYPE +chown04_16 chown04_16 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chown05_16 chown05_16 diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c index 04fb8b4..c4e74fb 100644 --- a/testcases/kernel/syscalls/chdir/chdir01.c +++ b/testcases/kernel/syscalls/chdir/chdir01.c @@ -59,9 +59,9 @@ #include "safe_macros.h" char *TCID = "chdir01"; -int TST_TOTAL = 1; +int TST_TOTAL = 2; -int exp_enos[] = { ENOTDIR, 0 }; +int exp_enos[] = { ENOTDIR, ELOOP, 0 }; void setup(void); void cleanup(void); @@ -120,6 +120,23 @@ int main(int ac, char **av) SAFE_CHDIR(cleanup, ".."); + /* ELOOP */ + SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2"); + SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1"); + + TEST(chdir("test_eloop1")); + + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "call succeeded unexpectedly"); + } else if (TEST_ERRNO != ELOOP) { + tst_resm(TFAIL | TTERRNO, + "failed unexpectedly; wanted ELOOP"); + } else { + tst_resm(TPASS, "failed as expected with ELOOP"); + } + + SAFE_UNLINK(cleanup, "test_eloop1"); + SAFE_UNLINK(cleanup, "test_eloop2"); } cleanup(); diff --git a/testcases/kernel/syscalls/chmod/chmod06.c b/testcases/kernel/syscalls/chmod/chmod06.c index 0745f02..0dd2433 100644 --- a/testcases/kernel/syscalls/chmod/chmod06.c +++ b/testcases/kernel/syscalls/chmod/chmod06.c @@ -92,9 +92,11 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> +#include <sys/mount.h> #include "test.h" #include "usctest.h" +#include "safe_macros.h" #define MODE_RWX (S_IRWXU|S_IRWXG|S_IRWXO) #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) @@ -102,16 +104,33 @@ #define TEST_FILE1 "tfile_1" #define TEST_FILE2 "testdir_1/tfile_2" #define TEST_FILE3 "t_file/tfile_3" +#define TEST_FILE4 "test_file4" +#define MNT_POINT "mntpoint" + +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) int setup1(); /* setup function to test chmod for EPERM */ int setup2(); /* setup function to test chmod for EACCES */ int setup3(); /* setup function to test chmod for ENOTDIR */ int longpath_setup(); /* setup function to test chmod for ENAMETOOLONG */ +static void help(); char *test_home; /* variable to hold TESTHOME env. */ char Longpathname[PATH_MAX + 2]; char High_address_node[64]; +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; + struct test_case_t { /* test case struct. to hold ref. test cond's */ char *pathname; mode_t mode; @@ -140,8 +159,10 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */ { "", FILE_MODE, ENOENT, NULL}, /* Pathname contains a regular file. */ - { -TEST_FILE3, FILE_MODE, ENOTDIR, setup3},}; + {TEST_FILE3, FILE_MODE, ENOTDIR, setup3}, + {MNT_POINT, FILE_MODE, EROFS, NULL}, + {TEST_FILE4, FILE_MODE, ELOOP, NULL}, +}; char *TCID = "chmod06"; int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases); @@ -162,9 +183,16 @@ int main(int ac, char **av) char nobody_uid[] = "nobody"; struct passwd *ltpuser; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, options, help); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + /* Check for mandatory option of the testcase */ + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device " + "used for mounting with -D option"); + } + setup(); TEST_EXP_ENOS(exp_enos); @@ -240,6 +268,19 @@ void setup() tst_tmpdir(); + tst_mkfs(NULL, device, fstype, NULL); + + SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); + + /* + * mount a read-only file system for test EROFS + */ + if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; + bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); if (bad_addr == MAP_FAILED) @@ -249,6 +290,13 @@ void setup() for (i = 0; i < TST_TOTAL; i++) if (test_cases[i].setupfunc != NULL) test_cases[i].setupfunc(); + + /* + * create two symbolic links who point to each other for + * test ELOOP. + */ + SAFE_SYMLINK(cleanup, "test_file4", "test_file5"); + SAFE_SYMLINK(cleanup, "test_file5", "test_file4"); } /* @@ -355,5 +403,16 @@ void cleanup() if (chmod(DIR_TEMP, MODE_RWX) == -1) tst_resm(TBROK | TERRNO, "chmod(%s) failed", DIR_TEMP); + if (mount_flag && umount(MNT_POINT) < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } tst_rmdir(); } + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} diff --git a/testcases/kernel/syscalls/chown/chown04.c b/testcases/kernel/syscalls/chown/chown04.c index f45afc5..47b54bb 100644 --- a/testcases/kernel/syscalls/chown/chown04.c +++ b/testcases/kernel/syscalls/chown/chown04.c @@ -88,24 +88,41 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> +#include <sys/mount.h> #include "test.h" #include "usctest.h" +#include "safe_macros.h" #define MODE_RWX (S_IRWXU|S_IRWXG|S_IRWXO) #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) #define DIR_TEMP "testdir_1" #define TEST_FILE1 "tfile_1" #define TEST_FILE2 (DIR_TEMP "/tfile_2") #define TEST_FILE3 "t_file/tfile_3" +#define TEST_FILE4 "test_eloop1" +#define TEST_FILE5 "mntpoint" void setup1(); void setup2(); void setup3(); void longpath_setup(); +static void help(void); char Longpathname[PATH_MAX + 2]; char high_address_node[64]; +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; struct test_case_t { char *pathname; @@ -119,11 +136,14 @@ struct test_case_t { (char *)-1, EFAULT, NULL}, { Longpathname, ENAMETOOLONG, longpath_setup}, { "", ENOENT, NULL}, { -TEST_FILE3, ENOTDIR, setup3},}; + TEST_FILE3, ENOTDIR, setup3}, { + TEST_FILE4, ELOOP, NULL}, { + TEST_FILE5, EROFS, NULL},}; char *TCID = "chown04"; int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases); -int exp_enos[] = { EPERM, EACCES, EFAULT, ENAMETOOLONG, ENOENT, ENOTDIR, 0 }; +int exp_enos[] = { EPERM, EACCES, EFAULT, ENAMETOOLONG, ENOENT, ENOTDIR, + ELOOP, EROFS, 0 }; struct passwd *ltpuser; @@ -141,8 +161,13 @@ int main(int ac, char **av) uid_t user_id; gid_t group_id; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, options, help); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device used for " + "mounting with -D option"); + } setup(); @@ -185,9 +210,12 @@ int main(int ac, char **av) void setup() { int i; + int fd; tst_require_root(NULL); + tst_mkfs(NULL, device, fstype, NULL); + tst_sig(FORK, DEF_HANDLER, cleanup); ltpuser = getpwnam("nobody"); @@ -208,6 +236,19 @@ void setup() test_cases[3].pathname = bad_addr; + SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2"); + SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1"); + + SAFE_SETEUID(cleanup, 0); + SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE); + if (mount(device, "mntpoint", fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; + + SAFE_SETEUID(cleanup, ltpuser->pw_uid); + for (i = 0; i < TST_TOTAL; i++) if (test_cases[i].setupfunc != NULL) test_cases[i].setupfunc(); @@ -290,7 +331,18 @@ void cleanup() if (seteuid(0) == -1) tst_resm(TWARN | TERRNO, "seteuid(0) failed"); + if (mount_flag && umount("mntpoint") < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } tst_rmdir(); } + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-30 03:51:12
|
The branch, master, has been updated via b3c1c0fc2373b27227f268c88945ead56eedb067 (commit) from 8bec5d12646894cf29be8231ef5cb54fa468e22f (commit) - Log ----------------------------------------------------------------- commit b3c1c0fc2373b27227f268c88945ead56eedb067 Author: Alexey Kodanev <ale...@or...> Date: Tue Oct 29 18:04:30 2013 +0400 device-drivers: pci: check memory region for flag IORESOURCE_PREFETCH This is done to make sure there will be no side effects if we change it somehow in the test (e.g. we're not changing I/O ports implemented as memory regions). Remove annoying printk messages. Signed-off-by: Alexey Kodanev <ale...@or...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: .../device-drivers/pci/tpci_kernel/ltp_tpci.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c index 4e92f5e..d2ffacd 100644 --- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c +++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c @@ -99,8 +99,6 @@ static int probe_pci_dev(unsigned int bus, unsigned int slot) { struct pci_dev *dev; - prk_info("find arbitrary pci device for test"); - if (ltp_pci.dev) { pci_dev_put(ltp_pci.dev); ltp_pci.dev = NULL; @@ -467,7 +465,8 @@ static int test_assign_resources(void) r->name, r->flags, (unsigned long)r->start, (unsigned long)r->end); - if ((r->flags & IORESOURCE_MEM) == IORESOURCE_MEM) { + if (r->flags & IORESOURCE_MEM && + r->flags & IORESOURCE_PREFETCH) { ret = pci_assign_resource(dev, i); prk_info("assign resource to '%d', ret '%d'", i, ret); rc |= (ret < 0 && ret != -EBUSY) ? TFAIL : TPASS; @@ -718,8 +717,6 @@ static ssize_t sys_bus_slot(struct device *dev, bus = res >> 8 & 0xFF; slot = res & 0xFF; - prk_info("get bus '%u' slot '%u'", bus, slot); - ret = probe_pci_dev(bus, slot); if (ret) return ret; hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-29 06:51:12
|
The branch, master, has been updated via 8bec5d12646894cf29be8231ef5cb54fa468e22f (commit) via 700999e72a5a8a7e961f63b32622c9cdc6447f8c (commit) from 4177e38064cd4c35176132c5c38ac54e07f9033f (commit) - Log ----------------------------------------------------------------- commit 8bec5d12646894cf29be8231ef5cb54fa468e22f Author: Stanislav Kholmanskikh <sta...@or...> Date: Fri Oct 25 16:32:35 2013 +0400 kernel/connectors: TCONF vs TBROK, and fix check for root Fixed check for root the same way as in 08dcfbb5a4ebad9319c54935a600ab936708c6da. If the test is run on unsupported kernels it should return TCONF, not TBROK. Fixed this. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> Reviewed-by: Wanlong Gao <gao...@cn...> commit 700999e72a5a8a7e961f63b32622c9cdc6447f8c Author: Honggyu Kim <hon...@lg...> Date: Mon Oct 28 12:06:32 2013 +0900 ext4-new-features: fix syntax error in configure In configure, string comparison is done using double assignment. /bin/sh doesn't allow to compare strings using "==". So "==" is modified to "=". Signed-off-by: Honggyu Kim <hon...@lg...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/connectors/pec/run_pec_test | 8 ++++---- testcases/kernel/fs/ext4-new-features/configure | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/connectors/pec/run_pec_test b/testcases/kernel/connectors/pec/run_pec_test index 7577ffa..2729485 100755 --- a/testcases/kernel/connectors/pec/run_pec_test +++ b/testcases/kernel/connectors/pec/run_pec_test @@ -33,14 +33,14 @@ export TST_COUNT=1 exit_status=0 -if [ "$USER" != root ]; then - tst_brkm TBROK ignored "Test must be run as root" +if [ $(id -u) != 0 ]; then + tst_brkm TCONF ignored "Test must be run as root" exit 0; fi grep cn_proc /proc/net/connector > /dev/null if [ $? -ne 0 ]; then - tst_brkm TBROK ignored "Process Event Connector is not supported or kernel is below 2.6.26" + tst_brkm TCONF ignored "Process Event Connector is not supported or kernel is below 2.6.26" exit 0; fi @@ -77,7 +77,7 @@ run_case() fi if [ $ret2 -eq 2 ]; then - tst_brkm TBROK NULL "connector may not be supported" + tst_brkm TCONF NULL "connector may not be supported" exit 0 fi diff --git a/testcases/kernel/fs/ext4-new-features/configure b/testcases/kernel/fs/ext4-new-features/configure index 13f43f9..12849e5 100755 --- a/testcases/kernel/fs/ext4-new-features/configure +++ b/testcases/kernel/fs/ext4-new-features/configure @@ -14,9 +14,9 @@ read EXT4_DEV echo "The partition is: $EXT4_DEV, Are you sure(Y/N)?" read RESULT -if [ "$RESULT" == "Y" ] || [ "$RESULT" == "y" ]; then +if [ "$RESULT" = "Y" ] || [ "$RESULT" = "y" ]; then echo "EXT4_DEV=$EXT4_DEV" > ./ext4-test-config -elif [ "$RESULT" == "N" ]; then +elif [ "$RESULT" = "N" ]; then echo "Give up specifing a partition!" else echo "Your input is wrong($RESULT)." hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-28 05:51:08
|
The branch, master, has been updated via 4177e38064cd4c35176132c5c38ac54e07f9033f (commit) from df737303b55e7d2847661e0c3a779672a2ab1752 (commit) - Log ----------------------------------------------------------------- commit 4177e38064cd4c35176132c5c38ac54e07f9033f Author: Shuang Qiu <shu...@or...> Date: Tue Oct 22 17:22:34 2013 +0800 Fix cgroup_regression_test.sh script issue Testcase cgroup sometimes fail although there is no bug found. Initialize the exit status to fix it. Using "rmdir cgroup/" to clean up test_dir sometimes failed because there may be subdir not removed in cgroup/. Using "rmdir -p cgroup/*" instead. Signed-off-by: Shuang Qiu <shu...@or...> Acked-by: Cyril Hrubis <ch...@su...> Reviewed-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: .../controllers/cgroup/cgroup_regression_test.sh | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh index f5e0b4b..356c000 100755 --- a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh +++ b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh @@ -28,6 +28,8 @@ export TCID="cgroup_regression_test" export TST_TOTAL=10 export TST_COUNT=1 +failed=0 + tst_kvercmp 2 6 29 if [ $? -eq 0 ]; then tst_brkm TCONF ignored "test must be run with kernel 2.6.29 or newer" @@ -523,7 +525,7 @@ for ((cur = 1; cur <= $TST_TOTAL; cur++)) test_$cur } -rmdir cgroup/ +rmdir -p cgroup/* exit $failed hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-24 11:51:13
|
The branch, master, has been updated via df737303b55e7d2847661e0c3a779672a2ab1752 (commit) from 69d3b326811ba347e75335756ae7c5334deb9f11 (commit) - Log ----------------------------------------------------------------- commit df737303b55e7d2847661e0c3a779672a2ab1752 Author: Alexey Kodanev <ale...@or...> Date: Thu Oct 24 13:25:53 2013 +0400 device-drivers: tbio: enable build and run Signed-off-by: Alexey Kodanev <ale...@or...> ----------------------------------------------------------------------- Summary of changes: runtest/kernel_misc | 1 + testcases/kernel/device-drivers/Makefile | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/runtest/kernel_misc b/runtest/kernel_misc index db210ec..3e3d016 100644 --- a/runtest/kernel_misc +++ b/runtest/kernel_misc @@ -3,3 +3,4 @@ fw_load fw_load rtc01 rtc01 block_dev block_dev tpci tpci +tbio tbio diff --git a/testcases/kernel/device-drivers/Makefile b/testcases/kernel/device-drivers/Makefile index c97d327..9f80094 100644 --- a/testcases/kernel/device-drivers/Makefile +++ b/testcases/kernel/device-drivers/Makefile @@ -21,5 +21,6 @@ include $(top_srcdir)/include/mk/env_pre.mk SUBDIRS := block \ pci \ rtc \ + tbio \ include $(top_srcdir)/include/mk/generic_trunk_target.mk hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-23 16:51:09
|
The branch, master, has been updated via 69d3b326811ba347e75335756ae7c5334deb9f11 (commit) via 82a13465123b31108d914fe148646c58e23532be (commit) from 6c5ad9bbf066eaf00fbe4aaecc5a2c727a28f14d (commit) - Log ----------------------------------------------------------------- commit 69d3b326811ba347e75335756ae7c5334deb9f11 Author: Alexey Kodanev <ale...@or...> Date: Tue Oct 22 16:16:42 2013 +0400 device-drivers: tbio: fixes Obsolete code updated to the actual kernel BIO API. User-space program rewritten to use LTP lib. Signed-off-by: Alexey Kodanev <ale...@or...> commit 82a13465123b31108d914fe148646c58e23532be Author: Alexey Kodanev <ale...@or...> Date: Fri Oct 18 13:39:43 2013 +0400 device-drivers: tbio: rearrange test files Signed-off-by: Alexey Kodanev <ale...@or...> ----------------------------------------------------------------------- Summary of changes: .../kernel/device-drivers/{block => tbio}/Makefile | 0 .../device-drivers/tbio/kernel_space/Makefile | 22 - .../device-drivers/tbio/kernel_space/load_tbio.sh | 5 - .../kernel/device-drivers/tbio/kernel_space/tbio.c | 589 -------------------- .../kernel/device-drivers/tbio/kernel_space/tbio.h | 96 ---- .../device-drivers/tbio/tbio_kernel/.gitignore | 7 + .../device-drivers/tbio/tbio_kernel/Makefile | 33 ++ .../device-drivers/tbio/tbio_kernel/ltp_tbio.c | 569 +++++++++++++++++++ .../tbio/{kernel_space => tbio_kernel}/str_tbio.h | 0 .../kernel/device-drivers/tbio/tbio_kernel/tbio.h | 71 +++ .../device-drivers/tbio/tbio_user/.gitignore | 1 + .../block_dev_user => tbio/tbio_user}/Makefile | 0 .../kernel/device-drivers/tbio/tbio_user/tbio.c | 334 +++++++++++ .../kernel/device-drivers/tbio/user_space/Makefile | 9 - .../device-drivers/tbio/user_space/tbio_ki.c | 86 --- .../device-drivers/tbio/user_space/user_tbio.c | 348 ------------ .../device-drivers/tbio/user_space/user_tbio.h | 22 - 17 files changed, 1015 insertions(+), 1177 deletions(-) copy testcases/kernel/device-drivers/{block => tbio}/Makefile (100%) delete mode 100644 testcases/kernel/device-drivers/tbio/kernel_space/Makefile delete mode 100755 testcases/kernel/device-drivers/tbio/kernel_space/load_tbio.sh delete mode 100644 testcases/kernel/device-drivers/tbio/kernel_space/tbio.c delete mode 100644 testcases/kernel/device-drivers/tbio/kernel_space/tbio.h create mode 100644 testcases/kernel/device-drivers/tbio/tbio_kernel/.gitignore create mode 100644 testcases/kernel/device-drivers/tbio/tbio_kernel/Makefile create mode 100644 testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c rename testcases/kernel/device-drivers/tbio/{kernel_space => tbio_kernel}/str_tbio.h (100%) create mode 100644 testcases/kernel/device-drivers/tbio/tbio_kernel/tbio.h create mode 100644 testcases/kernel/device-drivers/tbio/tbio_user/.gitignore copy testcases/kernel/device-drivers/{block/block_dev_user => tbio/tbio_user}/Makefile (100%) create mode 100644 testcases/kernel/device-drivers/tbio/tbio_user/tbio.c delete mode 100644 testcases/kernel/device-drivers/tbio/user_space/Makefile delete mode 100644 testcases/kernel/device-drivers/tbio/user_space/tbio_ki.c delete mode 100644 testcases/kernel/device-drivers/tbio/user_space/user_tbio.c delete mode 100644 testcases/kernel/device-drivers/tbio/user_space/user_tbio.h diff --git a/testcases/kernel/device-drivers/block/Makefile b/testcases/kernel/device-drivers/tbio/Makefile similarity index 100% copy from testcases/kernel/device-drivers/block/Makefile copy to testcases/kernel/device-drivers/tbio/Makefile diff --git a/testcases/kernel/device-drivers/tbio/kernel_space/Makefile b/testcases/kernel/device-drivers/tbio/kernel_space/Makefile deleted file mode 100644 index 2bbd1f5..0000000 --- a/testcases/kernel/device-drivers/tbio/kernel_space/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -# -# Makefile for GCOV profiling kernel module -# - -#KERNELDIR := /usr/src/linux-2.5.64-gcov -EXTRA_CFLAGS := -Wall - -ifneq ($(KERNELRELEASE),) - -obj-m := tbio.o -else -KDIR := /lib/modules/$(shell uname -r)/build -PWD := $(shell pwd) - -default: - $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules -# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules -endif - -clean: - rm -f *.o rm -f .*.cmd rm -f *.bb* rm -f *.ko rm -f *.mod.* 2>/dev/null || true - diff --git a/testcases/kernel/device-drivers/tbio/kernel_space/load_tbio.sh b/testcases/kernel/device-drivers/tbio/kernel_space/load_tbio.sh deleted file mode 100755 index 724bd65..0000000 --- a/testcases/kernel/device-drivers/tbio/kernel_space/load_tbio.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -insmod -f ./tbio.ko || insmod -f ./tbio.o || exit 1 -rm -f /dev/tbio0 -major=`awk '/tbio/{print \$1}' /proc/devices` -mknod /dev/tbio0 b $major 0 diff --git a/testcases/kernel/device-drivers/tbio/kernel_space/tbio.c b/testcases/kernel/device-drivers/tbio/kernel_space/tbio.c deleted file mode 100644 index 447d223..0000000 --- a/testcases/kernel/device-drivers/tbio/kernel_space/tbio.c +++ /dev/null @@ -1,589 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - - * This module will test block io layer. - * - * module: tbio - * Copyright (c) International Business Machines Corp., 2003 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; - * - * FILE : tbio.c - * USAGE : kernel_space:./load_tbio.sh - * user_space :./test_bio - * - * DESCRIPTION : The module will test block i/o layer for kernel 2.5 - * REQUIREMENTS: - * 1) glibc 2.1.91 or above. - * - * HISTORY : - * 11/19/2003 Kai Zhao (lt...@cn...) - * - * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) - * - */ - -#ifndef __KERNEL__ -#define __KERNEL__ -#endif - -#include <linux/module.h> -//#include <linux/moduleparam.h> -#include <linux/init.h> - -#include <linux/kernel.h> -#include <linux/fs.h> -#include <linux/errno.h> -#include <linux/types.h> -#include <linux/vmalloc.h> -#include <linux/genhd.h> -#include <linux/blkdev.h> -#include <linux/buffer_head.h> -#include "tbio.h" - -#define BLK_DEFAULT_TIMEOUT (60 * HZ) -MODULE_AUTHOR("Kai Zhao <lt...@cn...>"); -MODULE_DESCRIPTION(TMOD_DRIVER_NAME); -MODULE_LICENSE("GPL"); - -//module_param(major_num , int , 0); -static int hardsect_size = 1024; -//module_param(hardsect_size , int , 0); -static int nsectors = 1024; -//module_param(nsectors , int , 0); - -static struct bio *tbiop = NULL, *tbiop_dup = NULL; -//static struct bio_pair *bio_pairp = NULL; -static struct request_queue Queue; - -static struct tbio_device { - unsigned long size; - spinlock_t lock; - u8 *data; - struct gendisk *gd; - struct block_device *bdev; -} Device; - -static int send_request(request_queue_t * q, struct bio *bio, - struct block_device *bdev, struct tbio_interface *inter, - int writing) -{ - struct request *rq; - void *buffer = NULL; - unsigned long start_time; - int err; - - rq = blk_get_request(q, writing ? WRITE : READ, __GFP_WAIT); - rq->cmd_len = inter->cmd_len; - //printk("inter.cmd %s\n" , inter->cmd); - if (copy_from_user(rq->cmd, inter->cmd, inter->cmd_len)) - goto out_request; - //printk("tbio: rq->cmd : %s\n",rq->cmd); - if (sizeof(rq->cmd) != inter->cmd_len) - memset(rq->cmd + inter->cmd_len, 0, - sizeof(rq->cmd) - inter->cmd_len); - - rq->bio = rq->biotail = NULL; - - blk_rq_bio_prep(q, rq, bio); - - rq->data = buffer; - rq->data_len = inter->data_len; - - rq->timeout = 0; - if (!rq->timeout) - rq->timeout = q->sg_timeout; - if (!rq->timeout) - rq->timeout = BLK_DEFAULT_TIMEOUT; - - start_time = jiffies; - - DECLARE_COMPLETION(wait); - - rq->rq_disk = bdev->bd_disk; - - rq->waiting = &wait; - elv_add_request(q, rq, 1, 1); - generic_unplug_device(q); - wait_for_completion(&wait); - //printk("tbio: completion\n"); - if (rq->errors) { - err = -EIO; - printk("tbio: rq->errors\n"); - return err; - } - - blk_put_request(rq); - - return 0; -out_request: - blk_put_request(rq); - return -EFAULT; - -} - -static int tbio_io(struct block_device *bdev, struct tbio_interface *uptr) -{ - tbio_interface_t inter; - struct bio *bio = NULL; - int reading = 0, writing = 0; - void *buffer = NULL; - //struct request *rq; - request_queue_t *q; - q = bdev_get_queue(Device.bdev); - - if (copy_from_user(&inter, uptr, sizeof(tbio_interface_t))) { - printk("tbio: copy_from_user\n"); - return -EFAULT; - } - - if (inter.data_len > (q->max_sectors << 9)) { - printk("tbio: inter.in_len > q->max_sectors << 9\n"); - return -EIO; - } - - if (inter.data_len) { - - switch (inter.direction) { - default: - return -EINVAL; - case TBIO_TO_DEV: - writing = 1; - break; - case TBIO_FROM_DEV: - reading = 1; - break; - } - - bio = bio_map_user(bdev, (unsigned long)inter.data, - inter.data_len, reading); - - if (!bio) { - printk("tbio : bio_map_user failed\n"); - buffer = - kmalloc(inter.data_len, q->bounce_gfp | GFP_USER); - if (!buffer) { - printk("tbio: buffer no memory\n"); - return -1; - } - copy_from_user(buffer, inter.data, inter.data_len); - printk("tbio: buffer %s\n", (char *)buffer); - } - - } - - send_request(q, bio, bdev, &inter, writing); - - if (bio) - bio_unmap_user(bio, reading); - return 0; -} - -static int test_bio_put(struct bio *biop) -{ - - if (biop) - bio_put(biop); - - return 0; -} - -static int test_bio_clone(void) -{ - tbiop_dup = bio_clone(tbiop, GFP_NOIO); - if (tbiop_dup == NULL) { - printk("tbio: bio_clone failed\n"); - return -1; - } - - test_bio_put(tbiop_dup); - - return 0; -} - -static int test_bio_add_page(void) -{ - int res = 0, i = 0, offset = 0; - unsigned long addr = 0; - struct page *ppage = NULL; - - for (i = 0; i < 128; i++) { - - addr = get_zeroed_page(GFP_KERNEL); - - if (addr == 0) { - printk("tbio: get free page failed %ld\n", addr); - return -1; - } - - ppage = virt_to_page(addr); - if (ppage == NULL) { - printk - ("tbio: covert virture page to page struct failed\n"); - return -1; - } - - res = bio_add_page(tbiop, ppage, PAGE_SIZE, offset); - if (res < 0) { - printk("bio_add_page :res %d\n", res); - return -1; - } - offset += res; - // printk ("tbio: bio_add_page : %d\n", res); - } - return 0; -} - -static int test_do_bio_alloc(int num) -{ - tbiop = bio_alloc(GFP_KERNEL, num); - if (tbiop == NULL) { - printk("tbio: bio_alloc failed\n"); - return -1; - } - bio_put(tbiop); - - return 0; -} - -static int test_bio_alloc(void) -{ - int res = 0; - res = test_do_bio_alloc(2); - if (res < 0) { - printk("can not alloc bio for %d\n", 2); - return -1; - } - - res = test_do_bio_alloc(8); - if (res < 0) { - printk("can not alloc bio for %d\n", 8); - return -1; - } - res = test_do_bio_alloc(32); - if (res < 0) { - printk("can not alloc bio for %d\n", 32); - return -1; - } - res = test_do_bio_alloc(96); - if (res < 0) { - printk("can not alloc bio for %d\n", 96); - return -1; - } - res = test_do_bio_alloc(BIO_MAX_PAGES); - if (res < 0) { - printk("can not alloc bio for %d\n", BIO_MAX_PAGES); - return -1; - } - - tbiop = bio_alloc(GFP_KERNEL, BIO_MAX_PAGES); - if (tbiop == NULL) { - printk("tbio: bio_alloc failed\n"); - return -1; - } - - return 0; -} - -static int test_bio_split(struct block_device *bdev, - struct tbio_interface *uptr) -{ - tbio_interface_t inter; - struct bio *bio = NULL; - struct bio_pair *bio_pairp = NULL; - int reading = 0, writing = 0; - void *buffer = NULL; - request_queue_t *q; - q = bdev_get_queue(Device.bdev); - - if (copy_from_user(&inter, uptr, sizeof(tbio_interface_t))) { - printk("tbio: copy_from_user\n"); - return -EFAULT; - } - - if (inter.data_len > (q->max_sectors << 9)) { - printk("tbio: inter.in_len > q->max_sectors << 9\n"); - return -EIO; - } - - if (inter.data_len) { - - switch (inter.direction) { - default: - return -EINVAL; - case TBIO_TO_DEV: - writing = 1; - break; - case TBIO_FROM_DEV: - reading = 1; - break; - } - - bio = bio_map_user(bdev, (unsigned long)inter.data, - inter.data_len, reading); - - if (!bio) { - printk("tbio : bio_map_user failed\n"); - buffer = - kmalloc(inter.data_len, q->bounce_gfp | GFP_USER); - if (!buffer) { - printk("tbio: buffer no memory\n"); - return -1; - } - copy_from_user(buffer, inter.data, inter.data_len); - printk("tbio: buffer %s\n", (char *)buffer); - } else { - // printk("tbio: bio sectors %d\n", bio_sectors(bio)); - // printk("tbio: split now\n"); - bio_pairp = bio_split(bio, bio_split_pool, 2); - - if (bio_pairp == NULL) { - printk("tbio: bio_split failed\n"); - bio_unmap_user(bio, reading); - return -1; - } - } - - } - - send_request(q, &(bio_pairp->bio1), bdev, &inter, writing); - q = bdev_get_queue(Device.bdev); - send_request(q, &(bio_pairp->bio2), bdev, &inter, writing); - - if (bio_pairp) { - bio_pair_release(bio_pairp); - return 0; - } - - if (bio) - bio_unmap_user(bio, reading); - - return 0; - -} - -static int test_bio_get_nr_vecs(void) -{ - int number = 0; - - if (!tbiop) { - printk("tbio: tbiop is NULL\n"); - return -1; - } - - number = bio_get_nr_vecs(tbiop->bi_bdev); - - if (number < 0) { - printk("tbio: bio_get_nr_vec failed\n"); - return -1; - } - //printk("bio_get_nr_vecs: %d\n",number); - return 0; -} - -static int tbio_ioctl(struct inode *ino, struct file *file, - unsigned int cmd, unsigned long arg) -{ - int err; -// request_queue_t *q; - - //q = bdev_get_queue(Device.bdev); - - printk("ttbio: ioctl 0x%x 0x%lx\n", cmd, arg); - - switch (cmd) { - case LTP_TBIO_DO_IO: - { - err = bd_claim(Device.bdev, current); - if (err) { - printk("tbio:bd_claim\n"); - break; - } - - err = - tbio_io(Device.bdev, (struct tbio_interface *)arg); - bd_release(Device.bdev); - } - break; - - case LTP_TBIO_CLONE: - err = test_bio_clone(); - break; - case LTP_TBIO_ADD_PAGE: - err = test_bio_add_page(); - break; - case LTP_TBIO_ALLOC: - err = test_bio_alloc(); - break; - case LTP_TBIO_GET_NR_VECS: - err = test_bio_get_nr_vecs(); - break; - case LTP_TBIO_PUT: - err = test_bio_put(tbiop); - break; - case LTP_TBIO_SPLIT: - { - err = bd_claim(Device.bdev, current); - if (err) { - printk("tbio:bd_claim\n"); - break; - } - - err = - test_bio_split(Device.bdev, - (struct tbio_interface *)arg); - bd_release(Device.bdev); - - } - break; - //case LTP_TBIO_PAIR_RELEASE: err = test_bio_pair_release();break; - - } - return 0; -} - -static void tbio_transfer(struct request *req, struct tbio_device *dev) -{ - - struct bio *bio = req->bio; - - //printk("tbio: bio_data(bio) %s\n" , (char *)bio_data(bio)); - if (bio_data_dir(bio)) { - printk("tbio: write \"%s\" to dev\n", (char *)bio_data(bio)); - memcpy(dev->data, bio_data(bio), bio->bi_size); - } else { - memcpy(bio_data(bio), dev->data, bio->bi_size); - printk("tbio: read \"%s\" from dev\n", (char *)bio_data(bio)); - } - -} - -static void tbio_request(request_queue_t * q) -{ - struct request *req; - - while ((req = elv_next_request(q)) != NULL) { - - tbio_transfer(req, &Device); - end_request(req, 1); - } -} - -static int tbio_open(struct inode *inode, struct file *filep) -{ - if (!Device.bdev) { - Device.bdev = inode->i_bdev; - //atomic_inc((atomic_t)&Device.bdev->bd_part_count); - } - - return 0; -} - -static int tbio_release(struct inode *inode, struct file *filep) -{ - return 0; -} - -int tbio_media_changed(struct gendisk *gd) -{ - return 0; -} - -int tbio_revalidate(struct gendisk *gd) -{ - return 0; -} - -static struct block_device_operations tbio_ops = { - .owner = THIS_MODULE, - .open = tbio_open, - .ioctl = tbio_ioctl, - .release = tbio_release, - .media_changed = tbio_media_changed, - .revalidate_disk = tbio_revalidate -}; - -static int __init tbio_init(void) -{ - Device.size = nsectors * hardsect_size; - int result; - spin_lock_init(&Device.lock); - Device.data = vmalloc(Device.size); - if (Device.data == NULL) - return -ENOMEM; - Device.bdev = NULL; - - result = register_blkdev(TBIO_MAJOR, DEVICE_NAME); //, &tbio_ops); - - printk(KERN_ALERT "LTP BIO: register_blkdev result=%d major %d\n", - result, TBIO_MAJOR); - - if (result <= 0) { - printk(KERN_WARNING "tbio:unable to get major number\n"); - goto out; - } - - Device.gd = alloc_disk(1); - if (!Device.gd) - goto out_unregister; - Device.gd->major = TBIO_MAJOR; - Device.gd->first_minor = 0; - Device.gd->fops = &tbio_ops; - Device.gd->private_data = &Device; - strcpy(Device.gd->disk_name, "tbio0"); - set_capacity(Device.gd, nsectors); - blk_init_queue(tbio_request, &Device.lock); - Device.gd->queue = &Queue; - add_disk(Device.gd); - - return 0; - -out_unregister: - unregister_chrdev(TBIO_MAJOR, "tbio"); -out: - vfree(Device.data); - return -ENOMEM; -} - -static void tbio_exit(void) -{ - if (Device.bdev) { - invalidate_bdev(Device.bdev, 1); - bdput(Device.bdev); - } - - del_gendisk(Device.gd); - put_disk(Device.gd); - unregister_blkdev(TBIO_MAJOR, "tbio"); - vfree(Device.data); -} - -module_init(tbio_init); -module_exit(tbio_exit); diff --git a/testcases/kernel/device-drivers/tbio/kernel_space/tbio.h b/testcases/kernel/device-drivers/tbio/kernel_space/tbio.h deleted file mode 100644 index e650399..0000000 --- a/testcases/kernel/device-drivers/tbio/kernel_space/tbio.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - - * In this header file keep all flags and other - * structures that will be needed in both kernel - * and user space. Specifically the ioctl flags - * will go in here so that in user space a program - * can specify flags for the ioctl call. - * - * module: tbio - * Copyright (c) International Business Machines Corp., 2003 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; - * - * FILE : tbio.h - * USAGE : kernel_space:./load_tbio.sh - * user_space :./test_bio - * - * DESCRIPTION : The module will test block i/o layer for kernel 2.5 - * REQUIREMENTS: - * 1) glibc 2.1.91 or above. - * - * HISTORY : - * 11/19/2003 Kai Zhao (lt...@cn...) - * - * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) - * - */ - -#define TMOD_DRIVER_NAME "ltp test block I/O layer module" -#define DEVICE_NAME "/dev/tbio" -#define MAG_NUM 'k' -#define TBIO_MAJOR 258 - -#define TBIO_TO_DEV 1 -#define TBIO_FROM_DEV 2 - -/* put ioctl flags here, use the _IO macro which is - found in linux/ioctl.h, takes a letter, and an - integer */ - -#define LTP_TBIO_CLONE _IO(MAG_NUM,1) -#define LTP_TBIO_ALLOC _IO(MAG_NUM,2) -#define LTP_TBIO_GET_NR_VECS _IO(MAG_NUM,3) -#define LTP_TBIO_PUT _IO(MAG_NUM,4) -#define LTP_TBIO_SPLIT _IO(MAG_NUM,5) -#define LTP_TBIO_DO_IO _IO(MAG_NUM,6) -#define LTP_TBIO_ADD_PAGE _IO(MAG_NUM,7) - -/* memory between the kernel and user space is - seperated, so that if a structure is needed - to be passed between kernel and user space - a call must be made to copy_to_user or copy - from user. Use this structure to streamline - that process. For example: A function that - writes to a disc takes in a ki_write_t - pointer from userspace. In the user space - program specify the length of the pointer as - in_len, and in_data as the actual structure. */ - -struct tbio_interface { - void *data; // input data - int data_len; // input data length - int direction; // read or write form DEV - unsigned char *cmd; // read or write - int cmd_len; // length of cmd -}; -typedef struct tbio_interface tbio_interface_t; - diff --git a/testcases/kernel/device-drivers/tbio/tbio_kernel/.gitignore b/testcases/kernel/device-drivers/tbio/tbio_kernel/.gitignore new file mode 100644 index 0000000..7ce5765 --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_kernel/.gitignore @@ -0,0 +1,7 @@ +/ltp_tbio.ko +/*.mod.c +/modules.order +/.tmp_versions +/.*.ko +/.*.cmd +/Module.symvers diff --git a/testcases/kernel/device-drivers/tbio/tbio_kernel/Makefile b/testcases/kernel/device-drivers/tbio/tbio_kernel/Makefile new file mode 100644 index 0000000..6c6ba92 --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_kernel/Makefile @@ -0,0 +1,33 @@ +# Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +ifneq ($(KERNELRELEASE),) + +obj-m := ltp_tbio.o + +else + +top_srcdir ?= ../../../../.. +include $(top_srcdir)/include/mk/env_pre.mk + +REQ_VERSION_MAJOR := 2 +REQ_VERSION_PATCH := 6 +MAKE_TARGETS := ltp_tbio.ko + +include $(top_srcdir)/include/mk/module.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +endif diff --git a/testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c b/testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c new file mode 100644 index 0000000..5198b82 --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_kernel/ltp_tbio.c @@ -0,0 +1,569 @@ +/* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * This module will test block io layer. + * + * module: tbio + * + * FILE : tbio.c + * USAGE : kernel_space:./load_tbio.sh + * user_space :./test_bio + * + * DESCRIPTION : The module will test block i/o layer for kernel 2.5 + * REQUIREMENTS: + * 1) glibc 2.1.91 or above. + * + * HISTORY : + * 11/19/2003 Kai Zhao (lt...@cn...) + * + * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) + * + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/errno.h> +#include <linux/types.h> +#include <linux/vmalloc.h> +#include <linux/genhd.h> +#include <linux/blkdev.h> +#include <linux/buffer_head.h> + +#include "tbio.h" + +MODULE_AUTHOR("Kai Zhao <lt...@cn...>"); +MODULE_AUTHOR("Alexey Kodanev <ale...@or...>"); +MODULE_DESCRIPTION(TMOD_DRIVER_NAME); +MODULE_LICENSE("GPL"); + +#define prk_err(fmt, ...) \ + pr_err(TBIO_DEVICE_NAME ": " fmt "\n", ##__VA_ARGS__) +#define prk_info(fmt, ...) \ + pr_info(TBIO_DEVICE_NAME ": " fmt "\n", ##__VA_ARGS__) + +static int nsectors = 4096; +module_param(nsectors, int, 0444); +MODULE_PARM_DESC(nsectors, "The number of sectors"); + +static struct bio *tbiop, *tbiop_dup; + +static struct tbio_device { + unsigned long size; + spinlock_t lock; + u8 *data; + struct gendisk *gd; + struct block_device *bdev; + struct request_queue *q; +} tbio_dev; + +static int send_request(struct request_queue *q, struct bio *bio, + struct block_device *bdev, struct tbio_interface *inter, + int writing) +{ + struct request *rq; + rq = blk_make_request(q, bio, GFP_KERNEL); + if (!rq) { + prk_err("failed to make request"); + return -EFAULT; + } + + rq->cmd_len = inter->cmd_len; + + if (copy_from_user(rq->cmd, inter->cmd, inter->cmd_len)) + goto out_request; + + if (sizeof(rq->cmd) != inter->cmd_len) { + memset(rq->cmd + inter->cmd_len, 0, + sizeof(rq->cmd) - inter->cmd_len); + } + + rq->__sector = bio->bi_sector; + + if (blk_execute_rq(q, bdev->bd_disk, rq, 0)) + goto out_request; + + blk_put_request(rq); + + return 0; + +out_request: + + blk_put_request(rq); + return -EFAULT; +} + +static int tbio_io(struct block_device *bdev, struct tbio_interface *uptr) +{ + int ret; + tbio_interface_t inter; + struct bio *bio = NULL; + int reading = 0, writing = 0; + void *buf = NULL; + struct request_queue *q = bdev_get_queue(bdev); + + if (copy_from_user(&inter, uptr, sizeof(tbio_interface_t))) { + prk_err("copy_from_user"); + return -EFAULT; + } + + if (inter.data_len > (q->limits.max_sectors << 9)) { + prk_err("inter.in_len > q->max_sectors << 9"); + return -EIO; + } + + if (inter.data_len) { + + switch (inter.direction) { + default: + return -EINVAL; + case TBIO_TO_DEV: + writing = 1; + break; + case TBIO_FROM_DEV: + reading = 1; + break; + } + + bio = bio_map_user(q, bdev, (unsigned long)inter.data, + inter.data_len, reading, GFP_KERNEL); + + if (!bio) { + prk_err("bio_map_user failed"); + buf = kmalloc(inter.data_len, q->bounce_gfp | GFP_USER); + if (!buf) { + prk_err("buffer no memory"); + return -1; + } + ret = copy_from_user(buf, inter.data, inter.data_len); + if (ret) + prk_err("copy_from_user() failed"); + + prk_info("buffer %s\n, copy_from_user returns '%d'", + (char *)buf, ret); + } + + } + + send_request(q, bio, bdev, &inter, writing); + + if (bio) + bio_unmap_user(bio); + return 0; +} + +static int test_bio_put(struct bio *biop) +{ + if (biop) + bio_put(biop); + + return 0; +} + +static int test_bio_clone(void) +{ + tbiop_dup = bio_clone(tbiop, GFP_NOIO); + if (tbiop_dup == NULL) { + prk_err("bio_clone failed"); + return -1; + } + + test_bio_put(tbiop_dup); + + return 0; +} + +static int test_bio_add_page(void) +{ + int ret = 0, i = 0, offset = 0; + unsigned long addr = 0; + struct page *ppage = NULL; + + for (i = 0; i < 128; i++) { + + addr = get_zeroed_page(GFP_KERNEL); + + if (addr == 0) { + prk_err("get free page failed %ld", addr); + ret = -1; + break; + } + + ppage = virt_to_page(addr); + if (ppage == NULL) { + prk_err("covert virture page to page struct failed"); + ret = -1; + break; + } + + ret = bio_add_page(tbiop, ppage, PAGE_SIZE, offset); + if (ret < 0) { + prk_err("bio_add_page failed"); + break; + } + offset += ret; + } + + return ret; +} + +static int test_do_bio_alloc(int num) +{ + tbiop = bio_alloc(GFP_KERNEL, num); + if (tbiop == NULL) { + prk_err("bio_alloc failed"); + return -1; + } + bio_put(tbiop); + + return 0; +} + +static int test_bio_alloc(void) +{ + if (test_do_bio_alloc(2) < 0) { + prk_err("can not alloc bio for %d", 2); + return -1; + } + + if (test_do_bio_alloc(8) < 0) { + prk_err("can not alloc bio for %d", 8); + return -1; + } + + if (test_do_bio_alloc(32) < 0) { + prk_err("can not alloc bio for %d", 32); + return -1; + } + + if (test_do_bio_alloc(96) < 0) { + prk_err("can not alloc bio for %d", 96); + return -1; + } + + if (test_do_bio_alloc(BIO_MAX_PAGES) < 0) { + prk_err("can not alloc bio for %d", BIO_MAX_PAGES); + return -1; + } + + tbiop = bio_alloc(GFP_KERNEL, BIO_MAX_PAGES); + if (tbiop == NULL) { + prk_err("bio_alloc failed"); + return -1; + } + + tbiop->bi_bdev = tbio_dev.bdev; + tbiop->bi_sector = 0; + + return 0; +} + +static int test_bio_split(struct block_device *bdev, + struct tbio_interface *uptr) +{ + int ret; + tbio_interface_t inter; + struct bio *bio = NULL; + struct bio_pair *bio_pairp = NULL; + int reading = 0, writing = 0; + void *buf = NULL; + struct request_queue *q = bdev_get_queue(bdev); + if (!q) { + prk_err("bdev_get_queue() failed"); + return -EFAULT; + } + + prk_info("test_bio_split"); + + if (copy_from_user(&inter, uptr, sizeof(tbio_interface_t))) { + prk_err("copy_from_user"); + return -EFAULT; + } + + if (inter.data_len > (q->limits.max_sectors << 9)) { + prk_err("inter.in_len > q->limits.max_sectors << 9"); + return -EIO; + } + + prk_info("inter.data_len is %d", inter.data_len); + if (inter.data_len) { + + switch (inter.direction) { + default: + return -EINVAL; + case TBIO_TO_DEV: + writing = 1; + break; + case TBIO_FROM_DEV: + reading = 1; + break; + } + + bio = bio_map_user(q, bdev, (unsigned long)inter.data, + inter.data_len, reading, GFP_KERNEL); + + if (!bio) { + prk_err("bio_map_user failed"); + buf = kmalloc(inter.data_len, q->bounce_gfp | GFP_USER); + if (!buf) { + prk_err("buffer no memory"); + return -1; + } + ret = copy_from_user(buf, inter.data, inter.data_len); + if (ret) + prk_err("copy_from_user() failed"); + + prk_info("buffer %s", (char *)buf); + } else { + bio_pairp = bio_split(bio, 2); + + if (bio_pairp == NULL) { + prk_err("bio_split failed"); + bio_unmap_user(bio); + return -1; + } + } + + } + + send_request(q, &(bio_pairp->bio1), bdev, &inter, writing); + q = bdev_get_queue(bdev); + send_request(q, &(bio_pairp->bio2), bdev, &inter, writing); + + if (bio_pairp) + bio_pair_release(bio_pairp); + + if (bio) + bio_unmap_user(bio); + + return 0; +} + +static int test_bio_get_nr_vecs(void) +{ + int number = 0; + + number = bio_get_nr_vecs(tbio_dev.bdev); + + if (number < 0) { + prk_err("bio_get_nr_vec failed"); + return -1; + } + + prk_info("bio_get_nr_vecs: %d", number); + return 0; +} + +static int tbio_ioctl(struct block_device *blk, fmode_t mode, + unsigned cmd, unsigned long arg) +{ + int err = 0; + + tbio_dev.bdev = blkdev_get_by_path( + DEVICE_NAME, FMODE_READ | FMODE_WRITE, NULL); + + switch (cmd) { + case LTP_TBIO_DO_IO: + prk_info("TEST-CASE: LTP_TBIO_DO_IO:"); + err = tbio_io(tbio_dev.bdev, (struct tbio_interface *)arg); + break; + case LTP_TBIO_CLONE: + prk_info("TEST-CASE: LTP_TBIO_CLONE:"); + err = test_bio_clone(); + break; + case LTP_TBIO_ADD_PAGE: + prk_info("TEST-CASE: LTP_TBIO_ADD_PAGE:"); + err = test_bio_add_page(); + break; + case LTP_TBIO_ALLOC: + prk_info("TEST-CASE: LTP_TBIO_ALLOC:"); + err = test_bio_alloc(); + break; + case LTP_TBIO_GET_NR_VECS: + prk_info("TEST-CASE: LTP_TBIO_GET_NR_VECS:"); + err = test_bio_get_nr_vecs(); + break; + case LTP_TBIO_PUT: + prk_info("TEST-CASE: LTP_TBIO_PUT:"); + err = test_bio_put(tbiop); + break; + case LTP_TBIO_SPLIT: + prk_info("TEST-CASE: LTP_TBIO_SPLIT:"); + err = test_bio_split(tbio_dev.bdev, + (struct tbio_interface *)arg); + break; + } + + prk_info("TEST-CASE DONE"); + blkdev_put(tbio_dev.bdev, FMODE_READ | FMODE_WRITE); + return err; +} + +static int tbio_transfer(struct request *req, struct tbio_device *dev) +{ + unsigned int i = 0, offset = 0; + char *buf; + unsigned long flags; + size_t size; + + struct bio_vec *bv; + struct req_iterator iter; + + size = blk_rq_cur_bytes(req); + prk_info("bio req of size %zu:", size); + offset = blk_rq_pos(req) * 512; + + rq_for_each_segment(bv, req, iter) { + size = bv->bv_len; + prk_info("%s bio(%u), segs(%u) sect(%u) pos(%lu) off(%u)", + (bio_data_dir(iter.bio) == READ) ? "READ" : "WRITE", + i, bio_segments(iter.bio), bio_sectors(iter.bio), + iter.bio->bi_sector, offset); + + if (get_capacity(req->rq_disk) * 512 < offset) { + prk_info("Error, small capacity %zu, offset %u", + get_capacity(req->rq_disk) * 512, + offset); + continue; + } + + buf = bvec_kmap_irq(bv, &flags); + if (bio_data_dir(iter.bio) == WRITE) + memcpy(dev->data + offset, buf, size); + else + memcpy(buf, dev->data + offset, size); + offset += size; + flush_kernel_dcache_page(bv->bv_page); + bvec_kunmap_irq(buf, &flags); + ++i; + } + + return 0; +} + +static void tbio_request(struct request_queue *q) +{ + int ret = 0; + struct request *req; + + while ((req = blk_fetch_request(q)) != NULL) { + + ret = tbio_transfer(req, &tbio_dev); + + spin_unlock_irq(q->queue_lock); + blk_end_request_all(req, ret); + spin_lock_irq(q->queue_lock); + } +} + +static int tbio_open(struct block_device *blk, fmode_t mode) +{ + return 0; +} + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) +static int tbio_release(struct gendisk *gd, fmode_t mode) +#else +static void tbio_release(struct gendisk *gd, fmode_t mode) +#endif +{ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) + return 0; +#endif +} + +int tbio_media_changed(struct gendisk *gd) +{ + return 0; +} + +int tbio_revalidate(struct gendisk *gd) +{ + return 0; +} + +static const struct block_device_operations tbio_ops = { + .owner = THIS_MODULE, + .open = tbio_open, + .ioctl = tbio_ioctl, + .release = tbio_release, + .media_changed = tbio_media_changed, + .revalidate_disk = tbio_revalidate +}; + +static int __init tbio_init(void) +{ + tbio_dev.size = nsectors * 512; + + tbio_dev.data = vmalloc(tbio_dev.size); + if (tbio_dev.data == NULL) + return -ENOMEM; + strcpy(tbio_dev.data, "tbio data"); + tbio_dev.bdev = NULL; + + TBIO_MAJOR = register_blkdev(0, DEVICE_NAME); + if (TBIO_MAJOR <= 0) { + prk_err("unable to get major number"); + goto out; + } + prk_info("register_blkdev major %d", TBIO_MAJOR); + + spin_lock_init(&tbio_dev.lock); + tbio_dev.q = blk_init_queue(tbio_request, &tbio_dev.lock); + if (!tbio_dev.q) { + prk_err("failed to init queue"); + goto out_unregister; + } + + tbio_dev.gd = alloc_disk(1); + if (!tbio_dev.gd) + goto out_unregister; + tbio_dev.gd->major = TBIO_MAJOR; + tbio_dev.gd->first_minor = 0; + tbio_dev.gd->fops = &tbio_ops; + tbio_dev.gd->private_data = &tbio_dev; + tbio_dev.gd->queue = tbio_dev.q; + strcpy(tbio_dev.gd->disk_name, "tbio"); + set_capacity(tbio_dev.gd, nsectors); + tbio_dev.gd->queue->queuedata = tbio_dev.gd; + + add_disk(tbio_dev.gd); + + return 0; + +out_unregister: + unregister_blkdev(TBIO_MAJOR, DEVICE_NAME); +out: + vfree(tbio_dev.data); + return -ENOMEM; +} +module_init(tbio_init); + +static void tbio_exit(void) +{ + blk_cleanup_queue(tbio_dev.q); + del_gendisk(tbio_dev.gd); + put_disk(tbio_dev.gd); + unregister_blkdev(TBIO_MAJOR, DEVICE_NAME); + vfree(tbio_dev.data); + prk_info("exit"); +} +module_exit(tbio_exit); diff --git a/testcases/kernel/device-drivers/tbio/kernel_space/str_tbio.h b/testcases/kernel/device-drivers/tbio/tbio_kernel/str_tbio.h similarity index 100% rename from testcases/kernel/device-drivers/tbio/kernel_space/str_tbio.h rename to testcases/kernel/device-drivers/tbio/tbio_kernel/str_tbio.h diff --git a/testcases/kernel/device-drivers/tbio/tbio_kernel/tbio.h b/testcases/kernel/device-drivers/tbio/tbio_kernel/tbio.h new file mode 100644 index 0000000..cf6df73 --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_kernel/tbio.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * In this header file keep all flags and other + * structures that will be needed in both kernel + * and user space. Specifically the ioctl flags + * will go in here so that in user space a program + * can specify flags for the ioctl call. + * + * HISTORY : + * 11/19/2003 Kai Zhao (lt...@cn...) + * + * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) + * + */ + +#define TMOD_DRIVER_NAME "ltp test block I/O layer module" +#define TBIO_DEVICE_NAME "ltp_tbio" +#define DEVICE_NAME "/dev/tbio" +#define MAG_NUM 'k' +int TBIO_MAJOR; + +#define TBIO_TO_DEV 1 +#define TBIO_FROM_DEV 2 + +/* put ioctl flags here, use the _IO macro which is + found in linux/ioctl.h, takes a letter, and an + integer */ + +#define LTP_TBIO_CLONE _IO(MAG_NUM,1) +#define LTP_TBIO_ALLOC _IO(MAG_NUM,2) +#define LTP_TBIO_GET_NR_VECS _IO(MAG_NUM,3) +#define LTP_TBIO_PUT _IO(MAG_NUM,4) +#define LTP_TBIO_SPLIT _IO(MAG_NUM,5) +#define LTP_TBIO_DO_IO _IO(MAG_NUM,6) +#define LTP_TBIO_ADD_PAGE _IO(MAG_NUM,7) + +/* memory between the kernel and user space is + seperated, so that if a structure is needed + to be passed between kernel and user space + a call must be made to copy_to_user or copy + from user. Use this structure to streamline + that process. For example: A function that + writes to a disc takes in a ki_write_t + pointer from userspace. In the user space + program specify the length of the pointer as + in_len, and in_data as the actual structure. */ + +struct tbio_interface { + void *data; /* input data */ + int data_len; /* input data length */ + int direction; /* read or write form DEV */ + char *cmd; /* read or write */ + int cmd_len; /* length of cmd */ +}; +typedef struct tbio_interface tbio_interface_t; diff --git a/testcases/kernel/device-drivers/tbio/tbio_user/.gitignore b/testcases/kernel/device-drivers/tbio/tbio_user/.gitignore new file mode 100644 index 0000000..79076dc --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_user/.gitignore @@ -0,0 +1 @@ +/tbio diff --git a/testcases/kernel/device-drivers/block/block_dev_user/Makefile b/testcases/kernel/device-drivers/tbio/tbio_user/Makefile similarity index 100% copy from testcases/kernel/device-drivers/block/block_dev_user/Makefile copy to testcases/kernel/device-drivers/tbio/tbio_user/Makefile diff --git a/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c new file mode 100644 index 0000000..81085a3 --- /dev/null +++ b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c @@ -0,0 +1,334 @@ +/* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * This is the main of your user space test program, + * which will open the correct kernel bioule, find the + * file descriptor value and use that value to make + * ioctl calls to the system + * + * Use the ki_generic and other ki_testname functions + * to abstract the calls from the main + * + * FILE : user_tbio.c + * USAGE : kernel_space:./load_tbio.sh + * user_space :./test_bio + * + * DESCRIPTION : The bioule will test block i/o layer for kernel 2.5 + * REQUIREMENTS: + * 1) glibc 2.1.91 or above. + * + * HISTORY : + * 11/19/2003 Kai Zhao (lt...@cn...) + * + * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) + * + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/types.h> +#include <linux/kernel.h> +#include <unistd.h> +#include <string.h> + +#include "test.h" +#include "usctest.h" +#include "safe_macros.h" +#include "tst_module.h" + +#include "../tbio_kernel/tbio.h" + +char *TCID = TBIO_DEVICE_NAME; + +static const char module_name[] = "ltp_tbio.ko"; +static int module_loaded; +static int tbio_fd = -1; + +void cleanup(void) +{ + + if (tbio_fd != -1) { + close(tbio_fd); + tbio_fd = -1; + } + + if (module_loaded) + tst_module_unload(NULL, module_name); + + TEST_CLEANUP; +} + + +void setup(void) +{ + tst_require_root(NULL); + + if (tst_kvercmp(2, 6, 0) < 0) { + tst_brkm(TCONF, NULL, + "Test must be run with kernel 2.6 or newer"); + } + + tst_module_load(cleanup, module_name, NULL); + module_loaded = 1; + + dev_t devt; + struct stat st; + + SAFE_FILE_SCANF(cleanup, "/sys/class/block/tbio/dev", + "%d:0", &TBIO_MAJOR); + + devt = makedev(TBIO_MAJOR, 0); + /* + * Check for the /dev/tbase node, and create if it does not + * exist. + */ + errno = 0; + if (stat(DEVICE_NAME, &st)) { + if (errno == ENOENT) { + /* dev node does not exist */ + if (mknod(DEVICE_NAME, S_IFCHR | S_IRUSR | S_IWUSR | + S_IRGRP | S_IWGRP, devt)) { + tst_brkm(TBROK | TERRNO, cleanup, + "mknod failed at %s:%d", + __FILE__, __LINE__); + } + } else { + tst_brkm(TBROK | TERRNO, cleanup, + "problem with tbase device node directory"); + } + } else { + /* + * /dev/tbio CHR device exists. Check to make sure it is for a + * block device and that it has the right major and minor. + */ + if ((!(st.st_mode & S_IFCHR)) || (st.st_rdev != devt)) { + /* Recreate the dev node */ + if (!unlink(DEVICE_NAME)) { + if (mknod(DEVICE_NAME, S_IFCHR | S_IRUSR | + S_IWUSR | S_IRGRP | S_IWGRP, devt)) { + tst_brkm(TBROK | TERRNO, cleanup, + "mknod failed at %s:%d", + __FILE__, __LINE__); + } + } else { + tst_brkm(TBROK | TERRNO, cleanup, + "unlink failed"); + } + } + } + + tbio_fd = open(DEVICE_NAME, O_RDWR); + if (tbio_fd < 0) { + tst_brkm(TBROK | TERRNO, cleanup, "open of %s failed", + DEVICE_NAME); + } + + tst_resm(TINFO, "Device opened successfully "); +} + + +int tbio_to_dev(int fd, int flag) +{ + int rc; + tbio_interface_t bif; + + memset(&bif, 0, sizeof(tbio_interface_t)); + rc = posix_memalign(&bif.data, 512, 1024); + if (rc) { + tst_resm(TINFO, "posix_memalign failed"); + return -1; + } + + strcpy(bif.data, "User space data"); + bif.data_len = 1024; + bif.direction = TBIO_TO_DEV; + bif.cmd = SAFE_MALLOC(cleanup, 6); + if (bif.cmd == NULL) { + tst_resm(TINFO, "malloc cmd space failed"); + free(bif.data); + return -1; + } + strcpy(bif.cmd, "WRITE"); + bif.cmd_len = 6; + + rc = ioctl(fd, flag, &bif); + if (rc) { + free(bif.data); + free(bif.cmd); + tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); + return rc; + } + + free(bif.data); + free(bif.cmd); + + return 0; + +} + +int tbio_from_dev(int fd, int flag) +{ + int rc; + tbio_interface_t bif; + + memset(&bif, 0, sizeof(tbio_interface_t)); + rc = posix_memalign(&bif.data, 512, 1024); + if (rc) { + tst_resm(TINFO, "posix_memalign failed"); + return -1; + } + + memset(bif.data, 0, 1024); + + bif.data_len = 1024; + bif.direction = TBIO_FROM_DEV; + bif.cmd = SAFE_MALLOC(cleanup, 6); + if (bif.cmd == NULL) { + tst_resm(TINFO, "malloc cmd space failed"); + free(bif.data); + return -1; + } + strcpy(bif.cmd, "READ"); + bif.cmd_len = 6; + + rc = ioctl(fd, flag, &bif); + if (rc) { + free(bif.data); + free(bif.cmd); + tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); + return rc; + } + + if (strcmp(bif.data, "User space data")) { + tst_resm(TINFO, "TBIO_FROM_DEV failed"); + free(bif.data); + free(bif.cmd); + return -1; + } + + free(bif.data); + free(bif.cmd); + + return 0; + +} + +int tbio_split_to_dev(int fd, int flag) +{ + int rc; + tbio_interface_t bif; + + memset(&bif, 0, sizeof(tbio_interface_t)); + rc = posix_memalign(&bif.data, 512, 2048); + if (rc) { + tst_resm(TINFO, "posix_memalign failed"); + return -1; + } + + strcpy(bif.data, "User space data"); + bif.data_len = 2048; + bif.direction = TBIO_TO_DEV; + bif.cmd = SAFE_MALLOC(cleanup, 6); + if (bif.cmd == NULL) { + tst_resm(TINFO, "malloc cmd space failed"); + free(bif.data); + return -1; + } + strcpy(bif.cmd, "WRITE"); + bif.cmd_len = 6; + + rc = ioctl(fd, flag, &bif); + if (rc) { + free(bif.data); + free(bif.cmd); + tst_resm(TINFO, "Ioctl error for TBIO_TO_DEV"); + return rc; + } + + free(bif.data); + free(bif.cmd); + + return 0; + +} + +int ki_generic(int fd, int flag) +{ + tbio_interface_t bif; + + int rc = ioctl(fd, flag, &bif); + if (rc) + tst_resm(TINFO | TERRNO, "ioctl error"); + + return rc; +} + + +int main(void) +{ + setup(); + + if (ki_generic(tbio_fd, LTP_TBIO_ALLOC)) + tst_resm(TFAIL, "failed on LTP_TBIO_ALLOC test"); + else + tst_resm(TPASS, "success on LTP_TBIO_ALLOC test"); + + if (ki_generic(tbio_fd, LTP_TBIO_CLONE)) + tst_resm(TFAIL, "failed on LTP_TBIO_CLONE test"); + else + tst_resm(TPASS, "success on LTP_TBIO_CLONE test"); + + if (ki_generic(tbio_fd, LTP_TBIO_GET_NR_VECS)) + tst_resm(TFAIL, "failed on LTP_TBIO_GET_NR_VECS test"); + else + tst_resm(TPASS, "success on LTP_TBIO_GET_NR_VECS test"); + + if (ki_generic(tbio_fd, LTP_TBIO_ADD_PAGE)) + tst_resm(TFAIL, "failed on LTP_TBIO_ADD_PAGE test"); + else + tst_resm(TPASS, "success on LTP_TBIO_ADD_PAGE test"); + + if (tbio_split_to_dev(tbio_fd, LTP_TBIO_SPLIT)) + tst_resm(TFAIL, "failed on LTP_TBIO_SPLIT:write to dev"); + else + tst_resm(TPASS, "success on LTP_TBIO_SPLIT:write to dev"); + + if (tbio_to_dev(tbio_fd, LTP_TBIO_DO_IO)) + tst_resm(TFAIL, "failed on LTP_TBIO_DO_IO:write to dev"); + else + tst_resm(TPASS, "success on LTP_TBIO_DO_IO:write to dev"); + + if (tbio_from_dev(tbio_fd, LTP_TBIO_DO_IO)) + tst_resm(TFAIL, "failed on LTP_TBIO_DO_IO:read from dev"); + else + tst_resm(TPASS, "success on LTP_TBIO_DO_IO:read from dev"); + + if (ki_generic(tbio_fd, LTP_TBIO_PUT)) + tst_resm(TFAIL, "failed on LTP_TBIO_PUT test"); + else + tst_resm(TPASS, "success on LTP_TBIO_PUT test"); + + cleanup(); + + tst_exit(); +} diff --git a/testcases/kernel/device-drivers/tbio/user_space/Makefile b/testcases/kernel/device-drivers/tbio/user_space/Makefile deleted file mode 100644 index 9fe124e..0000000 --- a/testcases/kernel/device-drivers/tbio/user_space/Makefile +++ /dev/null @@ -1,9 +0,0 @@ - -CFLAGS += -O2 -Wall -W -g -OBJS = tbio_ki.o user_tbio.o - -test_bio: $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ - -clean: - rm -f $(OBJS) test_bio diff --git a/testcases/kernel/device-drivers/tbio/user_space/tbio_ki.c b/testcases/kernel/device-drivers/tbio/user_space/tbio_ki.c deleted file mode 100644 index b5d6d46..0000000 --- a/testcases/kernel/device-drivers/tbio/user_space/tbio_ki.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * This file will include user space functions that will drive - * the kernel module to test various functions and kernel - * calls. Each function will need to setup the tif structure - * so that the in parameters and out parameters are correctly - * initialized - * - * use bif structure for passing params between user - * space and kernel space, in some tests it is really not - * needed, and if nothing is needed to pass in utilize - * the ki_generic function below. the tif structure makes - * it easy to maintain all the tests if they have the same - * process in kernel space to read in params in the kernel - * module no matter what the test is - * - * module: tbio - * Copyright (c) International Business Machines Corp., 2003 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; - * - * FILE : tbio_ki.c - * USAGE : kernel_space:./load_tbio.sh - * user_space :./test_bio - * - * DESCRIPTION : The module will test block i/o layer for kernel 2.5 - * REQUIREMENTS: - * 1) glibc 2.1.91 or above. - * - * HISTORY : - * 11/19/2003 Kai Zhao (lt...@cn...) - * - * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <sys/ioctl.h> -#include "../kernel_space/tbio.h" - -int ki_generic(int fd, int flag) -{ - int rc; - tbio_interface_t bif; - - rc = ioctl(fd, flag, &bif); - if (rc) { - printf("Ioctl error\n"); - return rc; - } - - return rc; -} - -#if 0 - -#endif diff --git a/testcases/kernel/device-drivers/tbio/user_space/user_tbio.c b/testcases/kernel/device-drivers/tbio/user_space/user_tbio.c deleted file mode 100644 index d3e88d1..0000000 --- a/testcases/kernel/device-drivers/tbio/user_space/user_tbio.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * This is the main of your user space test program, - * which will open the correct kernel bioule, find the - * file descriptor value and use that value to make - * ioctl calls to the system - * - * Use the ki_generic and other ki_testname functions - * to abstract the calls from the main - * - * bioule: tbio - * Copyright (c) International Business Machines Corp., 2003 - * - * This program is free software; you can redistribute it and/or bioify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; - * - * FILE : user_tbio.c - * USAGE : kernel_space:./load_tbio.sh - * user_space :./test_bio - * - * DESCRIPTION : The bioule will test block i/o layer for kernel 2.5 - * REQUIREMENTS: - * 1) glibc 2.1.91 or above. - * - * HISTORY : - * 11/19/2003 Kai Zhao (lt...@cn...) - * - * CODE COVERAGE: 74.9% - fs/bio.c (Total Coverage) - * - */ - -#define _GNU_SOURCE -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/types.h> -#include <linux/kernel.h> - -#include "user_tbio.h" -#include "../kernel_space/tbio.h" - -static int tbio_fd = -1; /* file descriptor */ - -int tbioopen() -{ - - dev_t devt; - struct stat st; - int rc = 0; - - devt = makedev(TBIO_MAJOR, 0); - - if (rc) { - if (errno == ENOENT) { - /* dev node does not exist. */ - rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | - S_IRGRP | S_IXGRP | - S_IROTH | S_IXOTH)); - } else { - printf - ("ERROR: Problem with Base dev directory. Error code from stat() is %d\n\n", - errno); - } - - } else { - if (!(st.st_mode & S_IFDIR)) { - rc = unlink(DEVICE_NAME); - if (!rc) { - rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | - S_IRGRP | S_IXGRP | - S_IROTH | S_IXOTH)); - } - } - } - - /* - * Check for the /dev/tbase node, and create if it does not - * exist. - */ - rc = stat(DEVICE_NAME, &st); - if (rc) { - if (errno == ENOENT) { - /* dev node does not exist */ - rc = mknod(DEVICE_NAME, - (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | - S_IWGRP), devt); - } else { - printf - ("ERROR:Problem with tbase device node directory. Error code form stat() is %d\n\n", - errno); - } - - } else { - /* - * /dev/tbio CHR device exists. Check to make sure it is for a - * block device and that it has the right major and minor. - */ - if ((!(st.st_mode & S_IFCHR)) || (st.st_rdev != devt)) { - - /* Recreate the dev node. */ - rc = unlink(DEVICE_NAME); - if (!rc) { - rc = mknod(DEVICE_NAME, - (S_IFCHR | S_IRUSR | S_IWUSR | - S_IRGRP | S_IWGRP), devt); - } - } - } - - tbio_fd = open(DEVICE_NAME, O_RDWR); - - if (tbio_fd < 0) { - printf("ERROR: Open of device %s failed %d errno = %d\n", - DEVICE_NAME, tbio_fd, errno); - return errno; - } else { - printf("Device opened successfully \n"); - return 0; - } - -} - -int tbioclose() -{ - - if (tbio_fd != -1) { - close(tbio_fd); - tbio_fd = -1; - } - - return 0; -} - -int tbio_to_dev(int fd, int flag) -{ - int rc; - tbio_interface_t bif; - - memset(&bif, 0, sizeof(tbio_interface_t)); - rc = posix_memalign(&bif.data, 512, 1024); - if (rc) { - printf("posix_memalign failed\n"); - return -1; - } - - strcpy(bif.data, "User space data"); - bif.data_len = 1024; - bif.direction = TBIO_TO_DEV; - bif.cmd = (char *)malloc(6); - if (bif.cmd == NULL) { - printf("malloc cmd space failed\n"); - free(bif.data); - return -1; - } - strcpy(bif.cmd, "WRITE"); - bif.cmd_len = 6; - - rc = ioctl(fd, flag, &bif); - if (rc) { - free(bif.data); - free(bif.cmd); - printf("Ioctl error for TBIO_TO_DEV\n"); - return rc; - } - - free(bif.data); - free(bif.cmd); - - return 0; - -} - -int tbio_from_dev(int fd, int flag) -{ - int rc; - tbio_interface_t bif; - - memset(&bif, 0, sizeof(tbio_interface_t)); - rc = posix_memalign(&bif.data, 512, 1024); - if (rc) { - printf("posix_memalign failed\n"); - return -1; - } - - memset(bif.data, 0, 1024); - - bif.data_len = 1024; - bif.direction = TBIO_FROM_DEV; - bif.cmd = (char *)malloc(6); - if (bif.cmd == NULL) { - printf("malloc cmd space failed\n"); - free(bif.data); - return -1; - } - strcpy(bif.cmd, "READ"); - bif.cmd_len = 6; - - rc = ioctl(fd, flag, &bif); - if (rc) { - free(bif.data); - free(bif.cmd); - printf("Ioctl error for TBIO_TO_DEV\n"); - return rc; - } - //printf("read from dev %s\n",bif.data); - if (strcmp(bif.data, "User space data")) { - printf("TBIO_FROM_DEV failed\n"); - free(bif.data); - free(bif.cmd); - return -1; - } - - free(bif.data); - free(bif.cmd); - - return 0; - -} - -int tbio_split_to_dev(int fd, int flag) -{ - int rc; - tbio_interface_t bif; - - memset(&bif, 0, sizeof(tbio_interface_t)); - rc = posix_memalign(&bif.data, 512, 2048); - if (rc) { - printf("posix_memalign failed\n"); - return -1; - } - - strcpy(bif.data, "User space data"); - bif.data_len = 2048; - bif.direction = TBIO_TO_DEV; - bif.cmd = (char *)malloc(6); - if (bif.cmd == NULL) { - printf("malloc cmd space failed\n"); - free(bif.data); - return -1; - } - strcpy(bif.cmd, "WRITE"); - bif.cmd_len = 6; - - rc = ioctl(fd, flag, &bif); - if (rc) { - free(bif.data); - free(bif.cmd); - printf("Ioctl error for TBIO_TO_DEV\n"); - return rc; - } - - free(bif.data); - free(bif.cmd); - - return 0; - -} - -int main() -{ - int rc; - - /* open the bioule */ - rc = tbioopen(); - if (rc) { - printf("Test bio Driver may not be loaded\n"); - exit(1); - } - - if (ki_generic(tbio_fd, LTP_TBIO_ALLOC)) - printf("Failed on LTP_TBIO_ALLOC test\n"); - else - printf("Success on LTP_TBIO_ALLOC test\n"); - - if (ki_generic(tbio_fd, LTP_TBIO_CLONE)) - printf("Failed on LTP_TBIO_CLONE test\n"); - else - printf("Success on LTP_TBIO_CLONE test\n"); - - if (ki_generic(tbio_fd, LTP_TBIO_GET_NR_VECS)) - printf("Failed on LTP_TBIO_GET_NR_VECS test\n"); - else - printf("Success on LTP_TBIO_GET_NR_VECS test\n"); - - if (ki_generic(tbio_fd, LTP_TBIO_ADD_PAGE)) - printf("Failed on LTP_TBIO_ADD_PAGE test\n"); - else - printf("Success on LTP_TBIO_ADD_PAGE test\n"); - - if (tbio_split_to_dev(tbio_fd, LTP_TBIO_SPLIT)) - printf("Failed on LTP_TBIO_SPLIT:write to dev\n"); - else - printf("Success on LTP_TBIO_SPLIT:write to dev\n"); - - if (tbio_to_dev(tbio_fd, LTP_TBIO_DO_I... [truncated message content] |
From: Cyril H. <su...@li...> - 2013-10-23 14:51:19
|
The branch, master, has been updated via 6c5ad9bbf066eaf00fbe4aaecc5a2c727a28f14d (commit) via ecd42f7904cb7a2843ee8057a81213f360c68e2b (commit) via c26dd371acbd490b57bf7804371fef065de764ca (commit) via 11a84a6b532b9951a912c0d7a5be72846c33cb54 (commit) from 5ffe7cfe1bf70497ba5a015badc11e97b2003b5f (commit) - Log ----------------------------------------------------------------- commit 6c5ad9bbf066eaf00fbe4aaecc5a2c727a28f14d Author: Cyril Hrubis <ch...@su...> Date: Wed Oct 23 16:17:07 2013 +0200 getcontext01: Cleanup. Add void, static where needed, removed unused comments. Signed-off-by: Cyril Hrubis <ch...@su...> commit ecd42f7904cb7a2843ee8057a81213f360c68e2b Author: Honggyu Kim <hon...@lg...> Date: Wed Oct 23 21:07:30 2013 +0900 getcontext01: check getcontext function in libc getcontext function is implemented depends on libc version and arch. Some libc version for specific arch does not implement getcontext yet. In that case, getcontext just sets errno to ENOSYS and returns -1. For example, getcontext is not implemented before libc-2.17 in ARM. Current test goes to TFAIL when lower version of libc is used in ARM. This patch sets the test as TCONF if libc does not implement getcontext. If ENOSYS is not set and -1 is returned, it goes to TFAIL as it was. Signed-off-by: Honggyu Kim <hon...@lg...> commit c26dd371acbd490b57bf7804371fef065de764ca Author: Jan Stancek <jst...@re...> Date: Thu Oct 17 12:48:46 2013 +0200 getrusage04: skip it on Xen Skip this test on Xen, as it is known to fail, presumably because Xen is not able to account virtual CPU time with same accuracy as on the real CPU. Signed-off-by: Jan Stancek <jst...@re...> Acked-by: Cyril Hrubis <ch...@su...> commit 11a84a6b532b9951a912c0d7a5be72846c33cb54 Author: Jan Stancek <jst...@re...> Date: Thu Oct 17 12:44:49 2013 +0200 lib: add tst_is_virt() The initial version supports only generic check for xen dom0/domU, but should allow to easily extend it for other types of checks, (e.g. KVM guest) if needed later. Signed-off-by: Jan Stancek <jst...@re...> Acked-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: include/test.h | 5 ++ .../migrate_pages_common.h => lib/tst_virt.c | 36 +++++++++--- .../kernel/syscalls/getcontext/getcontext01.c | 62 ++++++++------------ testcases/kernel/syscalls/getrusage/getrusage04.c | 3 + 4 files changed, 60 insertions(+), 46 deletions(-) copy testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h => lib/tst_virt.c (64%) diff --git a/include/test.h b/include/test.h index d9eba31..94fc721 100644 --- a/include/test.h +++ b/include/test.h @@ -63,6 +63,9 @@ #define TRERRNO 0x300 /* Capture errno information from TEST_RETURN to output; useful for pthread-like APIs :). */ +/* virt types for tst_is_virt() */ +#define VIRT_XEN 1 /* xen dom0/domU */ + /* * Ensure that NUMSIGS is defined. * It should be defined in signal.h or sys/signal.h on @@ -189,6 +192,8 @@ int tst_is_cwd_ramfs(void); /* lib/tst_cwd_has_free.c */ int tst_cwd_has_free(int required_kib); +int tst_is_virt(int virt_type); + /* lib/self_exec.c */ void maybe_run_child(void (*child)(), char *fmt, ...); int self_exec(char *argv0, char *fmt, ...); diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h b/lib/tst_virt.c similarity index 64% copy from testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h copy to lib/tst_virt.c index d821b07..0141c3d 100644 --- a/testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h +++ b/lib/tst_virt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Linux Test Project, Inc. + * Copyright (C) 2013 Linux Test Project * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -22,12 +22,32 @@ * 02110-1301, USA. */ -#ifndef MIGRATE_PAGES_COMMON_H -#define MIGRATE_PAGES_COMMON_H +#include <unistd.h> +#include "test.h" -#define bitsperlong (8 * sizeof(unsigned long)) +static int is_xen(void) +{ + char hypervisor_type[3]; -void set_bit(unsigned long *b, unsigned int n, unsigned int v); -int check_ret(long expected_ret); -int check_errno(long expected_errno); -#endif + if (access("/proc/xen", F_OK) == 0) + return 1; + + if (access("/sys/hypervisor/type", F_OK) == 0) { + SAFE_FILE_SCANF(NULL, "/sys/hypervisor/type", "%3s", + hypervisor_type); + return strncmp("xen", hypervisor_type, + sizeof(hypervisor_type)) == 0; + } + + return 0; +} + +int tst_is_virt(int virt_type) +{ + switch (virt_type) { + case VIRT_XEN: + return is_xen(); + } + tst_brkm(TBROK, NULL, "invalid virt_type flag: %d", virt_type); + return 0; +} diff --git a/testcases/kernel/syscalls/getcontext/getcontext01.c b/testcases/kernel/syscalls/getcontext/getcontext01.c index 03b2df9..c854518 100644 --- a/testcases/kernel/syscalls/getcontext/getcontext01.c +++ b/testcases/kernel/syscalls/getcontext/getcontext01.c @@ -1,5 +1,6 @@ /* * Copyright (c) Wipro Technologies Ltd, 2005. All Rights Reserved. + * Author: Prashant P Yendigeri <pra...@wi...> * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -12,26 +13,7 @@ * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ -/********************************************************** - * - * TEST IDENTIFIER : getcontext01 - * - * EXECUTED BY : root / superuser - * - * TEST TITLE : Basic tests for getcontext(2) - * - * TEST CASE TOTAL : 1 - * - * AUTHOR : Prashant P Yendigeri - * <pra...@wi...> - * - * DESCRIPTION - * This is a Phase I test for the getcontext(2) system call. - * It is intended to provide a limited exposure of the system call. - * - **********************************************************/ #include <features.h> @@ -47,60 +29,64 @@ char *TCID = "getcontext01"; #if !defined(__UCLIBC__) -void setup(); -void cleanup(); +static void setup(void); +static void cleanup(void); int TST_TOTAL = 1; -int exp_enos[] = { 0 }; /* must be a 0 terminated list */ +static void test_getcontext(void) +{ + ucontext_t ptr; + + TEST(getcontext(&ptr)); + + if (TEST_RETURN == -1) { + if (errno == ENOSYS) + tst_resm(TCONF, "getcontext not implemented in libc"); + else + tst_resm(TFAIL | TTERRNO, "getcontext failed"); + } else if (TEST_RETURN == 0) { + tst_resm(TPASS, "getcontext passed"); + } else { + tst_resm(TFAIL, "Unexpected return value %li", TEST_RETURN); + } +} int main(int ac, char **av) { int lc; char *msg; - ucontext_t ptr; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); - TEST_EXP_ENOS(exp_enos); - for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; - TEST(getcontext(&ptr)); - - if (TEST_RETURN == -1) - tst_resm(TFAIL | TTERRNO, "getcontext failed"); - else if (TEST_RETURN >= 0) - tst_resm(TPASS, "getcontext passed"); - + test_getcontext(); } cleanup(); - tst_exit(); } -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; } -void cleanup() +static void cleanup(void) { TEST_CLEANUP; - } #else /* systems that dont support obsolete getcontext */ -int main() +int main(void) { tst_brkm(TCONF, NULL, "system doesn't have getcontext support"); } diff --git a/testcases/kernel/syscalls/getrusage/getrusage04.c b/testcases/kernel/syscalls/getrusage/getrusage04.c index 96e24a4..fa5fe2d 100644 --- a/testcases/kernel/syscalls/getrusage/getrusage04.c +++ b/testcases/kernel/syscalls/getrusage/getrusage04.c @@ -205,6 +205,9 @@ static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); + if (tst_is_virt(VIRT_XEN)) + tst_brkm(TCONF, NULL, "This testcase is not supported on Xen."); + BIAS_MAX = guess_timer_resolution(); TEST_PAUSE; hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-23 13:51:07
|
The branch, master, has been updated via 5ffe7cfe1bf70497ba5a015badc11e97b2003b5f (commit) from ba293cb1bc6f2dc48be2eac55e2f4c4eb1a47d1e (commit) - Log ----------------------------------------------------------------- commit 5ffe7cfe1bf70497ba5a015badc11e97b2003b5f Author: Cyril Hrubis <ch...@su...> Date: Wed Oct 23 15:13:49 2013 +0200 syscalls: Remove acct02. This adds a test for EPERM with acct(NULL) to acct01 and drops acct02 which is messy and all the cases are now covered by the acct01. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: doc/testcases/kernel.txt | 10 --- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/acct/acct01.c | 1 + testcases/kernel/syscalls/acct/acct02.c | 118 ------------------------------- 7 files changed, 1 insertions(+), 132 deletions(-) delete mode 100644 testcases/kernel/syscalls/acct/acct02.c diff --git a/doc/testcases/kernel.txt b/doc/testcases/kernel.txt index e84e1ae..9d181fd 100644 --- a/doc/testcases/kernel.txt +++ b/doc/testcases/kernel.txt @@ -688,16 +688,6 @@ ltp/testcases/kernel/syscalls/acct/acct01.c <\test_location> <\testname> -<testname=acct02> - <description> - Issues calls to acct() and tests the returned values against expected - results - - <\description> - <test_location> - ltp/testcases/kernel/syscalls/acct/acct02.c - <\test_location> -<\testname> <testname=adjtimex01> <description> Basic test for adjtimex(). diff --git a/runtest/ltplite b/runtest/ltplite index 8ff55ee..60140e2 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -68,7 +68,6 @@ access04 access04 access05 access05 acct01 acct01 -acct02 acct02 adjtimex01 adjtimex01 adjtimex02 adjtimex02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 0533d4d..7e7f1b7 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -10,7 +10,6 @@ access04 access04 access05 access05 acct01 acct01 -acct02 acct02 adjtimex01 adjtimex01 adjtimex02 adjtimex02 diff --git a/runtest/syscalls b/runtest/syscalls index 09e5f7f..0486b95 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -11,7 +11,6 @@ access04 access04 access05 access05 acct01 acct01 -acct02 acct02 add_key01 add_key01 add_key02 add_key02 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index ad23c2e..0effa6b 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -7,7 +7,6 @@ /access/access04 /access/access05 /acct/acct01 -/acct/acct02 /add_key/add_key01 /add_key/add_key02 /adjtimex/adjtimex01 diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index ee794cc..c38d4db 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -63,6 +63,7 @@ static struct test_case_t { {TEST_FILE3, "ENOENT", ENOENT, NULL, NULL}, {TEST_FILE4, "ENOTDIR", ENOTDIR, NULL, NULL}, {TEST_FILE5, "EPERM", EPERM, setup2, cleanup2}, + {NULL, "EPERM", EPERM, setup2, cleanup2}, }; char *TCID = "acct01"; diff --git a/testcases/kernel/syscalls/acct/acct02.c b/testcases/kernel/syscalls/acct/acct02.c deleted file mode 100644 index f1c7bf6..0000000 --- a/testcases/kernel/syscalls/acct/acct02.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2002 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* 12/03/2002 Port to LTP ro...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ - -/* - * NAME - * acct02.c -- test acct - * - * CALLS - * acct - * - * ALGORITHM - * issue calls to acct and test the returned values against - * expected results - * - * RESTRICTIONS - * This must run root since the acct call may only be done - * by root. Use the TERM flag, to clean up files. - */ - -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <pwd.h> -#include <sys/types.h> - -/** LTP Port **/ -#include "test.h" -#include "usctest.h" - -#define FAILED 0 -#define PASSED 1 - -char *TCID = "acct02"; -int TST_TOTAL = 2; -/**************/ - -char fname[80]; -struct passwd *ltpuser; - -/*--------------------------------------------------------------*/ -int main(argc, argv) -int argc; -char *argv[]; -{ - - /* Get the user id "nobody" */ - if ((ltpuser = getpwnam("nobody")) == NULL) { - tst_resm(TBROK, "nobody not found in /etc/passwd"); - tst_exit(); - } - - /* Switch to "nobody" */ - setuid(ltpuser->pw_uid); - -/*--------------------------------------------------------------*/ - - /* Attempt to turn off acct as non-root - */ - if (acct(NULL) != -1) { - tst_resm(TBROK | TERRNO, - "Non-root attempting to disable acct: didn't fail"); - tst_exit(); - } - - if (errno != EPERM) { - if (errno == ENOSYS) { - tst_resm(TCONF, - "BSD process accounting is not configured in this kernel."); - tst_resm(TCONF, "Test will not run."); - tst_exit(); - } else { - tst_resm(TBROK | TERRNO, - "Non-root acct disable failed as we wanted EPERM errno"); - tst_exit(); - } - } else - tst_resm(TPASS, "Received expected error: EPERM"); - -//------------------------------------------------- - if (acct("/anystring") != -1) { - tst_resm(TBROK | TERRNO, - "Non-root attempting to enable acct: didn't fail"); - tst_exit(); - } - - if (errno != EPERM) { - tst_resm(TFAIL | TERRNO, - "Non-root acct enable failed as we wanted EPERM errno"); - tst_exit(); - } else - tst_resm(TPASS, "Received expected error: EPERM"); - -//------------------------------------------------- - - tst_exit(); /* THIS CALL DOES NOT RETURN - EXITS!! */ -/*--------------------------------------------------------------*/ - tst_exit(); -} hooks/post-receive -- ltp |
From: Cyril H. <su...@li...> - 2013-10-23 12:51:44
|
The branch, master, has been updated via ba293cb1bc6f2dc48be2eac55e2f4c4eb1a47d1e (commit) via 226edbe58217837e076d94b2d0d882a13117da6c (commit) via 49e58686340a5f5f939018b8f0520ad6c04c8445 (commit) from b968712a8cce12862e24d0461b073eaabe9cd3aa (commit) - Log ----------------------------------------------------------------- commit ba293cb1bc6f2dc48be2eac55e2f4c4eb1a47d1e Author: Zeng Linggang <zen...@cn...> Date: Wed Oct 23 14:51:35 2013 +0800 acct/acct01.c: clean up Using loops to the test. Signed-off-by: Zeng Linggang <zen...@cn...> commit 226edbe58217837e076d94b2d0d882a13117da6c Author: Wang, Xiaoguang <wan...@cn...> Date: Tue Oct 22 16:27:16 2013 +0800 tst_res: add some common errno values Signed-off-by: Xiaoguang Wang <wan...@cn...> commit 49e58686340a5f5f939018b8f0520ad6c04c8445 Author: Wang, Xiaoguang <wan...@cn...> Date: Mon Oct 21 16:30:16 2013 +0800 access/access05.c: clean up Signed-off-by: Xiaoguang Wang <wan...@cn...> ----------------------------------------------------------------------- Summary of changes: lib/tst_res.c | 5 + testcases/kernel/syscalls/access/access05.c | 204 +++++++++------------------ testcases/kernel/syscalls/acct/acct01.c | 196 ++++++++++++++------------ 3 files changed, 179 insertions(+), 226 deletions(-) diff --git a/lib/tst_res.c b/lib/tst_res.c index 245bd5f..f73022b 100644 --- a/lib/tst_res.c +++ b/lib/tst_res.c @@ -249,7 +249,12 @@ static const char *strerrnodef(int err) PAIR(EPIPE) PAIR(EDOM) PAIR(ERANGE) + PAIR(EDEADLK) PAIR(ENAMETOOLONG) + PAIR(ENOLCK) + PAIR(ENOSYS) + PAIR(ENOTEMPTY) + PAIR(ELOOP) }; return pair_lookup(errno_pairs, err); } diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c index be86225..739b4b2 100644 --- a/testcases/kernel/syscalls/access/access05.c +++ b/testcases/kernel/syscalls/access/access05.c @@ -49,6 +49,7 @@ #include "test.h" #include "usctest.h" +#include "safe_macros.h" #define INV_OK -1 #define TEST_FILE1 "test_file1" @@ -56,13 +57,6 @@ #define TEST_FILE3 "test_file3" #define TEST_FILE4 "test_file4" -#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) - -static void setup1(void); /* setup() to test access() for EACCES */ -static void setup2(void); /* setup() to test access() for EACCES */ -static void setup3(void); /* setup() to test access() for EACCES */ -static void setup4(void); /* setup() to test access() for EINVAL */ -static void longpath_setup(); /* setup function to test access() for ENAMETOOLONG */ #if !defined(UCLINUX) static char high_address_node[64]; @@ -74,22 +68,21 @@ static struct test_case_t { char *pathname; int a_mode; int exp_errno; - void (*setupfunc) (void); } test_cases[] = { - {TEST_FILE1, R_OK, EACCES, setup1}, - {TEST_FILE2, W_OK, EACCES, setup2}, - {TEST_FILE3, X_OK, EACCES, setup3}, - {TEST_FILE4, INV_OK, EINVAL, setup4}, + {TEST_FILE1, R_OK, EACCES}, + {TEST_FILE2, W_OK, EACCES}, + {TEST_FILE3, X_OK, EACCES}, + {TEST_FILE4, INV_OK, EINVAL}, #if !defined(UCLINUX) - {(char *)-1, R_OK, EFAULT, NULL}, - {high_address_node, R_OK, EFAULT, NULL}, + {(char *)-1, R_OK, EFAULT}, + {high_address_node, R_OK, EFAULT}, #endif - {"", W_OK, ENOENT, NULL}, - {longpathname, R_OK, ENAMETOOLONG, longpath_setup}, + {"", W_OK, ENOENT}, + {longpathname, R_OK, ENAMETOOLONG}, }; char *TCID = "access05"; -int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases); +int TST_TOTAL = ARRAY_SIZE(test_cases); static int exp_enos[] = { EACCES, EFAULT, EINVAL, ENOENT, ENAMETOOLONG, 0 }; @@ -97,6 +90,7 @@ static const char nobody_uid[] = "nobody"; static struct passwd *ltpuser; static void setup(void); +static void access_verify(int i); static void cleanup(void); static char *bad_addr; @@ -105,8 +99,6 @@ int main(int ac, char **av) { int lc; char *msg; - char *file_name; - int access_mode; int i; msg = parse_opts(ac, av, NULL, NULL); @@ -120,39 +112,8 @@ int main(int ac, char **av) for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) { - file_name = test_cases[i].pathname; - access_mode = test_cases[i].a_mode; - -#if !defined(UCLINUX) - if (file_name == high_address_node) - file_name = get_high_address(); -#endif - - /* - * Call access(2) to test different test conditions. - * verify that it fails with -1 return value and - * sets appropriate errno. - */ - TEST(access(file_name, access_mode)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, - "access(%s, %#o) succeeded unexpectedly", - file_name, access_mode); - continue; - } - - if (TEST_ERRNO == test_cases[i].exp_errno) - tst_resm(TPASS | TTERRNO, - "access failed as expected"); - else - tst_resm(TFAIL | TTERRNO, - "access failed unexpectedly; expected: " - "%d - %s", - test_cases[i].exp_errno, - strerror(test_cases[i].exp_errno)); - } + for (i = 0; i < TST_TOTAL; i++) + access_verify(i); } cleanup(); @@ -161,17 +122,13 @@ int main(int ac, char **av) static void setup(void) { - int i; + int fd; tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_require_root(NULL); - ltpuser = getpwnam(nobody_uid); - if (ltpuser == NULL) - tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed"); - if (setuid(ltpuser->pw_uid) == -1) - tst_brkm(TBROK | TERRNO, NULL, "setuid failed"); - + ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid); + SAFE_SETUID(cleanup, ltpuser->pw_uid); TEST_PAUSE; #if !defined(UCLINUX) @@ -179,98 +136,73 @@ static void setup(void) MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); if (bad_addr == MAP_FAILED) tst_brkm(TBROK | TERRNO, NULL, "mmap failed"); - test_cases[5].pathname = bad_addr; + test_cases[4].pathname = bad_addr; + + test_cases[5].pathname = get_high_address(); #endif tst_tmpdir(); - for (i = 0; i < TST_TOTAL; i++) - if (test_cases[i].setupfunc != NULL) - test_cases[i].setupfunc(); + /* + * create TEST_FILE1 to test R_OK EACCESS + */ + fd = SAFE_CREAT(cleanup, TEST_FILE1, 0333); + SAFE_CLOSE(cleanup, fd); + + /* + * create TEST_FILE2 to test W_OK EACCESS + */ + fd = SAFE_CREAT(cleanup, TEST_FILE2, 0555); + SAFE_CLOSE(cleanup, fd); + + /* + * create TEST_FILE3 to test X_OK EACCESS + */ + fd = SAFE_CREAT(cleanup, TEST_FILE3, 0666); + SAFE_CLOSE(cleanup, fd); + + /* + * create TEST_FILE4 to test EINVAL + */ + fd = SAFE_CREAT(cleanup, TEST_FILE4, 0333); + SAFE_CLOSE(cleanup, fd); + + /* + *setup to create a node with a name length exceeding + *the MAX length of PATH_MAX. + */ + memset(longpathname, 'a', sizeof(longpathname) - 1); } -static void setup_file(const char *file, mode_t perms) -{ - int fd = open(file, O_RDWR | O_CREAT, FILE_MODE); - if (fd == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "open(%s, O_RDWR|O_CREAT, %#o) failed", - file, FILE_MODE); - - if (fchmod(fd, perms) < 0) - tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, %#o) failed", - file, perms); - if (close(fd) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", file); -} - -/* - * setup1() - Setup function to test access() for return value -1 - * and errno EACCES when read access denied for specified - * testfile. - * - * Creat/open a testfile and close it. - * Deny read access permissions on testfile. - * This function returns 0. - */ -static void setup1(void) -{ - setup_file(TEST_FILE1, 0333); -} - -/* - * setup2() - Setup function to test access() for return value -1 and - * errno EACCES when write access denied on testfile. - * - * Creat/open a testfile and close it. - * Deny write access permissions on testfile. - * This function returns 0. - */ -static void setup2(void) +static void access_verify(int i) { - setup_file(TEST_FILE2, 0555); -} + char *file_name; + int access_mode; -/* - * setup3() - Setup function to test access() for return value -1 and - * errno EACCES when execute access denied on testfile. - * - * Creat/open a testfile and close it. - * Deny search access permissions on testfile. - * This function returns 0. - */ -static void setup3(void) -{ - setup_file(TEST_FILE3, 0666); -} + file_name = test_cases[i].pathname; + access_mode = test_cases[i].a_mode; -/* - * setup4() - Setup function to test access() for return value -1 - * and errno EINVAL when specified access mode argument is - * invalid. - * - * Creat/open a testfile and close it. - * This function returns 0. - */ -static void setup4(void) -{ - setup_file(TEST_FILE4, FILE_MODE); -} + TEST(access(file_name, access_mode)); -/* - * longpath_setup() - setup to create a node with a name length exceeding - * the MAX. length of PATH_MAX. - */ -static void longpath_setup(void) -{ - int i; + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "access(%s, %#o) succeeded unexpectedly", + file_name, access_mode); + return; + } - for (i = 0; i <= (PATH_MAX + 1); i++) - longpathname[i] = 'a'; + if (TEST_ERRNO == test_cases[i].exp_errno) { + tst_resm(TPASS | TTERRNO, "access failed as expected"); + } else { + tst_resm(TFAIL | TTERRNO, + "access failed unexpectedly; expected: " + "%d - %s", test_cases[i].exp_errno, + strerror(test_cases[i].exp_errno)); + } } static void cleanup(void) { TEST_CLEANUP; + tst_rmdir(); } diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c index 462fd5a..ee794cc 100644 --- a/testcases/kernel/syscalls/acct/acct01.c +++ b/testcases/kernel/syscalls/acct/acct01.c @@ -1,39 +1,29 @@ /* * - * Copyright (c) International Business Machines Corp., 2002 + * Copyright (c) International Business Machines Corp., 2002 * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* 12/03/2002 Port to LTP ro...@us... */ +/* 12/03/2002 Port to LTP ro...@us... */ /* 06/30/2001 Port to Linux nsh...@us... */ /* - * NAME - * acct01.c -- test acct - * - * CALLS - * acct - * * ALGORITHM * issue calls to acct and test the returned values against * expected results - * - * RESTRICTIONS - * This must run root since the acct call may only be done - * by root. Use the TERM flag, to clean up files. */ #include <sys/types.h> @@ -41,7 +31,7 @@ #include <errno.h> #include <fcntl.h> #include <pwd.h> -#include <stdio.h> /* needed by testhead.h */ +#include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -49,100 +39,126 @@ #include "usctest.h" #include "safe_macros.h" -char *TCID = "acct01"; -int TST_TOTAL = 6; +#define TEST_FILE1 "/" +#define TEST_FILE2 "/dev/null" +#define TEST_FILE3 "/tmp/does/not/exist" +#define TEST_FILE4 "/etc/fstab/" +#define TEST_FILE5 "./tmpfile" + +static void setup(void); +static void cleanup(void); +static void setup2(void); +static void cleanup2(void); +static void acct_verify(int); + +static struct test_case_t { + char *filename; + char *exp_errval; + int exp_errno; + void (*setupfunc) (); + void (*cleanfunc) (); +} test_cases[] = { + {TEST_FILE1, "EISDIR", EISDIR, NULL, NULL}, + {TEST_FILE2, "EACCES", EACCES, NULL, NULL}, + {TEST_FILE3, "ENOENT", ENOENT, NULL, NULL}, + {TEST_FILE4, "ENOTDIR", ENOTDIR, NULL, NULL}, + {TEST_FILE5, "EPERM", EPERM, setup2, cleanup2}, +}; -char tmpbuf[80]; -int fd; +char *TCID = "acct01"; +int TST_TOTAL = ARRAY_SIZE(test_cases); +static struct passwd *ltpuser; +static int exp_enos[] = { EISDIR, EACCES, ENOENT, ENOTDIR, EPERM, 0 }; -static void cleanup(void) +int main(int argc, char *argv[]) { + int lc; + int i; - if (acct(NULL) == -1) - tst_resm(TBROK | TERRNO, "acct(NULL) failed"); + setup(); - tst_rmdir(); + TEST_EXP_ENOS(exp_enos); + + for (lc = 0; TEST_LOOPING(lc); lc++) { + tst_count = 0; + for (i = 0; i < TST_TOTAL; i++) + acct_verify(i); + } + + cleanup(); + tst_exit(); } static void setup(void) { + int fd; - /* - * XXX: FreeBSD says you must always be superuser, but Linux says you - * need to have CAP_SYS_PACCT capability. - * - * Either way, it's better to do this to test out the EPERM - * requirement. - */ tst_require_root(NULL); tst_tmpdir(); + ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); + + fd = SAFE_CREAT(cleanup, TEST_FILE5, 0777); + SAFE_CLOSE(cleanup, fd); + + if (acct(TEST_FILE5) == -1) + tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); + /* turn off acct, so we are in a known state */ if (acct(NULL) == -1) { - if (errno == ENOSYS) + if (errno == ENOSYS) { tst_brkm(TCONF, cleanup, - "BSD process accounting is not configured in this " - "kernel"); - else + "BSD process accounting is not configured in " + "this kernel"); + } else { tst_brkm(TBROK | TERRNO, cleanup, "acct(NULL) failed"); + } } } -int main(int argc, char *argv[]) +static void acct_verify(int i) { - struct passwd *pwent; - setup(); + if (test_cases[i].setupfunc) + test_cases[i].setupfunc(); - /* EISDIR */ - if (acct("/") == -1 && errno == EISDIR) - tst_resm(TPASS, "Failed with EISDIR as expected"); - else - tst_brkm(TFAIL | TERRNO, cleanup, - "didn't fail as expected; expected EISDIR"); - - /* EACCES */ - if (acct("/dev/null") == -1 && errno == EACCES) - tst_resm(TPASS, "Failed with EACCES as expected"); - else - tst_brkm(TFAIL | TERRNO, cleanup, - "didn't fail as expected; expected EACCES"); - - /* ENOENT */ - if (acct("/tmp/does/not/exist") == -1 && errno == ENOENT) - tst_resm(TPASS, "Failed with ENOENT as expected"); - else - tst_brkm(TBROK | TERRNO, cleanup, - "didn't fail as expected; expected ENOENT"); - - /* ENOTDIR */ - if (acct("/etc/fstab/") == -1 && errno == ENOTDIR) - tst_resm(TPASS, "Failed with ENOTDIR as expected"); - else - tst_brkm(TFAIL | TERRNO, cleanup, - "didn't fail as expected; expected ENOTDIR"); - - /* EPERM */ - sprintf(tmpbuf, "./%s.%d", TCID, getpid()); - fd = SAFE_CREAT(cleanup, tmpbuf, 0777); - SAFE_CLOSE(cleanup, fd); + TEST(acct(test_cases[i].filename)); - if (acct(tmpbuf) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "acct failed unexpectedly"); + if (test_cases[i].cleanfunc) + test_cases[i].cleanfunc(); - pwent = SAFE_GETPWNAM(cleanup, "nobody"); - SAFE_SETEUID(cleanup, pwent->pw_uid); + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "acct(%s) succeeded unexpectedly", + test_cases[i].filename); + return; + } + if (TEST_ERRNO == test_cases[i].exp_errno) { + tst_resm(TPASS | TTERRNO, "acct failed as expected"); + } else { + tst_resm(TFAIL | TTERRNO, + "acct failed unexpectedly; expected: %d - %s", + test_cases[i].exp_errno, + strerror(test_cases[i].exp_errno)); + } +} - if (acct(tmpbuf) == -1 && errno == EPERM) - tst_resm(TPASS, "Failed with EPERM as expected"); - else - tst_brkm(TBROK | TERRNO, cleanup, - "didn't fail as expected; expected EPERM"); +static void setup2(void) +{ + SAFE_SETEUID(cleanup, ltpuser->pw_uid); +} +static void cleanup2(void) +{ SAFE_SETEUID(cleanup, 0); - SAFE_UNLINK(cleanup, tmpbuf); +} - cleanup(); - tst_exit(); +static void cleanup(void) +{ + TEST_CLEANUP; + + if (acct(NULL) == -1) + tst_resm(TBROK | TERRNO, "acct(NULL) failed"); + + tst_rmdir(); } hooks/post-receive -- ltp |