Add a test for this function, to cover the various features. Expand the
expect_str length to take acount of the ~300-bytes lines generated in one
case.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 include/test/test.h |  4 +--
 test/print_ut.c     | 82 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/include/test/test.h b/include/test/test.h
index 0b124edd601..ac91cc13aef 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -32,8 +32,8 @@ struct unit_test_state {
        struct udevice *testdev;
        int force_fail_alloc;
        int skip_post_probe;
-       char expect_str[256];
-       char actual_str[256];
+       char expect_str[512];
+       char actual_str[512];
 };
 
 /* Test flags for each test */
diff --git a/test/print_ut.c b/test/print_ut.c
index bb690f2b327..4c814a306ea 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -10,11 +10,14 @@
 #endif
 #include <display_options.h>
 #include <log.h>
+#include <mapmem.h>
 #include <version.h>
 #include <test/suites.h>
 #include <test/test.h>
 #include <test/ut.h>
 
+#define BUF_SIZE       0x100
+
 #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
                        "and a lot more text to come"
 
@@ -147,6 +150,85 @@ static int print_printf(struct unit_test_state *uts)
 }
 PRINT_TEST(print_printf, 0);
 
+static int print_display_buffer(struct unit_test_state *uts)
+{
+       u8 *buf;
+       int i;
+
+       buf = map_sysmem(0, BUF_SIZE);
+       memset(buf, '\0', BUF_SIZE);
+       for (i = 0; i < 0x11; i++)
+               buf[i] = i * 0x11;
+
+       /* bytes */
+       console_record_reset();
+       print_buffer(0, buf, 1, 0x12, 0);
+       ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff    ..\"3DUfw........");
+       ut_assert_nextline("00000010: 10 00                                     
         ..");
+       ut_assert_console_end();
+
+       /* line length */
+       console_record_reset();
+       print_buffer(0, buf, 1, 0x12, 8);
+       ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77    ..\"3DUfw");
+       ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff    ........");
+       ut_assert_nextline("00000010: 10 00                      ..");
+       ut_assert_console_end();
+
+       /* long line */
+       console_record_reset();
+       buf[0x41] = 0x41;
+       print_buffer(0, buf, 1, 0x42, 0x40);
+       ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    
..\"3DUfw........................................................");
+       ut_assert_nextline("00000040: 00 41                                     
                                                                                
                                                                         .A");
+       ut_assert_console_end();
+
+       /* address */
+       console_record_reset();
+       print_buffer(0x12345678, buf, 1, 0x12, 0);
+       ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff    ..\"3DUfw........");
+       ut_assert_nextline("12345688: 10 00                                     
         ..");
+       ut_assert_console_end();
+
+       /* 16-bit */
+       console_record_reset();
+       print_buffer(0, buf, 2, 9, 0);
+       ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee   
 ..\"3DUfw........");
+       ut_assert_nextline("00000010: 0010                                      
 ..");
+       ut_assert_console_end();
+
+       /* 32-bit */
+       console_record_reset();
+       print_buffer(0, buf, 4, 5, 0);
+       ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc    
..\"3DUfw........");
+       ut_assert_nextline("00000010: 00000010                               
....");
+       ut_assert_console_end();
+
+       /* 64-bit */
+       console_record_reset();
+       print_buffer(0, buf, 8, 3, 0);
+       ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988    
..\"3DUfw........");
+       ut_assert_nextline("00000010: 0000000000000010                     
........");
+       ut_assert_console_end();
+
+       /* ASCII */
+       console_record_reset();
+       buf[1] = 31;
+       buf[2] = 32;
+       buf[3] = 33;
+       for (i = 0; i < 4; i++)
+               buf[4 + i] = 126 + i;
+       buf[8] = 255;
+       print_buffer(0, buf, 1, 10, 0);
+       ut_assert_nextline("00000000: 00 1f 20 21 7e 7f 80 81 ff 99             
         .. !~.....");
+       ut_assert_console_end();
+
+       unmap_sysmem(buf);
+
+       return 0;
+}
+PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC);
+
 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.31.0.rc2.261.g7f71774620-goog

Reply via email to