[PATCH v2 05/12] test: Use ut_asserteq_str() instead of ut_assertok(strcmp())

Marek Behún kabel at kernel.org
Thu Nov 4 00:23:25 CET 2021


From: Marek Behún <marek.behun at nic.cz>

Use the ut_asserteq_str() assertion instead of strcmp() function and
ut_assertok()ing it's result.

Signed-off-by: Marek Behún <marek.behun at nic.cz>
---
 test/dm/cpu.c     |  4 ++--
 test/dm/soc.c     |  4 ++--
 test/dm/sysinfo.c |  6 +++---
 test/dm/usb.c     |  2 +-
 test/dm/virtio.c  |  2 +-
 test/print_ut.c   | 32 ++++++++++++++++----------------
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/test/dm/cpu.c b/test/dm/cpu.c
index d7e596ee39..0cda364131 100644
--- a/test/dm/cpu.c
+++ b/test/dm/cpu.c
@@ -32,7 +32,7 @@ static int dm_test_cpu(struct unit_test_state *uts)
 	ut_asserteq(cpu_is_current(dev), 1);
 
 	ut_assertok(cpu_get_desc(dev, text, sizeof(text)));
-	ut_assertok(strcmp(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"));
+	ut_asserteq_str(text, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
 
 	ut_assertok(cpu_get_info(dev, &info));
 	ut_asserteq(info.cpu_freq, 42 * 42 * 42 * 42 * 42);
@@ -42,7 +42,7 @@ static int dm_test_cpu(struct unit_test_state *uts)
 	ut_asserteq(cpu_get_count(dev), 42);
 
 	ut_assertok(cpu_get_vendor(dev, text, sizeof(text)));
-	ut_assertok(strcmp(text, "Languid Example Garbage Inc."));
+	ut_asserteq_str(text, "Languid Example Garbage Inc.");
 
 	return 0;
 }
diff --git a/test/dm/soc.c b/test/dm/soc.c
index 17e1b5ba01..6e14c98391 100644
--- a/test/dm/soc.c
+++ b/test/dm/soc.c
@@ -91,10 +91,10 @@ static int dm_test_soc(struct unit_test_state *uts)
 	ut_assertok(soc_get(&dev));
 
 	ut_assertok(soc_get_machine(dev, text, sizeof(text)));
-	ut_assertok(strcmp(text, "SANDBOX123"));
+	ut_asserteq_str(text, "SANDBOX123");
 
 	ut_assertok(soc_get_family(dev, text, sizeof(text)));
-	ut_assertok(strcmp(text, "SANDBOX1xx"));
+	ut_asserteq_str(text, "SANDBOX1xx");
 
 	ut_assertok(soc_get_revision(dev, text, sizeof(text)));
 	ut_asserteq_str(text, "1.0");
diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c
index 488412ab14..2c1bd1ce40 100644
--- a/test/dm/sysinfo.c
+++ b/test/dm/sysinfo.c
@@ -36,7 +36,7 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 
 	ut_asserteq(6, sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
 				       str));
-	ut_assertok(strcmp(str, "R'lyeh"));
+	ut_asserteq_str(str, "R'lyeh");
 
 	ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
 	ut_asserteq(0, i);
@@ -46,7 +46,7 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 
 	ut_asserteq(7, sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
 				       str));
-	ut_assertok(strcmp(str, "Carcosa"));
+	ut_asserteq_str(str, "Carcosa");
 
 	ut_assertok(sysinfo_get_int(sysinfo, INT_TEST1, &i));
 	ut_asserteq(1, i);
@@ -56,7 +56,7 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
 
 	ut_asserteq(7, sysinfo_get_str(sysinfo, STR_VACATIONSPOT, sizeof(str),
 				       str));
-	ut_assertok(strcmp(str, "Yuggoth"));
+	ut_asserteq_str(str, "Yuggoth");
 
 	return 0;
 }
diff --git a/test/dm/usb.c b/test/dm/usb.c
index 5d6ceefce0..055134a485 100644
--- a/test/dm/usb.c
+++ b/test/dm/usb.c
@@ -56,7 +56,7 @@ static int dm_test_usb_flash(struct unit_test_state *uts)
 	ut_asserteq(512, dev_desc->blksz);
 	memset(cmp, '\0', sizeof(cmp));
 	ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp));
-	ut_assertok(strcmp(cmp, "this is a test"));
+	ut_asserteq_str(cmp, "this is a test");
 	ut_assertok(usb_stop());
 
 	return 0;
diff --git a/test/dm/virtio.c b/test/dm/virtio.c
index 9a7e658cce..7154449f60 100644
--- a/test/dm/virtio.c
+++ b/test/dm/virtio.c
@@ -28,7 +28,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts)
 	/* check the child virtio-blk device is bound */
 	ut_assertok(device_find_first_child(bus, &dev));
 	ut_assertnonnull(dev);
