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