Source-Changes-HG archive

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

[src/trunk]: src/tests/kernel Added tests for the linear hook APIs



details:   https://anonhg.NetBSD.org/src/rev/4d6c2cca0577
branches:  trunk
changeset: 987502:4d6c2cca0577
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Sep 30 02:00:19 2021 +0000

description:
Added tests for the linear hook APIs

diffstat:

 distrib/sets/lists/base/shl.mi                             |    5 +-
 distrib/sets/lists/comp/mi                                 |    4 +-
 distrib/sets/lists/debug/mi                                |    3 +-
 distrib/sets/lists/debug/shl.mi                            |    3 +-
 distrib/sets/lists/tests/mi                                |    3 +-
 sys/rump/kern/Makefile.rumpkerncomp                        |    4 +-
 sys/rump/kern/lib/libsimplehook_tester/Makefile            |   13 +
 sys/rump/kern/lib/libsimplehook_tester/simplehook_tester.c |  724 +++++++++++++
 tests/kernel/Makefile                                      |    3 +-
 tests/kernel/t_simplehook.sh                               |  294 +++++
 10 files changed, 1048 insertions(+), 8 deletions(-)

diffs (truncated from 1163 to 300 lines):

diff -r 95bf1d99ec38 -r 4d6c2cca0577 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi    Thu Sep 30 01:26:07 2021 +0000
+++ b/distrib/sets/lists/base/shl.mi    Thu Sep 30 02:00:19 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.927 2021/09/24 13:13:07 christos Exp $
+# $NetBSD: shl.mi,v 1.928 2021/09/30 02:00:19 yamaguchi Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -741,6 +741,9 @@
 ./usr/lib/librumpkern_nv.so                    base-rump-shlib         rump
 ./usr/lib/librumpkern_nv.so.0                  base-rump-shlib         rump
 ./usr/lib/librumpkern_nv.so.0.0                        base-rump-shlib         rump
+./usr/lib/librumpkern_simplehook_tester.so     base-rump-shlib         rump
+./usr/lib/librumpkern_simplehook_tester.so.0   base-rump-shlib         rump
+./usr/lib/librumpkern_simplehook_tester.so.0.0 base-rump-shlib         rump
 ./usr/lib/librumpkern_sljit.so                 base-rump-shlib         rump,sljit
 ./usr/lib/librumpkern_sljit.so.0               base-rump-shlib         rump,sljit
 ./usr/lib/librumpkern_sljit.so.0.0             base-rump-shlib         rump,sljit
diff -r 95bf1d99ec38 -r 4d6c2cca0577 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Thu Sep 30 01:26:07 2021 +0000
+++ b/distrib/sets/lists/comp/mi        Thu Sep 30 02:00:19 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2394 2021/09/30 01:26:07 yamaguchi Exp $
+#      $NetBSD: mi,v 1.2395 2021/09/30 02:00:19 yamaguchi Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -4062,6 +4062,8 @@
 ./usr/lib/librumpkern_ksem_p.a                 comp-obsolete           obsolete
 ./usr/lib/librumpkern_nv.a                     comp-c-lib              rump
 ./usr/lib/librumpkern_nv_p.a                   comp-c-proflib          rump,profile
+./usr/lib/librumpkern_simplehook_tester.a      comp-c-lib              rump
+./usr/lib/librumpkern_simplehook_tester_p.a    comp-c-proflib          rump,profile
 ./usr/lib/librumpkern_sljit.a                  comp-c-lib              rump,sljit
 ./usr/lib/librumpkern_sljit_p.a                        comp-c-proflib          rump,sljit,profile
 ./usr/lib/librumpkern_solaris.a                        comp-c-lib              rump,zfs
diff -r 95bf1d99ec38 -r 4d6c2cca0577 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Thu Sep 30 01:26:07 2021 +0000
+++ b/distrib/sets/lists/debug/mi       Thu Sep 30 02:00:19 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.361 2021/09/19 15:51:28 thorpej Exp $
+# $NetBSD: mi,v 1.362 2021/09/30 02:00:19 yamaguchi 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
@@ -208,6 +208,7 @@
 ./usr/lib/librumpkern_crypto_g.a               comp-c-debuglib         debuglib,rump
 ./usr/lib/librumpkern_ksem_g.a                 comp-obsolete           obsolete,compatfile
 ./usr/lib/librumpkern_nv_g.a                   comp-c-debuglib         debuglib,rump
+./usr/lib/librumpkern_simplehook_tester_g.a    comp-c-debuglib         debuglib,rump
 ./usr/lib/librumpkern_sljit_g.a                        comp-c-debuglib         debuglib,rump,sljit
 ./usr/lib/librumpkern_solaris_g.a              comp-c-debuglib         debuglib,rump,zfs
 ./usr/lib/librumpkern_sysproxy_g.a             comp-c-debuglib         debuglib,rump
