Re: [PATCH v3 13/18] lib: Add tests for simple_itoa()

2021-11-12 Thread Tom Rini
On Thu, Oct 14, 2021 at 12:48:06PM -0600, Simon Glass wrote:

> Add test and a comment for this function.
> 
> Signed-off-by: Simon Glass 
> Reviewed-by: Artem Lapkin 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 13/18] lib: Add tests for simple_itoa()

2021-10-18 Thread art

Reviewed-by: Artem Lapkin 



[PATCH v3 13/18] lib: Add tests for simple_itoa()

2021-10-14 Thread Simon Glass
Add test and a comment for this function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/vsprintf.h | 13 -
 test/print_ut.c| 17 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index 83d187e53d4..4479df0af3f 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...)
  * See the vsprintf() documentation for format string extensions over C99.
  */
 int vsprintf(char *buf, const char *fmt, va_list args);
-char *simple_itoa(ulong i);
+
+/**
+ * simple_itoa() - convert an unsigned integer to a string
+ *
+ * This returns a static string containing the decimal representation of the
+ * given value. The returned value may be overwritten by other calls to the
+ * same function, so should be used immediately
+ *
+ * @val: Value to convert
+ * @return string containing the decimal representation of @val
+ */
+char *simple_itoa(ulong val);
 
 /**
  * Format a string and place it in a buffer
diff --git a/test/print_ut.c b/test/print_ut.c
index 11d8580e55c..4fbb15b6d3c 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -328,6 +329,22 @@ static int print_do_hex_dump(struct unit_test_state *uts)
 }
 PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC);
 
+static int print_itoa(struct unit_test_state *uts)
+{
+   ut_asserteq_str("123", simple_itoa(123));
+   ut_asserteq_str("0", simple_itoa(0));
+   ut_asserteq_str("2147483647", simple_itoa(0x7fff));
+   ut_asserteq_str("4294967295", simple_itoa(0x));
+   if (sizeof(ulong) == 8) {
+   ut_asserteq_str("9223372036854775807",
+   simple_itoa((1UL << 63) - 1));
+   ut_asserteq_str("18446744073709551615", simple_itoa(-1));
+   }
+
+   return 0;
+}
+PRINT_TEST(print_itoa, 0);
+
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
-- 
2.33.0.1079.g6e70778dc9-goog