diff mbox series

[v4,4/6] mmc: sdhci-of-aspeed: Add KUnit tests for phase calculations

Message ID 20201207142556.2045481-5-andrew@aj.id.au (mailing list archive)
State New, archived
Headers show
Series mmc: sdhci-of-aspeed: Expose phase delay tuning | expand

Commit Message

Andrew Jeffery Dec. 7, 2020, 2:25 p.m. UTC
Converting degrees of phase to logic delays is irritating to test on
hardware, so lets exercise the function using KUnit.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 drivers/mmc/host/Kconfig                |  14 ++++
 drivers/mmc/host/Makefile               |   1 +
 drivers/mmc/host/sdhci-of-aspeed-test.c | 100 ++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/mmc/host/sdhci-of-aspeed-test.c

Comments

kernel test robot Dec. 7, 2020, 10:27 p.m. UTC | #1
Hi Andrew,

I love your patch! Yet something to improve:

[auto build test ERROR on joel-aspeed/for-next]
[also build test ERROR on linus/master v5.10-rc7 next-20201207]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andrew-Jeffery/mmc-sdhci-of-aspeed-Expose-phase-delay-tuning/20201207-223013
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joel/aspeed.git for-next
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/0b6ccdd94c4a194549dfc4a3212bd6be5d2841ef
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Andrew-Jeffery/mmc-sdhci-of-aspeed-Expose-phase-delay-tuning/20201207-223013
        git checkout 0b6ccdd94c4a194549dfc4a3212bd6be5d2841ef
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:(.toc+0x0): undefined reference to `kunit_binary_assert_format'
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o: in function `.aspeed_sdhci_remove':
>> sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_remove+0x34): undefined reference to `.sdhci_remove_host'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_remove+0x5c): undefined reference to `.sdhci_pltfm_free'
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o: in function `.aspeed_sdhci_get_max_clock':
>> sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_get_max_clock+0x54): undefined reference to `.sdhci_pltfm_clk_get_max_clock'
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o: in function `.aspeed_sdhci_probe':
>> sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x8c): undefined reference to `.sdhci_pltfm_init'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x2c0): undefined reference to `.sdhci_get_property'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x374): undefined reference to `.mmc_of_parse'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x3bc): undefined reference to `.mmc_of_parse_clk_phase'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x3d0): undefined reference to `.sdhci_add_host'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_probe+0x424): undefined reference to `.sdhci_pltfm_free'
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o: in function `.aspeed_sdhci_phase_hs200':
>> sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x270): undefined reference to `.kunit_do_assertion'
>> powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x2f8): undefined reference to `.kunit_do_assertion'
   powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x380): undefined reference to `.kunit_do_assertion'
   powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x410): undefined reference to `.kunit_do_assertion'
   powerpc64-linux-ld: sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x4a8): undefined reference to `.kunit_do_assertion'
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_phase_hs200+0x530): more undefined references to `.kunit_do_assertion' follow
   powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o: in function `.aspeed_sdhci_set_clock':
>> sdhci-of-aspeed-test.c:(.text.aspeed_sdhci_set_clock+0x5c4): undefined reference to `.sdhci_enable_clk'
>> powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:(.data.rel.aspeed_sdc_driver+0xa0): undefined reference to `sdhci_pltfm_pmops'
>> powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:(.data.rel.ro.aspeed_sdhci_ops+0x20): undefined reference to `sdhci_set_uhs_signaling'
>> powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:(.data.rel.ro.aspeed_sdhci_ops+0x88): undefined reference to `sdhci_reset'
>> powerpc64-linux-ld: drivers/mmc/host/sdhci-of-aspeed-test.o:(.data.rel.ro.aspeed_sdhci_ops+0xd8): undefined reference to `sdhci_pltfm_clk_get_max_clock'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 596f32637315..9f910655d6ea 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -168,6 +168,20 @@  config MMC_SDHCI_OF_ASPEED
 
 	  If unsure, say N.
 