diff -r 95bf1d99ec38 -r 4d6c2cca0577 distrib/sets/lists/debug/shl.mi
--- a/distrib/sets/lists/debug/shl.mi   Thu Sep 30 01:26:07 2021 +0000
+++ b/distrib/sets/lists/debug/shl.mi   Thu Sep 30 02:00:19 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.284 2021/09/24 13:13:07 christos Exp $
+# $NetBSD: shl.mi,v 1.285 2021/09/30 02:00:19 yamaguchi Exp $
 ./usr/lib/libbfd_g.a                                           comp-c-debuglib debuglib,compatfile,binutils
 ./usr/libdata/debug/lib                                                base-sys-usr    debug,dynamicroot,compatdir
 ./usr/libdata/debug/lib/libavl.so.0.0.debug                    comp-zfs-debug  debug,dynamicroot,zfs
@@ -261,6 +261,7 @@
 ./usr/libdata/debug/usr/lib/librumpkern_crypto.so.0.0.debug    comp-rump-debug debug,rump
 ./usr/libdata/debug/usr/lib/librumpkern_ksem.so.0.0.debug      comp-obsolete   obsolete,compatfile
 ./usr/libdata/debug/usr/lib/librumpkern_nv.so.0.0.debug                comp-rump-debug debug,rump
+./usr/libdata/debug/usr/lib/librumpkern_simplehook_tester.so.0.0.debug comp-rump-debug debug,rump
 ./usr/libdata/debug/usr/lib/librumpkern_sljit.so.0.0.debug     comp-rump-debug debug,rump,sljit
 ./usr/libdata/debug/usr/lib/librumpkern_solaris.so.0.0.debug   comp-rump-debug debug,rump,zfs
 ./usr/libdata/debug/usr/lib/librumpkern_sysproxy.so.0.0.debug  comp-rump-debug debug,rump
diff -r 95bf1d99ec38 -r 4d6c2cca0577 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Sep 30 01:26:07 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Sep 30 02:00:19 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1130 2021/09/26 03:17:59 rillig Exp $
+# $NetBSD: mi,v 1.1131 2021/09/30 02:00:19 yamaguchi Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2237,6 +2237,7 @@
 ./usr/tests/kernel/t_pty                               tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_rnd                               tests-kernel-tests      atf,rump
 ./usr/tests/kernel/t_sigaction                         tests-obsolete          obsolete
+./usr/tests/kernel/t_simplehook                                tests-kernel-tests      atf,rump
 ./usr/tests/kernel/t_subr_prf                          tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_sysctl                            tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_sysv                              tests-kernel-tests      compattestfile,atf
diff -r 95bf1d99ec38 -r 4d6c2cca0577 sys/rump/kern/Makefile.rumpkerncomp
--- a/sys/rump/kern/Makefile.rumpkerncomp       Thu Sep 30 01:26:07 2021 +0000
+++ b/sys/rump/kern/Makefile.rumpkerncomp       Thu Sep 30 02:00:19 2021 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile.rumpkerncomp,v 1.13 2018/09/22 12:54:34 rmind Exp $
+#      $NetBSD: Makefile.rumpkerncomp,v 1.14 2021/09/30 02:00:20 yamaguchi Exp $
 #
 
 .include <bsd.own.mk>
 
-RUMPKERNCOMPS= crypto nv sysproxy tty z
+RUMPKERNCOMPS= crypto nv sysproxy tty z simplehook_tester
 RUMPSYSEMUS=   sys_cygwin sys_linux sys_sunos
 
 .if make(rumpdescribe)
