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 BLD_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 SRC_DIR).
If the directory containing the acceptance tests happens to be a link
to a directory (kept as LNK_DIR), it's assumed to it points to the
source tree (SRC_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 BLD_DIR and SRC_DIR are
the same and LNK_DIR is set None.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
tests/acceptance/avocado_qemu/__init__.py | 27 ++++++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 6618ea67c1..ac7597f7fe 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -16,8 +16,23 @@ 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 BLD_DIR for
+#: that purpose. Be aware that if this code is moved outside of a source
+#: and build tree, it will not be accurate.
+BLD_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+
+if os.path.islink(os.path.dirname(os.path.dirname(__file__))):
+ #: The link to the acceptance tests dir in the source code directory. If
+ #: build dir is the same as the source dir, this is set to None
+ LNK_DIR = os.path.dirname(os.path.dirname(__file__))
+ #: The QEMU root source directory
+ SRC_DIR = os.path.dirname(os.path.dirname(os.readlink(LNK_DIR)))
+else:
+ LNK_DIR = None
+ SRC_DIR = BLD_DIR
+
+sys.path.append(os.path.join(SRC_DIR, 'python'))
from qemu.machine import QEMUMachine
@@ -49,10 +64,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(BLD_DIR,
qemu_bin_relative_path)
- 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 wait_for_console_pattern(test, success_message, failure_message=None):
@@ -122,7 +137,7 @@ class Test(avocado.Test):
self.qemu_bin = self.params.get('qemu_bin',
default=default_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())
--
2.21.0
On 12/19/19 12:24 AM, Cleber Rosa wrote:
> 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 BLD_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 SRC_DIR).
Can we name this BUILD_DIR?
This would be more in line with the other buildsys files (configure/make).
> If the directory containing the acceptance tests happens to be a link
> to a directory (kept as LNK_DIR), it's assumed to it points to the
> source tree (SRC_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 BLD_DIR and SRC_DIR are
> the same and LNK_DIR is set None.
Similarly, can we name this CURRENT_DIR instead of LNK_DIR?
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
> tests/acceptance/avocado_qemu/__init__.py | 27 ++++++++++++++++++-----
> 1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 6618ea67c1..ac7597f7fe 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -16,8 +16,23 @@ 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 BLD_DIR for
> +#: that purpose. Be aware that if this code is moved outside of a source
> +#: and build tree, it will not be accurate.
> +BLD_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
> +
> +if os.path.islink(os.path.dirname(os.path.dirname(__file__))):
> + #: The link to the acceptance tests dir in the source code directory. If
> + #: build dir is the same as the source dir, this is set to None
> + LNK_DIR = os.path.dirname(os.path.dirname(__file__))
> + #: The QEMU root source directory
> + SRC_DIR = os.path.dirname(os.path.dirname(os.readlink(LNK_DIR)))
> +else:
> + LNK_DIR = None
> + SRC_DIR = BLD_DIR
> +
> +sys.path.append(os.path.join(SRC_DIR, 'python'))
>
> from qemu.machine import QEMUMachine
>
> @@ -49,10 +64,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(BLD_DIR,
> qemu_bin_relative_path)
> - 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 wait_for_console_pattern(test, success_message, failure_message=None):
> @@ -122,7 +137,7 @@ class Test(avocado.Test):
> self.qemu_bin = self.params.get('qemu_bin',
> default=default_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())
>
On Thu, Dec 19, 2019 at 01:02:39AM +0100, Philippe Mathieu-Daudé wrote: > On 12/19/19 12:24 AM, Cleber Rosa wrote: > > 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 BLD_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 SRC_DIR). > > Can we name this BUILD_DIR? > Yes, of course. > This would be more in line with the other buildsys files (configure/make). > That's a good point. > > If the directory containing the acceptance tests happens to be a link > > to a directory (kept as LNK_DIR), it's assumed to it points to the > > source tree (SRC_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 BLD_DIR and SRC_DIR are > > the same and LNK_DIR is set None. > > Similarly, can we name this CURRENT_DIR instead of LNK_DIR? > Yes, or maybe even drop it? TBH, I can only see use cases for build and source dirs. So, I assume you'd propose SRC_DIR would be SOURCE_DIR? Cheers, - Cleber.
On 12/19/19 1:25 AM, Cleber Rosa wrote: > On Thu, Dec 19, 2019 at 01:02:39AM +0100, Philippe Mathieu-Daudé wrote: >> On 12/19/19 12:24 AM, Cleber Rosa wrote: >>> 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 BLD_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 SRC_DIR). >> >> Can we name this BUILD_DIR? >> > > Yes, of course. > >> This would be more in line with the other buildsys files (configure/make). >> > > That's a good point. > >>> If the directory containing the acceptance tests happens to be a link >>> to a directory (kept as LNK_DIR), it's assumed to it points to the >>> source tree (SRC_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 BLD_DIR and SRC_DIR are >>> the same and LNK_DIR is set None. >> >> Similarly, can we name this CURRENT_DIR instead of LNK_DIR? >> > > Yes, or maybe even drop it? TBH, I can only see use cases for build I haven't checked why you needed to add it, so if we don't need it, let's drop it :) > and source dirs. So, I assume you'd propose SRC_DIR would be > SOURCE_DIR? This one is understandable as it, but SOURCE_DIR is cleaner indeed. Thanks, Phil.
On 12/19/19 9:12 AM, Philippe Mathieu-Daudé wrote: > On 12/19/19 1:25 AM, Cleber Rosa wrote: >> On Thu, Dec 19, 2019 at 01:02:39AM +0100, Philippe Mathieu-Daudé wrote: >>> On 12/19/19 12:24 AM, Cleber Rosa wrote: >>>> 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 BLD_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 SRC_DIR). >>> >>> Can we name this BUILD_DIR? >>> >> >> Yes, of course. >> >>> This would be more in line with the other buildsys files >>> (configure/make). >>> >> >> That's a good point. >> >>>> If the directory containing the acceptance tests happens to be a link >>>> to a directory (kept as LNK_DIR), it's assumed to it points to the >>>> source tree (SRC_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 BLD_DIR and SRC_DIR are >>>> the same and LNK_DIR is set None. >>> >>> Similarly, can we name this CURRENT_DIR instead of LNK_DIR? >>> >> >> Yes, or maybe even drop it? TBH, I can only see use cases for build > > I haven't checked why you needed to add it, so if we don't need it, > let's drop it :) 1+ for dropping LNK_DIR variable. Thanks, Wainer > > >> and source dirs. So, I assume you'd propose SRC_DIR would be >> SOURCE_DIR? > > This one is understandable as it, but SOURCE_DIR is cleaner indeed. > > Thanks, > > Phil. > >
© 2016 - 2026 Red Hat, Inc.