mips: Add more Avocado tests
v2 cover mips: Add more Avocado tests
Hi,
It was a rainy week-end here, so I invested it to automatize some of my MIPS tests.
The BootLinuxSshTest is not Global warming friendly, it is not meant to run on a CI system but rather on a workstation previous to post a pull request.
It can surely be improved, but it is a good starting point.
v2: Decorate slow tests with skipIf(CONTINUOUS_INTEGRATION):
VENV /home/travis/build/philmd/qemu/tests/venv PIP /home/travis/build/philmd/qemu/tests/requirements.txt MKDIR /home/travis/build/philmd/qemu/tests/results
AVOCADO tests/acceptance
JOB ID : 02a2b1c585c12aebfbd8db2f330ed9730a547ae0
JOB LOG : /home/travis/build/philmd/qemu/tests/results/job-2019-05-23T16.05-02a2b1c/job.log
(01/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_x86_64_pc: PASS (5.41 s)
(02/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips_malta: PASS (3.33 s)
(03/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips64el_malta: PASS (3.47 s) (04/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips_malta_cpio: PASS (15.09 s) (05/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_aarch64_virt: PASS (2.48 s)
(06/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_virt: PASS (7.25 s)
(07/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_s390x_s390_ccw_virtio: PASS (4.66 s) (08/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_alpha_clipper: PASS (3.37 s)
(09/22) acceptance/cpu_queries.py:QueryCPUModelExpansion.test: PASS (0.16 s)
(10/22) acceptance/empty_cpu_model.py:EmptyCPUModel.test: PASS (0.02 s)
(11/22) acceptance/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_exit_error_msg_with_linux_v3_6: PASS (3.89 s) (12/22) acceptance/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16: PASS (15.14 s) (13/22) acceptance/linux_ssh_mips_malta.py:LinuxSSH.test_mips_malta32eb_kernel3_2_0: SKIP: Running on Travis-CI (14/22) acceptance/linux_ssh_mips_malta.py:LinuxSSH.test_mips_malta64el_kernel3_2_0: SKIP: Running on Travis-CI (15/22) acceptance/migration.py:Migration.test_migration_with_tcp_localhost: PASS (0.23 s)
(16/22) acceptance/version.py:Version.test_qmp_human_info_version: PASS (0.04 s)
(17/22) acceptance/virtio_version.py:VirtioVersionCheck.test_conventional_devs: PASS (1.20 s) (18/22) acceptance/virtio_version.py:VirtioVersionCheck.test_modern_only_devs: PASS (0.41 s) (19/22) acceptance/vnc.py:Vnc.test_no_vnc: PASS (0.03 s)
(20/22) acceptance/vnc.py:Vnc.test_no_vnc_change_password: PASS (0.04 s)
(21/22) acceptance/vnc.py:Vnc.test_vnc_change_password_requires_a_password: PASS (0.04 s)
(22/22) acceptance/vnc.py:Vnc.test_vnc_change_password: PASS (0.04 s)
RESULTS : PASS 20 | ERROR 0 | FAIL 0 | SKIP 2 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 68.64 s
Regards,
Phil.
Philippe Mathieu-Daudé (4):
BootLinuxConsoleTest: Let extract_from_deb handle various compressions
BootLinuxConsoleTest: Test nanoMIPS kernels on the I7200 CPU
BootLinuxConsoleTest: Run kerneltests BusyBox on Malta
BootLinuxSshTest: Test some userspace commands on Malta
MAINTAINERS | 1 + tests/acceptance/boot_linux_console.py | 113 ++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 230 +++++++++++++++++++++++ tests/requirements.txt | 1 + 4 files changed, 343 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/linux_ssh_mips_malta.py
Signature · 1 line
2.19.1
PATCH v2 1/4 BootLinuxConsoleTest: Let extract_from_deb handle various compressions
Debian binary package format supports various compressions.
Per man deb(5):
NAME
deb - Debian binary package format
FORMAT
...
The third, last required member is named data.tar. It contains the filesystem as a tar archive, either not compressed (supported since dpkg 1.10.24), or compressed with gzip (with .gz extension), xz (with .xz extension, supported since dpkg 1.15.6), bzip2 (with .bz2 extension, supported since dpkg 1.10.24) or lzma (with .lzma extension, supported since dpkg 1.13.25).
List the archive files to have the 3rd name with the correct extension.
The function avocado.utils.archive.extract() will handle the different compression format for us.
---
This patch is already in Eduardo's queue, but is required in this series.
--- tests/acceptance/boot_linux_console.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tests/acceptance/boot_linux_console.py +3 -2
@@ -55,8 +55,9 @@ class BootLinuxConsole(Test): """ cwd = os.getcwd() os.chdir(self.workdir) - process.run("ar x %s data.tar.gz" % deb) - archive.extract("data.tar.gz", self.workdir) + file_path = process.run("ar t %s" % deb).stdout_text.split()[2] + process.run("ar x %s %s" % (deb, file_path)) + archive.extract(file_path, self.workdir) os.chdir(cwd) return self.workdir + path
Signature · 1 line
2.19.1
PATCH v2 2/4 BootLinuxConsoleTest: Test nanoMIPS kernels on the I7200 CPU
In reply to Philippe Mathieu-DaudéSimilar to the x86_64/pc test, it boots a Linux kernel on a Malta machine and verify the serial is working.
Use the documentation added in commit f7d257cb4a17 to test nanoMIPS kernels and the I7200 CPU.
This test can be run using:
$ avocado --show=console run -t arch:mipsel tests/acceptance/boot_linux_console.py console: [ 0.000000] Linux version 4.15.18-00432-gb2eb9a8b (emubuild@mipscs563) (gcc version 6.3.0 (Codescape GNU Tools 2018.04-02 for nanoMIPS Linux)) #1 SMP Wed Jun 27 11:10:08 PDT 2018 console: [ 0.000000] GCRs appear to have been moved (expected them at 0x1fbf8000)! console: [ 0.000000] GCRs appear to have been moved (expected them at 0x1fbf8000)! console: [ 0.000000] CPU0 revision is: 00010000 (MIPS GENERIC QEMU) console: [ 0.000000] MIPS: machine is mti,malta console: [ 0.000000] Determined physical RAM map: console: [ 0.000000] memory: 08000000 @ 00000000 (usable) console: [ 0.000000] earlycon: ns16550a0 at I/O port 0x3f8 (options '38400n8') console: [ 0.000000] bootconsole [ns16550a0] enabled console: [ 0.000000] User-defined physical RAM map: console: [ 0.000000] memory: 10000000 @ 00000000 (usable) console: [ 0.000000] Initrd not found or empty - disabling initrd console: [ 0.000000] MIPS CPS SMP unable to proceed without a CM console: [ 0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes. console: [ 0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes console: [ 0.000000] This processor doesn't support highmem. -262144k highmem ignored console: [ 0.000000] Zone ranges: console: [ 0.000000] Normal [mem 0x0000000000000000-0x000000000fffffff] console: [ 0.000000] HighMem empty console: [ 0.000000] Movable zone start for each node console: [ 0.000000] Early memory node ranges console: [ 0.000000] node 0: [mem 0x0000000000000000-0x000000000fffffff] console: [ 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff] console: [ 0.000000] random: get_random_bytes called from start_kernel+0x60/0x2f0 with crng_init=0 console: [ 0.000000] percpu: Embedded 16 pages/cpu @(ptrval) s36620 r8192 d20724 u65536 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 64960 console: [ 0.000000] Kernel command line: printk.time=0 mem=256m@@0x0 console=ttyS0 earlycon
--- tests/acceptance/boot_linux_console.py | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
tests/acceptance/boot_linux_console.py +59 -0
@@ -4,12 +4,15 @@ # # Author: # Cleber Rosa <[email protected]> +# Philippe Mathieu-Daudé <[email protected]> # # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. import os import logging +import lzma +import shutil from avocado_qemu import Test from avocado.utils import process
@@ -136,6 +139,62 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash): + kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + kernel_path = self.workdir + "kernel" + with lzma.open(kernel_path_xz, 'rb') as f_in: + with open(kernel_path, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) + + self.vm.set_machine('malta') + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'mem=256m@@0x0 ' + + 'console=ttyS0') + self.vm.add_args('-no-reboot', + '-cpu', 'I7200', + '-kernel', kernel_path, + '-append', kernel_command_line) + self.vm.launch() + console_pattern = 'Kernel command line: %s' % kernel_command_line + self.wait_for_console_pattern(console_pattern) + + def test_mips_malta32el_nanomips_4k(self): + """ + :avocado: tags=arch:mipsel + :avocado: tags=machine:malta + :avocado: tags=endian:little + """ + kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' + 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' + 'generic_nano32r6el_page4k.xz') + kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6' + self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) + + def test_mips_malta32el_nanomips_16k_up(self): + """ + :avocado: tags=arch:mipsel + :avocado: tags=machine:malta + :avocado: tags=endian:little + """ + kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' + 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' + 'generic_nano32r6el_page16k_up.xz') + kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc' + self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) + + def test_mips_malta32el_nanomips_64k_dbg(self): + """ + :avocado: tags=arch:mipsel + :avocado: tags=machine:malta + :avocado: tags=endian:little + """ + kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/' + 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/' + 'generic_nano32r6el_page64k_dbg.xz') + kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180' + self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash) + def test_aarch64_virt(self): """ :avocado: tags=arch:aarch64
Signature · 1 line
2.19.1
PATCH v2 3/4 BootLinuxConsoleTest: Run kerneltests BusyBox on Malta
In reply to Philippe Mathieu-DaudéThis tests boots a Linux kernel on a Malta machine up to a busybox shell on the serial console. Few commands are executed before halting the machine (via reboot).
We use the initrd cpio image from the kerneltests project:
https://kerneltests.org/
If MIPS is a target being built, "make check-acceptance" will automatically include this test by the use of the "arch:mips" tags.
Alternatively, this test can be run using:
$ avocado --show=console run -t arch:mips tests/acceptance/boot_linux_console.py [...] console: Boot successful. [...] console: / # uname -a console: Linux buildroot 4.5.0-2-4kc-malta #1 Debian 4.5.5-1 (2016-05-29) mips GNU/Linux console: / # reboot console: / # reboot: Restarting system
--- tests/acceptance/boot_linux_console.py | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
tests/acceptance/boot_linux_console.py +49 -0
@@ -12,6 +12,7 @@ import os import logging import lzma +import gzip import shutil from avocado_qemu import Test
@@ -48,6 +49,11 @@ class BootLinuxConsole(Test): fail = 'Failure message found in console: %s' % failure_message self.fail(fail) + def exec_command_and_wait_for_pattern(self, command, success_message): + command += '\n' + self.vm.console_socket.sendall(command.encode()) + self.wait_for_console_pattern(success_message) + def extract_from_deb(self, deb, path): """ Extracts a file from a deb package into the test workdir
@@ -139,6 +145,49 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_mips_malta_cpio(self): + """ + :avocado: tags=arch:mips + :avocado: tags=machine:malta + :avocado: tags=endian:big + """ + deb_url = ('http://snapshot.debian.org/archive/debian/' + '20160601T041800Z/pool/main/l/linux/' + 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb') + deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, + '/boot/vmlinux-4.5.0-2-4kc-malta') + initrd_url = ('https://github.com/groeck/linux-build-test/raw/' + '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/' + 'mips/rootfs.cpio.gz') + initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99' + initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + initrd_path = self.workdir + "rootfs.cpio" + + with gzip.open(initrd_path_gz, 'rb') as f_in: + with open(initrd_path, 'wb') as f_out: + shutil.copyfileobj(f_in, f_out) + + self.vm.set_machine('malta') + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 console=tty ' + + 'rdinit=/sbin/init noreboot') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line, + '-no-reboot') + self.vm.launch() + self.wait_for_console_pattern('Boot successful.') + + self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo', + 'BogoMIPS') + self.exec_command_and_wait_for_pattern('uname -a', + 'Debian') + self.exec_command_and_wait_for_pattern('reboot', + 'reboot: Restarting system') + def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash): kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash) kernel_path = self.workdir + "kernel"
Signature · 1 line
2.19.1
Quoted 25 lines · Philippe Mathieu-Daudé
Hi,
It was a rainy week-end here, so I invested it to automatize some of my MIPS tests.
The BootLinuxSshTest is not Global warming friendly, it is not meant to run on a CI system but rather on a workstation previous to post a pull request.
It can surely be improved, but it is a good starting point.v2: Decorate slow tests with
skipIf(CONTINUOUS_INTEGRATION):VENV /home/travis/build/philmd/qemu/tests/venv PIP /home/travis/build/philmd/qemu/tests/requirements.txt MKDIR /home/travis/build/philmd/qemu/tests/resultsAVOCADO tests/acceptance
JOB ID :02a2b1c585c12aebfbd8db2f330ed9730a547ae0
JOB LOG :/home/travis/build/philmd/qemu/tests/results/job-2019-05-23T16.05-02a2b1c/job.log
(01/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_x86_64_pc: PASS (5.41 s) (02/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips_malta: PASS (3.33 s) (03/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips64el_malta: PASS (3.47 s) (04/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_mips_malta_cpio: PASS (15.09 s) (05/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_aarch64_virt: PASS (2.48 s) (06/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_virt: PASS (7.25 s)
Quoted 8 lines
(07/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_s390x_s390_ccw_virtio: PASS (4.66 s) (08/22) acceptance/boot_linux_console.py:BootLinuxConsole.test_alpha_clipper: PASS (3.37 s)
(09/22) acceptance/cpu_queries.py:QueryCPUModelExpansion.test: PASS (0.16 s)
(10/22) acceptance/empty_cpu_model.py:EmptyCPUModel.test: PASS (0.02 s)
(11/22) acceptance/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_exit_error_msg_with_linux_v3_6: PASS (3.89 s) (12/22) acceptance/linux_initrd.py:LinuxInitrd.test_with_2gib_file_should_work_with_linux_v4_16: PASS (15.14 s) (13/22) acceptance/linux_ssh_mips_malta.py:LinuxSSH.test_mips_malta32eb_kernel3_2_0: SKIP: Running on Travis-CI (14/22) acceptance/linux_ssh_mips_malta.py:LinuxSSH.test_mips_malta64el_kernel3_2_0: SKIP: Running on Travis-CI
Job output here:
https://travis-ci.org/philmd/qemu/jobs/536369687
"Ran for 16 min 26 sec"
Quoted 10 lines
(15/22) acceptance/migration.py:Migration.test_migration_with_tcp_localhost: PASS (0.23 s) (16/22) acceptance/version.py:Version.test_qmp_human_info_version: PASS (0.04 s) (17/22) acceptance/virtio_version.py:VirtioVersionCheck.test_conventional_devs: PASS (1.20 s) (18/22) acceptance/virtio_version.py:VirtioVersionCheck.test_modern_only_devs: PASS (0.41 s) (19/22) acceptance/vnc.py:Vnc.test_no_vnc: PASS (0.03 s)
(20/22) acceptance/vnc.py:Vnc.test_no_vnc_change_password: PASS (0.04 s) (21/22) acceptance/vnc.py:Vnc.test_vnc_change_password_requires_a_password: PASS (0.04 s) (22/22) acceptance/vnc.py:Vnc.test_vnc_change_password: PASS (0.04 s)
RESULTS : PASS 20 | ERROR 0 | FAIL 0 | SKIP 2 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 68.64 s
PATCH v2 4/4 BootLinuxSshTest: Test some userspace commands on Malta
In reply to Philippe Mathieu-DaudéThis tests boot a full VM and check the serial console until the SSH daemon is running, then start a SSH session and run some commands.
This test can be run using:
$ avocado --show=ssh run -t arch:mips tests/acceptance/linux_ssh_mips_malta.py ssh: Entering interactive session. ssh: # uname -a ssh: Linux debian-mips 3.2.0-4-4kc-malta #1 Debian 3.2.51-1 mips GNU/Linux ssh: # lspci -d 11ab:4620 ssh: 00:00.0 Host bridge: Marvell Technology Group Ltd. GT-64120/64120A/64121A System Controller (rev 10) ssh: # cat /sys/bus/i2c/devices/i2c-0/name ssh: SMBus PIIX4 adapter at 1100 ssh: # cat /proc/mtd ssh: dev: size erasesize name ssh: mtd0: 00100000 00010000 "YAMON" ssh: mtd1: 002e0000 00010000 "User FS" ssh: mtd2: 00020000 00010000 "Board Config" ssh: # md5sum /dev/mtd2ro ssh: 0dfbe8aa4c20b52e1b8bf3cb6cbdf193 /dev/mtd2ro ssh: # poweroff
---
v2: Add skipIf(getenv(CONTINUOUS_INTEGRATION))
--- MAINTAINERS | 1 + tests/acceptance/linux_ssh_mips_malta.py | 230 +++++++++++++++++++++++ tests/requirements.txt | 1 + 3 files changed, 232 insertions(+) create mode 100644 tests/acceptance/linux_ssh_mips_malta.py
MAINTAINERS +1 -0
@@ -934,6 +934,7 @@ M: Aurelien Jarno <[email protected]> R: Aleksandar Rikalo <[email protected]> S: Maintained F: hw/mips/mips_malta.c +F: tests/acceptance/linux_ssh_mips_malta.py Mipssim M: Aleksandar Markovic <[email protected]>
tests/acceptance/linux_ssh_mips_malta.py new file +230 -0
230 lines not on this page · raw message
tests/requirements.txt +1 -0
@@ -2,3 +2,4 @@ # in the tests/venv Python virtual environment. For more info, # refer to: https://pip.pypa.io/en/stable/user_guide/#id1 avocado-framework==68.0 +paramiko
Signature · 1 line
2.19.1
Re: [Qemu-devel] [PATCH v2 4/4] BootLinuxSshTest: Test some userspace commands on Malta
Quoted 23 lines · Philippe Mathieu-Daudé
This tests boot a full VM and check the serial console until the SSH daemon is running, then start a SSH session and run some commands.
This test can be run using:
$ avocado --show=ssh run -t arch:mips tests/acceptance/linux_ssh_mips_malta.py ssh: Entering interactive session. ssh: # uname -a ssh: Linux debian-mips 3.2.0-4-4kc-malta #1 Debian 3.2.51-1 mips GNU/Linux ssh: # lspci -d 11ab:4620 ssh: 00:00.0 Host bridge: Marvell Technology Group Ltd. GT-64120/64120A/64121A System Controller (rev 10) ssh: # cat /sys/bus/i2c/devices/i2c-0/name ssh: SMBus PIIX4 adapter at 1100 ssh: # cat /proc/mtd ssh: dev: size erasesize name ssh: mtd0: 00100000 00010000 "YAMON" ssh: mtd1: 002e0000 00010000 "User FS" ssh: mtd2: 00020000 00010000 "Board Config" ssh: # md5sum /dev/mtd2ro ssh: 0dfbe8aa4c20b52e1b8bf3cb6cbdf193 /dev/mtd2ro ssh: # poweroff
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Add skipIf(getenv(CONTINUOUS_INTEGRATION))
This will make the behavior of "make check-acceptance" different inside and outside Travis, in a way that is not documented anywhere. I thought we would be using Avocado tags to indicate which tests we want to skip.
But if it solves our immediate problems we're having, I won't NACK this. Can we at least add TODO comments indicating we should eventually get rid of the hack?
Quoted 267 lines
--- MAINTAINERS | 1 + tests/acceptance/linux_ssh_mips_malta.py | 230 +++++++++++++++++++++++ tests/requirements.txt | 1 + 3 files changed, 232 insertions(+) create mode 100644 tests/acceptance/linux_ssh_mips_malta.pyMAINTAINERS +1
-0@@ -934,6 +934,7 @@ M: Aurelien Jarno <[email protected]> R: Aleksandar Rikalo <[email protected]> S: Maintained F: hw/mips/mips_malta.c +F: tests/acceptance/linux_ssh_mips_malta.py Mipssim M: Aleksandar Markovic <[email protected]>tests/acceptance/linux_ssh_mips_malta.py new file +230
-0@@ -0,0 +1,230 @@ +# Functional test that boots a VM and run commands via a SSH session +# +# Copyright (c) Philippe Mathieu-Daudé <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import os +import re +import base64 +import logging +import paramiko +import time + +from avocado import skipIf +from avocado_qemu import Test +from avocado.utils import process +from avocado.utils import archive + + +class LinuxSSH(Test): + + timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg' + + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + VM_IP = '127.0.0.1' + + IMAGE_INFO = { + 'be': { + 'image_url': 'https://people.debian.org/~aurel32/qemu/mips/' + 'debian_wheezy_mips_standard.qcow2', + 'image_hash': '8987a63270df67345b2135a6b7a4885a35e392d5', + 'rsa_hostkey': b'AAAAB3NzaC1yc2EAAAADAQABAAABAQCca1VitiyLAdQOld' + b'zT43IOEVJZ0wHD78GJi8wDAjMiYWUzNSSn0rXGQsINHuH5' + b'IlF+kBZsHinb/FtKCAyS9a8uCHhQI4SuB4QhAb0+39MlUw' + b'Mm0CLkctgM2eUUZ6MQMQvDlqnue6CCkxN62EZYbaxmby7j' + b'CQa1125o1HRKBvdGm2zrJWxXAfA+f1v6jHLyE8Jnu83eQ+' + b'BFY25G+Vzx1PVc3zQBwJ8r0NGTRqy2//oWQP0h+bMsgeFe' + b'KH/J3RJM22vg6+I4JAdBFcxnK+l781h1FuRxOn4O/Xslbg' + b'go6WtB4V4TOsw2E/KfxI5IZ/icxF+swVcnvF46Hf3uQc/0' + b'BBqb', + }, + 'le': { + 'image_url': 'https://people.debian.org/~aurel32/qemu/mipsel/' + 'debian_wheezy_mipsel_standard.qcow2', + 'image_hash': '7866764d9de3ef536ffca24c9fb9f04ffdb45802', + 'rsa_hostkey': b'AAAAB3NzaC1yc2EAAAADAQABAAABAQClXJlBT71HL5yKvv' + b'gfC7jmxSWx5zSBCzET6CLZczwAafSIs7YKfNOy/dQTxhuk' + b'yIGFUugZFoF3E9PzdhunuyvyTd56MPoNIqFbb5rGokwU5I' + b'TOx3dBHZR0mClypL6MVrwe0bsiIb8GhF1zioNwcsaAZnAi' + b'KfXStVDtXvn/kLLq+xLABYt48CC5KYWoFaCoICskLAY+qo' + b'L+LWyAnQisj4jAH8VSaSKIImFpfkHWEXPhHcC4ZBlDKtnH' + b'po9vhfCHgnfW3Pzrqmk8BI4HysqPFVmJWkJGlGUL+sGeg3' + b'ZZolAYuDXGuBrw8ooPJq2v2dOH+z6dyD2q/ypmAbyPqj5C' + b'rc8H', + }, + } + + def wait_for_console_pattern(self, success_message, + failure_message='Oops'): + console = self.vm.console_socket.makefile() + console_logger = logging.getLogger('console') + while True: + msg = console.readline() + console_logger.debug(msg.strip()) + if success_message in msg: + break + if failure_message in msg: + fail = 'Failure message found in console: %s' % failure_message + self.fail(fail) + + def get_portfwd(self): + res = self.vm.command('human-monitor-command', + command_line='info usernet') + line = res.split('\r\n')[2] + port = re.split(r'.*TCP.HOST_FORWARD.*127\.0\.0\.1 (\d+)\s+10\..*', + line)[1] + self.log.debug("sshd listening on port:" + port) + return port + + def ssh_connect(self, username, password, rsa_hostkey_b64=None): + self.ssh_logger = logging.getLogger('ssh') + self.ssh_username = username + self.ssh_ps1 = '# ' if username is 'root' else '$ ' + self.ssh_client = paramiko.SSHClient() + port = self.get_portfwd() + if rsa_hostkey_b64: + rsa_hostkey_bin = base64.b64decode(rsa_hostkey_b64) + rsa_hostkey = paramiko.RSAKey(data = rsa_hostkey_bin) + ipport = '[%s]:%s' % (self.VM_IP, port) + self.ssh_logger.debug('ipport ' + ipport) + self.ssh_client.get_host_keys().add(ipport, 'ssh-rsa', rsa_hostkey) + for i in range(10): + try: + self.ssh_client.connect(self.VM_IP, int(port), + username, password, banner_timeout=90) + self.ssh_logger.info("Entering interactive session.") + return + except: + time.sleep(4) + pass + self.fail("sshd timeout") + + def ssh_disconnect_vm(self): + self.ssh_client.close() + + def ssh_command(self, command, is_root=True): + self.ssh_logger.info(self.ssh_ps1 + command) + stdin, stdout, stderr = self.ssh_client.exec_command(command) + stdout_lines = [line.strip('\n') for line in stdout] + for line in stdout_lines: + self.ssh_logger.info(line) + stderr_lines = [line.strip('\n') for line in stderr] + for line in stderr_lines: + self.ssh_logger.warning(line) + return stdout_lines, stderr_lines + + def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path): + image_url = self.IMAGE_INFO[endianess]['image_url'] + image_hash = self.IMAGE_INFO[endianess]['image_hash'] + image_path = self.fetch_asset(image_url, asset_hash=image_hash) + rsa_hostkey_b64 = self.IMAGE_INFO[endianess]['rsa_hostkey'] + + self.vm.set_machine('malta') + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=ttyS0 root=/dev/sda1') + self.vm.add_args('-no-reboot', + '-kernel', kernel_path, + '-append', kernel_command_line, + '-hda', image_path, + '-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', 'pcnet,netdev=vnet') + self.vm.launch() + + self.log.info('VM launched, waiting for sshd') + console_pattern = 'Starting OpenBSD Secure Shell server: sshd' + self.wait_for_console_pattern(console_pattern) + self.log.info('sshd ready') + + self.ssh_connect('root', 'root', rsa_hostkey_b64=rsa_hostkey_b64) + + def shutdown_via_ssh(self): + self.ssh_command('poweroff') + self.ssh_disconnect_vm() + self.wait_for_console_pattern('Power down') + + def run_common_commands(self): + stdout, stderr = self.ssh_command('lspci -d 11ab:4620') + self.assertIn(True, ["GT-64120" in line for line in stdout]) + + stdout, stderr = self.ssh_command('cat /sys/bus/i2c/devices/i2c-0/name') + self.assertIn(True, ["SMBus PIIX4 adapter" in line + for line in stdout]) + + stdout, stderr = self.ssh_command('cat /proc/mtd') + self.assertIn(True, ["YAMON" in line + for line in stdout]) + + # Empty 'Board Config' + stdout, stderr = self.ssh_command('md5sum /dev/mtd2ro') + self.assertIn(True, ["0dfbe8aa4c20b52e1b8bf3cb6cbdf193" in line + for line in stdout]) + + def do_test_mips_malta(self, endianess, kernel_path, uname_m): + self.boot_debian_wheezy_image_and_ssh_login(endianess, kernel_path) + + stdout, stderr = self.ssh_command('uname -a') + self.assertIn(True, [uname_m + " GNU/Linux" in line for line in stdout]) + + self.run_common_commands() + self.shutdown_via_ssh() + + @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI') + def test_mips_malta32eb_kernel3_2_0(self): + """ + :avocado: tags=arch:mips + :avocado: tags=machine:malta + :avocado: tags=endian:big + :avocado: tags=device:pcnet32 + """ + kernel_url = ('https://people.debian.org/~aurel32/qemu/mips/' + 'vmlinux-3.2.0-4-4kc-malta') + kernel_hash = '592e384a4edc16dade52a6cd5c785c637bcbc9ad' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + + self.do_test_mips_malta('be', kernel_path, 'mips') + + @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI') + def test_mips_malta32el_kernel3_2_0(self): + """ + :avocado: tags=arch:mipsel + :avocado: tags=machine:malta + :avocado: tags=endian:little + :avocado: tags=device:pcnet32 + """ + kernel_url = ('https://people.debian.org/~aurel32/qemu/mipsel/' + 'vmlinux-3.2.0-4-4kc-malta') + kernel_hash = 'a66bea5a8adaa2cb3d36a1d4e0ccdb01be8f6c2a' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + + self.do_test_mips_malta('le', kernel_path, 'mips') + + @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI') + def test_mips_malta64eb_kernel3_2_0(self): + """ + :avocado: tags=arch:mips64 + :avocado: tags=machine:malta + :avocado: tags=endian:big + :avocado: tags=device:pcnet32 + """ + kernel_url = ('https://people.debian.org/~aurel32/qemu/mips/' + 'vmlinux-3.2.0-4-5kc-malta') + kernel_hash = 'db6eea7de35d36c77d8c165b6bcb222e16eb91db' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + self.do_test_mips_malta('be', kernel_path, 'mips64') + + @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI') + def test_mips_malta64el_kernel3_2_0(self): + """ + :avocado: tags=arch:mips64el + :avocado: tags=machine:malta + :avocado: tags=endian:little + :avocado: tags=device:pcnet32 + """ + kernel_url = ('https://people.debian.org/~aurel32/qemu/mipsel/' + 'vmlinux-3.2.0-4-5kc-malta') + kernel_hash = '6a7f77245acf231415a0e8b725d91ed2f3487794' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + self.do_test_mips_malta('le', kernel_path, 'mips64')tests/requirements.txt +1
-0@@ -2,3 +2,4 @@ # in the tests/venv Python virtual environment. For more info, # refer to: https://pip.pypa.io/en/stable/user_guide/#id1 avocado-framework==68.0 +paramikoSignature · 1 line
2.19.1
Signature · 1 line
Eduardo