[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PULL 2/6] Acceptance tests: introduce BUILD_DIR and SOURCE_DIR

From: Cleber Rosa
Subject: [PULL 2/6] Acceptance tests: introduce BUILD_DIR and SOURCE_DIR
Date: Tue, 17 Mar 2020 20:19:28 -0400

Some tests may benefit from using resources from a build directory.
This introduces three variables that can help tests find resources in
those directories.

First, a BUILD_DIR is assumed to exist, given that the primary form of
running the acceptance tests is from a build directory (which may or
may not be the same as the source tree, that is, the SOURCE_DIR).

If the directory containing the acceptance tests happens to be a link
to a directory, it's assumed to it points to the source tree
(SOURCE_DIR), which is the behavior defined on the QEMU Makefiles.  If
the directory containing the acceptance tests is not a link, then a
in-tree build is assumed, and the BUILD_DIR and SOURCE_DIR have the
same value.

Signed-off-by: Cleber Rosa <address@hidden>
Reviewed-by: Wainer dos Santos Moschetta <address@hidden>
Tested-by: Wainer dos Santos Moschetta <address@hidden>
Reviewed-by: Willian Rampazzo <address@hidden>
Tested-by: Willian Rampazzo <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Cleber Rosa <address@hidden>
 tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py 
index d4358eb431..59e7b4f763 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -16,8 +16,21 @@ import tempfile
 import avocado
-SRC_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..')
-sys.path.append(os.path.join(SRC_ROOT_DIR, 'python'))
+#: The QEMU build root directory.  It may also be the source directory
+#: if building from the source dir, but it's safer to use BUILD_DIR for
+#: that purpose.  Be aware that if this code is moved outside of a source
+#: and build tree, it will not be accurate.
+if os.path.islink(os.path.dirname(os.path.dirname(__file__))):
+    # The link to the acceptance tests dir in the source code directory
+    lnk = os.path.dirname(os.path.dirname(__file__))
+    #: The QEMU root source directory
+    SOURCE_DIR = os.path.dirname(os.path.dirname(os.readlink(lnk)))
+sys.path.append(os.path.join(SOURCE_DIR, 'python'))
 from qemu.machine import QEMUMachine
@@ -49,10 +62,10 @@ def pick_default_qemu_bin(arch=None):
     if is_readable_executable_file(qemu_bin_relative_path):
         return qemu_bin_relative_path
-    qemu_bin_from_src_dir_path = os.path.join(SRC_ROOT_DIR,
+    qemu_bin_from_bld_dir_path = os.path.join(BUILD_DIR,
-    if is_readable_executable_file(qemu_bin_from_src_dir_path):
-        return qemu_bin_from_src_dir_path
+    if is_readable_executable_file(qemu_bin_from_bld_dir_path):
+        return qemu_bin_from_bld_dir_path
 def _console_interaction(test, success_message, failure_message,
@@ -153,7 +166,7 @@ class Test(avocado.Test):
         self.qemu_bin = self.params.get('qemu_bin',
         if self.qemu_bin is None:
-            self.cancel("No QEMU binary defined or found in the source tree")
+            self.cancel("No QEMU binary defined or found in the build tree")
     def _new_vm(self, *args):
         vm = QEMUMachine(self.qemu_bin, sock_dir=tempfile.mkdtemp())

reply via email to

[Prev in Thread] Current Thread [Next in Thread]