platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests
Subsystems (2)
PATCH 1/1 platform/chrome: cros_ec_proto: use KUNIT_EXPECT_MEMEQ() in KUnit tests
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.
---
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(-)
drivers/platform/chrome/cros_ec_proto_test.c +2 -2
@@ -1850,7 +1850,7 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_payload_4bytes(struct kunitKUNIT_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 kuniKUNIT_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,
Signature · 1 line
Masaharu Noguchi <[email protected]>