From 0cceb99ac59b1d383488ea3ce6511ffc01da5332 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 8 May 2021 07:00:05 -0600 Subject: display_options: Split print_buffer() into two functions At present print_buffer() outputs a hex dump but it is not possible to place this dump in a string. Refactor it into a top-level function which does the printing and a utility function that dumps a line into a string. This makes the code more generally useful. Signed-off-by: Simon Glass --- test/print_ut.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/print_ut.c') diff --git a/test/print_ut.c b/test/print_ut.c index 86b1a5477e..e2bcfbef00 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -227,6 +227,32 @@ static int print_display_buffer(struct unit_test_state *uts) } PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC); +static int print_hexdump_line(struct unit_test_state *uts) +{ + char *linebuf; + 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; + + /* Check buffer size calculations */ + linebuf = map_sysmem(0x400, BUF_SIZE); + memset(linebuf, '\xff', BUF_SIZE); + ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75)); + ut_asserteq(-1, linebuf[0]); + ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76)); + ut_asserteq(0, linebuf[75]); + ut_asserteq(-1, linebuf[76]); + + unmap_sysmem(buf); + + return 0; +} +PRINT_TEST(print_hexdump_line, UT_TESTF_CONSOLE_REC); + static int print_do_hex_dump(struct unit_test_state *uts) { u8 *buf; -- cgit v1.2.3