From: Simon Glass Date: Sat, 8 May 2021 12:59:59 +0000 (-0600) Subject: test: Add a test for print_buffer() X-Git-Tag: v2021.10~124^2~14^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c614ddf28b064d1de18b97edb6d0f5b91ce70376;p=platform%2Fkernel%2Fu-boot.git test: Add a test for print_buffer() 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 --- diff --git a/include/test/test.h b/include/test/test.h index bf7d785..0104e18 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 5fabdf8..b4dc902 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -8,11 +8,14 @@ #include #include #include +#include #include #include #include #include +#define BUF_SIZE 0x100 + #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \ "and a lot more text to come" @@ -145,6 +148,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);