Skip to contentSkip to conversation

HID: uclogic: Use KUNIT_EXPECT_MEMEQ

PATCH Applied José Expósito 3 participants 3 messages Dec 26, 2022 – Jan 18, 2023 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: uclogic: Use KUNIT_EXPECT_MEMEQ

Commit b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros") introduced a new macro to compare blocks of memory and, if the test fails, print the result in a human friendly format. For example, this is the output of a test failure:

Expected res == params->expected, but

     res ==
      01  02  aa  00  00  00  03  bb  00 <00> 00  04  05
     params->expected ==
      01  02  aa  00  00  00  03  bb  00 <01> 00  04  05

Use this new macro to replace KUNIT_EXPECT_EQ + memcmp.

---
 drivers/hid/hid-uclogic-rdesc-test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-uclogic-rdesc-test.c +1 -2
index b429c541bf2f..90bf4e586e01 100644
@@ -197,8 +197,7 @@ static void hid_test_uclogic_template(struct kunit *test)
 					   params->param_list,
 					   params->param_num);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
-	KUNIT_EXPECT_EQ(test, 0,
-			memcmp(res, params->expected, params->template_size));
+	KUNIT_EXPECT_MEMEQ(test, res, params->expected, params->template_size);
 	kfree(res);
 }
 
Signature · 1 line
2.38.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · José Expósito

Commit b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros") introduced a new macro to compare blocks of memory and, if the test fails, print the result in a human friendly format. For example, this is the output of a test failure:

Expected res == params->expected, but

Quoted 8 lines
      res ==
       01  02  aa  00  00  00  03  bb  00 <00> 00  04  05
      params->expected ==
       01  02  aa  00  00  00  03  bb  00 <01> 00  04  05

Use this new macro to replace KUNIT_EXPECT_EQ + memcmp.

Best Regards,
- Maíra Canal

Quoted 18 lines
---
  drivers/hid/hid-uclogic-rdesc-test.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-uclogic-rdesc-test.c +1 -2
index b429c541bf2f..90bf4e586e01 100644
@@ -197,8 +197,7 @@ static void hid_test_uclogic_template(struct kunit *test)
  					   params->param_list,
  					   params->param_num);
  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
-	KUNIT_EXPECT_EQ(test, 0,
-			memcmp(res, params->expected, params->template_size));
+	KUNIT_EXPECT_MEMEQ(test, res, params->expected, params->template_size);
  	kfree(res);
  }
 
maintainer Applied
#2 lore raw
In reply to José Expósito
Quoted 23 lines · José Expósito

Commit b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros") introduced a new macro to compare blocks of memory and, if the test fails, print the result in a human friendly format. For example, this is the output of a test failure:

Expected res == params->expected, but

     res ==
      01  02  aa  00  00  00  03  bb  00 <00> 00  04  05
     params->expected ==
      01  02  aa  00  00  00  03  bb  00 <01> 00  04  05

Use this new macro to replace KUNIT_EXPECT_EQ + memcmp.

---
 drivers/hid/hid-uclogic-rdesc-test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-uclogic-rdesc-test.c +0 -0
index b429c541bf2f..90bf4e586e01 100644

drivers/hid/hid-uclogic-rdesc-test.c static void hid_test_uclogic_template(struct kunit *test) · line 201

Quoted 7 lines
drivers/hid/hid-uclogic-rdesc-test.c +1 -2
@@ -197,8 +197,7 @@ static void hid_test_uclogic_template(struct kunit *test)
 					   params->param_list,
 					   params->param_num);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
-	KUNIT_EXPECT_EQ(test, 0,
-			memcmp(res, params->expected, params->template_size));
+	KUNIT_EXPECT_MEMEQ(test, res, params->expected, params->template_size);
 	kfree(res);

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs