Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: sdhci-of-aspeed: Add KUnit tests for phase calculations

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>
Link: https://lore.kernel.org/r/20210114031433.2388532-5-andrew@aj.id.au
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Andrew Jeffery and committed by
Ulf Hansson
0bbcd225 0c53dc32

+116
+14
drivers/mmc/host/Kconfig
··· 168 168 169 169 If unsure, say N. 170 170 171 + config MMC_SDHCI_OF_ASPEED_TEST 172 + bool "Tests for the ASPEED SDHCI driver" 173 + depends on MMC_SDHCI_OF_ASPEED && KUNIT=y 174 + help 175 + Enable KUnit tests for the ASPEED SDHCI driver. Select this 176 + option only if you will boot the kernel for the purpose of running 177 + unit tests (e.g. under UML or qemu). 178 + 179 + The KUnit tests generally exercise parts of the driver that do not 180 + directly touch the hardware, for example, the phase correction 181 + calculations. 182 + 183 + If unsure, say N. 184 + 171 185 config MMC_SDHCI_OF_AT91 172 186 tristate "SDHCI OF support for the Atmel SDMMC controller" 173 187 depends on MMC_SDHCI_PLTFM
+98
drivers/mmc/host/sdhci-of-aspeed-test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* Copyright (C) 2020 IBM Corp. */ 3 + 4 + #include <kunit/test.h> 5 + 6 + static void aspeed_sdhci_phase_ddr52(struct kunit *test) 7 + { 8 + int rate = 52000000; 9 + 10 + KUNIT_EXPECT_EQ(test, 0, 11 + aspeed_sdhci_phase_to_tap(NULL, rate, 0)); 12 + KUNIT_EXPECT_EQ(test, 0, 13 + aspeed_sdhci_phase_to_tap(NULL, rate, 1)); 14 + KUNIT_EXPECT_EQ(test, 1, 15 + aspeed_sdhci_phase_to_tap(NULL, rate, 2)); 16 + KUNIT_EXPECT_EQ(test, 1, 17 + aspeed_sdhci_phase_to_tap(NULL, rate, 3)); 18 + KUNIT_EXPECT_EQ(test, 2, 19 + aspeed_sdhci_phase_to_tap(NULL, rate, 4)); 20 + KUNIT_EXPECT_EQ(test, 3, 21 + aspeed_sdhci_phase_to_tap(NULL, rate, 5)); 22 + KUNIT_EXPECT_EQ(test, 14, 23 + aspeed_sdhci_phase_to_tap(NULL, rate, 23)); 24 + KUNIT_EXPECT_EQ(test, 15, 25 + aspeed_sdhci_phase_to_tap(NULL, rate, 24)); 26 + KUNIT_EXPECT_EQ(test, 15, 27 + aspeed_sdhci_phase_to_tap(NULL, rate, 25)); 28 + 29 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0, 30 + aspeed_sdhci_phase_to_tap(NULL, rate, 180)); 31 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 0, 32 + aspeed_sdhci_phase_to_tap(NULL, rate, 181)); 33 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, 34 + aspeed_sdhci_phase_to_tap(NULL, rate, 182)); 35 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, 36 + aspeed_sdhci_phase_to_tap(NULL, rate, 183)); 37 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 2, 38 + aspeed_sdhci_phase_to_tap(NULL, rate, 184)); 39 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 3, 40 + aspeed_sdhci_phase_to_tap(NULL, rate, 185)); 41 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14, 42 + aspeed_sdhci_phase_to_tap(NULL, rate, 203)); 43 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, 44 + aspeed_sdhci_phase_to_tap(NULL, rate, 204)); 45 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, 46 + aspeed_sdhci_phase_to_tap(NULL, rate, 205)); 47 + } 48 + 49 + static void aspeed_sdhci_phase_hs200(struct kunit *test) 50 + { 51 + int rate = 200000000; 52 + 53 + KUNIT_EXPECT_EQ(test, 0, 54 + aspeed_sdhci_phase_to_tap(NULL, rate, 0)); 55 + KUNIT_EXPECT_EQ(test, 0, 56 + aspeed_sdhci_phase_to_tap(NULL, rate, 5)); 57 + KUNIT_EXPECT_EQ(test, 1, 58 + aspeed_sdhci_phase_to_tap(NULL, rate, 6)); 59 + KUNIT_EXPECT_EQ(test, 1, 60 + aspeed_sdhci_phase_to_tap(NULL, rate, 7)); 61 + KUNIT_EXPECT_EQ(test, 14, 62 + aspeed_sdhci_phase_to_tap(NULL, rate, 89)); 63 + KUNIT_EXPECT_EQ(test, 15, 64 + aspeed_sdhci_phase_to_tap(NULL, rate, 90)); 65 + KUNIT_EXPECT_EQ(test, 15, 66 + aspeed_sdhci_phase_to_tap(NULL, rate, 91)); 67 + KUNIT_EXPECT_EQ(test, 15, 68 + aspeed_sdhci_phase_to_tap(NULL, rate, 96)); 69 + 70 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK, 71 + aspeed_sdhci_phase_to_tap(NULL, rate, 180)); 72 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK, 73 + aspeed_sdhci_phase_to_tap(NULL, rate, 185)); 74 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, 75 + aspeed_sdhci_phase_to_tap(NULL, rate, 186)); 76 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 1, 77 + aspeed_sdhci_phase_to_tap(NULL, rate, 187)); 78 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 14, 79 + aspeed_sdhci_phase_to_tap(NULL, rate, 269)); 80 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, 81 + aspeed_sdhci_phase_to_tap(NULL, rate, 270)); 82 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, 83 + aspeed_sdhci_phase_to_tap(NULL, rate, 271)); 84 + KUNIT_EXPECT_EQ(test, (int)ASPEED_SDHCI_TAP_PARAM_INVERT_CLK | 15, 85 + aspeed_sdhci_phase_to_tap(NULL, rate, 276)); 86 + } 87 + 88 + static struct kunit_case aspeed_sdhci_test_cases[] = { 89 + KUNIT_CASE(aspeed_sdhci_phase_ddr52), 90 + KUNIT_CASE(aspeed_sdhci_phase_hs200), 91 + {} 92 + }; 93 + 94 + static struct kunit_suite aspeed_sdhci_test_suite = { 95 + .name = "sdhci-of-aspeed", 96 + .test_cases = aspeed_sdhci_test_cases, 97 + }; 98 + kunit_test_suite(aspeed_sdhci_test_suite);
+4
drivers/mmc/host/sdhci-of-aspeed.c
··· 579 579 } 580 580 module_exit(aspeed_sdc_exit); 581 581 582 + #if defined(CONFIG_MMC_SDHCI_OF_ASPEED_TEST) 583 + #include "sdhci-of-aspeed-test.c" 584 + #endif 585 + 582 586 MODULE_DESCRIPTION("Driver for the ASPEED SD/SDIO/SDHCI Controllers"); 583 587 MODULE_AUTHOR("Ryan Chen <ryan_chen@aspeedtech.com>"); 584 588 MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");