Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012, The Chromium Authors |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 8 | #include <efi_api.h> |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 9 | #include <display_options.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 11 | #include <mapmem.h> |
Pali Rohár | ba87ddf | 2021-08-02 15:18:31 +0200 | [diff] [blame] | 12 | #include <version_string.h> |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 13 | #include <test/suites.h> |
| 14 | #include <test/test.h> |
| 15 | #include <test/ut.h> |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 16 | |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 17 | #define BUF_SIZE 0x100 |
| 18 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 19 | #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \ |
| 20 | "and a lot more text to come" |
| 21 | |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 22 | /* Declare a new print test */ |
| 23 | #define PRINT_TEST(_name, _flags) UNIT_TEST(_name, _flags, print_test) |
| 24 | |
| 25 | #if CONFIG_IS_ENABLED(LIB_UUID) |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 26 | /* Test printing GUIDs */ |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 27 | static int print_guid(struct unit_test_state *uts) |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 28 | { |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 29 | unsigned char guid[16] = { |
| 30 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 |
| 31 | }; |
| 32 | char str[40]; |
| 33 | |
| 34 | sprintf(str, "%pUb", guid); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 35 | ut_assertok(strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str)); |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 36 | sprintf(str, "%pUB", guid); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 37 | ut_assertok(strcmp("01020304-0506-0708-090A-0B0C0D0E0F10", str)); |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 38 | sprintf(str, "%pUl", guid); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 39 | ut_assertok(strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str)); |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 40 | sprintf(str, "%pUL", guid); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 41 | ut_assertok(strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str)); |
| 42 | |
| 43 | return 0; |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 44 | } |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 45 | PRINT_TEST(print_guid, 0); |
| 46 | #endif |
Heinrich Schuchardt | 6f03566 | 2019-04-29 08:08:43 +0200 | [diff] [blame] | 47 | |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 48 | #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD) |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 49 | /* Test efi_loader specific printing */ |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 50 | static int print_efi_ut(struct unit_test_state *uts) |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 51 | { |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 52 | char str[10]; |
| 53 | u8 buf[sizeof(struct efi_device_path_sd_mmc_path) + |
| 54 | sizeof(struct efi_device_path)]; |
| 55 | u8 *pos = buf; |
| 56 | struct efi_device_path *dp_end; |
| 57 | struct efi_device_path_sd_mmc_path *dp_sd = |
| 58 | (struct efi_device_path_sd_mmc_path *)pos; |
| 59 | |
| 60 | /* Create a device path for an SD card */ |
| 61 | dp_sd->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; |
| 62 | dp_sd->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SD; |
| 63 | dp_sd->dp.length = sizeof(struct efi_device_path_sd_mmc_path); |
| 64 | dp_sd->slot_number = 3; |
| 65 | pos += sizeof(struct efi_device_path_sd_mmc_path); |
| 66 | /* Append end node */ |
| 67 | dp_end = (struct efi_device_path *)pos; |
| 68 | dp_end->type = DEVICE_PATH_TYPE_END; |
| 69 | dp_end->sub_type = DEVICE_PATH_SUB_TYPE_END; |
| 70 | dp_end->length = sizeof(struct efi_device_path); |
| 71 | |
| 72 | snprintf(str, sizeof(str), "_%pD_", buf); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 73 | ut_assertok(strcmp("_/SD(3)_", str)); |
Heinrich Schuchardt | 3b47f33 | 2018-01-26 06:30:30 +0100 | [diff] [blame] | 74 | |
| 75 | /* NULL device path */ |
| 76 | snprintf(str, sizeof(str), "_%pD_", NULL); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 77 | ut_assertok(strcmp("_<NULL>_", str)); |
| 78 | |
| 79 | return 0; |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 80 | } |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 81 | PRINT_TEST(print_efi_ut, 0); |
| 82 | #endif |
Heinrich Schuchardt | 218d389 | 2018-01-10 18:06:08 +0100 | [diff] [blame] | 83 | |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 84 | static int print_printf(struct unit_test_state *uts) |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 85 | { |
| 86 | char big_str[400]; |
| 87 | int big_str_len; |
| 88 | char str[10], *s; |
| 89 | int len; |
| 90 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 91 | snprintf(str, sizeof(str), "testing"); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 92 | ut_assertok(strcmp("testing", str)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 93 | |
| 94 | snprintf(str, sizeof(str), "testing but too long"); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 95 | ut_assertok(strcmp("testing b", str)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 96 | |
| 97 | snprintf(str, 1, "testing none"); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 98 | ut_assertok(strcmp("", str)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 99 | |
| 100 | *str = 'x'; |
| 101 | snprintf(str, 0, "testing none"); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 102 | ut_asserteq('x', *str); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 103 | |
Rob Clark | 22ae0a7 | 2017-09-13 18:46:54 -0400 | [diff] [blame] | 104 | sprintf(big_str, "_%ls_", L"foo"); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 105 | ut_assertok(strcmp("_foo_", big_str)); |
Rob Clark | 22ae0a7 | 2017-09-13 18:46:54 -0400 | [diff] [blame] | 106 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 107 | /* Test the banner function */ |
| 108 | s = display_options_get_banner(true, str, sizeof(str)); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 109 | ut_asserteq_ptr(str, s); |
| 110 | ut_assertok(strcmp("\n\nU-Boo\n\n", s)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 111 | |
Heinrich Schuchardt | b144ab1 | 2019-04-26 18:39:00 +0200 | [diff] [blame] | 112 | /* Assert that we do not overwrite memory before the buffer */ |
| 113 | str[0] = '`'; |
| 114 | s = display_options_get_banner(true, str + 1, 1); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 115 | ut_asserteq_ptr(str + 1, s); |
| 116 | ut_assertok(strcmp("`", str)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 117 | |
Heinrich Schuchardt | b144ab1 | 2019-04-26 18:39:00 +0200 | [diff] [blame] | 118 | str[0] = '~'; |
| 119 | s = display_options_get_banner(true, str + 1, 2); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 120 | ut_asserteq_ptr(str + 1, s); |
| 121 | ut_assertok(strcmp("~\n", str)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 122 | |
Heinrich Schuchardt | b144ab1 | 2019-04-26 18:39:00 +0200 | [diff] [blame] | 123 | /* The last two characters are set to \n\n for all buffer sizes > 2 */ |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 124 | s = display_options_get_banner(false, str, sizeof(str)); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 125 | ut_asserteq_ptr(str, s); |
| 126 | ut_assertok(strcmp("U-Boot \n\n", s)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 127 | |
| 128 | /* Give it enough space for some of the version */ |
| 129 | big_str_len = strlen(version_string) - 5; |
| 130 | s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str, |
| 131 | big_str_len); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 132 | ut_asserteq_ptr(big_str, s); |
| 133 | ut_assertok(strncmp(version_string, s, big_str_len - 3)); |
| 134 | ut_assertok(strcmp("\n\n", s + big_str_len - 3)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 135 | |
| 136 | /* Give it enough space for the version and some of the build tag */ |
| 137 | big_str_len = strlen(version_string) + 9 + 20; |
| 138 | s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str, |
| 139 | big_str_len); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 140 | ut_asserteq_ptr(big_str, s); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 141 | len = strlen(version_string); |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 142 | ut_assertok(strncmp(version_string, s, len)); |
| 143 | ut_assertok(strncmp(", Build: ", s + len, 9)); |
| 144 | ut_assertok(strncmp(FAKE_BUILD_TAG, s + 9 + len, 12)); |
| 145 | ut_assertok(strcmp("\n\n", s + big_str_len - 3)); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 146 | |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 147 | return 0; |
| 148 | } |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 149 | PRINT_TEST(print_printf, 0); |
Simon Glass | 75ee32f | 2017-06-15 21:37:51 -0600 | [diff] [blame] | 150 | |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 151 | static int print_display_buffer(struct unit_test_state *uts) |
| 152 | { |
| 153 | u8 *buf; |
| 154 | int i; |
| 155 | |
| 156 | buf = map_sysmem(0, BUF_SIZE); |
| 157 | memset(buf, '\0', BUF_SIZE); |
| 158 | for (i = 0; i < 0x11; i++) |
| 159 | buf[i] = i * 0x11; |
| 160 | |
| 161 | /* bytes */ |
| 162 | console_record_reset(); |
| 163 | print_buffer(0, buf, 1, 0x12, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 164 | ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); |
| 165 | ut_assert_nextline("00000010: 10 00 .."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 166 | ut_assert_console_end(); |
| 167 | |
| 168 | /* line length */ |
| 169 | console_record_reset(); |
| 170 | print_buffer(0, buf, 1, 0x12, 8); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 171 | ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 ..\"3DUfw"); |
| 172 | ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff ........"); |
| 173 | ut_assert_nextline("00000010: 10 00 .."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 174 | ut_assert_console_end(); |
| 175 | |
| 176 | /* long line */ |
| 177 | console_record_reset(); |
| 178 | buf[0x41] = 0x41; |
| 179 | print_buffer(0, buf, 1, 0x42, 0x40); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 180 | 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........................................................"); |
| 181 | ut_assert_nextline("00000040: 00 41 .A"); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 182 | ut_assert_console_end(); |
| 183 | |
| 184 | /* address */ |
| 185 | console_record_reset(); |
| 186 | print_buffer(0x12345678, buf, 1, 0x12, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 187 | ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); |
| 188 | ut_assert_nextline("12345688: 10 00 .."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 189 | ut_assert_console_end(); |
| 190 | |
| 191 | /* 16-bit */ |
| 192 | console_record_reset(); |
| 193 | print_buffer(0, buf, 2, 9, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 194 | ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........"); |
| 195 | ut_assert_nextline("00000010: 0010 .."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 196 | ut_assert_console_end(); |
| 197 | |
| 198 | /* 32-bit */ |
| 199 | console_record_reset(); |
| 200 | print_buffer(0, buf, 4, 5, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 201 | ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........"); |
| 202 | ut_assert_nextline("00000010: 00000010 ...."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 203 | ut_assert_console_end(); |
| 204 | |
| 205 | /* 64-bit */ |
| 206 | console_record_reset(); |
| 207 | print_buffer(0, buf, 8, 3, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 208 | ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........"); |
| 209 | ut_assert_nextline("00000010: 0000000000000010 ........"); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 210 | ut_assert_console_end(); |
| 211 | |
| 212 | /* ASCII */ |
| 213 | console_record_reset(); |
| 214 | buf[1] = 31; |
| 215 | buf[2] = 32; |
| 216 | buf[3] = 33; |
| 217 | for (i = 0; i < 4; i++) |
| 218 | buf[4 + i] = 126 + i; |
| 219 | buf[8] = 255; |
| 220 | print_buffer(0, buf, 1, 10, 0); |
Simon Glass | 85c8fc5 | 2021-05-08 07:00:00 -0600 | [diff] [blame] | 221 | ut_assert_nextline("00000000: 00 1f 20 21 7e 7f 80 81 ff 99 .. !~....."); |
Simon Glass | 4a249ba | 2021-05-08 06:59:59 -0600 | [diff] [blame] | 222 | ut_assert_console_end(); |
| 223 | |
| 224 | unmap_sysmem(buf); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC); |
| 229 | |
Simon Glass | 02b8f1a | 2021-05-08 07:00:05 -0600 | [diff] [blame] | 230 | static int print_hexdump_line(struct unit_test_state *uts) |
| 231 | { |
| 232 | char *linebuf; |
| 233 | u8 *buf; |
| 234 | int i; |
| 235 | |
| 236 | buf = map_sysmem(0, BUF_SIZE); |
| 237 | memset(buf, '\0', BUF_SIZE); |
| 238 | for (i = 0; i < 0x11; i++) |
| 239 | buf[i] = i * 0x11; |
| 240 | |
| 241 | /* Check buffer size calculations */ |
| 242 | linebuf = map_sysmem(0x400, BUF_SIZE); |
| 243 | memset(linebuf, '\xff', BUF_SIZE); |
| 244 | ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75)); |
| 245 | ut_asserteq(-1, linebuf[0]); |
| 246 | ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76)); |
| 247 | ut_asserteq(0, linebuf[75]); |
| 248 | ut_asserteq(-1, linebuf[76]); |
| 249 | |
| 250 | unmap_sysmem(buf); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | PRINT_TEST(print_hexdump_line, UT_TESTF_CONSOLE_REC); |
| 255 | |
Simon Glass | 2650715 | 2021-05-08 07:00:02 -0600 | [diff] [blame] | 256 | static int print_do_hex_dump(struct unit_test_state *uts) |
| 257 | { |
| 258 | u8 *buf; |
| 259 | int i; |
| 260 | |
| 261 | buf = map_sysmem(0, BUF_SIZE); |
| 262 | memset(buf, '\0', BUF_SIZE); |
| 263 | for (i = 0; i < 0x11; i++) |
| 264 | buf[i] = i * 0x11; |
| 265 | |
| 266 | /* bytes */ |
| 267 | console_record_reset(); |
| 268 | print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, buf, 0x12); |
| 269 | ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); |
| 270 | ut_assert_nextline("00000010: 10 00 .."); |
| 271 | ut_assert_console_end(); |
| 272 | |
Simon Glass | f1d0647 | 2021-05-08 07:00:03 -0600 | [diff] [blame] | 273 | /* line length */ |
| 274 | console_record_reset(); |
| 275 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 8, 1, buf, 0x12, true); |
| 276 | ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 ..\"3DUfw"); |
| 277 | ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff ........"); |
| 278 | ut_assert_nextline("00000010: 10 00 .."); |
| 279 | ut_assert_console_end(); |
| 280 | unmap_sysmem(buf); |
| 281 | |
| 282 | /* long line */ |
| 283 | console_record_reset(); |
| 284 | buf[0x41] = 0x41; |
| 285 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 0x40, 1, buf, 0x42, true); |
| 286 | 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........................................................"); |
| 287 | ut_assert_nextline("00000040: 00 41 .A"); |
| 288 | ut_assert_console_end(); |
| 289 | |
Simon Glass | 2650715 | 2021-05-08 07:00:02 -0600 | [diff] [blame] | 290 | /* 16-bit */ |
| 291 | console_record_reset(); |
Simon Glass | f1d0647 | 2021-05-08 07:00:03 -0600 | [diff] [blame] | 292 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 2, buf, 0x12, true); |
Simon Glass | 2650715 | 2021-05-08 07:00:02 -0600 | [diff] [blame] | 293 | ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........"); |
| 294 | ut_assert_nextline("00000010: 0010 .."); |
| 295 | ut_assert_console_end(); |
| 296 | unmap_sysmem(buf); |
| 297 | |
| 298 | /* 32-bit */ |
| 299 | console_record_reset(); |
Simon Glass | f1d0647 | 2021-05-08 07:00:03 -0600 | [diff] [blame] | 300 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 4, buf, 0x14, true); |
Simon Glass | 2650715 | 2021-05-08 07:00:02 -0600 | [diff] [blame] | 301 | ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........"); |
| 302 | ut_assert_nextline("00000010: 00000010 ...."); |
| 303 | ut_assert_console_end(); |
| 304 | unmap_sysmem(buf); |
| 305 | |
| 306 | /* 64-bit */ |
| 307 | console_record_reset(); |
| 308 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 8, buf, 0x18, true); |
| 309 | ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........"); |
| 310 | ut_assert_nextline("00000010: 0000000000000010 ........"); |
| 311 | ut_assert_console_end(); |
| 312 | unmap_sysmem(buf); |
| 313 | |
| 314 | /* ASCII */ |
| 315 | console_record_reset(); |
| 316 | buf[1] = 31; |
| 317 | buf[2] = 32; |
| 318 | buf[3] = 33; |
| 319 | for (i = 0; i < 4; i++) |
| 320 | buf[4 + i] = 126 + i; |
| 321 | buf[8] = 255; |
Simon Glass | f1d0647 | 2021-05-08 07:00:03 -0600 | [diff] [blame] | 322 | print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 1, buf, 10, true); |
Simon Glass | 2650715 | 2021-05-08 07:00:02 -0600 | [diff] [blame] | 323 | ut_assert_nextline("00000000: 00 1f 20 21 7e 7f 80 81 ff 99 .. !~....."); |
| 324 | ut_assert_console_end(); |
| 325 | unmap_sysmem(buf); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC); |
| 330 | |
Simon Glass | d242368 | 2021-05-08 06:59:58 -0600 | [diff] [blame] | 331 | int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 332 | { |
| 333 | struct unit_test *tests = UNIT_TEST_SUITE_START(print_test); |
| 334 | const int n_ents = UNIT_TEST_SUITE_COUNT(print_test); |
| 335 | |
| 336 | return cmd_ut_category("print", "print_", tests, n_ents, argc, argv); |
| 337 | } |