s390x/cpumodel: Fix feature property error API violations
[qemu/ar7.git] / tests / acceptance / linux_ssh_mips_malta.py
blobfc13f9e4d4883b8fb406f1f8521288a2e1499cca
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 in result.stdout_text.splitlines()]
103 for line in stdout_lines:
104 self.ssh_logger.info(line)
105 stderr_lines = [line.rstrip() for line in result.stderr_text.splitlines()]
106 for line in stderr_lines:
107 self.ssh_logger.warning(line)
108 return stdout_lines, stderr_lines
110 def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
111 image_url, image_hash = self.get_image_info(endianess)
112 image_path = self.fetch_asset(image_url, asset_hash=image_hash)
114 self.vm.set_machine('malta')
115 self.vm.set_console()
116 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
117 + 'console=ttyS0 root=/dev/sda1')
118 self.vm.add_args('-no-reboot',
119 '-kernel', kernel_path,
120 '-append', kernel_command_line,
121 '-drive', 'file=%s,snapshot=on' % image_path,
122 '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
123 '-device', 'pcnet,netdev=vnet')
124 self.vm.launch()
126 self.log.info('VM launched, waiting for sshd')
127 console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
128 wait_for_console_pattern(self, console_pattern, 'Oops')
129 self.log.info('sshd ready')
131 self.ssh_connect('root', 'root')
133 def shutdown_via_ssh(self):
134 self.ssh_command('poweroff')
135 self.ssh_disconnect_vm()
136 wait_for_console_pattern(self, 'Power down', 'Oops')
138 def ssh_command_output_contains(self, cmd, exp):
139 stdout, _ = self.ssh_command(cmd)
140 for line in stdout:
141 if exp in line:
142 break
143 else:
144 self.fail('"%s" output does not contain "%s"' % (cmd, exp))
146 def run_common_commands(self, wordsize):
147 self.ssh_command_output_contains(
148 'cat /proc/cpuinfo',
149 self.CPU_INFO[wordsize]['cpu'])
150 self.ssh_command_output_contains(
151 'uname -m',
152 'mips')
153 self.ssh_command_output_contains(
154 'uname -r',
155 self.CPU_INFO[wordsize]['kernel_release'])
156 self.ssh_command_output_contains(
157 'cat /proc/interrupts',
158 'XT-PIC timer')
159 self.ssh_command_output_contains(
160 'cat /proc/interrupts',
161 'XT-PIC i8042')
162 self.ssh_command_output_contains(
163 'cat /proc/interrupts',
164 'XT-PIC serial')
165 self.ssh_command_output_contains(
166 'cat /proc/interrupts',
167 'XT-PIC ata_piix')
168 self.ssh_command_output_contains(
169 'cat /proc/interrupts',
170 'XT-PIC eth0')
171 self.ssh_command_output_contains(
172 'cat /proc/devices',
173 'input')
174 self.ssh_command_output_contains(
175 'cat /proc/devices',
176 'usb')
177 self.ssh_command_output_contains(
178 'cat /proc/devices',
179 'fb')
180 self.ssh_command_output_contains(
181 'cat /proc/ioports',
182 ' : serial')
183 self.ssh_command_output_contains(
184 'cat /proc/ioports',
185 ' : ata_piix')
186 self.ssh_command_output_contains(
187 'cat /proc/ioports',
188 ' : piix4_smbus')
189 self.ssh_command_output_contains(
190 'lspci -d 11ab:4620',
191 'GT-64120')
192 self.ssh_command_output_contains(
193 'cat /sys/bus/i2c/devices/i2c-0/name',
194 'SMBus PIIX4 adapter')
195 self.ssh_command_output_contains(
196 'cat /proc/mtd',
197 'YAMON')
198 # Empty 'Board Config' (64KB)
199 self.ssh_command_output_contains(
200 'md5sum /dev/mtd2ro',
201 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
203 def check_mips_malta(self, uname_m, endianess):
204 wordsize = 64 if '64' in uname_m else 32
205 kernel_url, kernel_hash = self.get_kernel_info(endianess, wordsize)
206 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
207 self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path)
209 stdout, _ = self.ssh_command('uname -a')
210 self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout])
212 self.run_common_commands(wordsize)
213 self.shutdown_via_ssh()
215 def test_mips_malta32eb_kernel3_2_0(self):
217 :avocado: tags=arch:mips
218 :avocado: tags=machine:malta
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=machine:malta
228 :avocado: tags=endian:little
229 :avocado: tags=device:pcnet32
231 self.check_mips_malta('mips', 'le')
233 def test_mips_malta64eb_kernel3_2_0(self):
235 :avocado: tags=arch:mips64
236 :avocado: tags=machine:malta
237 :avocado: tags=endian:big
238 :avocado: tags=device:pcnet32
240 self.check_mips_malta('mips64', 'be')
242 def test_mips_malta64el_kernel3_2_0(self):
244 :avocado: tags=arch:mips64el
245 :avocado: tags=machine:malta
246 :avocado: tags=endian:little
247 :avocado: tags=device:pcnet32
249 self.check_mips_malta('mips64', 'le')