diff -r 95bf1d99ec38 -r 4d6c2cca0577 sys/rump/kern/lib/libsimplehook_tester/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/kern/lib/libsimplehook_tester/Makefile   Thu Sep 30 02:00:19 2021 +0000
@@ -0,0 +1,13 @@
+
+
+LIB=   rumpkern_simplehook_tester
+COMMENT=Tester for simplehook
+
+SRCS=  simplehook_tester.c
+
+.ifdef RUMP_DEBUG
+CPPFLAGS.simplehook_tester.c+= -DSIMPLEHOOK_TESTER_DEBUG
+.endif
+
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
diff -r 95bf1d99ec38 -r 4d6c2cca0577 sys/rump/kern/lib/libsimplehook_tester/simplehook_tester.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/kern/lib/libsimplehook_tester/simplehook_tester.c        Thu Sep 30 02:00:19 2021 +0000
@@ -0,0 +1,724 @@
+/*     $NetBSD: simplehook_tester.c,v 1.1 2021/09/30 02:00:20 yamaguchi Exp $  */
+/*
+ * Copyright (c) 2021 Internet Initiative Japan 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>
+__KERNEL_RCSID(0, "$NetBSD: simplehook_tester.c,v 1.1 2021/09/30 02:00:20 yamaguchi Exp $");
+
+#include <sys/param.h>
+
+#include <sys/condvar.h>
+#include <sys/hook.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/sysctl.h>
+#include <sys/workqueue.h>
+
+#ifdef SIMPLEHOOK_TESTER_DEBUG
+#define HK_DPRINTF(a)  printf a
+#else
+#define HK_DPRINTF(a)  __nothing
+#endif
+
+MODULE(MODULE_CLASS_MISC, simplehook_tester, NULL);
+extern int simplehook_tester_init(void);
+struct tester_context;
+
+struct tester_hook {
+       struct tester_context   *th_ctx;
+       khook_t                 *th_hook;
+       size_t                   th_idx;
+       int                      th_count;
+       bool                     th_stopping;
+       bool                     th_stopped;
+       bool                     th_disestablish;
+};
+
+static struct tester_context {
+       kmutex_t                 ctx_mutex;
+       kcondvar_t               ctx_cv;
+       struct sysctllog        *ctx_sysctllog;
+       struct workqueue        *ctx_wq;
+       struct work              ctx_wk;
+       bool                     ctx_wk_enqueued;
+       bool                     ctx_wk_waiting;
+
+       khook_list_t            *ctx_hooks;
+       struct tester_hook       ctx_hook[2];
+
+       khook_t                 *ctx_nbhook;
+} tester_ctx;
+
+static int
+simplehook_tester_created(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node;
+       struct tester_context *ctx;
+       int error, val;
+       size_t i;
+
+       node = *rnode;
+       ctx = node.sysctl_data;
+
+       mutex_enter(&ctx->ctx_mutex);
+       val = ctx->ctx_hooks != NULL ? 1 : 0;
+       mutex_exit(&ctx->ctx_mutex);
+
+       node.sysctl_data = &val;
+       node.sysctl_size = sizeof(val);
+
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+       if (error || newp == NULL)
+               return error;
+
+       if (val != 0 && val != 1)
+               return EINVAL;
+
+       error = 0;
+       mutex_enter(&ctx->ctx_mutex);
+       if (val == 1) {
+               if (ctx->ctx_hooks != NULL) {
+                       error = EEXIST;
+               } else {
+                       HK_DPRINTF(("[%s, %d]: create hook list\n",
+                           __func__, __LINE__));
+                       ctx->ctx_hooks = simplehook_create(IPL_NONE,
+                           "tester hooks");
+                       KASSERT(ctx->ctx_hooks != NULL);
+               }
+       } else {
+               if (ctx->ctx_hooks == NULL) {
+                       error = ENXIO;
+               } else if (ctx->ctx_wk_waiting) {
+                       error = EBUSY;
+               } else {
+                       ctx->ctx_wk_waiting = true;
+                       mutex_exit(&ctx->ctx_mutex);
+
+                       workqueue_wait(ctx->ctx_wq, &ctx->ctx_wk);
+
+                       mutex_enter(&ctx->ctx_mutex);
+                       ctx->ctx_wk_waiting = false;
+
+                       HK_DPRINTF(("[%s, %d]: destroy hook list\n",
+                           __func__, __LINE__));
+                       simplehook_destroy(ctx->ctx_hooks);
+                       ctx->ctx_hooks = NULL;
+                       ctx->ctx_nbhook = NULL;
+                       for (i = 0; i < __arraycount(ctx->ctx_hook); i++) {
+                               ctx->ctx_hook[i].th_hook = NULL;
+                       }
+               }
+       }
+       mutex_exit(&ctx->ctx_mutex);
+
+       return error;
+}
+
+static void
+simplehook_tester_work(struct work *wk, void *xctx)
+{
+       struct tester_context *ctx;
+
+       ctx = xctx;
+
+       mutex_enter(&ctx->ctx_mutex);
+       ctx->ctx_wk_enqueued = false;
+       mutex_exit(&ctx->ctx_mutex);
+
+       simplehook_dohooks(ctx->ctx_hooks);
+}
+
+static int
+simplehook_tester_dohooks(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node;
+       struct tester_context *ctx;
+       int error, val;
+
+       node = *rnode;
+       ctx = node.sysctl_data;
+
+       mutex_enter(&ctx->ctx_mutex);
+       val = ctx->ctx_wk_enqueued ? 1 : 0;
+       mutex_exit(&ctx->ctx_mutex);
+
+       node.sysctl_data = &val;
+       node.sysctl_size = sizeof(val);
+
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+       if (error || newp == NULL)
+               return error;
+
+       if (val != 0 && val != 1)



Home | Main Index | Thread Index | Old Index