ppc/pnv: Introduce PnvChipClass::xscom_core_base() method
[qemu/ar7.git] / tests / acceptance / linux_ssh_mips_malta.py
blob4db18de800ecf2927134ead5dfc077838d182e68
1 # Functional test that boots a VM and run commands via a SSH session
3 # Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
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.
8 import os
9 import re
10 import base64
11 import logging
12 import time
14 from avocado import skipUnless
15 from avocado_qemu import Test
16 from avocado_qemu import wait_for_console_pattern
17 from avocado.utils import process
18 from avocado.utils import archive
19 from avocado.utils import ssh
22 class LinuxSSH(Test):
24 timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg'
26 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
27 VM_IP = '127.0.0.1'
29 BASE_URL = 'https://people.debian.org/~aurel32/qemu/'
30 IMAGE_INFO = {
31 'be': {'base_url': 'mips',
32 'image_name': 'debian_wheezy_mips_standard.qcow2',
33 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5',
34 'kernel_hash': {
35 32: '592e384a4edc16dade52a6cd5c785c637bcbc9ad',
36 64: 'db6eea7de35d36c77d8c165b6bcb222e16eb91db'}
38 'le': {'base_url': 'mipsel',
39 'image_name': 'debian_wheezy_mipsel_standard.qcow2',
40 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802',
41 'kernel_hash': {
42 32: 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a',
43 64: '6a7f77245acf231415a0e8b725d91ed2f3487794'}
46 CPU_INFO = {
47 32: {'cpu': 'MIPS 24Kc', 'kernel_release': '3.2.0-4-4kc-malta'},
48 64: {'cpu': 'MIPS 20Kc', 'kernel_release': '3.2.0-4-5kc-malta'}
51 def get_url(self, endianess, path=''):
52 qkey = {'le': 'el', 'be': ''}
53 return '%s/mips%s/%s' % (self.BASE_URL, qkey[endianess], path)
55 def get_image_info(self, endianess):
56 dinfo = self.IMAGE_INFO[endianess]
57 image_url = self.get_url(endianess, dinfo['image_name'])
58 image_hash = dinfo['image_hash']
59 return (image_url, image_hash)
61 def get_kernel_info(self, endianess, wordsize):
62 minfo = self.CPU_INFO[wordsize]
63 kernel_url = self.get_url(endianess,
64 'vmlinux-%s' % minfo['kernel_release'])
65 kernel_hash = self.IMAGE_INFO[endianess]['kernel_hash'][wordsize]
66 return kernel_url, kernel_hash
68 @skipUnless(ssh.SSH_CLIENT_BINARY, 'No SSH client available')
69 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
70 def setUp(self):
71 super(LinuxSSH, self).setUp()
73 def get_portfwd(self):
74 res = self.vm.command('human-monitor-command',
75 command_line='info usernet')
76 line = res.split('\r\n')[2]
77 port = re.split(r'.*TCP.HOST_FORWARD.*127\.0\.0\.1 (\d+)\s+10\..*',
78 line)[1]
79 self.log.debug("sshd listening on port:" + port)
80 return port
82 def ssh_connect(self, username, password):
83 self.ssh_logger = logging.getLogger('ssh')
84 port = self.get_portfwd()
85 self.ssh_session = ssh.Session(self.VM_IP, port=int(port),
86 user=username, password=password)
87 for i in range(10):
88 try:
89 self.ssh_session.connect()
90 return
91 except:
92 time.sleep(4)
93 pass
94 self.fail("sshd timeout")
96 def ssh_disconnect_vm(self):
97 self.ssh_session.quit()
99 def ssh_command(self, command, is_root=True):
100 self.ssh_logger.info(command)
101 result = self.ssh_session.cmd(command)
102 stdout_lines = [line.rstrip() for line
103 in result.stdout_text.splitlines()]
104 for line in stdout_lines:
105 self.ssh_logger.info(line)
106 stderr_lines = [line.rstrip() for line
107 in result.stderr_text.splitlines()]
108 for line in stderr_lines:
109 self.ssh_logger.warning(line)
110 return stdout_lines, stderr_lines
112 def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
113 image_url, image_hash = self.get_image_info(endianess)
114 image_path = self.fetch_asset(image_url, asset_hash=image_hash)
116 self.vm.set_machine('malta')
117 self.vm.set_console()
118 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
119 + 'console=ttyS0 root=/dev/sda1')
120 self.vm.add_args('-no-reboot',
121 '-kernel', kernel_path,
122 '-append', kernel_command_line,
123 '-drive', 'file=%s,snapshot=on' % image_path,
124 '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
125 '-device', 'pcnet,netdev=vnet')
126 self.vm.launch()
128 self.log.info('VM launched, waiting for sshd')
129 console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
130 wait_for_console_pattern(self, console_pattern, 'Oops')
131 self.log.info('sshd ready')
133 self.ssh_connect('root', 'root')
135 def shutdown_via_ssh(self):
136 self.ssh_command('poweroff')
137 self.ssh_disconnect_vm()
138 wait_for_console_pattern(self, 'Power down', 'Oops')
140 def ssh_command_output_contains(self, cmd, exp):
141 stdout, _ = self.ssh_command(cmd)
142 for line in stdout:
143 if exp in line:
144 break
145 else:
146 self.fail('"%s" output does not contain "%s"' % (cmd, exp))
148 def run_common_commands(self, wordsize):
149 self.ssh_command_output_contains(
150 'cat /proc/cpuinfo',
151 self.CPU_INFO[wordsize]['cpu'])
152 self.ssh_command_output_contains(
153 'uname -m',
154 'mips')
155 self.ssh_command_output_contains(
156 'uname -r',
157 self.CPU_INFO[wordsize]['kernel_release'])
158 self.ssh_command_output_contains(
159 'cat /proc/interrupts',
160 'XT-PIC timer')
161 self.ssh_command_output_contains(
162 'cat /proc/interrupts',
163 'XT-PIC i8042')
164 self.ssh_command_output_contains(
165 'cat /proc/interrupts',
166 'XT-PIC serial')
167 self.ssh_command_output_contains(
168 'cat /proc/interrupts',
169 'XT-PIC ata_piix')
170 self.ssh_command_output_contains(
171 'cat /proc/interrupts',
172 'XT-PIC eth0')
173 self.ssh_command_output_contains(
174 'cat /proc/devices',
175 'input')
176 self.ssh_command_output_contains(
177 'cat /proc/devices',
178 'usb')
179 self.ssh_command_output_contains(
180 'cat /proc/devices',
181 'fb')
182 self.ssh_command_output_contains(
183 'cat /proc/ioports',
184 ' : serial')
185 self.ssh_command_output_contains(
186 'cat /proc/ioports',
187 ' : ata_piix')
188 self.ssh_command_output_contains(
189 'cat /proc/ioports',
190 ' : piix4_smbus')
191 self.ssh_command_output_contains(
192 'lspci -d 11ab:4620',
193 'GT-64120')
194 self.ssh_command_output_contains(
195 'cat /sys/bus/i2c/devices/i2c-0/name',
196 'SMBus PIIX4 adapter')
197 self.ssh_command_output_contains(
198 'cat /proc/mtd',
199 'YAMON')
200 # Empty 'Board Config' (64KB)
201 self.ssh_command_output_contains(
202 'md5sum /dev/mtd2ro',
203 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
205 def check_mips_malta(self, uname_m, endianess):
206 wordsize = 64 if '64' in uname_m else 32
207 kernel_url, kernel_hash = self.get_kernel_info(endianess, wordsize)
208 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
209 self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path)
211 stdout, _ = self.ssh_command('uname -a')
212 self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout])
214 self.run_common_commands(wordsize)
215 self.shutdown_via_ssh()
217 def test_mips_malta32eb_kernel3_2_0(self):
219 :avocado: tags=arch:mips
220 :avocado: tags=machine:malta
221 :avocado: tags=endian:big
222 :avocado: tags=device:pcnet32
224 self.check_mips_malta('mips', 'be')
226 def test_mips_malta32el_kernel3_2_0(self):
228 :avocado: tags=arch:mipsel
229 :avocado: tags=machine:malta
230 :avocado: tags=endian:little
231 :avocado: tags=device:pcnet32
233 self.check_mips_malta('mips', 'le')
235 def test_mips_malta64eb_kernel3_2_0(self):
237 :avocado: tags=arch:mips64
238 :avocado: tags=machine:malta
239 :avocado: tags=endian:big
240 :avocado: tags=device:pcnet32
242 self.check_mips_malta('mips64', 'be')
244 def test_mips_malta64el_kernel3_2_0(self):
246 :avocado: tags=arch:mips64el
247 :avocado: tags=machine:malta
248 :avocado: tags=endian:little
249 :avocado: tags=device:pcnet32
251 self.check_mips_malta('mips64', 'le')