Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Tests for bdinfo command |
| 4 | * |
| 5 | * Copyright 2023 Marek Vasut <marek.vasut+renesas@mailbox.org> |
| 6 | */ |
| 7 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 8 | #include <alist.h> |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 9 | #include <console.h> |
| 10 | #include <mapmem.h> |
| 11 | #include <asm/global_data.h> |
| 12 | #include <dm/uclass.h> |
| 13 | #include <test/suites.h> |
| 14 | #include <test/ut.h> |
| 15 | #include <dm.h> |
| 16 | #include <env.h> |
| 17 | #include <lmb.h> |
| 18 | #include <net.h> |
Simon Glass | 3ddee31 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 19 | #include <serial.h> |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 20 | #include <video.h> |
| 21 | #include <vsprintf.h> |
| 22 | #include <asm/cache.h> |
| 23 | #include <asm/global_data.h> |
| 24 | #include <display_options.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | /* Declare a new bdinfo test */ |
| 29 | #define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo_test) |
| 30 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 31 | static int test_num_l(struct unit_test_state *uts, const char *name, |
| 32 | ulong value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 33 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 34 | ut_assert_nextline("%-12s= 0x%0*lx", name, 2 * (int)sizeof(value), |
| 35 | value); |
| 36 | |
| 37 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 40 | static int test_num_ll(struct unit_test_state *uts, const char *name, |
| 41 | unsigned long long value) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 42 | { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 43 | ut_assert_nextline("%-12s= 0x%.*llx", name, 2 * (int)sizeof(ulong), |
| 44 | value); |
| 45 | |
| 46 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 49 | static int test_eth(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 50 | { |
| 51 | const int idx = eth_get_dev_index(); |
| 52 | uchar enetaddr[6]; |
| 53 | char name[10]; |
| 54 | int ret; |
| 55 | |
| 56 | if (idx) |
| 57 | sprintf(name, "eth%iaddr", idx); |
| 58 | else |
| 59 | strcpy(name, "ethaddr"); |
| 60 | |
| 61 | ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr); |
| 62 | |
| 63 | ut_assert_nextline("current eth = %s", eth_get_name()); |
| 64 | if (!ret) |
| 65 | ut_assert_nextline("%-12s= (not set)", name); |
| 66 | else |
| 67 | ut_assert_nextline("%-12s= %pM", name, enetaddr); |
| 68 | ut_assert_nextline("IP addr = %s", env_get("ipaddr")); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 69 | |
| 70 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 73 | static int test_video_info(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 74 | { |
| 75 | const struct udevice *dev; |
| 76 | struct uclass *uc; |
| 77 | |
| 78 | uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) { |
| 79 | ut_assert_nextline("%-12s= %s %sactive", "Video", dev->name, |
| 80 | device_active(dev) ? "" : "in"); |
| 81 | if (device_active(dev)) { |
| 82 | struct video_priv *upriv = dev_get_uclass_priv(dev); |
| 83 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
| 84 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 85 | ut_assertok(test_num_ll(uts, "FB base", |
| 86 | (ulong)upriv->fb)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 87 | if (upriv->copy_fb) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 88 | ut_assertok(test_num_ll(uts, "FB copy", |
| 89 | (ulong)upriv->copy_fb)); |
| 90 | ut_assertok(test_num_l(uts, " copy size", |
| 91 | plat->copy_size)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 92 | } |
| 93 | ut_assert_nextline("%-12s= %dx%dx%d", "FB size", |
| 94 | upriv->xsize, upriv->ysize, |
| 95 | 1 << upriv->bpix); |
| 96 | } |
| 97 | } |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 98 | |
| 99 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 102 | static int lmb_test_dump_region(struct unit_test_state *uts, |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 103 | struct alist *lmb_rgn_lst, char *name) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 104 | { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 105 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 106 | unsigned long long base, size, end; |
| 107 | enum lmb_flags flags; |
| 108 | int i; |
| 109 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 110 | ut_assert_nextline(" %s.count = 0x%hx", name, lmb_rgn_lst->count); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 111 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 112 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 113 | base = rgn[i].base; |
| 114 | size = rgn[i].size; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 115 | end = base + size - 1; |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 116 | flags = rgn[i].flags; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 117 | |
Simon Glass | a44bd85 | 2023-10-01 19:15:16 -0600 | [diff] [blame] | 118 | if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) { |
| 119 | ut_assert_nextlinen(" %s[%d]\t[", name, i); |
| 120 | continue; |
| 121 | } |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 122 | ut_assert_nextlinen(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ", |
| 123 | name, i, base, end, size); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 124 | } |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 125 | |
| 126 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 129 | static int lmb_test_dump_all(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 130 | { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 131 | struct lmb *lmb = lmb_get(); |
| 132 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 133 | ut_assert_nextline("lmb_dump_all:"); |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 134 | ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory")); |
| 135 | ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved")); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 136 | |
| 137 | return 0; |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 140 | static int bdinfo_check_mem(struct unit_test_state *uts) |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 141 | { |
| 142 | struct bd_info *bd = gd->bd; |
| 143 | int i; |
| 144 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 145 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 146 | if (bd->bi_dram[i].size) { |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 147 | ut_assertok(test_num_l(uts, "DRAM bank", i)); |
| 148 | ut_assertok(test_num_ll(uts, "-> start", |
| 149 | bd->bi_dram[i].start)); |
| 150 | ut_assertok(test_num_ll(uts, "-> size", |
| 151 | bd->bi_dram[i].size)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static int bdinfo_test_all(struct unit_test_state *uts) |
| 159 | { |
| 160 | ut_assertok(test_num_l(uts, "boot_params", 0)); |
| 161 | |
| 162 | ut_assertok(bdinfo_check_mem(uts)); |
| 163 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 164 | /* CONFIG_SYS_HAS_SRAM testing not supported */ |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 165 | ut_assertok(test_num_l(uts, "flashstart", 0)); |
| 166 | ut_assertok(test_num_l(uts, "flashsize", 0)); |
| 167 | ut_assertok(test_num_l(uts, "flashoffset", 0)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 168 | ut_assert_nextline("baudrate = %lu bps", |
| 169 | env_get_ulong("baudrate", 10, 1234)); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 170 | ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr)); |
| 171 | ut_assertok(test_num_l(uts, "reloc off", gd->reloc_off)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 172 | ut_assert_nextline("%-12s= %u-bit", "Build", (uint)sizeof(void *) * 8); |
| 173 | |
| 174 | if (IS_ENABLED(CONFIG_CMD_NET)) |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 175 | ut_assertok(test_eth(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Make sure environment variable "fdtcontroladdr" address |
| 179 | * matches mapped control DT address. |
| 180 | */ |
| 181 | ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234)); |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 182 | ut_assertok(test_num_l(uts, "fdt_blob", |
| 183 | (ulong)map_to_sysmem(gd->fdt_blob))); |
| 184 | ut_assertok(test_num_l(uts, "new_fdt", |
| 185 | (ulong)map_to_sysmem(gd->new_fdt))); |
| 186 | ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 187 | |
| 188 | if (IS_ENABLED(CONFIG_VIDEO)) |
Simon Glass | 43b9a32 | 2023-10-01 19:15:17 -0600 | [diff] [blame] | 189 | ut_assertok(test_video_info(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 190 | |
| 191 | /* The gd->multi_dtb_fit may not be available, hence, #if below. */ |
| 192 | #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) |
Simon Glass | 0a5e069 | 2023-07-11 20:46:30 -0600 | [diff] [blame] | 193 | ut_assertok(test_num_l(uts, "multi_dtb_fit", (ulong)gd->multi_dtb_fit)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 194 | #endif |
| 195 | |
| 196 | if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 197 | ut_assertok(lmb_test_dump_all(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 198 | if (IS_ENABLED(CONFIG_OF_REAL)) |
| 199 | ut_assert_nextline("devicetree = %s", fdtdec_get_srcname()); |
| 200 | } |
| 201 | |
Simon Glass | 3ddee31 | 2023-07-12 09:04:37 -0600 | [diff] [blame] | 202 | if (IS_ENABLED(CONFIG_DM_SERIAL)) { |
| 203 | struct serial_device_info info; |
| 204 | |
| 205 | ut_assertnonnull(gd->cur_serial_dev); |
| 206 | ut_assertok(serial_getinfo(gd->cur_serial_dev, &info)); |
| 207 | |
| 208 | ut_assertok(test_num_l(uts, "serial addr", info.addr)); |
| 209 | ut_assertok(test_num_l(uts, " width", info.reg_width)); |
| 210 | ut_assertok(test_num_l(uts, " shift", info.reg_shift)); |
| 211 | ut_assertok(test_num_l(uts, " offset", info.reg_offset)); |
| 212 | ut_assertok(test_num_l(uts, " clock", info.clock)); |
| 213 | } |
| 214 | |
Simon Glass | 5087c77 | 2023-07-15 21:38:46 -0600 | [diff] [blame] | 215 | if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) { |
| 216 | ut_assert_nextlinen("stack ptr"); |
| 217 | ut_assertok(test_num_ll(uts, "ram_top ptr", |
| 218 | (unsigned long long)gd->ram_top)); |
| 219 | ut_assertok(test_num_l(uts, "malloc base", gd_malloc_start())); |
| 220 | } |
| 221 | |
Simon Glass | 43b9a32 | 2023-10-01 19:15:17 -0600 | [diff] [blame] | 222 | if (IS_ENABLED(CONFIG_X86)) |
| 223 | ut_check_skip_to_linen(uts, " high end ="); |
| 224 | |
Marek Vasut | eb0b1db | 2023-10-07 23:41:03 +0200 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int bdinfo_test_full(struct unit_test_state *uts) |
| 229 | { |
| 230 | /* Test BDINFO full print */ |
| 231 | ut_assertok(console_record_reset_enable()); |
| 232 | ut_assertok(run_commandf("bdinfo")); |
| 233 | ut_assertok(bdinfo_test_all(uts)); |
| 234 | ut_assertok(run_commandf("bdinfo -a")); |
| 235 | ut_assertok(bdinfo_test_all(uts)); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 236 | ut_assertok(ut_check_console_end(uts)); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
Marek Vasut | 391e5c3 | 2023-10-07 23:41:02 +0200 | [diff] [blame] | 241 | BDINFO_TEST(bdinfo_test_full, UT_TESTF_CONSOLE_REC); |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 242 | |
Marek Vasut | 2409924 | 2023-10-07 23:41:04 +0200 | [diff] [blame] | 243 | static int bdinfo_test_help(struct unit_test_state *uts) |
| 244 | { |
| 245 | /* Test BDINFO unknown option help text print */ |
| 246 | ut_assertok(console_record_reset_enable()); |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 247 | if (!CONFIG_IS_ENABLED(GETOPT)) { |
| 248 | ut_asserteq(0, run_commandf("bdinfo -h")); |
| 249 | ut_assertok(bdinfo_test_all(uts)); |
| 250 | } else { |
| 251 | ut_asserteq(1, run_commandf("bdinfo -h")); |
| 252 | ut_assert_nextlinen("bdinfo: invalid option -- h"); |
| 253 | ut_assert_nextlinen("bdinfo - print Board Info structure"); |
| 254 | ut_assert_nextline_empty(); |
| 255 | ut_assert_nextlinen("Usage:"); |
| 256 | ut_assert_nextlinen("bdinfo"); |
| 257 | } |
Marek Vasut | 2409924 | 2023-10-07 23:41:04 +0200 | [diff] [blame] | 258 | ut_assertok(ut_check_console_end(uts)); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | BDINFO_TEST(bdinfo_test_help, UT_TESTF_CONSOLE_REC); |
| 264 | |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 265 | static int bdinfo_test_memory(struct unit_test_state *uts) |
| 266 | { |
| 267 | /* Test BDINFO memory layout only print */ |
| 268 | ut_assertok(console_record_reset_enable()); |
| 269 | ut_assertok(run_commandf("bdinfo -m")); |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 270 | if (!CONFIG_IS_ENABLED(GETOPT)) |
| 271 | ut_assertok(bdinfo_test_all(uts)); |
| 272 | else |
| 273 | ut_assertok(bdinfo_check_mem(uts)); |
Marek Vasut | 3c5fd09 | 2023-10-07 23:41:05 +0200 | [diff] [blame] | 274 | ut_assertok(ut_check_console_end(uts)); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | BDINFO_TEST(bdinfo_test_memory, UT_TESTF_CONSOLE_REC); |
| 280 | |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 281 | static int bdinfo_test_eth(struct unit_test_state *uts) |
| 282 | { |
| 283 | /* Test BDINFO ethernet settings only print */ |
| 284 | ut_assertok(console_record_reset_enable()); |
| 285 | ut_assertok(run_commandf("bdinfo -e")); |
Marek Vasut | 949f0fe | 2023-12-10 16:01:56 +0100 | [diff] [blame] | 286 | if (!CONFIG_IS_ENABLED(GETOPT)) |
| 287 | ut_assertok(bdinfo_test_all(uts)); |
| 288 | else if (IS_ENABLED(CONFIG_CMD_NET)) |
Marek Vasut | f14a03b | 2023-10-07 23:41:06 +0200 | [diff] [blame] | 289 | ut_assertok(test_eth(uts)); |
| 290 | ut_assertok(ut_check_console_end(uts)); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | BDINFO_TEST(bdinfo_test_eth, UT_TESTF_CONSOLE_REC); |
| 296 | |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 297 | int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 298 | { |
| 299 | struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test); |
| 300 | const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test); |
| 301 | |
| 302 | return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv); |
| 303 | } |