1bbbd9b6eSWillian Rampazzo# Functional test that boots a VM and run commands via a SSH session 2bbbd9b6eSWillian Rampazzo# 3bbbd9b6eSWillian Rampazzo# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org> 4bbbd9b6eSWillian Rampazzo# 5bbbd9b6eSWillian Rampazzo# This work is licensed under the terms of the GNU GPL, version 2 or 6bbbd9b6eSWillian Rampazzo# later. See the COPYING file in the top-level directory. 7bbbd9b6eSWillian Rampazzo 8bbbd9b6eSWillian Rampazzoimport os 9bbbd9b6eSWillian Rampazzoimport re 10bbbd9b6eSWillian Rampazzoimport base64 11bbbd9b6eSWillian Rampazzoimport logging 12bbbd9b6eSWillian Rampazzoimport time 13bbbd9b6eSWillian Rampazzo 14bbbd9b6eSWillian Rampazzofrom avocado import skipUnless 152283b627SPhilippe Mathieu-Daudéfrom avocado_qemu import LinuxSSHMixIn 162283b627SPhilippe Mathieu-Daudéfrom avocado_qemu import QemuSystemTest 17bbbd9b6eSWillian Rampazzofrom avocado_qemu import wait_for_console_pattern 18bbbd9b6eSWillian Rampazzofrom avocado.utils import process 19bbbd9b6eSWillian Rampazzofrom avocado.utils import archive 20bbbd9b6eSWillian Rampazzofrom avocado.utils import ssh 21bbbd9b6eSWillian Rampazzo 22bbbd9b6eSWillian Rampazzo 23bbbd9b6eSWillian Rampazzo@skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout') 24bbbd9b6eSWillian Rampazzo@skipUnless(ssh.SSH_CLIENT_BINARY, 'No SSH client available') 252283b627SPhilippe Mathieu-Daudéclass LinuxSSH(QemuSystemTest, LinuxSSHMixIn): 26*bc401b97SCleber Rosa """ 27*bc401b97SCleber Rosa :avocado: tags=accel:tcg 28*bc401b97SCleber Rosa """ 29bbbd9b6eSWillian Rampazzo 30bbbd9b6eSWillian Rampazzo timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg' 31bbbd9b6eSWillian Rampazzo 32bbbd9b6eSWillian Rampazzo KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 33bbbd9b6eSWillian Rampazzo VM_IP = '127.0.0.1' 34bbbd9b6eSWillian Rampazzo 35bbbd9b6eSWillian Rampazzo BASE_URL = 'https://people.debian.org/~aurel32/qemu/' 36bbbd9b6eSWillian Rampazzo IMAGE_INFO = { 37bbbd9b6eSWillian Rampazzo 'be': {'base_url': 'mips', 38bbbd9b6eSWillian Rampazzo 'image_name': 'debian_wheezy_mips_standard.qcow2', 39bbbd9b6eSWillian Rampazzo 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5', 40bbbd9b6eSWillian Rampazzo 'kernel_hash': { 41bbbd9b6eSWillian Rampazzo 32: '592e384a4edc16dade52a6cd5c785c637bcbc9ad', 42bbbd9b6eSWillian Rampazzo 64: 'db6eea7de35d36c77d8c165b6bcb222e16eb91db'} 43bbbd9b6eSWillian Rampazzo }, 44bbbd9b6eSWillian Rampazzo 'le': {'base_url': 'mipsel', 45bbbd9b6eSWillian Rampazzo 'image_name': 'debian_wheezy_mipsel_standard.qcow2', 46bbbd9b6eSWillian Rampazzo 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802', 47bbbd9b6eSWillian Rampazzo 'kernel_hash': { 48bbbd9b6eSWillian Rampazzo 32: 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a', 49bbbd9b6eSWillian Rampazzo 64: '6a7f77245acf231415a0e8b725d91ed2f3487794'} 50bbbd9b6eSWillian Rampazzo } 51bbbd9b6eSWillian Rampazzo } 52bbbd9b6eSWillian Rampazzo CPU_INFO = { 53bbbd9b6eSWillian Rampazzo 32: {'cpu': 'MIPS 24Kc', 'kernel_release': '3.2.0-4-4kc-malta'}, 54bbbd9b6eSWillian Rampazzo 64: {'cpu': 'MIPS 20Kc', 'kernel_release': '3.2.0-4-5kc-malta'} 55bbbd9b6eSWillian Rampazzo } 56bbbd9b6eSWillian Rampazzo 57bbbd9b6eSWillian Rampazzo def get_url(self, endianess, path=''): 58bbbd9b6eSWillian Rampazzo qkey = {'le': 'el', 'be': ''} 59bbbd9b6eSWillian Rampazzo return '%s/mips%s/%s' % (self.BASE_URL, qkey[endianess], path) 60bbbd9b6eSWillian Rampazzo 61bbbd9b6eSWillian Rampazzo def get_image_info(self, endianess): 62bbbd9b6eSWillian Rampazzo dinfo = self.IMAGE_INFO[endianess] 63bbbd9b6eSWillian Rampazzo image_url = self.get_url(endianess, dinfo['image_name']) 64bbbd9b6eSWillian Rampazzo image_hash = dinfo['image_hash'] 65bbbd9b6eSWillian Rampazzo return (image_url, image_hash) 66bbbd9b6eSWillian Rampazzo 67bbbd9b6eSWillian Rampazzo def get_kernel_info(self, endianess, wordsize): 68bbbd9b6eSWillian Rampazzo minfo = self.CPU_INFO[wordsize] 69bbbd9b6eSWillian Rampazzo kernel_url = self.get_url(endianess, 70bbbd9b6eSWillian Rampazzo 'vmlinux-%s' % minfo['kernel_release']) 71bbbd9b6eSWillian Rampazzo kernel_hash = self.IMAGE_INFO[endianess]['kernel_hash'][wordsize] 72bbbd9b6eSWillian Rampazzo return kernel_url, kernel_hash 73bbbd9b6eSWillian Rampazzo 74bbbd9b6eSWillian Rampazzo def ssh_disconnect_vm(self): 75bbbd9b6eSWillian Rampazzo self.ssh_session.quit() 76bbbd9b6eSWillian Rampazzo 77bbbd9b6eSWillian Rampazzo def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path): 78bbbd9b6eSWillian Rampazzo image_url, image_hash = self.get_image_info(endianess) 79bbbd9b6eSWillian Rampazzo image_path = self.fetch_asset(image_url, asset_hash=image_hash) 80bbbd9b6eSWillian Rampazzo 81bbbd9b6eSWillian Rampazzo self.vm.set_console() 82bbbd9b6eSWillian Rampazzo kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 83bbbd9b6eSWillian Rampazzo + 'console=ttyS0 root=/dev/sda1') 84bbbd9b6eSWillian Rampazzo self.vm.add_args('-no-reboot', 85bbbd9b6eSWillian Rampazzo '-kernel', kernel_path, 86bbbd9b6eSWillian Rampazzo '-append', kernel_command_line, 87bbbd9b6eSWillian Rampazzo '-drive', 'file=%s,snapshot=on' % image_path, 88bbbd9b6eSWillian Rampazzo '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', 89bbbd9b6eSWillian Rampazzo '-device', 'pcnet,netdev=vnet') 90bbbd9b6eSWillian Rampazzo self.vm.launch() 91bbbd9b6eSWillian Rampazzo 92bbbd9b6eSWillian Rampazzo self.log.info('VM launched, waiting for sshd') 93bbbd9b6eSWillian Rampazzo console_pattern = 'Starting OpenBSD Secure Shell server: sshd' 94bbbd9b6eSWillian Rampazzo wait_for_console_pattern(self, console_pattern, 'Oops') 95bbbd9b6eSWillian Rampazzo self.log.info('sshd ready') 96bbbd9b6eSWillian Rampazzo 97bbbd9b6eSWillian Rampazzo self.ssh_connect('root', 'root', False) 98bbbd9b6eSWillian Rampazzo 99bbbd9b6eSWillian Rampazzo def shutdown_via_ssh(self): 100bbbd9b6eSWillian Rampazzo self.ssh_command('poweroff') 101bbbd9b6eSWillian Rampazzo self.ssh_disconnect_vm() 102bbbd9b6eSWillian Rampazzo wait_for_console_pattern(self, 'Power down', 'Oops') 103bbbd9b6eSWillian Rampazzo 104bbbd9b6eSWillian Rampazzo def run_common_commands(self, wordsize): 105bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 106bbbd9b6eSWillian Rampazzo 'cat /proc/cpuinfo', 107bbbd9b6eSWillian Rampazzo self.CPU_INFO[wordsize]['cpu']) 108bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 109bbbd9b6eSWillian Rampazzo 'uname -m', 110bbbd9b6eSWillian Rampazzo 'mips') 111bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 112bbbd9b6eSWillian Rampazzo 'uname -r', 113bbbd9b6eSWillian Rampazzo self.CPU_INFO[wordsize]['kernel_release']) 114bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 115bbbd9b6eSWillian Rampazzo 'cat /proc/interrupts', 116bbbd9b6eSWillian Rampazzo 'XT-PIC timer') 117bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 118bbbd9b6eSWillian Rampazzo 'cat /proc/interrupts', 119bbbd9b6eSWillian Rampazzo 'XT-PIC i8042') 120bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 121bbbd9b6eSWillian Rampazzo 'cat /proc/interrupts', 122bbbd9b6eSWillian Rampazzo 'XT-PIC serial') 123bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 124bbbd9b6eSWillian Rampazzo 'cat /proc/interrupts', 125bbbd9b6eSWillian Rampazzo 'XT-PIC ata_piix') 126bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 127bbbd9b6eSWillian Rampazzo 'cat /proc/interrupts', 128bbbd9b6eSWillian Rampazzo 'XT-PIC eth0') 129bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 130bbbd9b6eSWillian Rampazzo 'cat /proc/devices', 131bbbd9b6eSWillian Rampazzo 'input') 132bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 133bbbd9b6eSWillian Rampazzo 'cat /proc/devices', 134bbbd9b6eSWillian Rampazzo 'usb') 135bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 136bbbd9b6eSWillian Rampazzo 'cat /proc/devices', 137bbbd9b6eSWillian Rampazzo 'fb') 138bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 139bbbd9b6eSWillian Rampazzo 'cat /proc/ioports', 140bbbd9b6eSWillian Rampazzo ' : serial') 141bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 142bbbd9b6eSWillian Rampazzo 'cat /proc/ioports', 143bbbd9b6eSWillian Rampazzo ' : ata_piix') 144bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 145bbbd9b6eSWillian Rampazzo 'cat /proc/ioports', 146bbbd9b6eSWillian Rampazzo ' : piix4_smbus') 147bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 148bbbd9b6eSWillian Rampazzo 'lspci -d 11ab:4620', 149bbbd9b6eSWillian Rampazzo 'GT-64120') 150bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 151bbbd9b6eSWillian Rampazzo 'cat /sys/bus/i2c/devices/i2c-0/name', 152bbbd9b6eSWillian Rampazzo 'SMBus PIIX4 adapter') 153bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 154bbbd9b6eSWillian Rampazzo 'cat /proc/mtd', 155bbbd9b6eSWillian Rampazzo 'YAMON') 156bbbd9b6eSWillian Rampazzo # Empty 'Board Config' (64KB) 157bbbd9b6eSWillian Rampazzo self.ssh_command_output_contains( 158bbbd9b6eSWillian Rampazzo 'md5sum /dev/mtd2ro', 159bbbd9b6eSWillian Rampazzo '0dfbe8aa4c20b52e1b8bf3cb6cbdf193') 160bbbd9b6eSWillian Rampazzo 161bbbd9b6eSWillian Rampazzo def check_mips_malta(self, uname_m, endianess): 162bbbd9b6eSWillian Rampazzo wordsize = 64 if '64' in uname_m else 32 163bbbd9b6eSWillian Rampazzo kernel_url, kernel_hash = self.get_kernel_info(endianess, wordsize) 164bbbd9b6eSWillian Rampazzo kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) 165bbbd9b6eSWillian Rampazzo self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path) 166bbbd9b6eSWillian Rampazzo 167bbbd9b6eSWillian Rampazzo stdout, _ = self.ssh_command('uname -a') 168bbbd9b6eSWillian Rampazzo self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout]) 169bbbd9b6eSWillian Rampazzo 170bbbd9b6eSWillian Rampazzo self.run_common_commands(wordsize) 171bbbd9b6eSWillian Rampazzo self.shutdown_via_ssh() 172bbbd9b6eSWillian Rampazzo # Wait for VM to shut down gracefully 173bbbd9b6eSWillian Rampazzo self.vm.wait() 174bbbd9b6eSWillian Rampazzo 175bbbd9b6eSWillian Rampazzo def test_mips_malta32eb_kernel3_2_0(self): 176bbbd9b6eSWillian Rampazzo """ 177bbbd9b6eSWillian Rampazzo :avocado: tags=arch:mips 178bbbd9b6eSWillian Rampazzo :avocado: tags=endian:big 179bbbd9b6eSWillian Rampazzo :avocado: tags=device:pcnet32 180bbbd9b6eSWillian Rampazzo """ 181bbbd9b6eSWillian Rampazzo self.check_mips_malta('mips', 'be') 182bbbd9b6eSWillian Rampazzo 183bbbd9b6eSWillian Rampazzo def test_mips_malta32el_kernel3_2_0(self): 184bbbd9b6eSWillian Rampazzo """ 185bbbd9b6eSWillian Rampazzo :avocado: tags=arch:mipsel 186bbbd9b6eSWillian Rampazzo :avocado: tags=endian:little 187bbbd9b6eSWillian Rampazzo :avocado: tags=device:pcnet32 188bbbd9b6eSWillian Rampazzo """ 189bbbd9b6eSWillian Rampazzo self.check_mips_malta('mips', 'le') 190bbbd9b6eSWillian Rampazzo 191bbbd9b6eSWillian Rampazzo def test_mips_malta64eb_kernel3_2_0(self): 192bbbd9b6eSWillian Rampazzo """ 193bbbd9b6eSWillian Rampazzo :avocado: tags=arch:mips64 194bbbd9b6eSWillian Rampazzo :avocado: tags=endian:big 195bbbd9b6eSWillian Rampazzo :avocado: tags=device:pcnet32 196bbbd9b6eSWillian Rampazzo """ 197bbbd9b6eSWillian Rampazzo self.check_mips_malta('mips64', 'be') 198bbbd9b6eSWillian Rampazzo 199bbbd9b6eSWillian Rampazzo def test_mips_malta64el_kernel3_2_0(self): 200bbbd9b6eSWillian Rampazzo """ 201bbbd9b6eSWillian Rampazzo :avocado: tags=arch:mips64el 202bbbd9b6eSWillian Rampazzo :avocado: tags=endian:little 203bbbd9b6eSWillian Rampazzo :avocado: tags=device:pcnet32 204bbbd9b6eSWillian Rampazzo """ 205bbbd9b6eSWillian Rampazzo self.check_mips_malta('mips64', 'le') 206