From nobody Sun May 11 11:48:59 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass(p=none dis=none)  header.from=redhat.com
ARC-Seal: i=1; a=rsa-sha256; t=1734527754; cv=none;
	d=zohomail.com; s=zohoarc;
	b=jmXfB1T7RUH53ha1sWSrnplR/UgLUXeyNsrC3pTPAmoLWj5Eu5/m21Rg2fu3oR9Ql0AAKbwxE3Tc3iWFkpc6zod3nQBFaeVeayxl9BXYq+rldM1JgtIGT2jpVTM50h1JwKpiM6VoCMkAESw5WMP9KSh3089biLl9D7M4iQSnrlE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1734527754;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=4rjPuN3IFld4pUl6SnjEFUI6gXUHq4mMQ5h7w8p42HE=;
	b=ilDeqyTskmp3POW6vQXZhQ2hMdrO5y2PcySYDZ0aFole4gOzxmDdow20OZyTIrWDMKHq9kEhq7fJEPVeSmpyU3AaQ293gogmZ5l7tp0YGE1C68lDmiUPn5JRB+R1FWxYGPugYrHIfHYGZei310QauT7jr7PeJMuQk+h381Ct8Jg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=pass header.from=<thuth@redhat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1734527754627419.78822192322707;
 Wed, 18 Dec 2024 05:15:54 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tNttp-0002Ku-OD; Wed, 18 Dec 2024 08:15:39 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <thuth@redhat.com>) id 1tNttX-0002F6-2k
 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 08:15:20 -0500
Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <thuth@redhat.com>) id 1tNttO-0005St-KO
 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 08:15:16 -0500
Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com
 (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by
 relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,
 cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-ZdyBwAPxM5S0QEwqJqhMAg-1; Wed,
 18 Dec 2024 08:15:05 -0500
Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com
 (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest
 SHA256)
 (No client certificate requested)
 by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS
 id 3D0A51955F42; Wed, 18 Dec 2024 13:15:04 +0000 (UTC)
Received: from thuth-p1g4.redhat.com (unknown [10.39.192.114])
 by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP
 id 2662E30044C1; Wed, 18 Dec 2024 13:15:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1734527708;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=4rjPuN3IFld4pUl6SnjEFUI6gXUHq4mMQ5h7w8p42HE=;
 b=N4RMihkzFhwVIaJtmAfloT87vvOmgCam+TjCBE3xnp/KhHkM09IDva6hkyfKY6U8wxpyP6
 EJyWEzRAE41ieG3wh4vXAJpmgIODasS6CGZED/QZ3NKumWotw0X+KOWaErZjzhcJ3LW1ya
 9KJhF5N5aGKKlDIYn1t3670EIukI8k8=
X-MC-Unique: ZdyBwAPxM5S0QEwqJqhMAg-1
X-Mimecast-MFC-AGG-ID: ZdyBwAPxM5S0QEwqJqhMAg
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org,
 =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@linaro.org>,
 =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Cc: Peter Xu <peterx@redhat.com>,
	Fabiano Rosas <farosas@suse.de>
Subject: [PATCH v2 5/5] tests/functional: Convert the migration avocado test
Date: Wed, 18 Dec 2024 14:14:39 +0100
Message-ID: <20241218131439.255841-6-thuth@redhat.com>
In-Reply-To: <20241218131439.255841-1-thuth@redhat.com>
References: <20241218131439.255841-1-thuth@redhat.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com;
 helo=us-smtp-delivery-124.mimecast.com
X-Spam_score_int: -31
X-Spam_score: -3.2
X-Spam_bar: ---
X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001,
 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.116,
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @redhat.com)
X-ZM-MESSAGEID: 1734527755541116600
Content-Type: text/plain; charset="utf-8"

Now that we've got a find_free_port() function in the functional
test framework, we can convert the migration test, too.
While the original avocado test was only meant to run on aarch64,
ppc64 and x86, we can turn this into a more generic test by now
and run it on all architectures that have a default machine that
ships with a working firmware.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 MAINTAINERS                                   |   1 +
 tests/functional/meson.build                  |  19 +++
 .../test_migration.py}                        | 121 +++++-------------
 3 files changed, 54 insertions(+), 87 deletions(-)
 rename tests/{avocado/migration.py =3D> functional/test_migration.py} (41%)
 mode change 100644 =3D> 100755

