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 |