1bbbd9b6eSWillian Rampazzo# Functional test that boots a Linux kernel and checks the console 2bbbd9b6eSWillian Rampazzo# 3bbbd9b6eSWillian Rampazzo# Copyright (c) 2018 Red Hat, Inc. 4bbbd9b6eSWillian Rampazzo# 5bbbd9b6eSWillian Rampazzo# Author: 6bbbd9b6eSWillian Rampazzo# Cleber Rosa <crosa@redhat.com> 7bbbd9b6eSWillian Rampazzo# 8bbbd9b6eSWillian Rampazzo# This work is licensed under the terms of the GNU GPL, version 2 or 9bbbd9b6eSWillian Rampazzo# later. See the COPYING file in the top-level directory. 10bbbd9b6eSWillian Rampazzo 11bbbd9b6eSWillian Rampazzoimport os 12bbbd9b6eSWillian Rampazzoimport lzma 13bbbd9b6eSWillian Rampazzoimport gzip 14bbbd9b6eSWillian Rampazzoimport shutil 15bbbd9b6eSWillian Rampazzo 16bbbd9b6eSWillian Rampazzofrom avocado import skip 17bbbd9b6eSWillian Rampazzofrom avocado import skipUnless 189b45cc99SAlex Bennéefrom avocado import skipUnless 192283b627SPhilippe Mathieu-Daudéfrom avocado_qemu import QemuSystemTest 20bbbd9b6eSWillian Rampazzofrom avocado_qemu import exec_command 21bbbd9b6eSWillian Rampazzofrom avocado_qemu import exec_command_and_wait_for_pattern 22bbbd9b6eSWillian Rampazzofrom avocado_qemu import interrupt_interactive_console_until_pattern 23bbbd9b6eSWillian Rampazzofrom avocado_qemu import wait_for_console_pattern 24bbbd9b6eSWillian Rampazzofrom avocado.utils import process 25bbbd9b6eSWillian Rampazzofrom avocado.utils import archive 26bbbd9b6eSWillian Rampazzo 27bbbd9b6eSWillian Rampazzo""" 28bbbd9b6eSWillian RampazzoRound up to next power of 2 29bbbd9b6eSWillian Rampazzo""" 30bbbd9b6eSWillian Rampazzodef pow2ceil(x): 31bbbd9b6eSWillian Rampazzo return 1 if x == 0 else 2**(x - 1).bit_length() 32bbbd9b6eSWillian Rampazzo 33ffd0cac7SPhilippe Mathieu-Daudédef file_truncate(path, size): 34ffd0cac7SPhilippe Mathieu-Daudé if size != os.path.getsize(path): 35ffd0cac7SPhilippe Mathieu-Daudé with open(path, 'ab+') as fd: 36ffd0cac7SPhilippe Mathieu-Daudé fd.truncate(size) 37ffd0cac7SPhilippe Mathieu-Daudé 38bbbd9b6eSWillian Rampazzo""" 39bbbd9b6eSWillian RampazzoExpand file size to next power of 2 40bbbd9b6eSWillian Rampazzo""" 41bbbd9b6eSWillian Rampazzodef image_pow2ceil_expand(path): 42bbbd9b6eSWillian Rampazzo size = os.path.getsize(path) 43bbbd9b6eSWillian Rampazzo size_aligned = pow2ceil(size) 44bbbd9b6eSWillian Rampazzo if size != size_aligned: 45bbbd9b6eSWillian Rampazzo with open(path, 'ab+') as fd: 46bbbd9b6eSWillian Rampazzo fd.truncate(size_aligned) 47bbbd9b6eSWillian Rampazzo 482283b627SPhilippe Mathieu-Daudéclass LinuxKernelTest(QemuSystemTest): 49bbbd9b6eSWillian Rampazzo KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 50bbbd9b6eSWillian Rampazzo 51bbbd9b6eSWillian Rampazzo def wait_for_console_pattern(self, success_message, vm=None): 52bbbd9b6eSWillian Rampazzo wait_for_console_pattern(self, success_message, 53bbbd9b6eSWillian Rampazzo failure_message='Kernel panic - not syncing', 54bbbd9b6eSWillian Rampazzo vm=vm) 55bbbd9b6eSWillian Rampazzo 56bbbd9b6eSWillian Rampazzo def extract_from_deb(self, deb, path): 57bbbd9b6eSWillian Rampazzo """ 58bbbd9b6eSWillian Rampazzo Extracts a file from a deb package into the test workdir 59bbbd9b6eSWillian Rampazzo 60bbbd9b6eSWillian Rampazzo :param deb: path to the deb archive 61bbbd9b6eSWillian Rampazzo :param path: path within the deb archive of the file to be extracted 62bbbd9b6eSWillian Rampazzo :returns: path of the extracted file 63bbbd9b6eSWillian Rampazzo """ 64bbbd9b6eSWillian Rampazzo cwd = os.getcwd() 65bbbd9b6eSWillian Rampazzo os.chdir(self.workdir) 66bbbd9b6eSWillian Rampazzo file_path = process.run("ar t %s" % deb).stdout_text.split()[2] 67bbbd9b6eSWillian Rampazzo process.run("ar x %s %s" % (deb, file_path)) 68bbbd9b6eSWillian Rampazzo archive.extract(file_path, self.workdir) 69bbbd9b6eSWillian Rampazzo os.chdir(cwd) 70bbbd9b6eSWillian Rampazzo # Return complete path to extracted file. Because callers to 71bbbd9b6eSWillian Rampazzo # extract_from_deb() specify 'path' with a leading slash, it is 72bbbd9b6eSWillian Rampazzo # necessary to use os.path.relpath() as otherwise os.path.join() 73bbbd9b6eSWillian Rampazzo # interprets it as an absolute path and drops the self.workdir part. 74bbbd9b6eSWillian Rampazzo return os.path.normpath(os.path.join(self.workdir, 75bbbd9b6eSWillian Rampazzo os.path.relpath(path, '/'))) 76bbbd9b6eSWillian Rampazzo 77bbbd9b6eSWillian Rampazzo def extract_from_rpm(self, rpm, path): 78bbbd9b6eSWillian Rampazzo """ 79bbbd9b6eSWillian Rampazzo Extracts a file from an RPM package into the test workdir. 80bbbd9b6eSWillian Rampazzo 81bbbd9b6eSWillian Rampazzo :param rpm: path to the rpm archive 82bbbd9b6eSWillian Rampazzo :param path: path within the rpm archive of the file to be extracted 83bbbd9b6eSWillian Rampazzo needs to be a relative path (starting with './') because 84bbbd9b6eSWillian Rampazzo cpio(1), which is used to extract the file, expects that. 85bbbd9b6eSWillian Rampazzo :returns: path of the extracted file 86bbbd9b6eSWillian Rampazzo """ 87bbbd9b6eSWillian Rampazzo cwd = os.getcwd() 88bbbd9b6eSWillian Rampazzo os.chdir(self.workdir) 89bbbd9b6eSWillian Rampazzo process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True) 90bbbd9b6eSWillian Rampazzo os.chdir(cwd) 91bbbd9b6eSWillian Rampazzo return os.path.normpath(os.path.join(self.workdir, path)) 92bbbd9b6eSWillian Rampazzo 93bbbd9b6eSWillian Rampazzoclass BootLinuxConsole(LinuxKernelTest): 94bbbd9b6eSWillian Rampazzo """ 95bbbd9b6eSWillian Rampazzo Boots a Linux kernel and checks that the console is operational and the 96bbbd9b6eSWillian Rampazzo kernel command line is properly passed from QEMU to the kernel 97bbbd9b6eSWillian Rampazzo """ 98bbbd9b6eSWillian Rampazzo timeout = 90 99bbbd9b6eSWillian Rampazzo 100bbbd9b6eSWillian Rampazzo def test_x86_64_pc(self): 101bbbd9b6eSWillian Rampazzo """ 102bbbd9b6eSWillian Rampazzo :avocado: tags=arch:x86_64 103bbbd9b6eSWillian Rampazzo :avocado: tags=machine:pc 104bbbd9b6eSWillian Rampazzo """ 105bbbd9b6eSWillian Rampazzo kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 106bbbd9b6eSWillian Rampazzo '/linux/releases/29/Everything/x86_64/os/images/pxeboot' 107bbbd9b6eSWillian Rampazzo '/vmlinuz') 108bbbd9b6eSWillian Rampazzo kernel_hash = '23bebd2680757891cf7adedb033532163a792495' 109bbbd9b6eSWillian Rampazzo kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 110bbbd9b6eSWillian Rampazzo 111bbbd9b6eSWillian Rampazzo self.vm.set_console() 112bbbd9b6eSWillian Rampazzo kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 113bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 114bbbd9b6eSWillian Rampazzo '-append', kernel_command_line) 115bbbd9b6eSWillian Rampazzo self.vm.launch() 116bbbd9b6eSWillian Rampazzo console_pattern = 'Kernel command line: %s' % kernel_command_line 117bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern(console_pattern) 118bbbd9b6eSWillian Rampazzo 119bbbd9b6eSWillian Rampazzo def test_aarch64_xlnx_versal_virt(self): 120bbbd9b6eSWillian Rampazzo """ 121bbbd9b6eSWillian Rampazzo :avocado: tags=arch:aarch64 122bbbd9b6eSWillian Rampazzo :avocado: tags=machine:xlnx-versal-virt 123bbbd9b6eSWillian Rampazzo :avocado: tags=device:pl011 124bbbd9b6eSWillian Rampazzo :avocado: tags=device:arm_gicv3 125bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 126bbbd9b6eSWillian Rampazzo """ 127bbbd9b6eSWillian Rampazzo images_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/' 128bbbd9b6eSWillian Rampazzo 'bionic-updates/main/installer-arm64/' 1297fcc3f75SThomas Huth '20101020ubuntu543.19/images/') 130bbbd9b6eSWillian Rampazzo kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux' 1317fcc3f75SThomas Huth kernel_hash = 'e167757620640eb26de0972f578741924abb3a82' 132bbbd9b6eSWillian Rampazzo kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 133bbbd9b6eSWillian Rampazzo 134bbbd9b6eSWillian Rampazzo initrd_url = images_url + 'netboot/ubuntu-installer/arm64/initrd.gz' 1357fcc3f75SThomas Huth initrd_hash = 'cab5cb3fcefca8408aa5aae57f24574bfce8bdb9' 136bbbd9b6eSWillian Rampazzo initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 137bbbd9b6eSWillian Rampazzo 138bbbd9b6eSWillian Rampazzo self.vm.set_console() 139bbbd9b6eSWillian Rampazzo self.vm.add_args('-m', '2G', 140bbbd9b6eSWillian Rampazzo '-accel', 'tcg', 141bbbd9b6eSWillian Rampazzo '-kernel', kernel_path, 142bbbd9b6eSWillian Rampazzo '-initrd', initrd_path) 143bbbd9b6eSWillian Rampazzo self.vm.launch() 144bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Checked W+X mappings: passed') 145bbbd9b6eSWillian Rampazzo 146bbbd9b6eSWillian Rampazzo def test_arm_virt(self): 147bbbd9b6eSWillian Rampazzo """ 148bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 149bbbd9b6eSWillian Rampazzo :avocado: tags=machine:virt 150bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 151bbbd9b6eSWillian Rampazzo """ 152bbbd9b6eSWillian Rampazzo kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora' 153bbbd9b6eSWillian Rampazzo '/linux/releases/29/Everything/armhfp/os/images/pxeboot' 154bbbd9b6eSWillian Rampazzo '/vmlinuz') 155bbbd9b6eSWillian Rampazzo kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4' 156bbbd9b6eSWillian Rampazzo kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 157bbbd9b6eSWillian Rampazzo 158bbbd9b6eSWillian Rampazzo self.vm.set_console() 159bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 160bbbd9b6eSWillian Rampazzo 'console=ttyAMA0') 161bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 162bbbd9b6eSWillian Rampazzo '-append', kernel_command_line) 163bbbd9b6eSWillian Rampazzo self.vm.launch() 164bbbd9b6eSWillian Rampazzo console_pattern = 'Kernel command line: %s' % kernel_command_line 165bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern(console_pattern) 166bbbd9b6eSWillian Rampazzo 167bbbd9b6eSWillian Rampazzo def test_arm_emcraft_sf2(self): 168bbbd9b6eSWillian Rampazzo """ 169bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 170bbbd9b6eSWillian Rampazzo :avocado: tags=machine:emcraft-sf2 171bbbd9b6eSWillian Rampazzo :avocado: tags=endian:little 172bbbd9b6eSWillian Rampazzo :avocado: tags=u-boot 173bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 174bbbd9b6eSWillian Rampazzo """ 1750793fe01SPeter Maydell self.require_netdev('user') 1760793fe01SPeter Maydell 177bbbd9b6eSWillian Rampazzo uboot_url = ('https://raw.githubusercontent.com/' 178bbbd9b6eSWillian Rampazzo 'Subbaraya-Sundeep/qemu-test-binaries/' 179bbbd9b6eSWillian Rampazzo 'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot') 180bbbd9b6eSWillian Rampazzo uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2' 181bbbd9b6eSWillian Rampazzo uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash) 182bbbd9b6eSWillian Rampazzo spi_url = ('https://raw.githubusercontent.com/' 183bbbd9b6eSWillian Rampazzo 'Subbaraya-Sundeep/qemu-test-binaries/' 184bbbd9b6eSWillian Rampazzo 'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin') 185bbbd9b6eSWillian Rampazzo spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501' 186bbbd9b6eSWillian Rampazzo spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash) 187*4ec88f16SCleber Rosa spi_path_rw = os.path.join(self.workdir, os.path.basename(spi_path)) 188*4ec88f16SCleber Rosa shutil.copy(spi_path, spi_path_rw) 189bbbd9b6eSWillian Rampazzo 190*4ec88f16SCleber Rosa file_truncate(spi_path_rw, 16 << 20) # Spansion S25FL128SDPBHICO is 16 MiB 191a7f16aedSPhilippe Mathieu-Daudé 192bbbd9b6eSWillian Rampazzo self.vm.set_console() 193bbbd9b6eSWillian Rampazzo kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE 194bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', uboot_path, 195bbbd9b6eSWillian Rampazzo '-append', kernel_command_line, 196*4ec88f16SCleber Rosa '-drive', 'file=' + spi_path_rw + ',if=mtd,format=raw', 197bbbd9b6eSWillian Rampazzo '-no-reboot') 198bbbd9b6eSWillian Rampazzo self.vm.launch() 199bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Enter \'help\' for a list') 200bbbd9b6eSWillian Rampazzo 201bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15', 202bbbd9b6eSWillian Rampazzo 'eth0: link becomes ready') 203bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', 204bbbd9b6eSWillian Rampazzo '3 packets transmitted, 3 packets received, 0% packet loss') 205bbbd9b6eSWillian Rampazzo 206bbbd9b6eSWillian Rampazzo def test_arm_exynos4210_initrd(self): 207bbbd9b6eSWillian Rampazzo """ 208bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 209bbbd9b6eSWillian Rampazzo :avocado: tags=machine:smdkc210 210bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 211bbbd9b6eSWillian Rampazzo """ 212bbbd9b6eSWillian Rampazzo deb_url = ('https://snapshot.debian.org/archive/debian/' 213bbbd9b6eSWillian Rampazzo '20190928T224601Z/pool/main/l/linux/' 214bbbd9b6eSWillian Rampazzo 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb') 215bbbd9b6eSWillian Rampazzo deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82' 216bbbd9b6eSWillian Rampazzo deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 217bbbd9b6eSWillian Rampazzo kernel_path = self.extract_from_deb(deb_path, 218bbbd9b6eSWillian Rampazzo '/boot/vmlinuz-4.19.0-6-armmp') 219bbbd9b6eSWillian Rampazzo dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb' 220bbbd9b6eSWillian Rampazzo dtb_path = self.extract_from_deb(deb_path, dtb_path) 221bbbd9b6eSWillian Rampazzo 222bbbd9b6eSWillian Rampazzo initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 223bbbd9b6eSWillian Rampazzo '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 224bbbd9b6eSWillian Rampazzo 'arm/rootfs-armv5.cpio.gz') 225bbbd9b6eSWillian Rampazzo initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 226bbbd9b6eSWillian Rampazzo initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 227bbbd9b6eSWillian Rampazzo initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 228bbbd9b6eSWillian Rampazzo archive.gzip_uncompress(initrd_path_gz, initrd_path) 229bbbd9b6eSWillian Rampazzo 230bbbd9b6eSWillian Rampazzo self.vm.set_console() 231bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 232bbbd9b6eSWillian Rampazzo 'earlycon=exynos4210,0x13800000 earlyprintk ' + 233bbbd9b6eSWillian Rampazzo 'console=ttySAC0,115200n8 ' + 234bbbd9b6eSWillian Rampazzo 'random.trust_cpu=off cryptomgr.notests ' + 235bbbd9b6eSWillian Rampazzo 'cpuidle.off=1 panic=-1 noreboot') 236bbbd9b6eSWillian Rampazzo 237bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 238bbbd9b6eSWillian Rampazzo '-dtb', dtb_path, 239bbbd9b6eSWillian Rampazzo '-initrd', initrd_path, 240bbbd9b6eSWillian Rampazzo '-append', kernel_command_line, 241bbbd9b6eSWillian Rampazzo '-no-reboot') 242bbbd9b6eSWillian Rampazzo self.vm.launch() 243bbbd9b6eSWillian Rampazzo 244bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Boot successful.') 245bbbd9b6eSWillian Rampazzo # TODO user command, for now the uart is stuck 246bbbd9b6eSWillian Rampazzo 247bbbd9b6eSWillian Rampazzo def test_arm_cubieboard_initrd(self): 248bbbd9b6eSWillian Rampazzo """ 249bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 250bbbd9b6eSWillian Rampazzo :avocado: tags=machine:cubieboard 251bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 252bbbd9b6eSWillian Rampazzo """ 253bbbd9b6eSWillian Rampazzo deb_url = ('https://apt.armbian.com/pool/main/l/' 254dcc5c018SPeter Maydell 'linux-6.6.16/linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb') 255dcc5c018SPeter Maydell deb_hash = 'f7c3c8c5432f765445dc6e7eab02f3bbe668256b' 256bbbd9b6eSWillian Rampazzo deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 257bbbd9b6eSWillian Rampazzo kernel_path = self.extract_from_deb(deb_path, 258dcc5c018SPeter Maydell '/boot/vmlinuz-6.6.16-current-sunxi') 259dcc5c018SPeter Maydell dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb' 260bbbd9b6eSWillian Rampazzo dtb_path = self.extract_from_deb(deb_path, dtb_path) 261bbbd9b6eSWillian Rampazzo initrd_url = ('https://github.com/groeck/linux-build-test/raw/' 262bbbd9b6eSWillian Rampazzo '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 263bbbd9b6eSWillian Rampazzo 'arm/rootfs-armv5.cpio.gz') 264bbbd9b6eSWillian Rampazzo initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b' 265bbbd9b6eSWillian Rampazzo initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 266bbbd9b6eSWillian Rampazzo initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 267bbbd9b6eSWillian Rampazzo archive.gzip_uncompress(initrd_path_gz, initrd_path) 268bbbd9b6eSWillian Rampazzo 269bbbd9b6eSWillian Rampazzo self.vm.set_console() 270bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 271bbbd9b6eSWillian Rampazzo 'console=ttyS0,115200 ' 272bbbd9b6eSWillian Rampazzo 'usbcore.nousb ' 273bbbd9b6eSWillian Rampazzo 'panic=-1 noreboot') 274bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 275bbbd9b6eSWillian Rampazzo '-dtb', dtb_path, 276bbbd9b6eSWillian Rampazzo '-initrd', initrd_path, 277bbbd9b6eSWillian Rampazzo '-append', kernel_command_line, 278bbbd9b6eSWillian Rampazzo '-no-reboot') 279bbbd9b6eSWillian Rampazzo self.vm.launch() 280bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Boot successful.') 281bbbd9b6eSWillian Rampazzo 282bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 283bbbd9b6eSWillian Rampazzo 'Allwinner sun4i/sun5i') 284bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 285bbbd9b6eSWillian Rampazzo 'system-control@1c00000') 286d784c5fbSStrahinja Jankovic exec_command_and_wait_for_pattern(self, 'reboot', 287d784c5fbSStrahinja Jankovic 'reboot: Restarting system') 288d784c5fbSStrahinja Jankovic # Wait for VM to shut down gracefully 289d784c5fbSStrahinja Jankovic self.vm.wait() 290bbbd9b6eSWillian Rampazzo 291bbbd9b6eSWillian Rampazzo def test_arm_cubieboard_sata(self): 292bbbd9b6eSWillian Rampazzo """ 293bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 294bbbd9b6eSWillian Rampazzo :avocado: tags=machine:cubieboard 295bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 296bbbd9b6eSWillian Rampazzo """ 297bbbd9b6eSWillian Rampazzo deb_url = ('https://apt.armbian.com/pool/main/l/' 298dcc5c018SPeter Maydell 'linux-6.6.16/linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb') 299dcc5c018SPeter Maydell deb_hash = 'f7c3c8c5432f765445dc6e7eab02f3bbe668256b' 300bbbd9b6eSWillian Rampazzo deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) 301bbbd9b6eSWillian Rampazzo kernel_path = self.extract_from_deb(deb_path, 302dcc5c018SPeter Maydell '/boot/vmlinuz-6.6.16-current-sunxi') 303dcc5c018SPeter Maydell dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb' 304bbbd9b6eSWillian Rampazzo dtb_path = self.extract_from_deb(deb_path, dtb_path) 305bbbd9b6eSWillian Rampazzo rootfs_url = ('https://github.com/groeck/linux-build-test/raw/' 306bbbd9b6eSWillian Rampazzo '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/' 307bbbd9b6eSWillian Rampazzo 'arm/rootfs-armv5.ext2.gz') 308bbbd9b6eSWillian Rampazzo rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93' 309bbbd9b6eSWillian Rampazzo rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 310bbbd9b6eSWillian Rampazzo rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 311bbbd9b6eSWillian Rampazzo archive.gzip_uncompress(rootfs_path_gz, rootfs_path) 312bbbd9b6eSWillian Rampazzo 313bbbd9b6eSWillian Rampazzo self.vm.set_console() 314bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 315bbbd9b6eSWillian Rampazzo 'console=ttyS0,115200 ' 316bbbd9b6eSWillian Rampazzo 'usbcore.nousb ' 317bbbd9b6eSWillian Rampazzo 'root=/dev/sda ro ' 318bbbd9b6eSWillian Rampazzo 'panic=-1 noreboot') 319bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 320bbbd9b6eSWillian Rampazzo '-dtb', dtb_path, 321bbbd9b6eSWillian Rampazzo '-drive', 'if=none,format=raw,id=disk0,file=' 322bbbd9b6eSWillian Rampazzo + rootfs_path, 323bbbd9b6eSWillian Rampazzo '-device', 'ide-hd,bus=ide.0,drive=disk0', 324bbbd9b6eSWillian Rampazzo '-append', kernel_command_line, 325bbbd9b6eSWillian Rampazzo '-no-reboot') 326bbbd9b6eSWillian Rampazzo self.vm.launch() 327bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Boot successful.') 328bbbd9b6eSWillian Rampazzo 329bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 330bbbd9b6eSWillian Rampazzo 'Allwinner sun4i/sun5i') 331bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 332bbbd9b6eSWillian Rampazzo 'sda') 333d784c5fbSStrahinja Jankovic exec_command_and_wait_for_pattern(self, 'reboot', 334d784c5fbSStrahinja Jankovic 'reboot: Restarting system') 335d784c5fbSStrahinja Jankovic # Wait for VM to shut down gracefully 336d784c5fbSStrahinja Jankovic self.vm.wait() 337bbbd9b6eSWillian Rampazzo 33822bd244aSStrahinja Jankovic @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 33922bd244aSStrahinja Jankovic def test_arm_cubieboard_openwrt_22_03_2(self): 34022bd244aSStrahinja Jankovic """ 34122bd244aSStrahinja Jankovic :avocado: tags=arch:arm 34222bd244aSStrahinja Jankovic :avocado: tags=machine:cubieboard 34322bd244aSStrahinja Jankovic :avocado: tags=device:sd 34422bd244aSStrahinja Jankovic """ 34522bd244aSStrahinja Jankovic 34622bd244aSStrahinja Jankovic # This test download a 7.5 MiB compressed image and expand it 34722bd244aSStrahinja Jankovic # to 126 MiB. 34822bd244aSStrahinja Jankovic image_url = ('https://downloads.openwrt.org/releases/22.03.2/targets/' 34922bd244aSStrahinja Jankovic 'sunxi/cortexa8/openwrt-22.03.2-sunxi-cortexa8-' 35022bd244aSStrahinja Jankovic 'cubietech_a10-cubieboard-ext4-sdcard.img.gz') 35122bd244aSStrahinja Jankovic image_hash = ('94b5ecbfbc0b3b56276e5146b899eafa' 35222bd244aSStrahinja Jankovic '2ac5dc2d08733d6705af9f144f39f554') 35322bd244aSStrahinja Jankovic image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash, 35422bd244aSStrahinja Jankovic algorithm='sha256') 35522bd244aSStrahinja Jankovic image_path = archive.extract(image_path_gz, self.workdir) 35622bd244aSStrahinja Jankovic image_pow2ceil_expand(image_path) 35722bd244aSStrahinja Jankovic 35822bd244aSStrahinja Jankovic self.vm.set_console() 35922bd244aSStrahinja Jankovic self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 36022bd244aSStrahinja Jankovic '-nic', 'user', 36122bd244aSStrahinja Jankovic '-no-reboot') 36222bd244aSStrahinja Jankovic self.vm.launch() 36322bd244aSStrahinja Jankovic 36422bd244aSStrahinja Jankovic kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 36522bd244aSStrahinja Jankovic 'usbcore.nousb ' 36622bd244aSStrahinja Jankovic 'noreboot') 36722bd244aSStrahinja Jankovic 36822bd244aSStrahinja Jankovic self.wait_for_console_pattern('U-Boot SPL') 36922bd244aSStrahinja Jankovic 37022bd244aSStrahinja Jankovic interrupt_interactive_console_until_pattern( 37122bd244aSStrahinja Jankovic self, 'Hit any key to stop autoboot:', '=>') 37222bd244aSStrahinja Jankovic exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 37322bd244aSStrahinja Jankovic kernel_command_line + "'", '=>') 37422bd244aSStrahinja Jankovic exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 37522bd244aSStrahinja Jankovic 37622bd244aSStrahinja Jankovic self.wait_for_console_pattern( 37722bd244aSStrahinja Jankovic 'Please press Enter to activate this console.') 37822bd244aSStrahinja Jankovic 37922bd244aSStrahinja Jankovic exec_command_and_wait_for_pattern(self, ' ', 'root@') 38022bd244aSStrahinja Jankovic 38122bd244aSStrahinja Jankovic exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 38222bd244aSStrahinja Jankovic 'Allwinner sun4i/sun5i') 383d784c5fbSStrahinja Jankovic exec_command_and_wait_for_pattern(self, 'reboot', 384d784c5fbSStrahinja Jankovic 'reboot: Restarting system') 385d784c5fbSStrahinja Jankovic # Wait for VM to shut down gracefully 386d784c5fbSStrahinja Jankovic self.vm.wait() 38722bd244aSStrahinja Jankovic 388bbbd9b6eSWillian Rampazzo @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout') 389bbbd9b6eSWillian Rampazzo def test_arm_quanta_gsj(self): 390bbbd9b6eSWillian Rampazzo """ 391bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 392bbbd9b6eSWillian Rampazzo :avocado: tags=machine:quanta-gsj 393bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 394bbbd9b6eSWillian Rampazzo """ 395bbbd9b6eSWillian Rampazzo # 25 MiB compressed, 32 MiB uncompressed. 396bbbd9b6eSWillian Rampazzo image_url = ( 397bbbd9b6eSWillian Rampazzo 'https://github.com/hskinnemoen/openbmc/releases/download/' 398bbbd9b6eSWillian Rampazzo '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz') 399bbbd9b6eSWillian Rampazzo image_hash = '14895e634923345cb5c8776037ff7876df96f6b1' 400bbbd9b6eSWillian Rampazzo image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash) 401bbbd9b6eSWillian Rampazzo image_name = 'obmc.mtd' 402bbbd9b6eSWillian Rampazzo image_path = os.path.join(self.workdir, image_name) 403bbbd9b6eSWillian Rampazzo archive.gzip_uncompress(image_path_gz, image_path) 404bbbd9b6eSWillian Rampazzo 405bbbd9b6eSWillian Rampazzo self.vm.set_console() 406bbbd9b6eSWillian Rampazzo drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0' 407bbbd9b6eSWillian Rampazzo self.vm.add_args('-drive', drive_args) 408bbbd9b6eSWillian Rampazzo self.vm.launch() 409bbbd9b6eSWillian Rampazzo 410bbbd9b6eSWillian Rampazzo # Disable drivers and services that stall for a long time during boot, 411bbbd9b6eSWillian Rampazzo # to avoid running past the 90-second timeout. These may be removed 412bbbd9b6eSWillian Rampazzo # as the corresponding device support is added. 413bbbd9b6eSWillian Rampazzo kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + ( 414bbbd9b6eSWillian Rampazzo 'console=${console} ' 415bbbd9b6eSWillian Rampazzo 'mem=${mem} ' 416bbbd9b6eSWillian Rampazzo 'initcall_blacklist=npcm_i2c_bus_driver_init ' 417bbbd9b6eSWillian Rampazzo 'systemd.mask=systemd-random-seed.service ' 418bbbd9b6eSWillian Rampazzo 'systemd.mask=dropbearkey.service ' 419bbbd9b6eSWillian Rampazzo ) 420bbbd9b6eSWillian Rampazzo 421bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('> BootBlock by Nuvoton') 422bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') 423bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('>Skip DDR init.') 424bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('U-Boot ') 425bbbd9b6eSWillian Rampazzo interrupt_interactive_console_until_pattern( 426bbbd9b6eSWillian Rampazzo self, 'Hit any key to stop autoboot:', 'U-Boot>') 427bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern( 428bbbd9b6eSWillian Rampazzo self, "setenv bootargs ${bootargs} " + kernel_command_line, 429bbbd9b6eSWillian Rampazzo 'U-Boot>') 430bbbd9b6eSWillian Rampazzo exec_command_and_wait_for_pattern( 431bbbd9b6eSWillian Rampazzo self, 'run romboot', 'Booting Kernel from flash') 432bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 433bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 434bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('OpenBMC Project Reference Distro') 435bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('gsj login:') 436bbbd9b6eSWillian Rampazzo 437bbbd9b6eSWillian Rampazzo def test_arm_quanta_gsj_initrd(self): 438bbbd9b6eSWillian Rampazzo """ 439bbbd9b6eSWillian Rampazzo :avocado: tags=arch:arm 440bbbd9b6eSWillian Rampazzo :avocado: tags=machine:quanta-gsj 441bbbd9b6eSWillian Rampazzo :avocado: tags=accel:tcg 442bbbd9b6eSWillian Rampazzo """ 443bbbd9b6eSWillian Rampazzo initrd_url = ( 444bbbd9b6eSWillian Rampazzo 'https://github.com/hskinnemoen/openbmc/releases/download/' 445bbbd9b6eSWillian Rampazzo '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') 446bbbd9b6eSWillian Rampazzo initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300' 447bbbd9b6eSWillian Rampazzo initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) 448bbbd9b6eSWillian Rampazzo kernel_url = ( 449bbbd9b6eSWillian Rampazzo 'https://github.com/hskinnemoen/openbmc/releases/download/' 450bbbd9b6eSWillian Rampazzo '20200711-gsj-qemu-0/uImage-gsj.bin') 451bbbd9b6eSWillian Rampazzo kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' 452bbbd9b6eSWillian Rampazzo kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 453bbbd9b6eSWillian Rampazzo dtb_url = ( 454bbbd9b6eSWillian Rampazzo 'https://github.com/hskinnemoen/openbmc/releases/download/' 455bbbd9b6eSWillian Rampazzo '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') 456bbbd9b6eSWillian Rampazzo dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4' 457bbbd9b6eSWillian Rampazzo dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash) 458bbbd9b6eSWillian Rampazzo 459bbbd9b6eSWillian Rampazzo self.vm.set_console() 460bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 461bbbd9b6eSWillian Rampazzo 'console=ttyS0,115200n8 ' 462bbbd9b6eSWillian Rampazzo 'earlycon=uart8250,mmio32,0xf0001000') 463bbbd9b6eSWillian Rampazzo self.vm.add_args('-kernel', kernel_path, 464bbbd9b6eSWillian Rampazzo '-initrd', initrd_path, 465bbbd9b6eSWillian Rampazzo '-dtb', dtb_path, 466bbbd9b6eSWillian Rampazzo '-append', kernel_command_line) 467bbbd9b6eSWillian Rampazzo self.vm.launch() 468bbbd9b6eSWillian Rampazzo 469bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') 470bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') 471bbbd9b6eSWillian Rampazzo self.wait_for_console_pattern( 472bbbd9b6eSWillian Rampazzo 'Give root password for system maintenance') 473