Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Import ptrace(2) tests into appropriate directory tests/lib/...



details:   https://anonhg.NetBSD.org/src/rev/04f8115846c4
branches:  trunk
changeset: 352471:04f8115846c4
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Apr 02 21:44:00 2017 +0000

description:
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>

diffstat:

 distrib/sets/lists/debug/mi              |     9 +-
 distrib/sets/lists/tests/mi              |     9 +-
 tests/lib/libc/sys/Makefile              |    17 +-
 tests/lib/libc/sys/msg.h                 |   136 +
 tests/lib/libc/sys/t_ptrace.c            |   208 +
 tests/lib/libc/sys/t_ptrace_amd64_wait.h |   114 +
 tests/lib/libc/sys/t_ptrace_i386_wait.h  |   107 +
 tests/lib/libc/sys/t_ptrace_wait.c       |  7590 ++++++++++++++++++++++++++++++
 tests/lib/libc/sys/t_ptrace_wait.h       |   431 +
 tests/lib/libc/sys/t_ptrace_wait3.c      |    30 +
 tests/lib/libc/sys/t_ptrace_wait4.c      |    30 +
 tests/lib/libc/sys/t_ptrace_wait6.c      |    30 +
 tests/lib/libc/sys/t_ptrace_waitid.c     |    30 +
 tests/lib/libc/sys/t_ptrace_waitpid.c    |    30 +
 tests/lib/libc/sys/t_ptrace_x86_wait.h   |  1983 +++++++
 15 files changed, 10750 insertions(+), 4 deletions(-)

diffs (truncated from 10851 to 300 lines):

diff -r cef68663aed5 -r 04f8115846c4 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Sun Apr 02 20:18:37 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Sun Apr 02 21:44:00 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.202 2017/04/02 01:49:51 kamil Exp $
+# $NetBSD: mi,v 1.203 2017/04/02 21:44:00 kamil Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -2079,6 +2079,13 @@
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_poll.debug                        tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_posix_fadvise.debug       tests-lib-debug         debug,atf,rump
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_posix_fallocate.debug     tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace.debug              tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_wait.debug         tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_wait3.debug                tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_wait4.debug                tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_wait6.debug                tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_waitid.debug       tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_ptrace_waitpid.debug      tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_recvmmsg.debug            tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_revoke.debug              tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_select.debug              tests-lib-debug         debug,atf,compattestfile
diff -r cef68663aed5 -r 04f8115846c4 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Apr 02 20:18:37 2017 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Apr 02 21:44:00 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.731 2017/04/02 01:49:52 kamil Exp $
+# $NetBSD: mi,v 1.732 2017/04/02 21:44:00 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2762,6 +2762,13 @@
 ./usr/tests/lib/libc/sys/t_poll                        tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_posix_fadvise       tests-lib-tests         atf,rump
 ./usr/tests/lib/libc/sys/t_posix_fallocate     tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace              tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_wait         tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_wait3                tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_wait4                tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_wait6                tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_waitid       tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libc/sys/t_ptrace_waitpid      tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_recvmmsg            tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_revoke              tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libc/sys/t_select              tests-lib-tests         compattestfile,atf
diff -r cef68663aed5 -r 04f8115846c4 tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Sun Apr 02 20:18:37 2017 +0000
+++ b/tests/lib/libc/sys/Makefile       Sun Apr 02 21:44:00 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.48 2017/02/01 10:18:27 martin Exp $
+# $NetBSD: Makefile,v 1.49 2017/04/02 21:44:00 kamil Exp $
 
 MKMAN= no
 
@@ -51,6 +51,13 @@
 TESTS_C+=              t_pipe2
 TESTS_C+=              t_poll
 TESTS_C+=              t_posix_fallocate
+TESTS_C+=              t_ptrace
+TESTS_C+=              t_ptrace_wait
+TESTS_C+=              t_ptrace_wait3
+TESTS_C+=              t_ptrace_wait4
+TESTS_C+=              t_ptrace_wait6
+TESTS_C+=              t_ptrace_waitid
+TESTS_C+=              t_ptrace_waitpid
 TESTS_C+=              t_recvmmsg
 TESTS_C+=              t_revoke
 TESTS_C+=              t_select
@@ -82,7 +89,13 @@
 LDADD.t_posix_fadvise+= -lrumpvfs -lrump -lrumpuser -lrump -lpthread
 .endif
 
-CPPFLAGS.t_lwp_create.c += -D_KERNTYPES
+CPPFLAGS.t_lwp_create.c                += -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait.c       += -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait3.c      += -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait4.c      += -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait6.c      += -D_KERNTYPES
+CPPFLAGS.t_ptrace_waitid.c     += -D_KERNTYPES
+CPPFLAGS.t_ptrace_waitpid.c    += -D_KERNTYPES
 
 FILES=         truncate_test.root_owned
 FILESBUILD=    yes
