block: implement bdrv_snapshot_goto for blkreplay
[qemu/ar7.git] / tests / acceptance / linux_ssh_mips_malta.py
blob25a1df5098a132d3903ceb3349ec28a4368bbf09
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.utils import process
17 from avocado.utils import archive
18 from avocado.utils import ssh
21 class LinuxSSH(Test):
23 timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg'
25 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
26 VM_IP = '127.0.0.1'
28 IMAGE_INFO = {
29 'be': {'image_url': ('https://people.debian.org/~aurel32/qemu/mips/'
30 'debian_wheezy_mips_standard.qcow2'),
31 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5'},
32 'le': {'image_url': ('https://people.debian.org/~aurel32/qemu/mipsel/'
33 'debian_wheezy_mipsel_standard.qcow2'),
34 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802'}
38 @skipUnless(ssh.SSH_CLIENT_BINARY, 'No SSH client available')
39 @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
40 def setUp(self):
41 super(LinuxSSH, self).setUp()
43 def wait_for_console_pattern(self, success_message,
44 failure_message='Oops'):
45 console = self.vm.console_socket.makefile()
46 console_logger = logging.getLogger('console')
47 while True:
48 msg = console.readline()
49 console_logger.debug(msg.strip())
50 if success_message in msg:
51 break
52 if failure_message in msg:
53 fail = 'Failure message found in console: %s' % failure_message
54 self.fail(fail)
56 def get_portfwd(self):
57 res = self.vm.command('human-monitor-command',
58 command_line='info usernet')
59 line = res.split('\r\n')[2]
60 port = re.split(r'.*TCP.HOST_FORWARD.*127\.0\.0\.1 (\d+)\s+10\..*',
61 line)[1]
62 self.log.debug("sshd listening on port:" + port)
63 return port
65 def ssh_connect(self, username, password):
66 self.ssh_logger = logging.getLogger('ssh')
67 port = self.get_portfwd()
68 self.ssh_session = ssh.Session(self.VM_IP, port=int(port),
69 user=username, password=password)
70 for i in range(10):
71 try:
72 self.ssh_session.connect()
73 return
74 except:
75 time.sleep(4)
76 pass
77 self.fail("sshd timeout")
79 def ssh_disconnect_vm(self):
80 self.ssh_session.quit()
82 def ssh_command(self, command, is_root=True):
83 self.ssh_logger.info(command)
84 result = self.ssh_session.cmd(command)
85 stdout_lines = [line.rstrip() for line in result.stdout_text.splitlines()]
86 for line in stdout_lines:
87 self.ssh_logger.info(line)
88 stderr_lines = [line.rstrip() for line in result.stderr_text.splitlines()]
89 for line in stderr_lines:
90 self.ssh_logger.warning(line)
91 return stdout_lines, stderr_lines
93 def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
94 image_url = self.IMAGE_INFO[endianess]['image_url']
95 image_hash = self.IMAGE_INFO[endianess]['image_hash']
96 image_path = self.fetch_asset(image_url, asset_hash=image_hash)
98 self.vm.set_machine('malta')
99 self.vm.set_console()
100 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
101 + 'console=ttyS0 root=/dev/sda1')
102 self.vm.add_args('-no-reboot',
103 '-kernel', kernel_path,
104 '-append', kernel_command_line,
105 '-hda', image_path,
106 '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
107 '-device', 'pcnet,netdev=vnet')
108 self.vm.launch()
110 self.log.info('VM launched, waiting for sshd')
111 console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
112 self.wait_for_console_pattern(console_pattern)
113 self.log.info('sshd ready')
115 self.ssh_connect('root', 'root')
117 def shutdown_via_ssh(self):
118 self.ssh_command('poweroff')
119 self.ssh_disconnect_vm()
120 self.wait_for_console_pattern('Power down')
122 def ssh_command_output_contains(self, cmd, exp):
123 stdout, _ = self.ssh_command(cmd)
124 for line in stdout:
125 if exp in line:
126 break
127 else:
128 self.fail('"%s" output does not contain "%s"' % (cmd, exp))
130 def run_common_commands(self):
131 self.ssh_command_output_contains(
132 'cat /proc/cpuinfo',
133 '24Kc')
134 self.ssh_command_output_contains(
135 'uname -m',
136 'mips')
137 self.ssh_command_output_contains(
138 'uname -r',
139 '3.2.0-4-4kc-malta')
140 self.ssh_command_output_contains(
141 'cat /proc/interrupts',
142 'timer')
143 self.ssh_command_output_contains(
144 'cat /proc/interrupts',
145 'i8042')
146 self.ssh_command_output_contains(
147 'cat /proc/interrupts',
148 'serial')
149 self.ssh_command_output_contains(
150 'cat /proc/interrupts',
151 'ata_piix')
152 self.ssh_command_output_contains(
153 'cat /proc/interrupts',
154 'eth0')
155 self.ssh_command_output_contains(
156 'cat /proc/interrupts',
157 'eth0')
158 self.ssh_command_output_contains(
159 'cat /proc/devices',
160 'input')
161 self.ssh_command_output_contains(
162 'cat /proc/devices',
163 'usb')
164 self.ssh_command_output_contains(
165 'cat /proc/devices',
166 'fb')
167 self.ssh_command_output_contains(
168 'cat /proc/ioports',
169 'serial')
170 self.ssh_command_output_contains(
171 'cat /proc/ioports',
172 'ata_piix')
173 self.ssh_command_output_contains(
174 'cat /proc/ioports',
175 'piix4_smbus')
176 self.ssh_command_output_contains(
177 'lspci -d 11ab:4620',
178 'GT-64120')
179 self.ssh_command_output_contains(
180 'cat /sys/bus/i2c/devices/i2c-0/name',
181 'SMBus PIIX4 adapter')
182 self.ssh_command_output_contains(
183 'cat /proc/mtd',
184 'YAMON')
185 # Empty 'Board Config'
186 self.ssh_command_output_contains(
187 'md5sum /dev/mtd2ro',
188 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
190 def check_mips_malta(self, endianess, kernel_path, uname_m):
191 self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path)
193 stdout, _ = self.ssh_command('uname -a')
194 self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout])
196 self.run_common_commands()
197 self.shutdown_via_ssh()
199 def test_mips_malta32eb_kernel3_2_0(self):
201 :avocado: tags=arch:mips
202 :avocado: tags=machine:malta
203 :avocado: tags=endian:big
204 :avocado: tags=device:pcnet32
206 kernel_url = ('https://people.debian.org/~aurel32/qemu/mips/'
207 'vmlinux-3.2.0-4-4kc-malta')
208 kernel_hash = '592e384a4edc16dade52a6cd5c785c637bcbc9ad'
209 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
211 self.check_mips_malta('be', kernel_path, 'mips')
213 def test_mips_malta32el_kernel3_2_0(self):
215 :avocado: tags=arch:mipsel
216 :avocado: tags=machine:malta
217 :avocado: tags=endian:little
218 :avocado: tags=device:pcnet32
220 kernel_url = ('https://people.debian.org/~aurel32/qemu/mipsel/'
221 'vmlinux-3.2.0-4-4kc-malta')
222 kernel_hash = 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a'
223 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
225 self.check_mips_malta('le', kernel_path, 'mips')
227 def test_mips_malta64eb_kernel3_2_0(self):
229 :avocado: tags=arch:mips64
230 :avocado: tags=machine:malta
231 :avocado: tags=endian:big
232 :avocado: tags=device:pcnet32
234 kernel_url = ('https://people.debian.org/~aurel32/qemu/mips/'
235 'vmlinux-3.2.0-4-5kc-malta')
236 kernel_hash = 'db6eea7de35d36c77d8c165b6bcb222e16eb91db'
237 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
238 self.check_mips_malta('be', kernel_path, 'mips64')
240 def test_mips_malta64el_kernel3_2_0(self):
242 :avocado: tags=arch:mips64el
243 :avocado: tags=machine:malta
244 :avocado: tags=endian:little
245 :avocado: tags=device:pcnet32
247 kernel_url = ('https://people.debian.org/~aurel32/qemu/mipsel/'
248 'vmlinux-3.2.0-4-5kc-malta')
249 kernel_hash = '6a7f77245acf231415a0e8b725d91ed2f3487794'
250 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
251 self.check_mips_malta('le', kernel_path, 'mips64')