target/ppc: Add support for Radix partition-scoped translation
[qemu/ar7.git] / tests / acceptance / linux_ssh_mips_malta.py
blob90d7f2f167a2a4f2241c24fe272375327bb9d607
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_console()
117 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
118 + 'console=ttyS0 root=/dev/sda1')
119 self.vm.add_args('-no-reboot',
120 '-kernel', kernel_path,
121 '-append', kernel_command_line,
122 '-drive', 'file=%s,snapshot=on' % image_path,
123 '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
124 '-device', 'pcnet,netdev=vnet')
125 self.vm.launch()
127 self.log.info('VM launched, waiting for sshd')
128 console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
129 wait_for_console_pattern(self, console_pattern, 'Oops')
130 self.log.info('sshd ready')
132 self.ssh_connect('root', 'root')
134 def shutdown_via_ssh(self):
135 self.ssh_command('poweroff')
136 self.ssh_disconnect_vm()
137 wait_for_console_pattern(self, 'Power down', 'Oops')
139 def ssh_command_output_contains(self, cmd, exp):
140 stdout, _ = self.ssh_command(cmd)
141 for line in stdout:
142 if exp in line:
143 break
144 else:
145 self.fail('"%s" output does not contain "%s"' % (cmd, exp))
147 def run_common_commands(self, wordsize):
148 self.ssh_command_output_contains(
149 'cat /proc/cpuinfo',
150 self.CPU_INFO[wordsize]['cpu'])
151 self.ssh_command_output_contains(
152 'uname -m',
153 'mips')
154 self.ssh_command_output_contains(
155 'uname -r',
156 self.CPU_INFO[wordsize]['kernel_release'])
157 self.ssh_command_output_contains(
158 'cat /proc/interrupts',
159 'XT-PIC timer')
160 self.ssh_command_output_contains(
161 'cat /proc/interrupts',
162 'XT-PIC i8042')
163 self.ssh_command_output_contains(
164 'cat /proc/interrupts',
165 'XT-PIC serial')
166 self.ssh_command_output_contains(
167 'cat /proc/interrupts',
168 'XT-PIC ata_piix')
169 self.ssh_command_output_contains(
170 'cat /proc/interrupts',
171 'XT-PIC eth0')
172 self.ssh_command_output_contains(
173 'cat /proc/devices',
174 'input')
175 self.ssh_command_output_contains(
176 'cat /proc/devices',
177 'usb')
178 self.ssh_command_output_contains(
179 'cat /proc/devices',
180 'fb')
181 self.ssh_command_output_contains(
182 'cat /proc/ioports',
183 ' : serial')
184 self.ssh_command_output_contains(
185 'cat /proc/ioports',
186 ' : ata_piix')
187 self.ssh_command_output_contains(
188 'cat /proc/ioports',
189 ' : piix4_smbus')
190 self.ssh_command_output_contains(
191 'lspci -d 11ab:4620',
192 'GT-64120')
193 self.ssh_command_output_contains(
194 'cat /sys/bus/i2c/devices/i2c-0/name',
195 'SMBus PIIX4 adapter')
196 self.ssh_command_output_contains(
197 'cat /proc/mtd',
198 'YAMON')
199 # Empty 'Board Config' (64KB)
200 self.ssh_command_output_contains(
201 'md5sum /dev/mtd2ro',
202 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
204 def check_mips_malta(self, uname_m, endianess):
205 wordsize = 64 if '64' in uname_m else 32
206 kernel_url, kernel_hash = self.get_kernel_info(endianess, wordsize)
207 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
208 self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path)
210 stdout, _ = self.ssh_command('uname -a')
211 self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout])
213 self.run_common_commands(wordsize)
214 self.shutdown_via_ssh()
216 def test_mips_malta32eb_kernel3_2_0(self):
218 :avocado: tags=arch:mips
219 :avocado: tags=endian:big
220 :avocado: tags=device:pcnet32
222 self.check_mips_malta('mips', 'be')
224 def test_mips_malta32el_kernel3_2_0(self):
226 :avocado: tags=arch:mipsel
227 :avocado: tags=endian:little
228 :avocado: tags=device:pcnet32
230 self.check_mips_malta('mips', 'le')
232 def test_mips_malta64eb_kernel3_2_0(self):
234 :avocado: tags=arch:mips64
235 :avocado: tags=endian:big
236 :avocado: tags=device:pcnet32
238 self.check_mips_malta('mips64', 'be')
240 def test_mips_malta64el_kernel3_2_0(self):
242 :avocado: tags=arch:mips64el
243 :avocado: tags=endian:little
244 :avocado: tags=device:pcnet32
246 self.check_mips_malta('mips64', 'le')