Chrome platform driver development
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests
@ 2026-12-01 16:20 Masaharu Noguchi
  2026-12-02  3:43 ` Tzung-Bi Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Masaharu Noguchi @ 2026-12-01 16:20 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Guenter Roeck
  Cc: chrome-platform, Masaharu Noguchi

Replace KUNIT_EXPECT_EQ(test, memcmp(...), 0) with KUNIT_EXPECT_MEMEQ()
in cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes() and
cros_ec_proto_test_cmd_xfer_in_progress_payload_gt4bytes().

KUNIT_EXPECT_MEMEQ() is more readable and prints a hex dump of the
mismatched buffers on failure instead of just comparing the memcmp()
return value against 0.

Tested under ARCH=um with:
  ./tools/testing/kunit/kunit.py run \
    --kconfig_add CONFIG_COMPILE_TEST=y \
    --kconfig_add CONFIG_CHROME_PLATFORMS=y \
    --kconfig_add CONFIG_CROS_EC=y \
    --kconfig_add CONFIG_CROS_KUNIT_EC_PROTO_TEST=y \
    'cros_ec_proto_test'
All 56 subtests in cros_ec_proto_test pass.

Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
---
Note: An LLM (Gemini) was used to help locate this cleanup opportunity and
    draft the commit message; all changes were reviewed and verified by the
    submitter.
---
 drivers/platform/chrome/cros_ec_proto_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index cbaaf98d6877..ae2a7debd93e 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -1850,7 +1850,7 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes(struct kunit
 	KUNIT_EXPECT_EQ(test, msg->command, 0x1234);
 	KUNIT_EXPECT_EQ(test, msg->insize, sizeof(buf.data));
 	KUNIT_EXPECT_EQ(test, msg->version, 1);
-	KUNIT_EXPECT_EQ(test, memcmp(msg->data, resp_data, sizeof(resp_data)), 0);
+	KUNIT_EXPECT_MEMEQ(test, msg->data, resp_data, sizeof(resp_data));
 
 	/* Verify mock sequence */
 	{
@@ -1927,7 +1927,7 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_payload_gt4bytes(struct kuni
 	KUNIT_EXPECT_EQ(test, msg->outsize, 0);
 	KUNIT_EXPECT_EQ(test, msg->insize, sizeof(buf.data));
 	KUNIT_EXPECT_EQ(test, msg->version, 0);
-	KUNIT_EXPECT_EQ(test, memcmp(msg->data, resp_data, sizeof(resp_data)), 0);
+	KUNIT_EXPECT_MEMEQ(test, msg->data, resp_data, sizeof(resp_data));
 
 	/* Verify mock sequence */
 	{

---
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
change-id: 20261202-cros-ec-memeq-4a0b837cbe01

Best regards,
-- 
Masaharu Noguchi <nogunix@gmail.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests
  2026-12-01 16:20 [PATCH] platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests Masaharu Noguchi
@ 2026-12-02  3:43 ` Tzung-Bi Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Tzung-Bi Shih @ 2026-12-02  3:43 UTC (permalink / raw)
  To: Masaharu Noguchi; +Cc: Benson Leung, Guenter Roeck, chrome-platform

On Wed, Dec 02, 2026 at 01:20:22AM +0900, Masaharu Noguchi wrote:
> Replace KUNIT_EXPECT_EQ(test, memcmp(...), 0) with KUNIT_EXPECT_MEMEQ()
> in cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes() and
> cros_ec_proto_test_cmd_xfer_in_progress_payload_gt4bytes().
> 
> KUNIT_EXPECT_MEMEQ() is more readable and prints a hex dump of the
> mismatched buffers on failure instead of just comparing the memcmp()
> return value against 0.
> 
> [...]

Applied to

    https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[1/1] platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests
      commit: 7f6a0febc88dc88c5cd3f9d27b398eaff6043b91

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  3:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:20 [PATCH] platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests Masaharu Noguchi
2026-12-02  3:43 ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox