[libvirt] [PATCH 2/2] test: qemuhotplugtest mock virFileMakePath

Daniel Henrique Barboza danielhb413 at gmail.com
Wed Jan 15 17:32:38 UTC 2020



On 1/15/20 1:37 PM, Christian Ehrhardt wrote:
> In certain build environments (e.g. Debian and Ubuntu) $HOME is set
> to a non existing path intentionally. That breaks and crashes
> qemuhotplugtest by failing the init in virHostdevManagerGetDefault.
> 
> Avoid that issue by mocking the virFileMakePath behavior if it is
> passed a path that matches $HOME and doesn't exists. That fixes
> qemuhotplugtest in Debian/Ubuntu builds of v6.0.0.
> 
> Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
> ---
>   tests/qemuhotplugmock.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c
> index 43a9d79051..bd5eb3ceb6 100644
> --- a/tests/qemuhotplugmock.c
> +++ b/tests/qemuhotplugmock.c
> @@ -18,6 +18,7 @@
>   
>   #include <config.h>
>   
> +#include "virmock.h"
>   #include "qemu/qemu_hotplug.h"
>   #include "conf/domain_conf.h"
>   
> @@ -31,3 +32,20 @@ qemuDomainGetUnplugTimeout(virDomainObjPtr vm G_GNUC_UNUSED)
>           return 200;
>       return 100;
>   }
> +
> +VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
> +                       const char *, path)
> +{
> +    const char *home;
> +
> +    VIR_MOCK_REAL_INIT(virFileMakePath);
> +
> +    /* ignore non-existing homes (e.g. in build environments) */
> +    home = getenv("HOME");
> +    if (strstr(path, home)) {
> +        if (!g_file_test (home, G_FILE_TEST_EXISTS)) {
> +            return 0;
> +        }
> +    }

make syntax-check is not happy with the curly brackets here:


Whitespace after non-keyword:
../tests/qemuhotplugmock.c:46:         if (!g_file_test (home, G_FILE_TEST_EXISTS)) {
Curly brackets around single-line body:
../tests/qemuhotplugmock.c:46-48:
         if (!g_file_test (home, G_FILE_TEST_EXISTS)) {
             return 0;
         }
build-aux/syntax-check.mk: incorrect formatting
make: *** [../build-aux/syntax-check.mk:2173: spacing-check] Error 1
make: *** Waiting for unfinished jobs....
$


This fixes it:

$ git diff
diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c
index bd5eb3ceb6..fdad585e33 100644
--- a/tests/qemuhotplugmock.c
+++ b/tests/qemuhotplugmock.c
@@ -43,9 +43,8 @@ VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
      /* ignore non-existing homes (e.g. in build environments) */
      home = getenv("HOME");
      if (strstr(path, home)) {
-        if (!g_file_test (home, G_FILE_TEST_EXISTS)) {
+        if (!g_file_test(home, G_FILE_TEST_EXISTS))
              return 0;
-        }
      }
      return real_virFileMakePath(path);
  }



With this fixed:


Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>



> +    return real_virFileMakePath(path);
> +}
> 




More information about the libvir-list mailing list