[PATCH v3 3/5] tests/acceptance: Introduce QemuUserTest base class

Philippe Mathieu-Daudé posted 5 patches 4 years, 11 months ago
There is a newer version of this series
[PATCH v3 3/5] tests/acceptance: Introduce QemuUserTest base class
Posted by Philippe Mathieu-Daudé 4 years, 11 months ago
Similarly to the 'System' Test base class with methods for testing
system emulation, the QemuUserTest class contains methods useful to
test user-mode emulation.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/avocado_qemu/__init__.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 08b3fa1124f..b471bee66e0 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -20,6 +20,7 @@
 from avocado.utils import cloudinit
 from avocado.utils import datadrainer
 from avocado.utils import network
+from avocado.utils import process
 from avocado.utils import vmimage
 from avocado.utils.path import find_command
 
@@ -256,6 +257,19 @@ def fetch_asset(self, name,
                         find_only=find_only,
                         cancel_on_missing=cancel_on_missing)
 
+class QemuUserTest(QemuBaseTest):
+    def setUp(self):
+        self._ldpath = []
+        super(QemuUserTest, self).setUp("qemu-%s")
+
+    def add_ldpath(self, ldpath):
+        self._ldpath += [os.path.abspath(ldpath)]
+
+    def run(self, bin_path, args=[]):
+        qemu_args = " ".join(["-L %s" % ldpath for ldpath in self._ldpath])
+        bin_args = " ".join(args)
+        return process.run("%s %s %s %s" % (self.qemu_bin, qemu_args,
+                                            bin_path, bin_args))
 
 class LinuxTest(Test):
     """Facilitates having a cloud-image Linux based available.
-- 
2.26.2

Re: [PATCH v3 3/5] tests/acceptance: Introduce QemuUserTest base class
Posted by Wainer dos Santos Moschetta 4 years, 10 months ago
Hi,

On 3/15/21 8:08 PM, Philippe Mathieu-Daudé wrote:
> Similarly to the 'System' Test base class with methods for testing
> system emulation, the QemuUserTest class contains methods useful to
> test user-mode emulation.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   tests/acceptance/avocado_qemu/__init__.py | 14 ++++++++++++++
>   1 file changed, 14 insertions(+)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 08b3fa1124f..b471bee66e0 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -20,6 +20,7 @@
>   from avocado.utils import cloudinit
>   from avocado.utils import datadrainer
>   from avocado.utils import network
> +from avocado.utils import process
>   from avocado.utils import vmimage
>   from avocado.utils.path import find_command
>   
> @@ -256,6 +257,19 @@ def fetch_asset(self, name,
>                           find_only=find_only,
>                           cancel_on_missing=cancel_on_missing)
>   
> +class QemuUserTest(QemuBaseTest):
> +    def setUp(self):
> +        self._ldpath = []
> +        super(QemuUserTest, self).setUp("qemu-%s")

There is my comment on patch 02 regarding the setUp() argument. Apart 
from that, this code looks good to me:

Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>

> +
> +    def add_ldpath(self, ldpath):
> +        self._ldpath += [os.path.abspath(ldpath)]
> +
> +    def run(self, bin_path, args=[]):
> +        qemu_args = " ".join(["-L %s" % ldpath for ldpath in self._ldpath])
> +        bin_args = " ".join(args)
> +        return process.run("%s %s %s %s" % (self.qemu_bin, qemu_args,
> +                                            bin_path, bin_args))
>   
>   class LinuxTest(Test):
>       """Facilitates having a cloud-image Linux based available.