-	ut_assertok(strcmp(dev->name, "virtio-blk#0"));
+	ut_asserteq_str(dev->name, "virtio-blk#0");
 
 	/* check driver status */
 	ut_assertok(virtio_get_status(dev, &status));
diff --git a/test/print_ut.c b/test/print_ut.c
index 11d8580e55..70670a3a14 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -32,13 +32,13 @@ static int print_guid(struct unit_test_state *uts)
 	char str[40];
 
 	sprintf(str, "%pUb", guid);
-	ut_assertok(strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str));
+	ut_asserteq_str("01020304-0506-0708-090a-0b0c0d0e0f10", str);
 	sprintf(str, "%pUB", guid);
-	ut_assertok(strcmp("01020304-0506-0708-090A-0B0C0D0E0F10", str));
+	ut_asserteq_str("01020304-0506-0708-090A-0B0C0D0E0F10", str);
 	sprintf(str, "%pUl", guid);
-	ut_assertok(strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str));
+	ut_asserteq_str("04030201-0605-0807-090a-0b0c0d0e0f10", str);
 	sprintf(str, "%pUL", guid);
-	ut_assertok(strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str));
+	ut_asserteq_str("04030201-0605-0807-090A-0B0C0D0E0F10", str);
 
 	return 0;
 }
@@ -70,11 +70,11 @@ static int print_efi_ut(struct unit_test_state *uts)
 	dp_end->length = sizeof(struct efi_device_path);
 
 	snprintf(str, sizeof(str), "_%pD_", buf);
-	ut_assertok(strcmp("_/SD(3)_", str));
+	ut_asserteq_str("_/SD(3)_", str);
 
 	/* NULL device path */
 	snprintf(str, sizeof(str), "_%pD_", NULL);
-	ut_assertok(strcmp("_<NULL>_", str));
+	ut_asserteq_str("_<NULL>_", str);
 
 	return 0;
 }
@@ -89,41 +89,41 @@ static int print_printf(struct unit_test_state *uts)
 	int len;
 
 	snprintf(str, sizeof(str), "testing");
-	ut_assertok(strcmp("testing", str));
+	ut_asserteq_str("testing", str);
 
 	snprintf(str, sizeof(str), "testing but too long");
-	ut_assertok(strcmp("testing b", str));
+	ut_asserteq_str("testing b", str);
 
 	snprintf(str, 1, "testing none");
-	ut_assertok(strcmp("", str));
+	ut_asserteq_str("", str);
 
 	*str = 'x';
 	snprintf(str, 0, "testing none");
 	ut_asserteq('x', *str);
 
 	sprintf(big_str, "_%ls_", L"foo");
-	ut_assertok(strcmp("_foo_", big_str));
+	ut_asserteq_str("_foo_", big_str);
 
 	/* Test the banner function */
 	s = display_options_get_banner(true, str, sizeof(str));
 	ut_asserteq_ptr(str, s);
-	ut_assertok(strcmp("\n\nU-Boo\n\n", s));
+	ut_asserteq_str("\n\nU-Boo\n\n", s);
 
 	/* Assert that we do not overwrite memory before the buffer */
 	str[0] = '`';
 	s = display_options_get_banner(true, str + 1, 1);
 	ut_asserteq_ptr(str + 1, s);
-	ut_assertok(strcmp("`", str));
+	ut_asserteq_str("`", str);
 
 	str[0] = '~';
 	s = display_options_get_banner(true, str + 1, 2);
 	ut_asserteq_ptr(str + 1, s);
-	ut_assertok(strcmp("~\n", str));
+	ut_asserteq_str("~\n", str);
 
 	/* The last two characters are set to \n\n for all buffer sizes > 2 */
 	s = display_options_get_banner(false, str, sizeof(str));
 	ut_asserteq_ptr(str, s);
-	ut_assertok(strcmp("U-Boot \n\n", s));
+	ut_asserteq_str("U-Boot \n\n", s);
 
 	/* Give it enough space for some of the version */
 	big_str_len = strlen(version_string) - 5;
@@ -131,7 +131,7 @@ static int print_printf(struct unit_test_state *uts)
 					    big_str_len);
 	ut_asserteq_ptr(big_str, s);
 	ut_assertok(strncmp(version_string, s, big_str_len - 3));
-	ut_assertok(strcmp("\n\n", s + big_str_len - 3));
+	ut_asserteq_str("\n\n", s + big_str_len - 3);
 
 	/* Give it enough space for the version and some of the build tag */
 	big_str_len = strlen(version_string) + 9 + 20;
@@ -142,7 +142,7 @@ static int print_printf(struct unit_test_state *uts)
 	ut_assertok(strncmp(version_string, s, len));
 	ut_assertok(strncmp(", Build: ", s + len, 9));
 	ut_assertok(strncmp(FAKE_BUILD_TAG, s + 9 + len, 12));
-	ut_assertok(strcmp("\n\n", s + big_str_len - 3));
+	ut_asserteq_str("\n\n", s + big_str_len - 3);
 
 	return 0;
 }
-- 
2.32.0



More information about the U-Boot mailing list