1# SPDX-License-Identifier: GPL-2.0 2""" 3Unit-test runner 4 5Provides a test_ut() function which is used by conftest.py to run each unit 6test one at a time, as well setting up some files needed by the tests. 7 8# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 9""" 10import collections 11import gzip 12import os 13import os.path 14import pytest 15 16import utils 17# pylint: disable=E0611 18from tests import fs_helper 19from test_android import test_abootimg 20 21def mkdir_cond(dirname): 22 """Create a directory if it doesn't already exist 23 24 Args: 25 dirname (str): Name of directory to create 26 """ 27 if not os.path.exists(dirname): 28 os.mkdir(dirname) 29 30def copy_partition(ubman, fsfile, outname): 31 """Copy a partition into a disk iamge 32 33 Args: 34 ubman (ConsoleBase): U-Boot fixture 35 fsfile (str): Name of partition file 36 outname (str): Name of full-disk file to update 37 """ 38 utils.run_and_log(ubman, 39 f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc') 40 41def setup_bootmenu_image(ubman): 42 """Create a 20MB disk image with a single ext4 partition 43 44 This is modelled on Armbian 22.08 Jammy 45 """ 46 mmc_dev = 4 47 fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0x83) 48 49 script = '''# DO NOT EDIT THIS FILE 50# 51# Please edit /boot/armbianEnv.txt to set supported parameters 52# 53 54setenv load_addr "0x9000000" 55setenv overlay_error "false" 56# default values 57setenv rootdev "/dev/mmcblk%dp1" 58setenv verbosity "1" 59setenv console "both" 60setenv bootlogo "false" 61setenv rootfstype "ext4" 62setenv docker_optimizations "on" 63setenv earlycon "off" 64 65echo "Boot script loaded from ${devtype} ${devnum}" 66 67if test -e ${devtype} ${devnum} ${prefix}armbianEnv.txt; then 68 load ${devtype} ${devnum} ${load_addr} ${prefix}armbianEnv.txt 69 env import -t ${load_addr} ${filesize} 70fi 71 72if test "${logo}" = "disabled"; then setenv logo "logo.nologo"; fi 73 74if test "${console}" = "display" || test "${console}" = "both"; then setenv consoleargs "console=tty1"; fi 75if test "${console}" = "serial" || test "${console}" = "both"; then setenv consoleargs "console=ttyS2,1500000 ${consoleargs}"; fi 76if test "${earlycon}" = "on"; then setenv consoleargs "earlycon ${consoleargs}"; fi 77if test "${bootlogo}" = "true"; then setenv consoleargs "bootsplash.bootfile=bootsplash.armbian ${consoleargs}"; fi 78 79# get PARTUUID of first partition on SD/eMMC the boot script was loaded from 80if test "${devtype}" = "mmc"; then part uuid mmc ${devnum}:1 partuuid; fi 81 82setenv bootargs "root=${rootdev} rootwait rootfstype=${rootfstype} ${consoleargs} consoleblank=0 loglevel=${verbosity} ubootpart=${partuuid} usb-storage.quirks=${usbstoragequirks} ${extraargs} ${extraboardargs}" 83 84if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1"; fi 85 86load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd 87load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image 88 89load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} 90fdt addr ${fdt_addr_r} 91fdt resize 65536 92for overlay_file in ${overlays}; do 93 if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-${overlay_file}.dtbo; then 94 echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo" 95 fdt apply ${load_addr} || setenv overlay_error "true" 96 fi 97done 98for overlay_file in ${user_overlays}; do 99 if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then 100 echo "Applying user provided DT overlay ${overlay_file}.dtbo" 101 fdt apply ${load_addr} || setenv overlay_error "true" 102 fi 103done 104if test "${overlay_error}" = "true"; then 105 echo "Error applying DT overlays, restoring original DT" 106 load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile} 107else 108 if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-fixup.scr; then 109 echo "Applying kernel provided DT fixup script (${overlay_prefix}-fixup.scr)" 110 source ${load_addr} 111 fi 112 if test -e ${devtype} ${devnum} ${prefix}fixup.scr; then 113 load ${devtype} ${devnum} ${load_addr} ${prefix}fixup.scr 114 echo "Applying user provided fixup script (fixup.scr)" 115 source ${load_addr} 116 fi 117fi 118booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} 119 120# Recompile with: 121# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr 122''' 123 bootdir = os.path.join(mnt, 'boot') 124 mkdir_cond(bootdir) 125 cmd_fname = os.path.join(bootdir, 'boot.cmd') 126 scr_fname = os.path.join(bootdir, 'boot.scr') 127 with open(cmd_fname, 'w', encoding='ascii') as outf: 128 print(script, file=outf) 129 130 infname = os.path.join(ubman.config.source_dir, 131 'test/py/tests/bootstd/armbian.bmp.xz') 132 bmp_file = os.path.join(bootdir, 'boot.bmp') 133 utils.run_and_log( 134 ubman, 135 ['sh', '-c', f'xz -dc {infname} >{bmp_file}']) 136 137 mkimage = ubman.config.build_dir + '/tools/mkimage' 138 utils.run_and_log( 139 ubman, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}') 140 141 kernel = 'vmlinuz-5.15.63-rockchip64' 142 target = os.path.join(bootdir, kernel) 143 with open(target, 'wb') as outf: 144 print('kernel', outf) 145 146 symlink = os.path.join(bootdir, 'Image') 147 if os.path.exists(symlink): 148 os.remove(symlink) 149 utils.run_and_log( 150 ubman, f'echo here {kernel} {symlink}') 151 os.symlink(kernel, symlink) 152 153 fsfile = 'ext18M.img' 154 utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') 155 utils.run_and_log(ubman, f'mkfs.ext4 {fsfile} -d {mnt}') 156 copy_partition(ubman, fsfile, fname) 157 utils.run_and_log(ubman, f'rm -rf {mnt}') 158 utils.run_and_log(ubman, f'rm -f {fsfile}') 159 160def setup_bootflow_image(ubman): 161 """Create a 20MB disk image with a single FAT partition""" 162 mmc_dev = 1 163 fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0xc, second_part=True) 164 165 vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' 166 initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' 167 dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' 168 script = '''# extlinux.conf generated by appliance-creator 169ui menu.c32 170menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. 171menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. 172menu hidden 173timeout 20 174totaltimeout 600 175 176label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) 177 kernel /%s 178 append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB 179 fdtdir /%s/ 180 initrd /%s''' % (vmlinux, dtbdir, initrd) 181 ext = os.path.join(mnt, 'extlinux') 182 mkdir_cond(ext) 183 184 conf = os.path.join(ext, 'extlinux.conf') 185 with open(conf, 'w', encoding='ascii') as fd: 186 print(script, file=fd) 187 188 inf = os.path.join(ubman.config.persistent_data_dir, 'inf') 189 with open(inf, 'wb') as fd: 190 fd.write(gzip.compress(b'vmlinux')) 191 mkimage = ubman.config.build_dir + '/tools/mkimage' 192 utils.run_and_log( 193 ubman, f'{mkimage} -f auto -d {inf} {os.path.join(mnt, vmlinux)}') 194 195 with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd: 196 print('initrd', file=fd) 197 198 mkdir_cond(os.path.join(mnt, dtbdir)) 199 200 dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb') 201 utils.run_and_log( 202 ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};') 203 204 fsfile = 'vfat18M.img' 205 utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') 206 utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') 207 utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) 208 copy_partition(ubman, fsfile, fname) 209 utils.run_and_log(ubman, f'rm -rf {mnt}') 210 utils.run_and_log(ubman, f'rm -f {fsfile}') 211 212def setup_cros_image(ubman): 213 """Create a 20MB disk image with ChromiumOS partitions""" 214 Partition = collections.namedtuple('part', 'start,size,name') 215 parts = {} 216 disk_data = None 217 218 def pack_kernel(ubman, arch, kern, dummy): 219 """Pack a kernel containing some fake data 220 221 Args: 222 ubman (ConsoleBase): Console to use 223 arch (str): Architecture to use ('x86' or 'arm') 224 kern (str): Filename containing kernel 225 dummy (str): Dummy filename to use for config and bootloader 226 227 Return: 228 bytes: Packed-kernel data 229 """ 230 kern_part = os.path.join(ubman.config.result_dir, 231 f'kern-part-{arch}.bin') 232 utils.run_and_log( 233 ubman, 234 f'futility vbutil_kernel --pack {kern_part} ' 235 '--keyblock doc/chromium/files/devkeys/kernel.keyblock ' 236 '--signprivate doc/chromium/files/devkeys/kernel_data_key.vbprivk ' 237 f'--version 1 --config {dummy} --bootloader {dummy} ' 238 f'--vmlinuz {kern}') 239 240 with open(kern_part, 'rb') as inf: 241 kern_part_data = inf.read() 242 return kern_part_data 243 244 def set_part_data(partnum, data): 245 """Set the contents of a disk partition 246 247 This updates disk_data by putting data in the right place 248 249 Args: 250 partnum (int): Partition number to set 251 data (bytes): Data for that partition 252 """ 253 nonlocal disk_data 254 255 start = parts[partnum].start * sect_size 256 disk_data = disk_data[:start] + data + disk_data[start + len(data):] 257 258 mmc_dev = 5 259 fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') 260 utils.run_and_log(ubman, f'qemu-img create {fname} 20M') 261 utils.run_and_log(ubman, f'cgpt create {fname}') 262 263 uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' 264 uuid_kern = 'fe3a2a5d-4f32-41a7-b725-accc3285a309' 265 uuid_root = '3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' 266 uuid_rwfw = 'cab6e88e-abf3-4102-a07a-d4bb9be3c1d3' 267 uuid_reserved = '2e0a753d-9e48-43b0-8337-b15192cb1b5e' 268 uuid_efi = 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' 269 270 ptr = 40 271 272 # Number of sectors in 1MB 273 sect_size = 512 274 sect_1mb = (1 << 20) // sect_size 275 276 required_parts = [ 277 {'num': 0xb, 'label':'RWFW', 'type': uuid_rwfw, 'size': '1'}, 278 {'num': 6, 'label':'KERN_C', 'type': uuid_kern, 'size': '1'}, 279 {'num': 7, 'label':'ROOT_C', 'type': uuid_root, 'size': '1'}, 280 {'num': 9, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, 281 {'num': 0xa, 'label':'reserved', 'type': uuid_reserved, 'size': '1'}, 282 283 {'num': 2, 'label':'KERN_A', 'type': uuid_kern, 'size': '1M'}, 284 {'num': 4, 'label':'KERN_B', 'type': uuid_kern, 'size': '1M'}, 285 286 {'num': 8, 'label':'OEM', 'type': uuid_state, 'size': '1M'}, 287 {'num': 0xc, 'label':'EFI-SYSTEM', 'type': uuid_efi, 'size': '1M'}, 288 289 {'num': 5, 'label':'ROOT_B', 'type': uuid_root, 'size': '1'}, 290 {'num': 3, 'label':'ROOT_A', 'type': uuid_root, 'size': '1'}, 291 {'num': 1, 'label':'STATE', 'type': uuid_state, 'size': '1M'}, 292 ] 293 294 for part in required_parts: 295 size_str = part['size'] 296 if 'M' in size_str: 297 size = int(size_str[:-1]) * sect_1mb 298 else: 299 size = int(size_str) 300 utils.run_and_log( 301 ubman, 302 f"cgpt add -i {part['num']} -b {ptr} -s {size} -t {part['type']} {fname}") 303 ptr += size 304 305 utils.run_and_log(ubman, f'cgpt boot -p {fname}') 306 out = utils.run_and_log(ubman, f'cgpt show -q {fname}') 307 308 # We expect something like this: 309 # 8239 2048 1 Basic data 310 # 45 2048 2 ChromeOS kernel 311 # 8238 1 3 ChromeOS rootfs 312 # 2093 2048 4 ChromeOS kernel 313 # 8237 1 5 ChromeOS rootfs 314 # 41 1 6 ChromeOS kernel 315 # 42 1 7 ChromeOS rootfs 316 # 4141 2048 8 Basic data 317 # 43 1 9 ChromeOS reserved 318 # 44 1 10 ChromeOS reserved 319 # 40 1 11 ChromeOS firmware 320 # 6189 2048 12 EFI System Partition 321 322 # Create a dict (indexed by partition number) containing the above info 323 for line in out.splitlines(): 324 start, size, num, name = line.split(maxsplit=3) 325 parts[int(num)] = Partition(int(start), int(size), name) 326 327 # Set up the kernel command-line 328 dummy = os.path.join(ubman.config.result_dir, 'dummy.txt') 329 with open(dummy, 'wb') as outf: 330 outf.write(b'BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=/dev/nvme0n1p1 ro quiet splash vt.handoff=7') 331 332 # For now we just use dummy kernels. This limits testing to just detecting 333 # a signed kernel. We could add support for the x86 data structures so that 334 # testing could cover getting the cmdline, setup.bin and other pieces. 335 kern = os.path.join(ubman.config.result_dir, 'kern.bin') 336 with open(kern, 'wb') as outf: 337 outf.write(b'kernel\n') 338 339 with open(fname, 'rb') as inf: 340 disk_data = inf.read() 341 342 # put x86 kernel in partition 2 and arm one in partition 4 343 set_part_data(2, pack_kernel(ubman, 'x86', kern, dummy)) 344 set_part_data(4, pack_kernel(ubman, 'arm', kern, dummy)) 345 346 with open(fname, 'wb') as outf: 347 outf.write(disk_data) 348 349 return fname 350 351def setup_android_image(ubman): 352 """Create a 20MB disk image with Android partitions""" 353 Partition = collections.namedtuple('part', 'start,size,name') 354 parts = {} 355 disk_data = None 356 357 def set_part_data(partnum, data): 358 """Set the contents of a disk partition 359 360 This updates disk_data by putting data in the right place 361 362 Args: 363 partnum (int): Partition number to set 364 data (bytes): Data for that partition 365 """ 366 nonlocal disk_data 367 368 start = parts[partnum].start * sect_size 369 disk_data = disk_data[:start] + data + disk_data[start + len(data):] 370 371 mmc_dev = 7 372 fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') 373 utils.run_and_log(ubman, f'qemu-img create {fname} 20M') 374 utils.run_and_log(ubman, f'cgpt create {fname}') 375 376 ptr = 40 377 378 # Number of sectors in 1MB 379 sect_size = 512 380 sect_1mb = (1 << 20) // sect_size 381 382 required_parts = [ 383 {'num': 1, 'label':'misc', 'size': '1M'}, 384 {'num': 2, 'label':'boot_a', 'size': '4M'}, 385 {'num': 3, 'label':'boot_b', 'size': '4M'}, 386 {'num': 4, 'label':'vendor_boot_a', 'size': '4M'}, 387 {'num': 5, 'label':'vendor_boot_b', 'size': '4M'}, 388 ] 389 390 for part in required_parts: 391 size_str = part['size'] 392 if 'M' in size_str: 393 size = int(size_str[:-1]) * sect_1mb 394 else: 395 size = int(size_str) 396 utils.run_and_log( 397 ubman, 398 f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") 399 ptr += size 400 401 utils.run_and_log(ubman, f'cgpt boot -p {fname}') 402 out = utils.run_and_log(ubman, f'cgpt show -q {fname}') 403 404 # Create a dict (indexed by partition number) containing the above info 405 for line in out.splitlines(): 406 start, size, num, name = line.split(maxsplit=3) 407 parts[int(num)] = Partition(int(start), int(size), name) 408 409 with open(fname, 'rb') as inf: 410 disk_data = inf.read() 411 412 test_abootimg.AbootimgTestDiskImage(ubman, 'bootv4.img', test_abootimg.boot_img_hex) 413 boot_img = os.path.join(ubman.config.result_dir, 'bootv4.img') 414 with open(boot_img, 'rb') as inf: 415 set_part_data(2, inf.read()) 416 417 test_abootimg.AbootimgTestDiskImage(ubman, 'vendor_boot.img', test_abootimg.vboot_img_hex) 418 vendor_boot_img = os.path.join(ubman.config.result_dir, 'vendor_boot.img') 419 with open(vendor_boot_img, 'rb') as inf: 420 set_part_data(4, inf.read()) 421 422 with open(fname, 'wb') as outf: 423 outf.write(disk_data) 424 425 print(f'wrote to {fname}') 426 427 mmc_dev = 8 428 fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') 429 utils.run_and_log(ubman, f'qemu-img create {fname} 20M') 430 utils.run_and_log(ubman, f'cgpt create {fname}') 431 432 ptr = 40 433 434 # Number of sectors in 1MB 435 sect_size = 512 436 sect_1mb = (1 << 20) // sect_size 437 438 required_parts = [ 439 {'num': 1, 'label':'misc', 'size': '1M'}, 440 {'num': 2, 'label':'boot_a', 'size': '4M'}, 441 {'num': 3, 'label':'boot_b', 'size': '4M'}, 442 ] 443 444 for part in required_parts: 445 size_str = part['size'] 446 if 'M' in size_str: 447 size = int(size_str[:-1]) * sect_1mb 448 else: 449 size = int(size_str) 450 utils.run_and_log( 451 ubman, 452 f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}") 453 ptr += size 454 455 utils.run_and_log(ubman, f'cgpt boot -p {fname}') 456 out = utils.run_and_log(ubman, f'cgpt show -q {fname}') 457 458 # Create a dict (indexed by partition number) containing the above info 459 for line in out.splitlines(): 460 start, size, num, name = line.split(maxsplit=3) 461 parts[int(num)] = Partition(int(start), int(size), name) 462 463 with open(fname, 'rb') as inf: 464 disk_data = inf.read() 465 466 test_abootimg.AbootimgTestDiskImage(ubman, 'boot.img', test_abootimg.img_hex) 467 boot_img = os.path.join(ubman.config.result_dir, 'boot.img') 468 with open(boot_img, 'rb') as inf: 469 set_part_data(2, inf.read()) 470 471 with open(fname, 'wb') as outf: 472 outf.write(disk_data) 473 474 print(f'wrote to {fname}') 475 476 return fname 477 478def setup_cedit_file(ubman): 479 """Set up a .dtb file for use with testing expo and configuration editor""" 480 infname = os.path.join(ubman.config.source_dir, 481 'test/boot/files/expo_layout.dts') 482 inhname = os.path.join(ubman.config.source_dir, 483 'test/boot/files/expo_ids.h') 484 expo_tool = os.path.join(ubman.config.source_dir, 'tools/expo.py') 485 outfname = 'cedit.dtb' 486 utils.run_and_log( 487 ubman, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}') 488 489@pytest.mark.buildconfigspec('ut_dm') 490def test_ut_dm_init(ubman): 491 """Initialize data for ut dm tests.""" 492 493 fn = ubman.config.source_dir + '/testflash.bin' 494 if not os.path.exists(fn): 495 data = b'this is a test' 496 data += b'\x00' * ((4 * 1024 * 1024) - len(data)) 497 with open(fn, 'wb') as fh: 498 fh.write(data) 499 500 fn = ubman.config.source_dir + '/spi.bin' 501 if not os.path.exists(fn): 502 data = b'\x00' * (2 * 1024 * 1024) 503 with open(fn, 'wb') as fh: 504 fh.write(data) 505 506 # Create a file with a single partition 507 fn = ubman.config.source_dir + '/scsi.img' 508 if not os.path.exists(fn): 509 data = b'\x00' * (2 * 1024 * 1024) 510 with open(fn, 'wb') as fh: 511 fh.write(data) 512 utils.run_and_log( 513 ubman, f'sfdisk {fn}', stdin=b'type=83') 514 515 fs_helper.mk_fs(ubman.config, 'ext2', 0x200000, '2MB', None) 516 fs_helper.mk_fs(ubman.config, 'fat32', 0x100000, '1MB', None) 517 518 mmc_dev = 6 519 fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img') 520 data = b'\x00' * (12 * 1024 * 1024) 521 with open(fn, 'wb') as fh: 522 fh.write(data) 523 524 525def setup_efi_image(ubman): 526 """Create a 20MB disk image with an EFI app on it""" 527 devnum = 1 528 basename = 'flash' 529 fname, mnt = fs_helper.setup_image(ubman, devnum, 0xc, second_part=True, 530 basename=basename) 531 532 efi_dir = os.path.join(mnt, 'EFI') 533 mkdir_cond(efi_dir) 534 bootdir = os.path.join(efi_dir, 'BOOT') 535 mkdir_cond(bootdir) 536 efi_src = os.path.join(ubman.config.build_dir, 537 'lib/efi_loader/testapp.efi') 538 efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI') 539 with open(efi_src, 'rb') as inf: 540 with open(efi_dst, 'wb') as outf: 541 outf.write(inf.read()) 542 fsfile = 'vfat18M.img' 543 utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') 544 utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') 545 utils.run_and_log(ubman, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) 546 copy_partition(ubman, fsfile, fname) 547 utils.run_and_log(ubman, f'rm -rf {mnt}') 548 utils.run_and_log(ubman, f'rm -f {fsfile}') 549 550@pytest.mark.buildconfigspec('cmd_bootflow') 551@pytest.mark.buildconfigspec('sandbox') 552def test_ut_dm_init_bootstd(ubman): 553 """Initialise data for bootflow tests""" 554 555 setup_bootflow_image(ubman) 556 setup_bootmenu_image(ubman) 557 setup_cedit_file(ubman) 558 setup_cros_image(ubman) 559 setup_android_image(ubman) 560 setup_efi_image(ubman) 561 562 # Restart so that the new mmc1.img is picked up 563 ubman.restart_uboot() 564 565 566def test_ut(ubman, ut_subtest): 567 """Execute a "ut" subtest. 568 569 The subtests are collected in function generate_ut_subtest() from linker 570 generated lists by applying a regular expression to the lines of file 571 u-boot.sym. The list entries are created using the C macro UNIT_TEST(). 572 573 Strict naming conventions have to be followed to match the regular 574 expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in 575 test suite foo that can be executed via command 'ut foo bar' and is 576 implemented in C function foo_test_bar(). 577 578 Args: 579 ubman (ConsoleBase): U-Boot console 580 ut_subtest (str): test to be executed via command ut, e.g 'foo bar' to 581 execute command 'ut foo bar' 582 """ 583 584 if ut_subtest == 'hush hush_test_simple_dollar': 585 # ut hush hush_test_simple_dollar prints "Unknown command" on purpose. 586 with ubman.disable_check('unknown_command'): 587 output = ubman.run_command('ut ' + ut_subtest) 588 assert 'Unknown command \'quux\' - try \'help\'' in output 589 else: 590 output = ubman.run_command('ut ' + ut_subtest) 591 assert output.endswith('failures: 0') 592