On 30/7/24 19:03, Daniel P. Berrangé wrote:
From: Thomas Huth <th...@redhat.com>
The file is mostly a copy of the tests/avocado/avocado_qemu/__init__.py
file with some adjustments to get rid of the Avocado dependencies (i.e.
we also have to drop the LinuxSSHMixIn and LinuxTest for now).
The emulator binary and build directory are now passed via
environment variables that will be set via meson.build later.
Signed-off-by: Thomas Huth <th...@redhat.com>
[DB: split __init__.py into multiple files]
Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
tests/functional/qemu_test/__init__.py | 13 ++
tests/functional/qemu_test/cmd.py | 171 +++++++++++++++++++++++++
tests/functional/qemu_test/config.py | 36 ++++++
tests/functional/qemu_test/testcase.py | 154 ++++++++++++++++++++++
4 files changed, 374 insertions(+)
create mode 100644 tests/functional/qemu_test/__init__.py
create mode 100644 tests/functional/qemu_test/cmd.py
create mode 100644 tests/functional/qemu_test/config.py
create mode 100644 tests/functional/qemu_test/testcase.py
diff --git a/tests/functional/qemu_test/testcase.py
b/tests/functional/qemu_test/testcase.py
new file mode 100644
index 0000000000..82cc1d454f
--- /dev/null
+++ b/tests/functional/qemu_test/testcase.py
@@ -0,0 +1,154 @@
+# Test class and utilities for functional tests
+#
+# Copyright 2018, 2024 Red Hat, Inc.
+#
+# Original Author (Avocado-based tests):
+# Cleber Rosa <cr...@redhat.com>
+#
+# Adaption for standalone version:
+# Thomas Huth <th...@redhat.com>
+#
+# 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 logging
+import os
+import pycotap
+import sys
+import unittest
+import uuid
+
+from qemu.machine import QEMUMachine
+from qemu.utils import kvm_available, tcg_available
+
+from .cmd import run_cmd
+from .config import BUILD_DIR
+
+
+class QemuBaseTest(unittest.TestCase):
+
+ qemu_bin = os.getenv('QEMU_TEST_QEMU_BINARY')
+ arch = None
+
+ workdir = None
+ log = logging.getLogger('qemu-test')
+
+ def setUp(self, bin_prefix):
+ self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be
set')
+ self.arch = self.qemu_bin.split('-')[-1]
+
+ self.workdir = os.path.join(BUILD_DIR, 'tests/functional', self.arch,
+ self.id())
+ if not os.path.exists(self.workdir):
+ os.makedirs(self.workdir)
+
+ def main():
[*]
+ tr = pycotap.TAPTestRunner(message_log = pycotap.LogMode.LogToError,
+ test_output_log =
pycotap.LogMode.LogToError)
+ path = os.path.basename(sys.argv[0])[:-3]
Moving the 'path' line in [*] simplifies patch #9 (no duplication).
+ unittest.main(module = None, testRunner = tr, argv=["__dummy__", path])