1# Functional test that boots a Linux kernel and checks the console 2# 3# Copyright (c) 2018 Red Hat, Inc. 4# 5# Author: 6# Cleber Rosa <crosa@redhat.com> 7# 8# This work is licensed under the terms of the GNU GPL, version 2 or 9# later. See the COPYING file in the top-level directory. 10 11import os 12import lzma 13import gzip 14import shutil 15 16from avocado import skip 17from avocado import skipUnless 18from avocado import skipIf 19from avocado_qemu import QemuSystemTest 20from avocado_qemu import exec_command 21from avocado_qemu import exec_command_and_wait_for_pattern 22from avocado_qemu import interrupt_interactive_console_until_pattern 23from avocado_qemu import wait_for_console_pattern 24from avocado.utils import process 25from avocado.utils import archive 26 27""" 28Round up to next power of 2 29""" 30def pow2ceil(x): 31 return 1 if x == 0 else 2**(x - 1).bit_length() 32 33def file_truncate(path, size): 34 if size != os.path.getsize(path): 35 with open(path, 'ab+') as fd: 36 fd.truncate(size) 37 38""" 39Expand file size to next power of 2 40""" 41def image_pow2ceil_expand(path): 42 size = os.path.getsize(path) 43 size_aligned = pow2ceil(size) 44 if size != size_aligned: 45 with open(path, 'ab+') as fd: 46 fd.truncate(size_aligned) 47 48class LinuxKernelTest(QemuSystemTest): 49 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 50 51 def wait_for_console_pattern(self, success_message, vm=None): 52 wait_for_console_pattern(self, success_message, 53 failure_message='Kernel panic - not syncing', 54 vm=vm) 55 56 def extract_from_deb(self, deb, path): 57 """ 58 Extracts a file from a deb package into the test workdir 59 60 :param deb: path to the deb archive 61 :param path: path within the deb archive of the file to be extracted 62 :returns: path of the extracted file 63 """ 64 cwd = os.getcwd() 65 os.chdir(self.workdir) 66 file_path = process.run("ar t %s" % deb).stdout_text.split()[2] 67 process.run("ar x %s %s" % (deb, file_path)) 68 archive.extract(file_path, self.workdir) 69 os.chdir(cwd) 70 # Return complete path to extracted file. Because callers to 71 # extract_from_deb() specify 'path' with a leading slash, it is 72 # necessary to use os.path.relpath() as otherwise os.path.join() 73 # interprets it as an absolute path and drops the self.workdir part. 74 return os.path.normpath(os.path.join(self.workdir, 75 os.path.relpath(path, '/'))) 76 77 def extract_from_rpm(self, rpm, path): 78 """ 79 Extracts a file from an RPM package into the test workdir. 80 81 :param rpm: path to the rpm archive 82 :param path: path within the rpm archive of the file to be extracted 83 needs to be a relative path (starting with './') because 84 cpio(1), which is used to extract the file, expects that. 85 :returns: path of the extracted file 86 """ 87 cwd = os.getcwd() 88 os.chdir(self.workdir) 89 process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True) 90 os.chdir(cwd) 91 return os.path.normpath(os.path.join(self.workdir, path)) 92 93class BootLinuxConsole(LinuxKernelTest): 94 """ 95 Boots a Linux kernel and checks that the console is operational and the 96 kernel command line is properly passed from QEMU to the kernel 97 """ 98 timeout = 90 99 100 def test_x86_64_pc(self): 101 """ 102 :avocado: tags=arch:x86_64 103 :avocado: tags=machine:pc 104 """ 105 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 106 '/linux/releases/29/Everything/x86_64/os/images/pxeboot' 107 '/vmlinuz') 108 kernel_hash = '23bebd2680757891cf7adedb033532163a792495' 109 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 110 111 self.vm.set_console() 112 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 113 self.vm.add_args('-kernel', kernel_path, 114 '-append', kernel_command_line) 115 self.vm.launch() 116 console_pattern = 'Kernel command line: %s' % kernel_command_line 117 self.wait_for_console_pattern(console_pattern) 118 119 def test_mips_malta(self): 120 """ 121 :avocado: tags=arch:mips 122 :avocado: tags=machine:malta 123 :avocado: tags=endian:big 124 """ 125 deb_url = ('http://snapshot.debian.org/archive/debian/' 126 '20130217T032700Z/pool/main/l/linux-2.6/' 127 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb') 128 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04' 129 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 130 kernel_path = self.extract_from_deb(deb_path, 131 '/boot/vmlinux-2.6.32-5-4kc-malta') 132 133 self.vm.set_console() 134 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 135 self.vm.add_args('-kernel', kernel_path, 136 '-append', kernel_command_line) 137 self.vm.launch() 138 console_pattern = 'Kernel command line: %s' % kernel_command_line 139 self.wait_for_console_pattern(console_pattern) 140 141 def test_mips64el_malta(self): 142 """ 143 This test requires the ar tool to extract "data.tar.gz" from 144 the Debian package. 145 146 The kernel can be rebuilt using this Debian kernel source [1] and 147 following the instructions on [2]. 148 149 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/ 150 #linux-source-2.6.32_2.6.32-48 151 [2] https://kernel-team.pages.debian.net/kernel-handbook/ 152 ch-common-tasks.html#s-common-official 153 154 :avocado: tags=arch:mips64el 155 :avocado: tags=machine:malta 156 """ 157 deb_url = ('http://snapshot.debian.org/archive/debian/' 158 '20130217T032700Z/pool/main/l/linux-2.6/' 159 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb') 160 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5' 161 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 162 kernel_path = self.extract_from_deb(deb_path, 163 '/boot/vmlinux-2.6.32-5-5kc-malta') 164 165 self.vm.set_console() 166 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 167 self.vm.add_args('-kernel', kernel_path, 168 '-append', kernel_command_line) 169 self.vm.launch() 170 console_pattern = 'Kernel command line: %s' % kernel_command_line 171 self.wait_for_console_pattern(console_pattern) 172 173 def test_mips64el_fuloong2e(self): 174 """ 175 :avocado: tags=arch:mips64el 176 :avocado: tags=machine:fuloong2e 177 :avocado: tags=endian:little 178 """ 179 deb_url = ('http://archive.debian.org/debian/pool/main/l/linux/' 180 'linux-image-3.16.0-6-loongson-2e_3.16.56-1+deb8u1_mipsel.deb') 181 deb_hash = 'd04d446045deecf7b755ef576551de0c4184dd44' 182 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 183 kernel_path = self.extract_from_deb(deb_path, 184 '/boot/vmlinux-3.16.0-6-loongson-2e') 185 186 self.vm.set_console() 187 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 188 self.vm.add_args('-kernel', kernel_path, 189 '-append', kernel_command_line) 190 self.vm.launch() 191 console_pattern = 'Kernel command line: %s' % kernel_command_line 192 self.wait_for_console_pattern(console_pattern) 193 194 def test_mips_malta_cpio(self): 195 """ 196 :avocado: tags=arch:mips 197 :avocado: tags=machine:malta 198 :avocado: tags=endian:big 199 """ 200 deb_url = ('http://snapshot.debian.org/archive/debian/' 201 '20160601T041800Z/pool/main/l/linux/' 202 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb') 203 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8' 204 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 205 kernel_path = self.extract_from_deb(deb_path, 206 '/boot/vmlinux-4.5.0-2-4kc-malta') 207 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 208 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/' 209 'mips/rootfs.cpio.gz') 210 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99' 211 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 212 initrd_path = self.workdir + "rootfs.cpio" 213 archive.gzip_uncompress(initrd_path_gz, initrd_path) 214 215 self.vm.set_console() 216 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 217 + 'console=ttyS0 console=tty ' 218 + 'rdinit=/sbin/init noreboot') 219 self.vm.add_args('-kernel', kernel_path, 220 '-initrd', initrd_path, 221 '-append', kernel_command_line, 222 '-no-reboot') 223 self.vm.launch() 224 self.wait_for_console_pattern('Boot successful.') 225 226 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 227 'BogoMIPS') 228 exec_command_and_wait_for_pattern(self, 'uname -a', 229 'Debian') 230 exec_command_and_wait_for_pattern(self, 'reboot', 231 'reboot: Restarting system') 232 # Wait for VM to shut down gracefully 233 self.vm.wait() 234 235 @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') 236 def test_mips64el_malta_5KEc_cpio(self): 237 """ 238 :avocado: tags=arch:mips64el 239 :avocado: tags=machine:malta 240 :avocado: tags=endian:little 241 :avocado: tags=cpu:5KEc 242 """ 243 kernel_url = ('https://github.com/philmd/qemu-testing-blob/' 244 'raw/9ad2df38/mips/malta/mips64el/' 245 'vmlinux-3.19.3.mtoman.20150408') 246 kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754' 247 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 248 initrd_url = ('https://github.com/groeck/linux-build-test/' 249 'raw/8584a59e/rootfs/' 250 'mipsel64/rootfs.mipsel64r1.cpio.gz') 251 initrd_hash = '1dbb8a396e916847325284dbe2151167' 252 initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5', 253 asset_hash=initrd_hash) 254 initrd_path = self.workdir + "rootfs.cpio" 255 archive.gzip_uncompress(initrd_path_gz, initrd_path) 256 257 self.vm.set_console() 258 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 259 + 'console=ttyS0 console=tty ' 260 + 'rdinit=/sbin/init noreboot') 261 self.vm.add_args('-kernel', kernel_path, 262 '-initrd', initrd_path, 263 '-append', kernel_command_line, 264 '-no-reboot') 265 self.vm.launch() 266 wait_for_console_pattern(self, 'Boot successful.') 267 268 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 269 'MIPS 5KE') 270 exec_command_and_wait_for_pattern(self, 'uname -a', 271 '3.19.3.mtoman.20150408') 272 exec_command_and_wait_for_pattern(self, 'reboot', 273 'reboot: Restarting system') 274 # Wait for VM to shut down gracefully 275 self.vm.wait() 276 277 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash): 278 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 279 kernel_path = self.workdir + "kernel" 280 with lzma.open(kernel_path_xz, 'rb') as f_in: 281 with open(kernel_path, 'wb') as f_out: 282 shutil.copyfileobj(f_in, f_out) 283 284 self.vm.set_console() 285 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 286 + 'mem=256m@@0x0 ' 287 + 'console=ttyS0') 288 self.vm.add_args('-no-reboot', 289 '-kernel', kernel_path, 290 '-append', kernel_command_line) 291 self.vm.launch() 292 console_pattern = 'Kernel command line: %s' % kernel_command_line 293 self.wait_for_console_pattern(console_pattern) 294 295 def test_mips_malta32el_nanomips_4k(self): 296 """ 297 :avocado: tags=arch:mipsel 298 :avocado: tags=machine:malta 299 :avocado: tags=endian:little 300 :avocado: tags=cpu:I7200 301 """ 302 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 303 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 304 'generic_nano32r6el_page4k.xz') 305 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6' 306 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 307 308 def test_mips_malta32el_nanomips_16k_up(self): 309 """ 310 :avocado: tags=arch:mipsel 311 :avocado: tags=machine:malta 312 :avocado: tags=endian:little 313 :avocado: tags=cpu:I7200 314 """ 315 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 316 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 317 'generic_nano32r6el_page16k_up.xz') 318 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc' 319 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 320 321 def test_mips_malta32el_nanomips_64k_dbg(self): 322 """ 323 :avocado: tags=arch:mipsel 324 :avocado: tags=machine:malta 325 :avocado: tags=endian:little 326 :avocado: tags=cpu:I7200 327 """ 328 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' 329 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' 330 'generic_nano32r6el_page64k_dbg.xz') 331 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180' 332 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) 333 334 def test_aarch64_xlnx_versal_virt(self): 335 """ 336 :avocado: tags=arch:aarch64 337 :avocado: tags=machine:xlnx-versal-virt 338 :avocado: tags=device:pl011 339 :avocado: tags=device:arm_gicv3 340 :avocado: tags=accel:tcg 341 """ 342 images_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/' 343 'bionic-updates/main/installer-arm64/' 344 '20101020ubuntu543.19/images/') 345 kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux' 346 kernel_hash = 'e167757620640eb26de0972f578741924abb3a82' 347 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 348 349 initrd_url = images_url + 'netboot/ubuntu-installer/arm64/initrd.gz' 350 initrd_hash = 'cab5cb3fcefca8408aa5aae57f24574bfce8bdb9' 351 initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 352 353 self.vm.set_console() 354 self.vm.add_args('-m', '2G', 355 '-accel', 'tcg', 356 '-kernel', kernel_path, 357 '-initrd', initrd_path) 358 self.vm.launch() 359 self.wait_for_console_pattern('Checked W+X mappings: passed') 360 361 def test_arm_virt(self): 362 """ 363 :avocado: tags=arch:arm 364 :avocado: tags=machine:virt 365 :avocado: tags=accel:tcg 366 """ 367 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 368 '/linux/releases/29/Everything/armhfp/os/images/pxeboot' 369 '/vmlinuz') 370 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4' 371 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 372 373 self.vm.set_console() 374 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 375 'console=ttyAMA0') 376 self.vm.add_args('-kernel', kernel_path, 377 '-append', kernel_command_line) 378 self.vm.launch() 379 console_pattern = 'Kernel command line: %s' % kernel_command_line 380 self.wait_for_console_pattern(console_pattern) 381 382 def test_arm_emcraft_sf2(self): 383 """ 384 :avocado: tags=arch:arm 385 :avocado: tags=machine:emcraft-sf2 386 :avocado: tags=endian:little 387 :avocado: tags=u-boot 388 :avocado: tags=accel:tcg 389 """ 390 self.require_netdev('user') 391 392 uboot_url = ('https://raw.githubusercontent.com/' 393 'Subbaraya-Sundeep/qemu-test-binaries/' 394 'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot') 395 uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2' 396 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash) 397 spi_url = ('https://raw.githubusercontent.com/' 398 'Subbaraya-Sundeep/qemu-test-binaries/' 399 'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin') 400 spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501' 401 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash) 402 403 file_truncate(spi_path, 16 << 20) # Spansion S25FL128SDPBHICO is 16 MiB 404 405 self.vm.set_console() 406 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE 407 self.vm.add_args('-kernel', uboot_path, 408 '-append', kernel_command_line, 409 '-drive', 'file=' + spi_path + ',if=mtd,format=raw', 410 '-no-reboot') 411 self.vm.launch() 412 self.wait_for_console_pattern('Enter \'help\' for a list') 413 414 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15', 415 'eth0: link becomes ready') 416 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 417 '3 packets transmitted, 3 packets received, 0% packet loss') 418 419 def do_test_arm_raspi2(self, uart_id): 420 """ 421 :avocado: tags=accel:tcg 422 423 The kernel can be rebuilt using the kernel source referenced 424 and following the instructions on the on: 425 https://www.raspberrypi.org/documentation/linux/kernel/building.md 426 """ 427 serial_kernel_cmdline = { 428 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0', 429 } 430 deb_url = ('http://archive.raspberrypi.org/debian/' 431 'pool/main/r/raspberrypi-firmware/' 432 'raspberrypi-kernel_1.20190215-1_armhf.deb') 433 deb_hash = 'cd284220b32128c5084037553db3c482426f3972' 434 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 435 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 436 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 437 438 self.vm.set_console() 439 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 440 serial_kernel_cmdline[uart_id] + 441 ' root=/dev/mmcblk0p2 rootwait ' + 442 'dwc_otg.fiq_fsm_enable=0') 443 self.vm.add_args('-kernel', kernel_path, 444 '-dtb', dtb_path, 445 '-append', kernel_command_line, 446 '-device', 'usb-kbd') 447 self.vm.launch() 448 console_pattern = 'Kernel command line: %s' % kernel_command_line 449 self.wait_for_console_pattern(console_pattern) 450 console_pattern = 'Product: QEMU USB Keyboard' 451 self.wait_for_console_pattern(console_pattern) 452 453 def test_arm_raspi2_uart0(self): 454 """ 455 :avocado: tags=arch:arm 456 :avocado: tags=machine:raspi2b 457 :avocado: tags=device:pl011 458 :avocado: tags=accel:tcg 459 """ 460 self.do_test_arm_raspi2(0) 461 462 def test_arm_raspi2_initrd(self): 463 """ 464 :avocado: tags=arch:arm 465 :avocado: tags=machine:raspi2b 466 """ 467 deb_url = ('http://archive.raspberrypi.org/debian/' 468 'pool/main/r/raspberrypi-firmware/' 469 'raspberrypi-kernel_1.20190215-1_armhf.deb') 470 deb_hash = 'cd284220b32128c5084037553db3c482426f3972' 471 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 472 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') 473 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') 474 475 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 476 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 477 'arm/rootfs-armv7a.cpio.gz') 478 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 479 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 480 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 481 archive.gzip_uncompress(initrd_path_gz, initrd_path) 482 483 self.vm.set_console() 484 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 485 'earlycon=pl011,0x3f201000 console=ttyAMA0 ' 486 'panic=-1 noreboot ' + 487 'dwc_otg.fiq_fsm_enable=0') 488 self.vm.add_args('-kernel', kernel_path, 489 '-dtb', dtb_path, 490 '-initrd', initrd_path, 491 '-append', kernel_command_line, 492 '-no-reboot') 493 self.vm.launch() 494 self.wait_for_console_pattern('Boot successful.') 495 496 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 497 'BCM2835') 498 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 499 '/soc/cprman@7e101000') 500 exec_command_and_wait_for_pattern(self, 'halt', 'reboot: System halted') 501 # Wait for VM to shut down gracefully 502 self.vm.wait() 503 504 def test_arm_exynos4210_initrd(self): 505 """ 506 :avocado: tags=arch:arm 507 :avocado: tags=machine:smdkc210 508 :avocado: tags=accel:tcg 509 """ 510 deb_url = ('https://snapshot.debian.org/archive/debian/' 511 '20190928T224601Z/pool/main/l/linux/' 512 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb') 513 deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82' 514 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 515 kernel_path = self.extract_from_deb(deb_path, 516 '/boot/vmlinuz-4.19.0-6-armmp') 517 dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb' 518 dtb_path = self.extract_from_deb(deb_path, dtb_path) 519 520 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 521 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 522 'arm/rootfs-armv5.cpio.gz') 523 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 524 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 525 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 526 archive.gzip_uncompress(initrd_path_gz, initrd_path) 527 528 self.vm.set_console() 529 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 530 'earlycon=exynos4210,0x13800000 earlyprintk ' + 531 'console=ttySAC0,115200n8 ' + 532 'random.trust_cpu=off cryptomgr.notests ' + 533 'cpuidle.off=1 panic=-1 noreboot') 534 535 self.vm.add_args('-kernel', kernel_path, 536 '-dtb', dtb_path, 537 '-initrd', initrd_path, 538 '-append', kernel_command_line, 539 '-no-reboot') 540 self.vm.launch() 541 542 self.wait_for_console_pattern('Boot successful.') 543 # TODO user command, for now the uart is stuck 544 545 def test_arm_cubieboard_initrd(self): 546 """ 547 :avocado: tags=arch:arm 548 :avocado: tags=machine:cubieboard 549 :avocado: tags=accel:tcg 550 """ 551 deb_url = ('https://apt.armbian.com/pool/main/l/' 552 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 553 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 554 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 555 kernel_path = self.extract_from_deb(deb_path, 556 '/boot/vmlinuz-5.10.16-sunxi') 557 dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb' 558 dtb_path = self.extract_from_deb(deb_path, dtb_path) 559 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 560 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 561 'arm/rootfs-armv5.cpio.gz') 562 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 563 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 564 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 565 archive.gzip_uncompress(initrd_path_gz, initrd_path) 566 567 self.vm.set_console() 568 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 569 'console=ttyS0,115200 ' 570 'usbcore.nousb ' 571 'panic=-1 noreboot') 572 self.vm.add_args('-kernel', kernel_path, 573 '-dtb', dtb_path, 574 '-initrd', initrd_path, 575 '-append', kernel_command_line, 576 '-no-reboot') 577 self.vm.launch() 578 self.wait_for_console_pattern('Boot successful.') 579 580 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 581 'Allwinner sun4i/sun5i') 582 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 583 'system-control@1c00000') 584 exec_command_and_wait_for_pattern(self, 'reboot', 585 'reboot: Restarting system') 586 # Wait for VM to shut down gracefully 587 self.vm.wait() 588 589 def test_arm_cubieboard_sata(self): 590 """ 591 :avocado: tags=arch:arm 592 :avocado: tags=machine:cubieboard 593 :avocado: tags=accel:tcg 594 """ 595 deb_url = ('https://apt.armbian.com/pool/main/l/' 596 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 597 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 598 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 599 kernel_path = self.extract_from_deb(deb_path, 600 '/boot/vmlinuz-5.10.16-sunxi') 601 dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb' 602 dtb_path = self.extract_from_deb(deb_path, dtb_path) 603 rootfs_url = ('https://github.com/groeck/linux-build-test/raw/' 604 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 605 'arm/rootfs-armv5.ext2.gz') 606 rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93' 607 rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 608 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 609 archive.gzip_uncompress(rootfs_path_gz, rootfs_path) 610 611 self.vm.set_console() 612 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 613 'console=ttyS0,115200 ' 614 'usbcore.nousb ' 615 'root=/dev/sda ro ' 616 'panic=-1 noreboot') 617 self.vm.add_args('-kernel', kernel_path, 618 '-dtb', dtb_path, 619 '-drive', 'if=none,format=raw,id=disk0,file=' 620 + rootfs_path, 621 '-device', 'ide-hd,bus=ide.0,drive=disk0', 622 '-append', kernel_command_line, 623 '-no-reboot') 624 self.vm.launch() 625 self.wait_for_console_pattern('Boot successful.') 626 627 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 628 'Allwinner sun4i/sun5i') 629 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 630 'sda') 631 exec_command_and_wait_for_pattern(self, 'reboot', 632 'reboot: Restarting system') 633 # Wait for VM to shut down gracefully 634 self.vm.wait() 635 636 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 637 def test_arm_cubieboard_openwrt_22_03_2(self): 638 """ 639 :avocado: tags=arch:arm 640 :avocado: tags=machine:cubieboard 641 :avocado: tags=device:sd 642 """ 643 644 # This test download a 7.5 MiB compressed image and expand it 645 # to 126 MiB. 646 image_url = ('https://downloads.openwrt.org/releases/22.03.2/targets/' 647 'sunxi/cortexa8/openwrt-22.03.2-sunxi-cortexa8-' 648 'cubietech_a10-cubieboard-ext4-sdcard.img.gz') 649 image_hash = ('94b5ecbfbc0b3b56276e5146b899eafa' 650 '2ac5dc2d08733d6705af9f144f39f554') 651 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash, 652 algorithm='sha256') 653 image_path = archive.extract(image_path_gz, self.workdir) 654 image_pow2ceil_expand(image_path) 655 656 self.vm.set_console() 657 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 658 '-nic', 'user', 659 '-no-reboot') 660 self.vm.launch() 661 662 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 663 'usbcore.nousb ' 664 'noreboot') 665 666 self.wait_for_console_pattern('U-Boot SPL') 667 668 interrupt_interactive_console_until_pattern( 669 self, 'Hit any key to stop autoboot:', '=>') 670 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 671 kernel_command_line + "'", '=>') 672 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 673 674 self.wait_for_console_pattern( 675 'Please press Enter to activate this console.') 676 677 exec_command_and_wait_for_pattern(self, ' ', 'root@') 678 679 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 680 'Allwinner sun4i/sun5i') 681 exec_command_and_wait_for_pattern(self, 'reboot', 682 'reboot: Restarting system') 683 # Wait for VM to shut down gracefully 684 self.vm.wait() 685 686 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout') 687 def test_arm_quanta_gsj(self): 688 """ 689 :avocado: tags=arch:arm 690 :avocado: tags=machine:quanta-gsj 691 :avocado: tags=accel:tcg 692 """ 693 # 25 MiB compressed, 32 MiB uncompressed. 694 image_url = ( 695 'https://github.com/hskinnemoen/openbmc/releases/download/' 696 '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') 697 image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' 698 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) 699 image_name = 'obmc.mtd' 700 image_path = os.path.join(self.workdir, image_name) 701 archive.gzip_uncompress(image_path_gz, image_path) 702 703 self.vm.set_console() 704 drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' 705 self.vm.add_args('-drive', drive_args) 706 self.vm.launch() 707 708 # Disable drivers and services that stall for a long time during boot, 709 # to avoid running past the 90-second timeout. These may be removed 710 # as the corresponding device support is added. 711 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + ( 712 'console=${console} ' 713 'mem=${mem} ' 714 'initcall_blacklist=npcm_i2c_bus_driver_init ' 715 'systemd.mask=systemd-random-seed.service ' 716 'systemd.mask=dropbearkey.service ' 717 ) 718 719 self.wait_for_console_pattern('> BootBlock by Nuvoton') 720 self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') 721 self.wait_for_console_pattern('>Skip DDR init.') 722 self.wait_for_console_pattern('U-Boot ') 723 interrupt_interactive_console_until_pattern( 724 self, 'Hit any key to stop autoboot:', 'U-Boot>') 725 exec_command_and_wait_for_pattern( 726 self, "setenv bootargs ${bootargs} " + kernel_command_line, 727 'U-Boot>') 728 exec_command_and_wait_for_pattern( 729 self, 'run romboot', 'Booting Kernel from flash') 730 self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 731 self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 732 self.wait_for_console_pattern('OpenBMC Project Reference Distro') 733 self.wait_for_console_pattern('gsj login:') 734 735 def test_arm_quanta_gsj_initrd(self): 736 """ 737 :avocado: tags=arch:arm 738 :avocado: tags=machine:quanta-gsj 739 :avocado: tags=accel:tcg 740 """ 741 initrd_url = ( 742 'https://github.com/hskinnemoen/openbmc/releases/download/' 743 '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') 744 initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' 745 initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 746 kernel_url = ( 747 'https://github.com/hskinnemoen/openbmc/releases/download/' 748 '20200711-gsj-qemu-0/uImage-gsj.bin') 749 kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' 750 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 751 dtb_url = ( 752 'https://github.com/hskinnemoen/openbmc/releases/download/' 753 '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') 754 dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' 755 dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) 756 757 self.vm.set_console() 758 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 759 'console=ttyS0,115200n8 ' 760 'earlycon=uart8250,mmio32,0xf0001000') 761 self.vm.add_args('-kernel', kernel_path, 762 '-initrd', initrd_path, 763 '-dtb', dtb_path, 764 '-append', kernel_command_line) 765 self.vm.launch() 766 767 self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 768 self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 769 self.wait_for_console_pattern( 770 'Give root password for system maintenance') 771 772 def test_arm_bpim2u(self): 773 """ 774 :avocado: tags=arch:arm 775 :avocado: tags=machine:bpim2u 776 :avocado: tags=accel:tcg 777 """ 778 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 779 'linux-image-current-sunxi_21.02.2_armhf.deb') 780 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 781 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 782 kernel_path = self.extract_from_deb(deb_path, 783 '/boot/vmlinuz-5.10.16-sunxi') 784 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 785 'sun8i-r40-bananapi-m2-ultra.dtb') 786 dtb_path = self.extract_from_deb(deb_path, dtb_path) 787 788 self.vm.set_console() 789 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 790 'console=ttyS0,115200n8 ' 791 'earlycon=uart,mmio32,0x1c28000') 792 self.vm.add_args('-kernel', kernel_path, 793 '-dtb', dtb_path, 794 '-append', kernel_command_line) 795 self.vm.launch() 796 console_pattern = 'Kernel command line: %s' % kernel_command_line 797 self.wait_for_console_pattern(console_pattern) 798 799 def test_arm_bpim2u_initrd(self): 800 """ 801 :avocado: tags=arch:arm 802 :avocado: tags=accel:tcg 803 :avocado: tags=machine:bpim2u 804 """ 805 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 806 'linux-image-current-sunxi_21.02.2_armhf.deb') 807 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 808 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 809 kernel_path = self.extract_from_deb(deb_path, 810 '/boot/vmlinuz-5.10.16-sunxi') 811 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 812 'sun8i-r40-bananapi-m2-ultra.dtb') 813 dtb_path = self.extract_from_deb(deb_path, dtb_path) 814 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 815 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 816 'arm/rootfs-armv7a.cpio.gz') 817 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 818 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 819 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 820 archive.gzip_uncompress(initrd_path_gz, initrd_path) 821 822 self.vm.set_console() 823 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 824 'console=ttyS0,115200 ' 825 'panic=-1 noreboot') 826 self.vm.add_args('-kernel', kernel_path, 827 '-dtb', dtb_path, 828 '-initrd', initrd_path, 829 '-append', kernel_command_line, 830 '-no-reboot') 831 self.vm.launch() 832 self.wait_for_console_pattern('Boot successful.') 833 834 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 835 'Allwinner sun8i Family') 836 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 837 'system-control@1c00000') 838 exec_command_and_wait_for_pattern(self, 'reboot', 839 'reboot: Restarting system') 840 # Wait for VM to shut down gracefully 841 self.vm.wait() 842 843 def test_arm_bpim2u_gmac(self): 844 """ 845 :avocado: tags=arch:arm 846 :avocado: tags=accel:tcg 847 :avocado: tags=machine:bpim2u 848 :avocado: tags=device:sd 849 """ 850 self.require_netdev('user') 851 852 deb_url = ('https://apt.armbian.com/pool/main/l/linux-5.10.16-sunxi/' 853 'linux-image-current-sunxi_21.02.2_armhf.deb') 854 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 855 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 856 kernel_path = self.extract_from_deb(deb_path, 857 '/boot/vmlinuz-5.10.16-sunxi') 858 dtb_path = ('/usr/lib/linux-image-current-sunxi/' 859 'sun8i-r40-bananapi-m2-ultra.dtb') 860 dtb_path = self.extract_from_deb(deb_path, dtb_path) 861 rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/' 862 'buildroot-baseline/20221116.0/armel/rootfs.ext2.xz') 863 rootfs_hash = 'fae32f337c7b87547b10f42599acf109da8b6d9a' 864 rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 865 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 866 archive.lzma_uncompress(rootfs_path_xz, rootfs_path) 867 image_pow2ceil_expand(rootfs_path) 868 869 self.vm.set_console() 870 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 871 'console=ttyS0,115200 ' 872 'root=b300 rootwait rw ' 873 'panic=-1 noreboot') 874 self.vm.add_args('-kernel', kernel_path, 875 '-dtb', dtb_path, 876 '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', 877 '-net', 'nic,model=gmac,netdev=host_gmac', 878 '-netdev', 'user,id=host_gmac', 879 '-append', kernel_command_line, 880 '-no-reboot') 881 self.vm.launch() 882 shell_ready = "/bin/sh: can't access tty; job control turned off" 883 self.wait_for_console_pattern(shell_ready) 884 885 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 886 'Allwinner sun8i Family') 887 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 888 'mmcblk') 889 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up', 890 'eth0: Link is Up') 891 exec_command_and_wait_for_pattern(self, 'udhcpc eth0', 892 'udhcpc: lease of 10.0.2.15 obtained') 893 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 894 '3 packets transmitted, 3 packets received, 0% packet loss') 895 exec_command_and_wait_for_pattern(self, 'reboot', 896 'reboot: Restarting system') 897 # Wait for VM to shut down gracefully 898 self.vm.wait() 899 900 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 901 def test_arm_bpim2u_openwrt_22_03_3(self): 902 """ 903 :avocado: tags=arch:arm 904 :avocado: tags=machine:bpim2u 905 :avocado: tags=device:sd 906 """ 907 908 # This test download a 8.9 MiB compressed image and expand it 909 # to 127 MiB. 910 image_url = ('https://downloads.openwrt.org/releases/22.03.3/targets/' 911 'sunxi/cortexa7/openwrt-22.03.3-sunxi-cortexa7-' 912 'sinovoip_bananapi-m2-ultra-ext4-sdcard.img.gz') 913 image_hash = ('5b41b4e11423e562c6011640f9a7cd3b' 914 'dd0a3d42b83430f7caa70a432e6cd82c') 915 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash, 916 algorithm='sha256') 917 image_path = archive.extract(image_path_gz, self.workdir) 918 image_pow2ceil_expand(image_path) 919 920 self.vm.set_console() 921 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 922 '-nic', 'user', 923 '-no-reboot') 924 self.vm.launch() 925 926 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 927 'usbcore.nousb ' 928 'noreboot') 929 930 self.wait_for_console_pattern('U-Boot SPL') 931 932 interrupt_interactive_console_until_pattern( 933 self, 'Hit any key to stop autoboot:', '=>') 934 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 935 kernel_command_line + "'", '=>') 936 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 937 938 self.wait_for_console_pattern( 939 'Please press Enter to activate this console.') 940 941 exec_command_and_wait_for_pattern(self, ' ', 'root@') 942 943 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 944 'Allwinner sun8i Family') 945 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 946 'system-control@1c00000') 947 948 def test_arm_orangepi(self): 949 """ 950 :avocado: tags=arch:arm 951 :avocado: tags=machine:orangepi-pc 952 :avocado: tags=accel:tcg 953 """ 954 deb_url = ('https://apt.armbian.com/pool/main/l/' 955 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 956 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 957 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 958 kernel_path = self.extract_from_deb(deb_path, 959 '/boot/vmlinuz-5.10.16-sunxi') 960 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 961 dtb_path = self.extract_from_deb(deb_path, dtb_path) 962 963 self.vm.set_console() 964 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 965 'console=ttyS0,115200n8 ' 966 'earlycon=uart,mmio32,0x1c28000') 967 self.vm.add_args('-kernel', kernel_path, 968 '-dtb', dtb_path, 969 '-append', kernel_command_line) 970 self.vm.launch() 971 console_pattern = 'Kernel command line: %s' % kernel_command_line 972 self.wait_for_console_pattern(console_pattern) 973 974 def test_arm_orangepi_initrd(self): 975 """ 976 :avocado: tags=arch:arm 977 :avocado: tags=accel:tcg 978 :avocado: tags=machine:orangepi-pc 979 """ 980 deb_url = ('https://apt.armbian.com/pool/main/l/' 981 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 982 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 983 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 984 kernel_path = self.extract_from_deb(deb_path, 985 '/boot/vmlinuz-5.10.16-sunxi') 986 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 987 dtb_path = self.extract_from_deb(deb_path, dtb_path) 988 initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 989 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 990 'arm/rootfs-armv7a.cpio.gz') 991 initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c' 992 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 993 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 994 archive.gzip_uncompress(initrd_path_gz, initrd_path) 995 996 self.vm.set_console() 997 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 998 'console=ttyS0,115200 ' 999 'panic=-1 noreboot') 1000 self.vm.add_args('-kernel', kernel_path, 1001 '-dtb', dtb_path, 1002 '-initrd', initrd_path, 1003 '-append', kernel_command_line, 1004 '-no-reboot') 1005 self.vm.launch() 1006 self.wait_for_console_pattern('Boot successful.') 1007 1008 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 1009 'Allwinner sun8i Family') 1010 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 1011 'system-control@1c00000') 1012 exec_command_and_wait_for_pattern(self, 'reboot', 1013 'reboot: Restarting system') 1014 # Wait for VM to shut down gracefully 1015 self.vm.wait() 1016 1017 def test_arm_orangepi_sd(self): 1018 """ 1019 :avocado: tags=arch:arm 1020 :avocado: tags=accel:tcg 1021 :avocado: tags=machine:orangepi-pc 1022 :avocado: tags=device:sd 1023 """ 1024 self.require_netdev('user') 1025 1026 deb_url = ('https://apt.armbian.com/pool/main/l/' 1027 'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb') 1028 deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0' 1029 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1030 kernel_path = self.extract_from_deb(deb_path, 1031 '/boot/vmlinuz-5.10.16-sunxi') 1032 dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb' 1033 dtb_path = self.extract_from_deb(deb_path, dtb_path) 1034 rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/' 1035 'buildroot-baseline/20221116.0/armel/rootfs.ext2.xz') 1036 rootfs_hash = 'fae32f337c7b87547b10f42599acf109da8b6d9a' 1037 rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 1038 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 1039 archive.lzma_uncompress(rootfs_path_xz, rootfs_path) 1040 image_pow2ceil_expand(rootfs_path) 1041 1042 self.vm.set_console() 1043 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1044 'console=ttyS0,115200 ' 1045 'root=/dev/mmcblk0 rootwait rw ' 1046 'panic=-1 noreboot') 1047 self.vm.add_args('-kernel', kernel_path, 1048 '-dtb', dtb_path, 1049 '-drive', 'file=' + rootfs_path + ',if=sd,format=raw', 1050 '-append', kernel_command_line, 1051 '-no-reboot') 1052 self.vm.launch() 1053 shell_ready = "/bin/sh: can't access tty; job control turned off" 1054 self.wait_for_console_pattern(shell_ready) 1055 1056 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 1057 'Allwinner sun8i Family') 1058 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 1059 'mmcblk0') 1060 exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up', 1061 'eth0: Link is Up') 1062 exec_command_and_wait_for_pattern(self, 'udhcpc eth0', 1063 'udhcpc: lease of 10.0.2.15 obtained') 1064 exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 1065 '3 packets transmitted, 3 packets received, 0% packet loss') 1066 exec_command_and_wait_for_pattern(self, 'reboot', 1067 'reboot: Restarting system') 1068 # Wait for VM to shut down gracefully 1069 self.vm.wait() 1070 1071 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 1072 def test_arm_orangepi_bionic_20_08(self): 1073 """ 1074 :avocado: tags=arch:arm 1075 :avocado: tags=machine:orangepi-pc 1076 :avocado: tags=device:sd 1077 """ 1078 1079 # This test download a 275 MiB compressed image and expand it 1080 # to 1036 MiB, but the underlying filesystem is 1552 MiB... 1081 # As we expand it to 2 GiB we are safe. 1082 1083 image_url = ('https://archive.armbian.com/orangepipc/archive/' 1084 'Armbian_20.08.1_Orangepipc_bionic_current_5.8.5.img.xz') 1085 image_hash = ('b4d6775f5673486329e45a0586bf06b6' 1086 'dbe792199fd182ac6b9c7bb6c7d3e6dd') 1087 image_path_xz = self.fetch_asset(image_url, asset_hash=image_hash, 1088 algorithm='sha256') 1089 image_path = archive.extract(image_path_xz, self.workdir) 1090 image_pow2ceil_expand(image_path) 1091 1092 self.vm.set_console() 1093 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 1094 '-nic', 'user', 1095 '-no-reboot') 1096 self.vm.launch() 1097 1098 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1099 'console=ttyS0,115200 ' 1100 'loglevel=7 ' 1101 'nosmp ' 1102 'systemd.default_timeout_start_sec=9000 ' 1103 'systemd.mask=armbian-zram-config.service ' 1104 'systemd.mask=armbian-ramlog.service') 1105 1106 self.wait_for_console_pattern('U-Boot SPL') 1107 self.wait_for_console_pattern('Autoboot in ') 1108 exec_command_and_wait_for_pattern(self, ' ', '=>') 1109 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 1110 kernel_command_line + "'", '=>') 1111 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 1112 1113 self.wait_for_console_pattern('systemd[1]: Set hostname ' + 1114 'to <orangepipc>') 1115 self.wait_for_console_pattern('Starting Load Kernel Modules...') 1116 1117 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 1118 def test_arm_orangepi_uboot_netbsd9(self): 1119 """ 1120 :avocado: tags=arch:arm 1121 :avocado: tags=machine:orangepi-pc 1122 :avocado: tags=device:sd 1123 :avocado: tags=os:netbsd 1124 """ 1125 # This test download a 304MB compressed image and expand it to 2GB 1126 deb_url = ('http://snapshot.debian.org/archive/debian/' 1127 '20200108T145233Z/pool/main/u/u-boot/' 1128 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb') 1129 deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99' 1130 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1131 # We use the common OrangePi PC 'plus' build of U-Boot for our secondary 1132 # program loader (SPL). We will then set the path to the more specific 1133 # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt, 1134 # before to boot NetBSD. 1135 uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin' 1136 uboot_path = self.extract_from_deb(deb_path, uboot_path) 1137 image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/' 1138 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz') 1139 image_hash = '2babb29d36d8360adcb39c09e31060945259917a' 1140 image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) 1141 image_path = os.path.join(self.workdir, 'armv7.img') 1142 archive.gzip_uncompress(image_path_gz, image_path) 1143 image_pow2ceil_expand(image_path) 1144 image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path 1145 1146 # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc 1147 with open(uboot_path, 'rb') as f_in: 1148 with open(image_path, 'r+b') as f_out: 1149 f_out.seek(8 * 1024) 1150 shutil.copyfileobj(f_in, f_out) 1151 1152 self.vm.set_console() 1153 self.vm.add_args('-nic', 'user', 1154 '-drive', image_drive_args, 1155 '-global', 'allwinner-rtc.base-year=2000', 1156 '-no-reboot') 1157 self.vm.launch() 1158 wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1') 1159 interrupt_interactive_console_until_pattern(self, 1160 'Hit any key to stop autoboot:', 1161 'switch to partitions #0, OK') 1162 1163 exec_command_and_wait_for_pattern(self, '', '=>') 1164 cmd = 'setenv bootargs root=ld0a' 1165 exec_command_and_wait_for_pattern(self, cmd, '=>') 1166 cmd = 'setenv kernel netbsd-GENERIC.ub' 1167 exec_command_and_wait_for_pattern(self, cmd, '=>') 1168 cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb' 1169 exec_command_and_wait_for_pattern(self, cmd, '=>') 1170 cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; " 1171 "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; " 1172 "fdt addr ${fdt_addr_r}; " 1173 "bootm ${kernel_addr_r} - ${fdt_addr_r}'") 1174 exec_command_and_wait_for_pattern(self, cmd, '=>') 1175 1176 exec_command_and_wait_for_pattern(self, 'boot', 1177 'Booting kernel from Legacy Image') 1178 wait_for_console_pattern(self, 'Starting kernel ...') 1179 wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)') 1180 # Wait for user-space 1181 wait_for_console_pattern(self, 'Starting root file system check') 1182 1183 def test_aarch64_raspi3_atf(self): 1184 """ 1185 :avocado: tags=accel:tcg 1186 :avocado: tags=arch:aarch64 1187 :avocado: tags=machine:raspi3b 1188 :avocado: tags=cpu:cortex-a53 1189 :avocado: tags=device:pl011 1190 :avocado: tags=atf 1191 """ 1192 zip_url = ('https://github.com/pbatard/RPi3/releases/download/' 1193 'v1.15/RPi3_UEFI_Firmware_v1.15.zip') 1194 zip_hash = '74b3bd0de92683cadb14e008a7575e1d0c3cafb9' 1195 zip_path = self.fetch_asset(zip_url, asset_hash=zip_hash) 1196 1197 archive.extract(zip_path, self.workdir) 1198 efi_fd = os.path.join(self.workdir, 'RPI_EFI.fd') 1199 1200 self.vm.set_console(console_index=1) 1201 self.vm.add_args('-nodefaults', 1202 '-device', 'loader,file=%s,force-raw=true' % efi_fd) 1203 self.vm.launch() 1204 self.wait_for_console_pattern('version UEFI Firmware v1.15') 1205 1206 def test_s390x_s390_ccw_virtio(self): 1207 """ 1208 :avocado: tags=arch:s390x 1209 :avocado: tags=machine:s390-ccw-virtio 1210 """ 1211 kernel_url = ('https://archives.fedoraproject.org/pub/archive' 1212 '/fedora-secondary/releases/29/Everything/s390x/os/images' 1213 '/kernel.img') 1214 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313' 1215 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 1216 1217 self.vm.set_console() 1218 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0' 1219 self.vm.add_args('-nodefaults', 1220 '-kernel', kernel_path, 1221 '-append', kernel_command_line) 1222 self.vm.launch() 1223 console_pattern = 'Kernel command line: %s' % kernel_command_line 1224 self.wait_for_console_pattern(console_pattern) 1225 1226 def test_alpha_clipper(self): 1227 """ 1228 :avocado: tags=arch:alpha 1229 :avocado: tags=machine:clipper 1230 """ 1231 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/' 1232 'installer-alpha/20090123lenny10/images/cdrom/vmlinuz') 1233 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3' 1234 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 1235 1236 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir) 1237 1238 self.vm.set_console() 1239 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 1240 self.vm.add_args('-nodefaults', 1241 '-kernel', uncompressed_kernel, 1242 '-append', kernel_command_line) 1243 self.vm.launch() 1244 console_pattern = 'Kernel command line: %s' % kernel_command_line 1245 self.wait_for_console_pattern(console_pattern) 1246 1247 def test_m68k_q800(self): 1248 """ 1249 :avocado: tags=arch:m68k 1250 :avocado: tags=machine:q800 1251 """ 1252 deb_url = ('https://snapshot.debian.org/archive/debian-ports' 1253 '/20191021T083923Z/pool-m68k/main' 1254 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb') 1255 deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1' 1256 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 1257 kernel_path = self.extract_from_deb(deb_path, 1258 '/boot/vmlinux-5.3.0-1-m68k') 1259 1260 self.vm.set_console() 1261 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 1262 'console=ttyS0 vga=off') 1263 self.vm.add_args('-kernel', kernel_path, 1264 '-append', kernel_command_line) 1265 self.vm.launch() 1266 console_pattern = 'Kernel command line: %s' % kernel_command_line 1267 self.wait_for_console_pattern(console_pattern) 1268 console_pattern = 'No filesystem could mount root' 1269 self.wait_for_console_pattern(console_pattern) 1270 1271 def do_test_advcal_2018(self, day, tar_hash, kernel_name, console=0): 1272 tar_url = ('https://qemu-advcal.gitlab.io' 1273 '/qac-best-of-multiarch/download/day' + day + '.tar.xz') 1274 file_path = self.fetch_asset(tar_url, asset_hash=tar_hash) 1275 archive.extract(file_path, self.workdir) 1276 self.vm.set_console(console_index=console) 1277 self.vm.add_args('-kernel', 1278 self.workdir + '/day' + day + '/' + kernel_name) 1279 self.vm.launch() 1280 self.wait_for_console_pattern('QEMU advent calendar') 1281 1282 def test_arm_vexpressa9(self): 1283 """ 1284 :avocado: tags=arch:arm 1285 :avocado: tags=machine:vexpress-a9 1286 """ 1287 tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b' 1288 self.vm.add_args('-dtb', self.workdir + '/day16/vexpress-v2p-ca9.dtb') 1289 self.do_test_advcal_2018('16', tar_hash, 'winter.zImage') 1290 1291 def test_arm_ast2600_debian(self): 1292 """ 1293 :avocado: tags=arch:arm 1294 :avocado: tags=machine:rainier-bmc 1295 """ 1296 deb_url = ('http://snapshot.debian.org/archive/debian/' 1297 '20220606T211338Z/' 1298 'pool/main/l/linux/' 1299 'linux-image-5.17.0-2-armmp_5.17.6-1%2Bb1_armhf.deb') 1300 deb_hash = '8acb2b4439faedc2f3ed4bdb2847ad4f6e0491f73debaeb7f660c8abe4dcdc0e' 1301 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash, 1302 algorithm='sha256') 1303 kernel_path = self.extract_from_deb(deb_path, '/boot/vmlinuz-5.17.0-2-armmp') 1304 dtb_path = self.extract_from_deb(deb_path, 1305 '/usr/lib/linux-image-5.17.0-2-armmp/aspeed-bmc-ibm-rainier.dtb') 1306 1307 self.vm.set_console() 1308 self.vm.add_args('-kernel', kernel_path, 1309 '-dtb', dtb_path, 1310 '-net', 'nic') 1311 self.vm.launch() 1312 self.wait_for_console_pattern("Booting Linux on physical CPU 0xf00") 1313 self.wait_for_console_pattern("SMP: Total of 2 processors activated") 1314 self.wait_for_console_pattern("No filesystem could mount root") 1315 1316 def test_m68k_mcf5208evb(self): 1317 """ 1318 :avocado: tags=arch:m68k 1319 :avocado: tags=machine:mcf5208evb 1320 """ 1321 tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c' 1322 self.do_test_advcal_2018('07', tar_hash, 'sanity-clause.elf') 1323 1324 def test_or1k_sim(self): 1325 """ 1326 :avocado: tags=arch:or1k 1327 :avocado: tags=machine:or1k-sim 1328 """ 1329 tar_hash = '20334cdaf386108c530ff0badaecc955693027dd' 1330 self.do_test_advcal_2018('20', tar_hash, 'vmlinux') 1331 1332 def test_nios2_10m50(self): 1333 """ 1334 :avocado: tags=arch:nios2 1335 :avocado: tags=machine:10m50-ghrd 1336 """ 1337 tar_hash = 'e4251141726c412ac0407c5a6bceefbbff018918' 1338 self.do_test_advcal_2018('14', tar_hash, 'vmlinux.elf') 1339 1340 def test_ppc64_e500(self): 1341 """ 1342 :avocado: tags=arch:ppc64 1343 :avocado: tags=machine:ppce500 1344 :avocado: tags=cpu:e5500 1345 :avocado: tags=accel:tcg 1346 """ 1347 self.require_accelerator("tcg") 1348 tar_hash = '6951d86d644b302898da2fd701739c9406527fe1' 1349 self.do_test_advcal_2018('19', tar_hash, 'uImage') 1350 1351 def do_test_ppc64_powernv(self, proc): 1352 self.require_accelerator("tcg") 1353 images_url = ('https://github.com/open-power/op-build/releases/download/v2.7/') 1354 1355 kernel_url = images_url + 'zImage.epapr' 1356 kernel_hash = '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd' 1357 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash, 1358 algorithm='sha256') 1359 self.vm.set_console() 1360 self.vm.add_args('-kernel', kernel_path, 1361 '-append', 'console=tty0 console=hvc0', 1362 '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0', 1363 '-device', 'nvme,bus=pcie.2,addr=0x0,serial=1234', 1364 '-device', 'e1000e,bus=bridge1,addr=0x3', 1365 '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2') 1366 self.vm.launch() 1367 1368 self.wait_for_console_pattern("CPU: " + proc + " generation processor") 1369 self.wait_for_console_pattern("zImage starting: loaded") 1370 self.wait_for_console_pattern("Run /init as init process") 1371 self.wait_for_console_pattern("Creating 1 MTD partitions") 1372 1373 def test_ppc_powernv8(self): 1374 """ 1375 :avocado: tags=arch:ppc64 1376 :avocado: tags=machine:powernv8 1377 :avocado: tags=accel:tcg 1378 """ 1379 self.do_test_ppc64_powernv('P8') 1380 1381 def test_ppc_powernv9(self): 1382 """ 1383 :avocado: tags=arch:ppc64 1384 :avocado: tags=machine:powernv9 1385 :avocado: tags=accel:tcg 1386 """ 1387 self.do_test_ppc64_powernv('P9') 1388 1389 def test_ppc_g3beige(self): 1390 """ 1391 :avocado: tags=arch:ppc 1392 :avocado: tags=machine:g3beige 1393 :avocado: tags=accel:tcg 1394 """ 1395 # TODO: g3beige works with kvm_pr but we don't have a 1396 # reliable way ATM (e.g. looking at /proc/modules) to detect 1397 # whether we're running kvm_hv or kvm_pr. For now let's 1398 # disable this test if we don't have TCG support. 1399 self.require_accelerator("tcg") 1400 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc' 1401 self.vm.add_args('-M', 'graphics=off') 1402 self.do_test_advcal_2018('15', tar_hash, 'invaders.elf') 1403 1404 def test_ppc_mac99(self): 1405 """ 1406 :avocado: tags=arch:ppc 1407 :avocado: tags=machine:mac99 1408 :avocado: tags=accel:tcg 1409 """ 1410 # TODO: mac99 works with kvm_pr but we don't have a 1411 # reliable way ATM (e.g. looking at /proc/modules) to detect 1412 # whether we're running kvm_hv or kvm_pr. For now let's 1413 # disable this test if we don't have TCG support. 1414 self.require_accelerator("tcg") 1415 tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc' 1416 self.vm.add_args('-M', 'graphics=off') 1417 self.do_test_advcal_2018('15', tar_hash, 'invaders.elf') 1418 1419 # This test has a 6-10% failure rate on various hosts that look 1420 # like issues with a buggy kernel. As a result we don't want it 1421 # gating releases on Gitlab. 1422 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 1423 def test_sh4_r2d(self): 1424 """ 1425 :avocado: tags=arch:sh4 1426 :avocado: tags=machine:r2d 1427 """ 1428 tar_hash = 'fe06a4fd8ccbf2e27928d64472939d47829d4c7e' 1429 self.vm.add_args('-append', 'console=ttySC1') 1430 self.do_test_advcal_2018('09', tar_hash, 'zImage', console=1) 1431 1432 def test_sparc_ss20(self): 1433 """ 1434 :avocado: tags=arch:sparc 1435 :avocado: tags=machine:SS-20 1436 """ 1437 tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f' 1438 self.do_test_advcal_2018('11', tar_hash, 'zImage.elf') 1439 1440 def test_xtensa_lx60(self): 1441 """ 1442 :avocado: tags=arch:xtensa 1443 :avocado: tags=machine:lx60 1444 :avocado: tags=cpu:dc233c 1445 """ 1446 tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34' 1447 self.do_test_advcal_2018('02', tar_hash, 'santas-sleigh-ride.elf') 1448