diff --git a/MAINTAINERS b/MAINTAINERS
index 389b390de1..704648d57a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3429,6 +3429,7 @@ F: include/migration/
 F: include/qemu/userfaultfd.h
 F: migration/
 F: scripts/vmstate-static-checker.py
+F: tests/functional/test_migration.py
 F: tests/vmstate-static-checker-data/
 F: tests/qtest/migration/
 F: tests/qtest/migration-*
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 781bd7eae6..8c3d1c26da 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -70,6 +70,10 @@ tests_aarch64_system_thorough =3D [
   'multiprocess',
 ]
=20
+tests_alpha_system_quick =3D [
+  'migration',
+]
+
 tests_alpha_system_thorough =3D [
   'alpha_clipper',
 ]
@@ -167,6 +171,10 @@ tests_ppc_system_thorough =3D [
   'ppc_virtex_ml507',
 ]
=20
+tests_ppc64_system_quick =3D [
+  'migration',
+]
+
 tests_ppc64_system_thorough =3D [
   'ppc64_e500',
   'ppc64_hv',
@@ -176,6 +184,7 @@ tests_ppc64_system_thorough =3D [
 ]
=20
 tests_riscv32_system_quick =3D [
+  'migration',
   'riscv_opensbi',
 ]
=20
@@ -184,6 +193,7 @@ tests_riscv32_system_thorough =3D [
 ]
=20
 tests_riscv64_system_quick =3D [
+  'migration',
   'riscv_opensbi',
 ]
=20
@@ -210,10 +220,18 @@ tests_sh4eb_system_thorough =3D [
   'sh4eb_r2d',
 ]
=20
+tests_sparc_system_quick =3D [
+  'migration',
+]
+
 tests_sparc_system_thorough =3D [
   'sparc_sun4m',
 ]
=20
+tests_sparc64_system_quick =3D [
+  'migration',
+]
+
 tests_sparc64_system_thorough =3D [
   'sparc64_sun4u',
   'sparc64_tuxrun',
@@ -222,6 +240,7 @@ tests_sparc64_system_thorough =3D [
 tests_x86_64_system_quick =3D [
   'cpu_queries',
   'mem_addr_space',
+  'migration',
   'pc_cpu_hotplug_props',
   'virtio_version',
   'x86_cpu_model_versions',
diff --git a/tests/avocado/migration.py b/tests/functional/test_migration.py
old mode 100644
new mode 100755
similarity index 41%
rename from tests/avocado/migration.py
rename to tests/functional/test_migration.py
index be6234b3c2..5607d601eb
--- a/tests/avocado/migration.py
+++ b/tests/functional/test_migration.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+#
 # Migration test
 #
 # Copyright (c) 2019 Red Hat, Inc.
@@ -9,22 +11,14 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later.  See the COPYING file in the top-level directory.
=20
-
-import tempfile
 import os
+import tempfile
+import time
=20
-from avocado_qemu import QemuSystemTest
-from avocado import skipUnless
-
-from avocado.utils.network import ports
-from avocado.utils import wait
-from avocado.utils.path import find_command
-
+from qemu_test import QemuSystemTest, skipIfMissingCommands
+from qemu_test.ports import Ports
=20
 class MigrationTest(QemuSystemTest):
-    """
-    :avocado: tags=3Dmigration
-    """
=20
     timeout =3D 10
=20
@@ -33,103 +27,56 @@ def migration_finished(vm):
         return vm.cmd('query-migrate')['status'] in ('completed', 'failed')
=20
     def assert_migration(self, src_vm, dst_vm):
-        wait.wait_for(self.migration_finished,
-                      timeout=3Dself.timeout,
-                      step=3D0.1,
-                      args=3D(src_vm,))
-        wait.wait_for(self.migration_finished,
-                      timeout=3Dself.timeout,
-                      step=3D0.1,
-                      args=3D(dst_vm,))
+
+        end =3D time.monotonic() + self.timeout
+        while time.monotonic() < end and not self.migration_finished(src_v=
m):
+           time.sleep(0.1)
+
+        end =3D time.monotonic() + self.timeout
+        while time.monotonic() < end and not self.migration_finished(dst_v=
m):
+           time.sleep(0.1)
+
         self.assertEqual(src_vm.cmd('query-migrate')['status'], 'completed=
')
         self.assertEqual(dst_vm.cmd('query-migrate')['status'], 'completed=
')
         self.assertEqual(dst_vm.cmd('query-status')['status'], 'running')
         self.assertEqual(src_vm.cmd('query-status')['status'],'postmigrate=
')
=20
     def do_migrate(self, dest_uri, src_uri=3DNone):
-        dest_vm =3D self.get_vm('-incoming', dest_uri)
+        dest_vm =3D self.get_vm('-incoming', dest_uri, name=3D"dest-qemu")
         dest_vm.add_args('-nodefaults')
         dest_vm.launch()
         if src_uri is None:
             src_uri =3D dest_uri
-        source_vm =3D self.get_vm()
+        source_vm =3D self.get_vm(name=3D"source-qemu")
         source_vm.add_args('-nodefaults')
         source_vm.launch()
         source_vm.qmp('migrate', uri=3Dsrc_uri)
         self.assert_migration(source_vm, dest_vm)
=20
-    def _get_free_port(self):
+    def _get_free_port(self, ports):
         port =3D ports.find_free_port()
         if port is None:
-            self.cancel('Failed to find a free port')
+            self.skipTest('Failed to find a free port')
         return port
=20
-    def migration_with_tcp_localhost(self):
-        dest_uri =3D 'tcp:localhost:%u' % self._get_free_port()
-        self.do_migrate(dest_uri)
+    def test_migration_with_tcp_localhost(self):
+        with Ports() as ports:
+            dest_uri =3D 'tcp:localhost:%u' % self._get_free_port(ports)
+            self.do_migrate(dest_uri)
=20
-    def migration_with_unix(self):
+    def test_migration_with_unix(self):
         with tempfile.TemporaryDirectory(prefix=3D'socket_') as socket_pat=
h:
             dest_uri =3D 'unix:%s/qemu-test.sock' % socket_path
             self.do_migrate(dest_uri)
=20
-    @skipUnless(find_command('nc', default=3DFalse), "'nc' command not fou=
nd")
-    def migration_with_exec(self):
-        """The test works for both netcat-traditional and netcat-openbsd p=
ackages."""
-        free_port =3D self._get_free_port()
-        dest_uri =3D 'exec:nc -l localhost %u' % free_port
-        src_uri =3D 'exec:nc localhost %u' % free_port
-        self.do_migrate(dest_uri, src_uri)
-
-
-@skipUnless('aarch64' in os.uname()[4], "host !=3D target")
-class Aarch64(MigrationTest):
-    """
-    :avocado: tags=3Darch:aarch64
-    :avocado: tags=3Dmachine:virt
-    :avocado: tags=3Dcpu:max
-    """
-
-    def test_migration_with_tcp_localhost(self):
-        self.migration_with_tcp_localhost()
-
-    def test_migration_with_unix(self):
-        self.migration_with_unix()
-
-    def test_migration_with_exec(self):
-        self.migration_with_exec()
-
-
-@skipUnless('x86_64' in os.uname()[4], "host !=3D target")
-class X86_64(MigrationTest):
-    """
-    :avocado: tags=3Darch:x86_64
-    :avocado: tags=3Dmachine:pc
-    :avocado: tags=3Dcpu:qemu64
-    """
-
-    def test_migration_with_tcp_localhost(self):
-        self.migration_with_tcp_localhost()
-
-    def test_migration_with_unix(self):
-        self.migration_with_unix()
-
+    @skipIfMissingCommands('nc')
     def test_migration_with_exec(self):
-        self.migration_with_exec()
-
-
-@skipUnless('ppc64le' in os.uname()[4], "host !=3D target")
-class PPC64(MigrationTest):
-    """
-    :avocado: tags=3Darch:ppc64
-    :avocado: tags=3Dmachine:pseries
-    """
-
-    def test_migration_with_tcp_localhost(self):
-        self.migration_with_tcp_localhost()
-
-    def test_migration_with_unix(self):
-        self.migration_with_unix()
-
-    def test_migration_with_exec(self):
-        self.migration_with_exec()
+        """The test works for both netcat-traditional and netcat-openbsd p=
ackages."""
+        with Ports() as ports:
+            free_port =3D self._get_free_port(ports)
+            dest_uri =3D 'exec:nc -l localhost %u' % free_port
+            src_uri =3D 'exec:nc localhost %u' % free_port
+            self.do_migrate(dest_uri, src_uri)
+
+if __name__ =3D=3D '__main__':
+    QemuSystemTest.main()
--=20
2.47.1