linux_ssh_mips_malta.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # Functional test that boots a VM and run commands via a SSH session
  2. #
  3. # Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
  4. #
  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.
  7. import os
  8. import re
  9. import base64
  10. import logging
  11. import time
  12. from avocado import skipUnless
  13. from avocado_qemu import LinuxSSHMixIn
  14. from avocado_qemu import QemuSystemTest
  15. from avocado_qemu import wait_for_console_pattern
  16. from avocado.utils import process
  17. from avocado.utils import archive
  18. from avocado.utils import ssh
  19. @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
  20. @skipUnless(ssh.SSH_CLIENT_BINARY, 'No SSH client available')
  21. class LinuxSSH(QemuSystemTest, LinuxSSHMixIn):
  22. """
  23. :avocado: tags=accel:tcg
  24. """
  25. 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'
  28. BASE_URL = 'https://people.debian.org/~aurel32/qemu/'
  29. IMAGE_INFO = {
  30. 'be': {'base_url': 'mips',
  31. 'image_name': 'debian_wheezy_mips_standard.qcow2',
  32. 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5',
  33. 'kernel_hash': {
  34. 32: '592e384a4edc16dade52a6cd5c785c637bcbc9ad',
  35. 64: 'db6eea7de35d36c77d8c165b6bcb222e16eb91db'}
  36. },
  37. 'le': {'base_url': 'mipsel',
  38. 'image_name': 'debian_wheezy_mipsel_standard.qcow2',
  39. 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802',
  40. 'kernel_hash': {
  41. 32: 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a',
  42. 64: '6a7f77245acf231415a0e8b725d91ed2f3487794'}
  43. }
  44. }
  45. CPU_INFO = {
  46. 32: {'cpu': 'MIPS 24Kc', 'kernel_release': '3.2.0-4-4kc-malta'},
  47. 64: {'cpu': 'MIPS 20Kc', 'kernel_release': '3.2.0-4-5kc-malta'}
  48. }
  49. def get_url(self, endianess, path=''):
  50. qkey = {'le': 'el', 'be': ''}
  51. return '%s/mips%s/%s' % (self.BASE_URL, qkey[endianess], path)
  52. def get_image_info(self, endianess):
  53. dinfo = self.IMAGE_INFO[endianess]
  54. image_url = self.get_url(endianess, dinfo['image_name'])
  55. image_hash = dinfo['image_hash']
  56. return (image_url, image_hash)
  57. def get_kernel_info(self, endianess, wordsize):
  58. minfo = self.CPU_INFO[wordsize]
  59. kernel_url = self.get_url(endianess,
  60. 'vmlinux-%s' % minfo['kernel_release'])
  61. kernel_hash = self.IMAGE_INFO[endianess]['kernel_hash'][wordsize]
  62. return kernel_url, kernel_hash
  63. def ssh_disconnect_vm(self):
  64. self.ssh_session.quit()
  65. def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
  66. image_url, image_hash = self.get_image_info(endianess)
  67. image_path = self.fetch_asset(image_url, asset_hash=image_hash)
  68. self.vm.set_console()
  69. kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
  70. + 'console=ttyS0 root=/dev/sda1')
  71. self.vm.add_args('-no-reboot',
  72. '-kernel', kernel_path,
  73. '-append', kernel_command_line,
  74. '-drive', 'file=%s,snapshot=on' % image_path,
  75. '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
  76. '-device', 'pcnet,netdev=vnet')
  77. self.vm.launch()
  78. self.log.info('VM launched, waiting for sshd')
  79. console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
  80. wait_for_console_pattern(self, console_pattern, 'Oops')
  81. self.log.info('sshd ready')
  82. self.ssh_connect('root', 'root', False)
  83. def shutdown_via_ssh(self):
  84. self.ssh_command('poweroff')
  85. self.ssh_disconnect_vm()
  86. wait_for_console_pattern(self, 'Power down', 'Oops')
  87. def run_common_commands(self, wordsize):
  88. self.ssh_command_output_contains(
  89. 'cat /proc/cpuinfo',
  90. self.CPU_INFO[wordsize]['cpu'])
  91. self.ssh_command_output_contains(
  92. 'uname -m',
  93. 'mips')
  94. self.ssh_command_output_contains(
  95. 'uname -r',
  96. self.CPU_INFO[wordsize]['kernel_release'])
  97. self.ssh_command_output_contains(
  98. 'cat /proc/interrupts',
  99. 'XT-PIC timer')
  100. self.ssh_command_output_contains(
  101. 'cat /proc/interrupts',
  102. 'XT-PIC i8042')
  103. self.ssh_command_output_contains(
  104. 'cat /proc/interrupts',
  105. 'XT-PIC serial')
  106. self.ssh_command_output_contains(
  107. 'cat /proc/interrupts',
  108. 'XT-PIC ata_piix')
  109. self.ssh_command_output_contains(
  110. 'cat /proc/interrupts',
  111. 'XT-PIC eth0')
  112. self.ssh_command_output_contains(
  113. 'cat /proc/devices',
  114. 'input')
  115. self.ssh_command_output_contains(
  116. 'cat /proc/devices',
  117. 'usb')
  118. self.ssh_command_output_contains(
  119. 'cat /proc/devices',
  120. 'fb')
  121. self.ssh_command_output_contains(
  122. 'cat /proc/ioports',
  123. ' : serial')
  124. self.ssh_command_output_contains(
  125. 'cat /proc/ioports',
  126. ' : ata_piix')
  127. self.ssh_command_output_contains(
  128. 'cat /proc/ioports',
  129. ' : piix4_smbus')
  130. self.ssh_command_output_contains(
  131. 'lspci -d 11ab:4620',
  132. 'GT-64120')
  133. self.ssh_command_output_contains(
  134. 'cat /sys/bus/i2c/devices/i2c-0/name',
  135. 'SMBus PIIX4 adapter')
  136. self.ssh_command_output_contains(
  137. 'cat /proc/mtd',
  138. 'YAMON')
  139. # Empty 'Board Config' (64KB)
  140. self.ssh_command_output_contains(
  141. 'md5sum /dev/mtd2ro',
  142. '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
  143. def check_mips_malta(self, uname_m, endianess):
  144. wordsize = 64 if '64' in uname_m else 32
  145. kernel_url, kernel_hash = self.get_kernel_info(endianess, wordsize)
  146. kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
  147. self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path)
  148. stdout, _ = self.ssh_command('uname -a')
  149. self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout])
  150. self.run_common_commands(wordsize)
  151. self.shutdown_via_ssh()
  152. # Wait for VM to shut down gracefully
  153. self.vm.wait()
  154. def test_mips_malta32eb_kernel3_2_0(self):
  155. """
  156. :avocado: tags=arch:mips
  157. :avocado: tags=endian:big
  158. :avocado: tags=device:pcnet32
  159. """
  160. self.check_mips_malta('mips', 'be')
  161. def test_mips_malta32el_kernel3_2_0(self):
  162. """
  163. :avocado: tags=arch:mipsel
  164. :avocado: tags=endian:little
  165. :avocado: tags=device:pcnet32
  166. """
  167. self.check_mips_malta('mips', 'le')
  168. def test_mips_malta64eb_kernel3_2_0(self):
  169. """
  170. :avocado: tags=arch:mips64
  171. :avocado: tags=endian:big
  172. :avocado: tags=device:pcnet32
  173. """
  174. self.check_mips_malta('mips64', 'be')
  175. def test_mips_malta64el_kernel3_2_0(self):
  176. """
  177. :avocado: tags=arch:mips64el
  178. :avocado: tags=endian:little
  179. :avocado: tags=device:pcnet32
  180. """
  181. self.check_mips_malta('mips64', 'le')