[libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables

Daniel P. Berrangé posted 1 patch 3 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200504143925.728767-1-berrange@redhat.com
tests/testutils.c | 3 +++
1 file changed, 3 insertions(+)
[libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables
Posted by Daniel P. Berrangé 3 years, 11 months ago
To attempt to catch unit tests which accidentally create files in $HOME,
or $XDG_RUNTIME_DIR, poison these env vars by pointing them to
directories which don't exist. This should give easier to debug test
failures. For example:

$ VIR_TEST_DEBUG=1 ./qemuhotplugtest
Could not initialize HostdevManager - operation failed: Failed to create state dir '/bad-test-used-env-xdg-runtime-dir/libvirt/hostdevmgr'

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/testutils.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/testutils.c b/tests/testutils.c
index 5fd81b70a2..8533a02d73 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -767,6 +767,9 @@ int virTestMain(int argc,
         preloads[npreloads] = NULL;
     }
 
+    setenv("HOME", "/bad-test-used-env-home", 1);
+    setenv("XDG_RUNTIME_DIR", "/bad-test-used-env-xdg-runtime-dir", 1);
+
     va_start(ap, func);
     while ((lib = va_arg(ap, const char *))) {
         if (!virFileIsExecutable(lib)) {
-- 
2.26.2

Re: [libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables
Posted by Andrea Bolognani 3 years, 11 months ago
On Mon, 2020-05-04 at 15:39 +0100, Daniel P. Berrangé wrote:
> To attempt to catch unit tests which accidentally create files in $HOME,
> or $XDG_RUNTIME_DIR, poison these env vars by pointing them to
> directories which don't exist. This should give easier to debug test
> failures. For example:
> 
> $ VIR_TEST_DEBUG=1 ./qemuhotplugtest
> Could not initialize HostdevManager - operation failed: Failed to create state dir '/bad-test-used-env-xdg-runtime-dir/libvirt/hostdevmgr'
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  tests/testutils.c | 3 +++
>  1 file changed, 3 insertions(+)

This looks good, so

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>

but please don't merge it until

  https://www.redhat.com/archives/libvir-list/2020-May/msg00212.html

is in or you'll break all builds :)

-- 
Andrea Bolognani / Red Hat / Virtualization

Re: [libvirt PATCH] tests: poison $HOME and $XDG_RUNTIME_DIR env variables
Posted by Michal Privoznik 3 years, 11 months ago
On 5/4/20 4:39 PM, Daniel P. Berrangé wrote:
> To attempt to catch unit tests which accidentally create files in $HOME,
> or $XDG_RUNTIME_DIR, poison these env vars by pointing them to
> directories which don't exist. This should give easier to debug test
> failures. For example:
> 
> $ VIR_TEST_DEBUG=1 ./qemuhotplugtest
> Could not initialize HostdevManager - operation failed: Failed to create state dir '/bad-test-used-env-xdg-runtime-dir/libvirt/hostdevmgr'
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/testutils.c | 3 +++
>   1 file changed, 3 insertions(+)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal