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.
14 from avocado
import skipUnless
15 from avocado_qemu
import LinuxSSHMixIn
16 from avocado_qemu
import QemuSystemTest
17 from avocado_qemu
import wait_for_console_pattern
18 from avocado
.utils
import process
19 from avocado
.utils
import archive
20 from avocado
.utils
import ssh
23 @skipUnless(os
.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
24 @skipUnless(ssh
.SSH_CLIENT_BINARY
, 'No SSH client available')
25 class LinuxSSH(QemuSystemTest
, LinuxSSHMixIn
):
27 :avocado: tags=accel:tcg
30 timeout
= 150 # Not for 'configure --enable-debug --enable-debug-tcg'
32 KERNEL_COMMON_COMMAND_LINE
= 'printk.time=0 '
35 BASE_URL
= 'https://people.debian.org/~aurel32/qemu/'
37 'be': {'base_url': 'mips',
38 'image_name': 'debian_wheezy_mips_standard.qcow2',
39 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5',
41 32: '592e384a4edc16dade52a6cd5c785c637bcbc9ad',
42 64: 'db6eea7de35d36c77d8c165b6bcb222e16eb91db'}
44 'le': {'base_url': 'mipsel',
45 'image_name': 'debian_wheezy_mipsel_standard.qcow2',
46 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802',
48 32: 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a',
49 64: '6a7f77245acf231415a0e8b725d91ed2f3487794'}
53 32: {'cpu': 'MIPS 24Kc', 'kernel_release': '3.2.0-4-4kc-malta'},
54 64: {'cpu': 'MIPS 20Kc', 'kernel_release': '3.2.0-4-5kc-malta'}
57 def get_url(self
, endianess
, path
=''):
58 qkey
= {'le': 'el', 'be': ''}
59 return '%s/mips%s/%s' % (self
.BASE_URL
, qkey
[endianess
], path
)
61 def get_image_info(self
, endianess
):
62 dinfo
= self
.IMAGE_INFO
[endianess
]
63 image_url
= self
.get_url(endianess
, dinfo
['image_name'])
64 image_hash
= dinfo
['image_hash']
65 return (image_url
, image_hash
)
67 def get_kernel_info(self
, endianess
, wordsize
):
68 minfo
= self
.CPU_INFO
[wordsize
]
69 kernel_url
= self
.get_url(endianess
,
70 'vmlinux-%s' % minfo
['kernel_release'])
71 kernel_hash
= self
.IMAGE_INFO
[endianess
]['kernel_hash'][wordsize
]
72 return kernel_url
, kernel_hash
74 def ssh_disconnect_vm(self
):
75 self
.ssh_session
.quit()
77 def boot_debian_wheezy_image_and_ssh_login(self
, endianess
, kernel_path
):
78 image_url
, image_hash
= self
.get_image_info(endianess
)
79 image_path
= self
.fetch_asset(image_url
, asset_hash
=image_hash
)
82 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
83 + 'console=ttyS0 root=/dev/sda1')
84 self
.vm
.add_args('-no-reboot',
85 '-kernel', kernel_path
,
86 '-append', kernel_command_line
,
87 '-drive', 'file=%s,snapshot=on' % image_path
,
88 '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
89 '-device', 'pcnet,netdev=vnet')
92 self
.log
.info('VM launched, waiting for sshd')
93 console_pattern
= 'Starting OpenBSD Secure Shell server: sshd'
94 wait_for_console_pattern(self
, console_pattern
, 'Oops')
95 self
.log
.info('sshd ready')
97 self
.ssh_connect('root', 'root', False)
99 def shutdown_via_ssh(self
):
100 self
.ssh_command('poweroff')
101 self
.ssh_disconnect_vm()
102 wait_for_console_pattern(self
, 'Power down', 'Oops')
104 def run_common_commands(self
, wordsize
):
105 self
.ssh_command_output_contains(
107 self
.CPU_INFO
[wordsize
]['cpu'])
108 self
.ssh_command_output_contains(
111 self
.ssh_command_output_contains(
113 self
.CPU_INFO
[wordsize
]['kernel_release'])
114 self
.ssh_command_output_contains(
115 'cat /proc/interrupts',
117 self
.ssh_command_output_contains(
118 'cat /proc/interrupts',
120 self
.ssh_command_output_contains(
121 'cat /proc/interrupts',
123 self
.ssh_command_output_contains(
124 'cat /proc/interrupts',
126 self
.ssh_command_output_contains(
127 'cat /proc/interrupts',
129 self
.ssh_command_output_contains(
132 self
.ssh_command_output_contains(
135 self
.ssh_command_output_contains(
138 self
.ssh_command_output_contains(
141 self
.ssh_command_output_contains(
144 self
.ssh_command_output_contains(
147 self
.ssh_command_output_contains(
148 'lspci -d 11ab:4620',
150 self
.ssh_command_output_contains(
151 'cat /sys/bus/i2c/devices/i2c-0/name',
152 'SMBus PIIX4 adapter')
153 self
.ssh_command_output_contains(
156 # Empty 'Board Config' (64KB)
157 self
.ssh_command_output_contains(
158 'md5sum /dev/mtd2ro',
159 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
161 def check_mips_malta(self
, uname_m
, endianess
):
162 wordsize
= 64 if '64' in uname_m
else 32
163 kernel_url
, kernel_hash
= self
.get_kernel_info(endianess
, wordsize
)
164 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
165 self
.boot_debian_wheezy_image_and_ssh_login(endianess
, kernel_path
)
167 stdout
, _
= self
.ssh_command('uname -a')
168 self
.assertIn(True, [uname_m
+ " GNU/Linux" in line
for line
in stdout
])
170 self
.run_common_commands(wordsize
)
171 self
.shutdown_via_ssh()
172 # Wait for VM to shut down gracefully
175 def test_mips_malta32eb_kernel3_2_0(self
):
177 :avocado: tags=arch:mips
178 :avocado: tags=endian:big
179 :avocado: tags=device:pcnet32
181 self
.check_mips_malta('mips', 'be')
183 def test_mips_malta32el_kernel3_2_0(self
):
185 :avocado: tags=arch:mipsel
186 :avocado: tags=endian:little
187 :avocado: tags=device:pcnet32
189 self
.check_mips_malta('mips', 'le')
191 def test_mips_malta64eb_kernel3_2_0(self
):
193 :avocado: tags=arch:mips64
194 :avocado: tags=endian:big
195 :avocado: tags=device:pcnet32
197 self
.check_mips_malta('mips64', 'be')
199 def test_mips_malta64el_kernel3_2_0(self
):
201 :avocado: tags=arch:mips64el
202 :avocado: tags=endian:little
203 :avocado: tags=device:pcnet32
205 self
.check_mips_malta('mips64', 'le')