diff -r cef68663aed5 -r 04f8115846c4 tests/lib/libc/sys/msg.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/sys/msg.h  Sun Apr 02 21:44:00 2017 +0000
@@ -0,0 +1,136 @@
+/*     $NetBSD: msg.h,v 1.1 2017/04/02 21:44:00 kamil Exp $    */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+struct msg_fds {
+       int pfd[2];
+       int cfd[2];
+};
+
+#define CLOSEFD(fd) do { \
+       if (fd != -1) { \
+               close(fd); \
+               fd = -1; \
+       } \
+} while (/*CONSTCOND*/ 0)
+
+static int
+msg_open(struct msg_fds *fds)
+{
+       if (pipe(fds->pfd) == -1)
+               return -1;
+       if (pipe(fds->cfd) == -1) {
+               close(fds->pfd[0]);
+               close(fds->pfd[1]);
+               return -1;
+       }
+       return 0;
+}
+
+static void
+msg_close(struct msg_fds *fds)
+{
+       CLOSEFD(fds->pfd[0]);
+       CLOSEFD(fds->pfd[1]);
+       CLOSEFD(fds->cfd[0]);
+       CLOSEFD(fds->cfd[1]);
+}
+
+static int
+msg_write_child(const char *info, struct msg_fds *fds, void *msg, size_t len)
+{
+       ssize_t rv;
+       CLOSEFD(fds->cfd[1]);
+       CLOSEFD(fds->pfd[0]);
+
+       printf("Send %s\n", info);
+       rv = write(fds->pfd[1], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+//     printf("Wait %s\n", info);
+       rv = read(fds->cfd[0], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+       return 0;
+}
+
+static int
+msg_write_parent(const char *info, struct msg_fds *fds, void *msg, size_t len)
+{
+       ssize_t rv;
+       CLOSEFD(fds->pfd[1]);
+       CLOSEFD(fds->cfd[0]);
+
+       printf("Send %s\n", info);
+       rv = write(fds->cfd[1], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+//     printf("Wait %s\n", info);
+       rv = read(fds->pfd[0], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+       return 0;
+}
+
+static int
+msg_read_parent(const char *info, struct msg_fds *fds, void *msg, size_t len)
+{
+       ssize_t rv;
+       CLOSEFD(fds->pfd[1]);
+       CLOSEFD(fds->cfd[0]);
+
+       printf("Wait %s\n", info);
+       rv = read(fds->pfd[0], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+//     printf("Send %s\n", info);
+       rv = write(fds->cfd[1], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+       return 0;
+}
+
+static int
+msg_read_child(const char *info, struct msg_fds *fds, void *msg, size_t len)
+{
+       ssize_t rv;
+       CLOSEFD(fds->cfd[1]);
+       CLOSEFD(fds->pfd[0]);
+
+       printf("Wait %s\n", info);
+       rv = read(fds->cfd[0], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+//     printf("Send %s\n", info);
+       rv = write(fds->pfd[1], msg, len);
+       if (rv != (ssize_t)len)
+               return 1;
+       return 0;
+}
diff -r cef68663aed5 -r 04f8115846c4 tests/lib/libc/sys/t_ptrace.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/sys/t_ptrace.c     Sun Apr 02 21:44:00 2017 +0000
@@ -0,0 +1,208 @@
+/*     $NetBSD: t_ptrace.c,v 1.1 2017/04/02 21:44:00 kamil Exp $       */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_ptrace.c,v 1.1 2017/04/02 21:44:00 kamil Exp $");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <err.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "h_macros.h"
+
+/*
+ * A child process cannot call atf functions and expect them to magically
+ * work like in the parent.
+ * The printf(3) messaging from a child will not work out of the box as well
+ * without estabilishing a communication protocol with its parent. To not
+ * overcomplicate the tests - do not log from a child and use err(3)/errx(3)
+ * wrapped with FORKEE_ASSERT()/FORKEE_ASSERTX() as that is guaranteed to work.
+ */
+#define FORKEE_ASSERTX(x)                                                      \
+do {                                                                           \
+       int ret = (x);                                                          \
+       if (!ret)                                                               \
+               errx(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s",      \
+                    __FILE__, __LINE__, __func__, #x);                         \
+} while (0)
+
+#define FORKEE_ASSERT(x)                                                       \
+do {                                                                           \
+       int ret = (x);                                                          \
+       if (!ret)                                                               \
+               err(EXIT_FAILURE, "%s:%d %s(): Assertion failed for: %s",       \
+                    __FILE__, __LINE__, __func__, #x);                         \
+} while (0)
+
+ATF_TC(attach_pid0);
+ATF_TC_HEAD(attach_pid0, tc)
+{
+       atf_tc_set_md_var(tc, "descr",



Home | Main Index | Thread Index | Old Index