From: Brendan Higgins <brendanhiggins@google.com>
To: gregkh@linuxfoundation.org, keescook@google.com,
mcgrof@kernel.org, shuah@kernel.org
Cc: brakmo@fb.com, richard@nod.at, mpe@ellerman.id.au,
Tim.Bird@sony.com, linux-um@lists.infradead.org,
linux-kernel@vger.kernel.org, rostedt@goodmis.org,
julia.lawall@lip6.fr, joel@jms.id.au,
linux-kselftest@vger.kernel.org, khilman@baylibre.com,
joe@perches.com, jdike@addtoit.com,
Brendan Higgins <brendanhiggins@google.com>,
kunit-dev@googlegroups.com
Subject: [RFC v1 26/31] arch: um: added stubs for mock iomem for KUnit
Date: Tue, 16 Oct 2018 16:51:15 -0700 [thread overview]
Message-ID: <20181016235120.138227-27-brendanhiggins@google.com> (raw)
In-Reply-To: <20181016235120.138227-1-brendanhiggins@google.com>
This mocks out some iomem functions (functions like readl and writel),
for mocking hardware interfaces.
Signed-off-by: Brendan Higgins <brendanhiggins@google.com>
---
arch/um/Kconfig.common | 8 +++++-
arch/um/Kconfig.um | 5 ++++
arch/um/include/asm/Kbuild | 1 -
arch/um/include/asm/io-mock-shared.h | 33 +++++++++++++++++++++
arch/um/include/asm/io-mock.h | 43 ++++++++++++++++++++++++++++
arch/um/include/asm/io.h | 8 ++++++
arch/um/kernel/Makefile | 1 +
arch/um/kernel/io-mock.c | 40 ++++++++++++++++++++++++++
kunit/Kconfig | 1 +
9 files changed, 138 insertions(+), 2 deletions(-)
create mode 100644 arch/um/include/asm/io-mock-shared.h
create mode 100644 arch/um/include/asm/io-mock.h
create mode 100644 arch/um/kernel/io-mock.c
diff --git a/arch/um/Kconfig.common b/arch/um/Kconfig.common
index 07f84c842cc31..72e7efb74f7fd 100644
--- a/arch/um/Kconfig.common
+++ b/arch/um/Kconfig.common
@@ -19,7 +19,13 @@ config MMU
default y
config NO_IOMEM
- def_bool y
+ bool
+ default y if !KUNIT
+
+config HAS_IOMEM
+ bool "Turns on fake IOMEM support for KUnit"
+ depends on KUNIT
+ select MOCK_IOMEM
config ISA
bool
diff --git a/arch/um/Kconfig.um b/arch/um/Kconfig.um
index 20da5a8ca9490..8d35e0e2c23d1 100644
--- a/arch/um/Kconfig.um
+++ b/arch/um/Kconfig.um
@@ -122,3 +122,8 @@ config SECCOMP
defined by each seccomp mode.
If unsure, say Y.
+
+config PLATFORM_MOCK
+ bool "Enable a mock architecture used for unit testing."
+ depends on KUNIT && OF
+ default n
diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild
index b10dde6cb793b..9fd2827ab76d1 100644
--- a/arch/um/include/asm/Kbuild
+++ b/arch/um/include/asm/Kbuild
@@ -12,7 +12,6 @@ generic-y += ftrace.h
generic-y += futex.h
generic-y += hardirq.h
generic-y += hw_irq.h
-generic-y += io.h
generic-y += irq_regs.h
generic-y += irq_work.h
generic-y += kdebug.h
diff --git a/arch/um/include/asm/io-mock-shared.h b/arch/um/include/asm/io-mock-shared.h
new file mode 100644
index 0000000000000..6baf59cb17a58
--- /dev/null
+++ b/arch/um/include/asm/io-mock-shared.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_UM_IO_MOCK_SHARED_H
+#define _ASM_UM_IO_MOCK_SHARED_H
+
+#define readb readb
+u8 readb(const volatile void __iomem *);
+
+#define readw readw
+u16 readw(const volatile void __iomem *);
+
+#define readl readl
+u32 readl(const volatile void __iomem *);
+
+#ifdef CONFIG_64BIT
+#define readq readq
+u64 readq(const volatile void __iomem *);
+#endif /* CONFIG_64BIT */
+
+#define writeb writeb
+void writeb(u8, const volatile void __iomem *);
+
+#define writew writew
+void writew(u16, const volatile void __iomem *);
+
+#define writel writel
+void writel(u32, const volatile void __iomem *);
+
+#ifdef CONFIG_64BIT
+#define writeq writeq
+void writeq(u64, const volatile void __iomem *);
+#endif /* CONFIG_64BIT */
+
+#endif /* _ASM_UM_IO_MOCK_SHARED_H */
diff --git a/arch/um/include/asm/io-mock.h b/arch/um/include/asm/io-mock.h
new file mode 100644
index 0000000000000..bdc5cd1d4e33c
--- /dev/null
+++ b/arch/um/include/asm/io-mock.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Mock IO functions.
+ *
+ * Copyright (C) 2018, Google LLC.
+ * Author: Brendan Higgins <brendanhiggins@google.com>
+ */
+
+#ifndef _ASM_UM_IO_MOCK_H
+#define _ASM_UM_IO_MOCK_H
+
+#include <asm/io-mock-shared.h>
+#include <kunit/mock.h>
+
+DECLARE_FUNCTION_MOCK(readb,
+ RETURNS(u8), PARAMS(const volatile void __iomem *));
+
+DECLARE_FUNCTION_MOCK(readw,
+ RETURNS(u16), PARAMS(const volatile void __iomem *));
+
+DECLARE_FUNCTION_MOCK(readl,
+ RETURNS(u32), PARAMS(const volatile void __iomem *));
+
+#ifdef CONFIG_64BIT
+DECLARE_FUNCTION_MOCK(readq,
+ RETURNS(u64), PARAMS(const volatile void __iomem *));
+#endif /* CONFIG_64BIT */
+
+DECLARE_FUNCTION_MOCK_VOID_RETURN(writeb,
+ PARAMS(u8, const volatile void __iomem *));
+
+DECLARE_FUNCTION_MOCK_VOID_RETURN(writew,
+ PARAMS(u16, const volatile void __iomem *));
+
+DECLARE_FUNCTION_MOCK_VOID_RETURN(writel,
+ PARAMS(u32, const volatile void __iomem *));
+
+#ifdef CONFIG_64BIT
+DECLARE_FUNCTION_MOCK_VOID_RETURN(writeq,
+ PARAMS(u64, const volatile void __iomem *));
+#endif /* CONFIG_64BIT */
+
+#endif /* _ASM_UM_IO_MOCK_H */
diff --git a/arch/um/include/asm/io.h b/arch/um/include/asm/io.h
index 96f77b5232aaf..a7f61cf963756 100644
--- a/arch/um/include/asm/io.h
+++ b/arch/um/include/asm/io.h
@@ -2,11 +2,19 @@
#ifndef _ASM_UM_IO_H
#define _ASM_UM_IO_H
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#if IS_ENABLED(CONFIG_PLATFORM_MOCK)
+#include <asm/io-mock-shared.h>
+#endif
+
#define ioremap ioremap
static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
{
return (void __iomem *)(unsigned long)offset;
}
+#define ioremap_nocache ioremap
#define iounmap iounmap
static inline void iounmap(void __iomem *addr)
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile
index 2f36d515762ec..770c480d5a101 100644
--- a/arch/um/kernel/Makefile
+++ b/arch/um/kernel/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_GPROF) += gprof_syms.o
obj-$(CONFIG_GCOV) += gmon_syms.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
+obj-$(CONFIG_PLATFORM_MOCK) += io-mock.o
USER_OBJS := config.o
diff --git a/arch/um/kernel/io-mock.c b/arch/um/kernel/io-mock.c
new file mode 100644
index 0000000000000..e0d4648e97a6c
--- /dev/null
+++ b/arch/um/kernel/io-mock.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Mock IO functions.
+ *
+ * Copyright (C) 2018, Google LLC.
+ * Author: Brendan Higgins <brendanhiggins@google.com>
+ */
+
+#include <linux/mm.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <kunit/mock.h>
+
+DEFINE_FUNCTION_MOCK(readb,
+ RETURNS(u8), PARAMS(const volatile void __iomem *));
+
+DEFINE_FUNCTION_MOCK(readw,
+ RETURNS(u16), PARAMS(const volatile void __iomem *));
+
+DEFINE_FUNCTION_MOCK(readl,
+ RETURNS(u32), PARAMS(const volatile void __iomem *));
+
+#ifdef CONFIG_64BIT
+DEFINE_FUNCTION_MOCK(readq,
+ RETURNS(u64), PARAMS(const volatile void __iomem *));
+#endif /* CONFIG_64BIT */
+
+DEFINE_FUNCTION_MOCK_VOID_RETURN(writeb,
+ PARAMS(u8, const volatile void __iomem *));
+
+DEFINE_FUNCTION_MOCK_VOID_RETURN(writew,
+ PARAMS(u16, const volatile void __iomem *));
+
+DEFINE_FUNCTION_MOCK_VOID_RETURN(writel,
+ PARAMS(u32, const volatile void __iomem *));
+
+#ifdef CONFIG_64BIT
+DEFINE_FUNCTION_MOCK_VOID_RETURN(writeq,
+ PARAMS(u64, const volatile void __iomem *));
+#endif /* CONFIG_64BIT */
diff --git a/kunit/Kconfig b/kunit/Kconfig
index 5cb500355c873..9d4b7cfff9d92 100644
--- a/kunit/Kconfig
+++ b/kunit/Kconfig
@@ -6,6 +6,7 @@ menu "KUnit support"
config KUNIT
bool "Enable support for unit tests (KUnit)"
+ select HAS_IOMEM
help
Enables support for kernel unit tests (KUnit), a lightweight unit
testing and mocking framework for the Linux kernel. These tests are
--
2.19.1.331.ge82ca0e54c-goog
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
next prev parent reply other threads:[~2018-10-16 23:55 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-16 23:50 [RFC v1 00/31] kunit: Introducing KUnit, the Linux kernel unit testing framework Brendan Higgins
2018-10-16 23:50 ` [RFC v1 01/31] kunit: test: added string_stream a std::stream like string builder Brendan Higgins
2018-10-16 23:50 ` [RFC v1 02/31] kunit: test: adds KUnit test runner core Brendan Higgins
2018-10-16 23:50 ` [RFC v1 03/31] kunit: test: added test resource management API Brendan Higgins
2018-10-16 23:50 ` [RFC v1 04/31] kunit: test: added test_stream a std::stream like logger Brendan Higgins
2018-10-16 23:50 ` [RFC v1 05/31] kunit: test: added the concept of expectations Brendan Higgins
2018-10-16 23:50 ` [RFC v1 06/31] arch: um: enabled running kunit from User Mode Linux Brendan Higgins
2018-10-17 15:29 ` Kieran Bingham
2018-10-17 17:43 ` Brendan Higgins
2018-10-17 17:52 ` Tim.Bird
2018-10-17 21:09 ` Brendan Higgins
2018-10-17 21:18 ` Tim.Bird
2018-10-17 22:45 ` Brendan Higgins
2018-10-16 23:50 ` [RFC v1 07/31] kunit: test: added initial tests Brendan Higgins
2018-10-16 23:50 ` [RFC v1 08/31] arch: um: added shim to trap to allow installing a fault catcher for tests Brendan Higgins
2018-10-16 23:50 ` [RFC v1 09/31] kunit: test: added the concept of assertions Brendan Higgins
2018-10-16 23:50 ` [RFC v1 10/31] kunit: test: added concept of initcalls Brendan Higgins
2018-10-16 23:51 ` [RFC v1 11/31] kunit: test: added concept of post conditions Brendan Higgins
2018-10-16 23:51 ` [RFC v1 12/31] checkpatch: added support for struct MOCK(foo) syntax Brendan Higgins
2018-10-16 23:59 ` Joe Perches
2018-10-17 0:03 ` Brendan Higgins
2018-10-16 23:51 ` [RFC v1 13/31] kunit: mock: added parameter list minipulation macros Brendan Higgins
2018-10-16 23:51 ` [RFC v1 14/31] kunit: mock: added internal mock infrastructure Brendan Higgins
2018-10-16 23:51 ` [RFC v1 15/31] kunit: mock: added basic matchers and actions Brendan Higgins
2018-10-16 23:51 ` [RFC v1 16/31] kunit: mock: added class mocking support Brendan Higgins
2018-10-16 23:51 ` [RFC v1 17/31] kunit: mock: added struct param matcher Brendan Higgins
2018-10-16 23:51 ` [RFC v1 18/31] kunit: mock: added parameter formatters Brendan Higgins
2018-10-16 23:51 ` [RFC v1 19/31] kunit: mock: implemented nice, strict and naggy mock distinctions Brendan Higgins
2018-10-16 23:51 ` [RFC v1 20/31] kunit: mock: add ability to mock functions with void context Brendan Higgins
2018-10-16 23:51 ` [RFC v1 21/31] kunit: mock: added support for arbitrary function mocking Brendan Higgins
2018-10-16 23:51 ` [RFC v1 22/31] kunit: mock: add the concept of spyable functions Brendan Higgins
2018-10-17 22:46 ` Rob Herring
2018-10-18 1:32 ` Brendan Higgins
2018-10-16 23:51 ` [RFC v1 23/31] kunit: mock: add parameter capturers Brendan Higgins
2018-10-16 23:51 ` [RFC v1 24/31] kunit: improved sigsegv stack trace printing Brendan Higgins
2018-10-16 23:51 ` [RFC v1 25/31] kunit: added concept of platform mocking Brendan Higgins
2018-10-16 23:51 ` Brendan Higgins [this message]
2018-10-17 22:28 ` [RFC v1 26/31] arch: um: added stubs for mock iomem for KUnit Rob Herring
2018-10-18 1:14 ` Brendan Higgins
2018-10-16 23:51 ` [RFC v1 27/31] Documentation: kunit: adds complete documentation " Brendan Higgins
2018-10-16 23:51 ` [RFC v1 28/31] kunit: added Python libraries for handing KUnit config and kernel Brendan Higgins
2018-10-16 23:51 ` [RFC v1 29/31] kunit: added KUnit wrapper script and simple output parser Brendan Higgins
2018-10-16 23:51 ` [RFC v1 30/31] kunit.py: improved output from python wrapper Brendan Higgins
2018-10-16 23:51 ` [RFC v1 31/31] MAINTAINERS: add entry for KUnit the unit testing framework Brendan Higgins
2018-10-17 9:08 ` [RFC v1 00/31] kunit: Introducing KUnit, the Linux kernel " Daniel Vetter
2018-10-17 17:49 ` Tim.Bird
2018-10-17 22:22 ` Brendan Higgins
2018-10-17 20:43 ` Rob Herring
2018-10-17 23:12 ` Randy Dunlap
2018-10-18 2:05 ` Brendan Higgins
2018-10-18 3:55 ` Dan Williams
2018-10-19 6:27 ` Brendan Higgins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181016235120.138227-27-brendanhiggins@google.com \
--to=brendanhiggins@google.com \
--cc=Tim.Bird@sony.com \
--cc=brakmo@fb.com \
--cc=gregkh@linuxfoundation.org \
--cc=jdike@addtoit.com \
--cc=joe@perches.com \
--cc=joel@jms.id.au \
--cc=julia.lawall@lip6.fr \
--cc=keescook@google.com \
--cc=khilman@baylibre.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=mcgrof@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=richard@nod.at \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).