From: Tzung-Bi Shih <tzungbi@kernel.org>
To: bleung@chromium.org, brendan.higgins@linux.dev, davidgow@google.com
Cc: tzungbi@kernel.org, rmoar@google.com, rostedt@goodmis.org,
mhiramat@kernel.org, naveen@kernel.org,
anil.s.keshavamurthy@intel.com, davem@davemloft.net,
chrome-platform@lists.linux.dev, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 5/7] platform/chrome: kunit: cros_ec_spi: Call .probe() directly
Date: Tue, 20 May 2025 08:24:32 +0000 [thread overview]
Message-ID: <20250520082435.2255639-6-tzungbi@kernel.org> (raw)
In-Reply-To: <20250520082435.2255639-1-tzungbi@kernel.org>
Get the spi_driver and call .probe() directly.
For running the tests:
$ ./tools/testing/kunit/kunit.py run \
--arch=x86_64 \
--kconfig_add CONFIG_FTRACE=y \
--kconfig_add CONFIG_FUNCTION_TRACER=y \
--kconfig_add CONFIG_MODULES=y \
--kconfig_add CONFIG_DEBUG_KERNEL=y \
--kconfig_add CONFIG_KALLSYMS_ALL=y \
--kconfig_add CONFIG_LIVEPATCH=y \
--kconfig_add CONFIG_KUNIT_FTRACE_STUBS=y \
--kconfig_add CONFIG_CHROME_PLATFORMS=y \
--kconfig_add CONFIG_CROS_EC=y \
--kconfig_add CONFIG_SPI=y \
--kconfig_add CONFIG_CROS_EC_SPI=y \
--kconfig_add CONFIG_CROS_KUNIT_EC_SPI_TEST=y \
cros_ec_spi*
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_spi_test.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_spi_test.c b/drivers/platform/chrome/cros_ec_spi_test.c
index 2a021569a726..52dea75ecabf 100644
--- a/drivers/platform/chrome/cros_ec_spi_test.c
+++ b/drivers/platform/chrome/cros_ec_spi_test.c
@@ -27,6 +27,7 @@ struct cros_ec_spi_test_priv {
struct device dev;
struct spi_controller *fake_ctlr;
struct spi_device *fake_spi_device;
+ struct spi_driver *spi_drv;
int fake_cros_ec_register_called;
struct cros_ec_device *ec_dev;
@@ -117,16 +118,12 @@ static int find_target_driver(struct device_driver *drv, void *data)
static int cros_ec_spi_test_init(struct kunit *test)
{
struct cros_ec_spi_test_priv *priv;
- struct spi_board_info board_info = {};
int ret;
struct device_driver *drv;
- enum probe_type orig;
kunit_activate_ftrace_stub(test, cros_ec_register, fake_cros_ec_register);
kunit_activate_ftrace_stub(test, cros_ec_unregister, fake_cros_ec_unregister);
- sized_strscpy(board_info.modalias, "cros-ec-spi", SPI_NAME_SIZE);
-
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, priv);
test->priv = priv;
@@ -151,21 +148,17 @@ static int cros_ec_spi_test_init(struct kunit *test)
ret = spi_register_controller(priv->fake_ctlr);
KUNIT_ASSERT_EQ(test, ret, 0);
- /*
- * Force to use synchronous probe so that the upcoming SPI device gets
- * probed correctly and synchronously.
- */
ret = bus_for_each_drv(&spi_bus_type, NULL, &drv, find_target_driver);
KUNIT_ASSERT_EQ(test, ret, 0);
KUNIT_ASSERT_NOT_NULL(test, drv);
- orig = drv->probe_type;
- drv->probe_type = PROBE_FORCE_SYNCHRONOUS;
- priv->fake_spi_device = spi_new_device(priv->fake_ctlr, &board_info);
- /* Restore to original probe type. */
- drv->probe_type = orig;
+ priv->fake_spi_device = spi_alloc_device(priv->fake_ctlr);
KUNIT_ASSERT_NOT_NULL(test, priv->fake_spi_device);
+ priv->spi_drv = container_of(drv, struct spi_driver, driver);
+ ret = priv->spi_drv->probe(priv->fake_spi_device);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_register_called, 1);
KUNIT_ASSERT_NOT_NULL(test, priv->ec_dev);
KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_unregister_called, 0);
@@ -180,9 +173,10 @@ static void cros_ec_spi_test_exit(struct kunit *test)
{
struct cros_ec_spi_test_priv *priv = test->priv;
- spi_unregister_device(priv->fake_spi_device);
+ priv->spi_drv->remove(priv->fake_spi_device);
KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_unregister_called, 1);
+ spi_dev_put(priv->fake_spi_device);
spi_unregister_controller(priv->fake_ctlr);
device_del(&priv->dev);
class_destroy(priv->fake_class);
--
2.49.0.1101.gccaa498523-goog
next prev parent reply other threads:[~2025-05-20 8:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 8:24 [RFC PATCH 0/7] platform/chrome: Add Kunit tests for protocol device drivers Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 1/7] kunit: expose ftrace-based API for stubbing out functions during tests Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 2/7] platform/chrome: kunit: cros_ec_i2c: Add tests with ftrace stub Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 3/7] platform/chrome: kunit: cros_ec_i2c: Use static stub instead Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 4/7] platform/chrome: kunit: cros_ec_spi: Add tests with ftrace stub Tzung-Bi Shih
2025-05-20 8:24 ` Tzung-Bi Shih [this message]
2025-05-20 8:24 ` [RFC PATCH 6/7] kunit: Expose 'kprobes stub' API to redirect functions Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 7/7] platform/chrome: kunit: cros_ec_spi: Use kprobes stub instead Tzung-Bi Shih
2025-05-20 16:04 ` [RFC PATCH 0/7] platform/chrome: Add Kunit tests for protocol device drivers Daniel Latypov
2025-06-30 6:32 ` Tzung-Bi Shih
2025-07-01 5:22 ` Daniel Latypov
2025-07-01 12:20 ` Tzung-Bi Shih
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=20250520082435.2255639-6-tzungbi@kernel.org \
--to=tzungbi@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=bleung@chromium.org \
--cc=brendan.higgins@linux.dev \
--cc=chrome-platform@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen@kernel.org \
--cc=rmoar@google.com \
--cc=rostedt@goodmis.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