Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/modules Re-arrange the ufetchstore tests to look like ...
details: https://anonhg.NetBSD.org/src/rev/444e9bd98e6c
branches: trunk
changeset: 450486:444e9bd98e6c
user: christos <christos%NetBSD.org@localhost>
date: Mon Apr 15 23:41:23 2019 +0000
description:
Re-arrange the ufetchstore tests to look like the other ones.
diffstat:
tests/modules/Makefile | 12 +-
tests/modules/t_ufetchstore.c | 1315 +++++++++++++++++
tests/modules/ufetchstore/Makefile | 17 +-
tests/modules/ufetchstore/Makefile.inc | 2 -
tests/modules/ufetchstore/common.h | 59 +
tests/modules/ufetchstore/module/Makefile | 14 -
tests/modules/ufetchstore/module/common.h | 59 -
tests/modules/ufetchstore/module/ufetchstore_tester.c | 230 --
tests/modules/ufetchstore/ufetchstore_tester.c | 230 ++
9 files changed, 1618 insertions(+), 320 deletions(-)
diffs (truncated from 1996 to 300 lines):
diff -r 31e754fbca6a -r 444e9bd98e6c tests/modules/Makefile
--- a/tests/modules/Makefile Mon Apr 15 23:16:59 2019 +0000
+++ b/tests/modules/Makefile Mon Apr 15 23:41:23 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.16 2019/04/06 03:06:29 thorpej Exp $
+# $NetBSD: Makefile,v 1.17 2019/04/15 23:41:23 christos Exp $
.include <bsd.own.mk>
@@ -13,8 +13,12 @@
TESTS_C= t_modctl
TESTS_C+= t_builtin
TESTS_C+= t_kcov
-LDADD= -lprop
-LDADD+= -lrumpfs_kernfs -lrumpvfs -lrump -lrumpuser -lrump -lpthread
+TESTS_C+= t_ufetchstore
+CPPFLAGS.t_ufetchstore.c+=-I${.CURDIR}/ufetchstore
+.for i in t_modctl t_builtin t_kcov
+LDADD.${i}= -lprop
+LDADD.${i}+= -lrumpfs_kernfs -lrumpvfs -lrump -lrumpuser -lrump -lpthread
+.endfor
TESTS_SH= t_abi_uvm
TESTS_SH+= t_modload
@@ -28,6 +32,4 @@
SUBDIR+= threadpool_tester
SUBDIR+= ufetchstore
-ATFFILE_EXTRA_SUBDIRS= t_ufetchstore
-
.include <bsd.test.mk>
diff -r 31e754fbca6a -r 444e9bd98e6c tests/modules/t_ufetchstore.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/t_ufetchstore.c Mon Apr 15 23:41:23 2019 +0000
@@ -0,0 +1,1315 @@
+/* $NetBSD: t_ufetchstore.c,v 1.1 2019/04/15 23:41:23 christos Exp $ */
+
+/*
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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>
+__COPYRIGHT("@(#) Copyright (c) 2019\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_ufetchstore.c,v 1.1 2019/04/15 23:41:23 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <atf-c.h>
+
+#include "common.h"
+
+#define mib_name "kern.ufetchstore_test.test"
+
+static bool module_loaded;
+
+#define MODULE_PATH \
+ "/usr/tests/modules/ufetchstore_tester/ufetchstore_tester.kmod"
+#define MODULE_NAME "ufetchstore_tester"
+
+#define CHECK_MODULE() \
+do { \
+ load_module(); \
+ if (! module_loaded) { \
+ atf_tc_skip("loading '%s' module failed.", MODULE_NAME);\
+ } \
+} while (/*CONSTCOND*/0)
+
+static void
+load_module(void)
+{
+#ifndef SKIP_MODULE
+ if (module_loaded)
+ return;
+
+ modctl_load_t params = {
+ .ml_filename = MODULE_PATH,
+ .ml_flags = MODCTL_NO_PROP,
+ };
+
+ if (modctl(MODCTL_LOAD, ¶ms) != 0) {
+ warn("failed to load module '%s'", MODULE_PATH);
+ } else {
+ module_loaded = true;
+ }
+#else
+ module_loaded = true;
+#endif /* ! SKIP_MODULE */
+}
+
+#define UADDR(x) ((uintptr_t)(x))
+
+static void
+unload_module(void)
+{
+#ifndef SKIP_MODULE
+ char module_name[] = MODULE_NAME;
+
+ if (modctl(MODCTL_UNLOAD, module_name) != 0) {
+ warn("failed to unload module '%s'", MODULE_NAME);
+ } else {
+ module_loaded = false;
+ }
+#endif /* ! SKIP_MODULE */
+}
+
+static unsigned long
+vm_max_address_raw(void)
+{
+ static unsigned long max_addr = 0;
+ int rv;
+
+ if (max_addr == 0) {
+ size_t max_addr_size = sizeof(max_addr);
+ rv = sysctlbyname("vm.maxaddress", &max_addr, &max_addr_size,
+ NULL, 0);
+ if (rv != 0)
+ err(1, "sysctlbyname('vm.maxaddress')");
+ }
+ return max_addr;
+}
+
+static void *
+vm_max_address(void)
+{
+ return (void *)vm_max_address_raw();
+}
+
+static void *
+vm_max_address_minus(unsigned int adj)
+{
+ return (void *)(vm_max_address_raw() - adj);
+}
+
+static int
+do_sysctl(struct ufetchstore_test_args *args)
+{
+ uint64_t arg_addr64 = (uintptr_t)args;
+ int rv;
+
+ args->fetchstore_error = EBADF; /* poison */
+ args->pointer_size = (int)sizeof(void *);
+
+ /*
+ * Yes, the intent is to provide the pointer, not the structure,
+ * to the kernel side of the test harness.
+ */
+ rv = sysctlbyname(mib_name, NULL, NULL, &arg_addr64,
+ sizeof(arg_addr64));
+ if (rv != 0) {
+ rv = errno;
+ warn("sysctlbyname('%s') -> %d", mib_name, rv);
+ return rv;
+ }
+ return 0;
+}
+
+static int
+do_ufetch_8(const uint8_t *uaddr, uint8_t *res)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_LOAD,
+ .size = 8,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ *res = args.val8;
+ return args.fetchstore_error;
+}
+
+static int
+do_ufetch_16(const uint16_t *uaddr, uint16_t *res)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_LOAD,
+ .size = 16,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ *res = args.val16;
+ return args.fetchstore_error;
+}
+
+static int
+do_ufetch_32(const uint32_t *uaddr, uint32_t *res)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_LOAD,
+ .size = 32,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ *res = args.val32;
+ return args.fetchstore_error;
+}
+
+#ifdef _LP64
+static int
+do_ufetch_64(const uint64_t *uaddr, uint64_t *res)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_LOAD,
+ .size = 64,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ *res = args.val64;
+ return args.fetchstore_error;
+}
+#endif /* _LP64 */
+
+static int
+do_ustore_8(uint8_t *uaddr, uint8_t val)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_STORE,
+ .size = 8,
+ .val8 = val,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ return args.fetchstore_error;
+}
+
+static int
+do_ustore_16(uint16_t *uaddr, uint16_t val)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_STORE,
+ .size = 16,
+ .val16 = val,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ return args.fetchstore_error;
+}
+
+static int
+do_ustore_32(uint32_t *uaddr, uint32_t val)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_STORE,
+ .size = 32,
+ .val32 = val,
+ };
+
+ ATF_REQUIRE_EQ(do_sysctl(&args), 0);
+ return args.fetchstore_error;
+}
+
+#ifdef _LP64
+static int
+do_ustore_64(uint64_t *uaddr, uint64_t val)
+{
+ struct ufetchstore_test_args args = {
+ .uaddr64 = UADDR(uaddr),
+ .test_op = OP_STORE,
+ .size = 64,
+ .val64 = val,
+ };
+
Home |
Main Index |
Thread Index |
Old Index