Skip to content

Commit

Permalink
mmc: sdhci-of-aspeed: Add KUnit tests for phase calculations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
amboar authored and intel-lab-lkp committed Dec 7, 2020
1 parent a954c49 commit 0b6ccdd
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/mmc/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/mmc/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
100 changes: 100 additions & 0 deletions drivers/mmc/host/sdhci-of-aspeed-test.c
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 0b6ccdd

Please sign in to comment.