+config MMC_SDHCI_OF_ASPEED_TEST
+	bool "Test for the ASPEED SDHCI controller"
+	depends on MMC_SDHCI_OF_ASPEED && KUNIT
+	help
+	  Enable KUnit tests for the ASPEED SDHCI driver. Select this
+	  option only if you will boot the kernel for the purpose of running
+	  unit tests (e.g. under UML or qemu).
+
+	  The KUnit tests generally exercise parts of the driver that do not
+	  directly touch the hardware, for example, the phase correction
+	  calculations.
+
+	  If unsure, say N.
+
 config MMC_SDHCI_OF_AT91
 	tristate "SDHCI OF support for the Atmel SDMMC controller"
 	depends on MMC_SDHCI_PLTFM
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 451c25fc2c69..3ee59d5802cf 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -90,6 +90,7 @@  obj-$(CONFIG_MMC_SDHCI_DOVE)		+= sdhci-dove.o
 obj-$(CONFIG_MMC_SDHCI_TEGRA)		+= sdhci-tegra.o
 obj-$(CONFIG_MMC_SDHCI_OF_ARASAN)	+= sdhci-of-arasan.o
 obj-$(CONFIG_MMC_SDHCI_OF_ASPEED)	+= sdhci-of-aspeed.o
+obj-$(CONFIG_MMC_SDHCI_OF_ASPEED_TEST)	+= sdhci-of-aspeed-test.o
 obj-$(CONFIG_MMC_SDHCI_OF_AT91)		+= sdhci-of-at91.o
 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC)	+= sdhci-of-esdhc.o
 obj-$(CONFIG_MMC_SDHCI_OF_HLWD)		+= sdhci-of-hlwd.o
diff --git a/drivers/mmc/host/sdhci-of-aspeed-test.c b/drivers/mmc/host/sdhci-of-aspeed-test.c
new file mode 100644
index 000000000000..fb79b278fb81
--- /dev/null
+++ b/drivers/mmc/host/sdhci-of-aspeed-test.c
@@ -0,0 +1,100 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (C) 2020 IBM Corp. */
+
+#include <kunit/test.h>
+
+#include "sdhci-of-aspeed.c"
+
+static void aspeed_sdhci_phase_ddr52(struct kunit *test)
+{
+	int rate = 52000000;
+
+	KUNIT_EXPECT_EQ(test, 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 0));
+	KUNIT_EXPECT_EQ(test, 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 1));
+	KUNIT_EXPECT_EQ(test, 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 2));
+	KUNIT_EXPECT_EQ(test, 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 3));
+	KUNIT_EXPECT_EQ(test, 2,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 4));
+	KUNIT_EXPECT_EQ(test, 3,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 5));
+	KUNIT_EXPECT_EQ(test, 14,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 23));
+	KUNIT_EXPECT_EQ(test, 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 24));
+	KUNIT_EXPECT_EQ(test, 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 25));
+
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 180));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 181));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 182));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 183));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 184));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 185));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 203));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 204));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 205));
+}
+
+static void aspeed_sdhci_phase_hs200(struct kunit *test)
+{
+	int rate = 200000000;
+
+	KUNIT_EXPECT_EQ(test, 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 0));
+	KUNIT_EXPECT_EQ(test, 0,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 5));
+	KUNIT_EXPECT_EQ(test, 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 6));
+	KUNIT_EXPECT_EQ(test, 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 7));
+	KUNIT_EXPECT_EQ(test, 14,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 89));
+	KUNIT_EXPECT_EQ(test, 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 90));
+	KUNIT_EXPECT_EQ(test, 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 91));
+	KUNIT_EXPECT_EQ(test, 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 96));
+
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 180));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 185));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 186));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 187));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 269));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 270));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 271));
+	KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15,
+			aspeed_sdhci_phase_to_tap(NULL, rate, 276));
+}
+
+static struct kunit_case aspeed_sdhci_test_cases[] = {
+	KUNIT_CASE(aspeed_sdhci_phase_ddr52),
+	KUNIT_CASE(aspeed_sdhci_phase_hs200),
+	{}
+};
+
+static struct kunit_suite aspeed_sdhci_test_suite = {
+	.name = "sdhci-of-aspeed",
+	.test_cases = aspeed_sdhci_test_cases,
+};
+kunit_test_suite(aspeed_sdhci_test_suite);