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 3/7] platform/chrome: kunit: cros_ec_i2c: Use static stub instead
Date: Tue, 20 May 2025 08:24:30 +0000 [thread overview]
Message-ID: <20250520082435.2255639-4-tzungbi@kernel.org> (raw)
In-Reply-To: <20250520082435.2255639-1-tzungbi@kernel.org>
For running the tests:
$ ./tools/testing/kunit/kunit.py run \
--arch=x86_64 \
--kconfig_add CONFIG_CHROME_PLATFORMS=y \
--kconfig_add CONFIG_CROS_EC=y \
--kconfig_add CONFIG_I2C=y \
--kconfig_add CONFIG_CROS_EC_I2C=y \
--kconfig_add CONFIG_CROS_KUNIT_EC_I2C_TEST=y \
cros_ec_i2c*
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/Kconfig | 1 -
drivers/platform/chrome/cros_ec.c | 6 ++++++
drivers/platform/chrome/cros_ec_i2c_test.c | 10 +++++-----
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index 5e0b44fb7ca7..bf10c0625be8 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -331,7 +331,6 @@ config CROS_KUNIT_EC_I2C_TEST
tristate "Kunit tests for ChromeOS EC over I2C" if !KUNIT_ALL_TESTS
depends on KUNIT && CROS_EC
default KUNIT_ALL_TESTS
- depends on KUNIT_FTRACE_STUBS
depends on CROS_EC_I2C
help
Kunit tests for ChromeOS EC over I2C.
diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index 110771a8645e..62327fa0ff34 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -18,6 +18,8 @@
#include <linux/slab.h>
#include <linux/suspend.h>
+#include <kunit/static_stub.h>
+
#include "cros_ec.h"
static struct cros_ec_platform ec_p = {
@@ -179,6 +181,8 @@ static int cros_ec_ready_event(struct notifier_block *nb,
*/
int cros_ec_register(struct cros_ec_device *ec_dev)
{
+ KUNIT_STATIC_STUB_REDIRECT(cros_ec_register, ec_dev);
+
struct device *dev = ec_dev->dev;
int err = 0;
@@ -318,6 +322,8 @@ EXPORT_SYMBOL(cros_ec_register);
*/
void cros_ec_unregister(struct cros_ec_device *ec_dev)
{
+ KUNIT_STATIC_STUB_REDIRECT(cros_ec_unregister, ec_dev);
+
platform_device_unregister(ec_dev->pd);
platform_device_unregister(ec_dev->ec);
mutex_destroy(&ec_dev->lock);
diff --git a/drivers/platform/chrome/cros_ec_i2c_test.c b/drivers/platform/chrome/cros_ec_i2c_test.c
index 3a7f1a17d82d..5d41cdeec4b7 100644
--- a/drivers/platform/chrome/cros_ec_i2c_test.c
+++ b/drivers/platform/chrome/cros_ec_i2c_test.c
@@ -3,7 +3,7 @@
* Kunit tests for ChromeOS Embedded Controller I2C interface.
*/
#include <kunit/test.h>
-#include <kunit/ftrace_stub.h>
+#include <kunit/static_stub.h>
#include <linux/i2c.h>
#include <linux/platform_data/cros_ec_proto.h>
@@ -106,8 +106,8 @@ static int cros_ec_i2c_test_init(struct kunit *test)
I2C_BOARD_INFO("cros-ec-i2c", I2C_ADDR),
};
- kunit_activate_ftrace_stub(test, cros_ec_register, fake_cros_ec_register);
- kunit_activate_ftrace_stub(test, cros_ec_unregister, fake_cros_ec_unregister);
+ kunit_activate_static_stub(test, cros_ec_register, fake_cros_ec_register);
+ kunit_activate_static_stub(test, cros_ec_unregister, fake_cros_ec_unregister);
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, priv);
@@ -142,8 +142,8 @@ static void cros_ec_i2c_test_exit(struct kunit *test)
i2c_del_adapter(priv->fake_adap);
- kunit_deactivate_ftrace_stub(test, cros_ec_register);
- kunit_deactivate_ftrace_stub(test, cros_ec_unregister);
+ kunit_deactivate_static_stub(test, cros_ec_register);
+ kunit_deactivate_static_stub(test, cros_ec_unregister);
}
static int cros_ec_i2c_test_cmd_xfer_init(struct kunit *test)
--
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 ` Tzung-Bi Shih [this message]
2025-05-20 8:24 ` [RFC PATCH 4/7] platform/chrome: kunit: cros_ec_spi: " Tzung-Bi Shih
2025-05-20 8:24 ` [RFC PATCH 5/7] platform/chrome: kunit: cros_ec_spi: Call .probe() directly Tzung-Bi Shih
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-4-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