[PATCH] tests: Fix libxlxml2domconfigtest

Jim Fehlig posted 1 patch 3 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20221111022546.9688-1-jfehlig@suse.com
tests/libxlmock.c                           | 15 +++++++++++++++
tests/libxlxml2domconfigdata/vnuma-hvm.json |  5 +++++
2 files changed, 20 insertions(+)
[PATCH] tests: Fix libxlxml2domconfigtest
Posted by Jim Fehlig 3 weeks, 2 days ago
Downstream CI recently encountered failures of libxlxml2domconfigtest when
building libvirt packages against Xen 4.17 rc3 packages. The test fails on
vnuma_hvm config, where suddently the actual json produced by
libxl_domain_config_to_json() contains a 'pnode' entry in the 'vnuma_nodes'
list, which is absent in the expected json. It appears the test has thus far
passed by luck. E.g. I was able to make the test pass in the failing
environment by changing the meson buildtype from debugoptimized to debug.

When a VM config contains vnuma settings, libxlMakeVnumaList() checks if the
number of requested vnuma nodes exceeds the number of physical nodes. The
number of physical nodes is retrieved with libxl_get_physinfo(), which can
return wildly different results in the context of unit tests. This change
mocks libxl_get_physinfo() to return consistent results. All fields of the
libxl_physinfo struct are set to 0 except nr_nodes, which is set to 6 to
ensure the vnuma_hvm configuration is properly tested.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 tests/libxlmock.c                           | 15 +++++++++++++++
 tests/libxlxml2domconfigdata/vnuma-hvm.json |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/tests/libxlmock.c b/tests/libxlmock.c
index 4754597e5b..205d34df19 100644
--- a/tests/libxlmock.c
+++ b/tests/libxlmock.c
@@ -70,6 +70,21 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
     return &info;
 }
 
+VIR_MOCK_IMPL_RET_ARGS(libxl_get_physinfo,
+                       int,
+                       libxl_ctx *, ctx,
+                       libxl_physinfo *, physinfo)
+{
+    memset(physinfo, 0, sizeof(*physinfo));
+    physinfo->nr_nodes = 6;
+
+    /* silence gcc warning about unused function */
+    if (0)
+        real_libxl_get_physinfo(ctx, physinfo);
+
+    return 0;
+}
+
 VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
                        int, 0,
                        libxl_ctx *, ctx,
diff --git a/tests/libxlxml2domconfigdata/vnuma-hvm.json b/tests/libxlxml2domconfigdata/vnuma-hvm.json
index 2556c82d5f..c90ee823a4 100644
--- a/tests/libxlxml2domconfigdata/vnuma-hvm.json
+++ b/tests/libxlxml2domconfigdata/vnuma-hvm.json
@@ -39,6 +39,7 @@
                     41,
                     51
                 ],
+		"pnode": 1,
                 "vcpus": [
                     1
                 ]
@@ -53,6 +54,7 @@
                     31,
                     41
                 ],
+		"pnode": 2,
                 "vcpus": [
                     2
                 ]
@@ -67,6 +69,7 @@
                     21,
                     31
                 ],
+		"pnode": 3,
                 "vcpus": [
                     3
                 ]
@@ -81,6 +84,7 @@
                     10,
                     21
                 ],
+		"pnode": 4,
                 "vcpus": [
                     4
                 ]
@@ -95,6 +99,7 @@
                     21,
                     10
                 ],
+		"pnode": 5,
                 "vcpus": [
                     5
                 ]
-- 
2.37.3
Re: [PATCH] tests: Fix libxlxml2domconfigtest
Posted by Michal Prívozník 3 weeks, 2 days ago
On 11/11/22 03:25, Jim Fehlig wrote:
> Downstream CI recently encountered failures of libxlxml2domconfigtest when
> building libvirt packages against Xen 4.17 rc3 packages. The test fails on
> vnuma_hvm config, where suddently the actual json produced by
> libxl_domain_config_to_json() contains a 'pnode' entry in the 'vnuma_nodes'
> list, which is absent in the expected json. It appears the test has thus far
> passed by luck. E.g. I was able to make the test pass in the failing
> environment by changing the meson buildtype from debugoptimized to debug.
> 
> When a VM config contains vnuma settings, libxlMakeVnumaList() checks if the
> number of requested vnuma nodes exceeds the number of physical nodes. The
> number of physical nodes is retrieved with libxl_get_physinfo(), which can
> return wildly different results in the context of unit tests. This change
> mocks libxl_get_physinfo() to return consistent results. All fields of the
> libxl_physinfo struct are set to 0 except nr_nodes, which is set to 6 to
> ensure the vnuma_hvm configuration is properly tested.
> 
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  tests/libxlmock.c                           | 15 +++++++++++++++
>  tests/libxlxml2domconfigdata/vnuma-hvm.json |  5 +++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/tests/libxlmock.c b/tests/libxlmock.c
> index 4754597e5b..205d34df19 100644
> --- a/tests/libxlmock.c
> +++ b/tests/libxlmock.c
> @@ -70,6 +70,21 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
>      return &info;
>  }
>  
> +VIR_MOCK_IMPL_RET_ARGS(libxl_get_physinfo,
> +                       int,
> +                       libxl_ctx *, ctx,
> +                       libxl_physinfo *, physinfo)
> +{
> +    memset(physinfo, 0, sizeof(*physinfo));
> +    physinfo->nr_nodes = 6;
> +
> +    /* silence gcc warning about unused function */
> +    if (0)
> +        real_libxl_get_physinfo(ctx, physinfo);
> +
> +    return 0;
> +}
> +
>  VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
>                         int, 0,
>                         libxl_ctx *, ctx,
> diff --git a/tests/libxlxml2domconfigdata/vnuma-hvm.json b/tests/libxlxml2domconfigdata/vnuma-hvm.json
> index 2556c82d5f..c90ee823a4 100644
> --- a/tests/libxlxml2domconfigdata/vnuma-hvm.json
> +++ b/tests/libxlxml2domconfigdata/vnuma-hvm.json
> @@ -39,6 +39,7 @@
>                      41,
>                      51
>                  ],
> +		"pnode": 1,

These look misaligned... and in fact they are, because you've used TABs.
Can you please switch to spaces?

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

Michal
Re: [PATCH] tests: Fix libxlxml2domconfigtest
Posted by Jim Fehlig 3 weeks, 2 days ago
On 11/11/22 02:09, Michal Prívozník wrote:
> On 11/11/22 03:25, Jim Fehlig wrote:
>> Downstream CI recently encountered failures of libxlxml2domconfigtest when
>> building libvirt packages against Xen 4.17 rc3 packages. The test fails on
>> vnuma_hvm config, where suddently the actual json produced by
>> libxl_domain_config_to_json() contains a 'pnode' entry in the 'vnuma_nodes'
>> list, which is absent in the expected json. It appears the test has thus far
>> passed by luck. E.g. I was able to make the test pass in the failing
>> environment by changing the meson buildtype from debugoptimized to debug.
>>
>> When a VM config contains vnuma settings, libxlMakeVnumaList() checks if the
>> number of requested vnuma nodes exceeds the number of physical nodes. The
>> number of physical nodes is retrieved with libxl_get_physinfo(), which can
>> return wildly different results in the context of unit tests. This change
>> mocks libxl_get_physinfo() to return consistent results. All fields of the
>> libxl_physinfo struct are set to 0 except nr_nodes, which is set to 6 to
>> ensure the vnuma_hvm configuration is properly tested.
>>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>> ---
>>   tests/libxlmock.c                           | 15 +++++++++++++++
>>   tests/libxlxml2domconfigdata/vnuma-hvm.json |  5 +++++
>>   2 files changed, 20 insertions(+)
>>
>> diff --git a/tests/libxlmock.c b/tests/libxlmock.c
>> index 4754597e5b..205d34df19 100644
>> --- a/tests/libxlmock.c
>> +++ b/tests/libxlmock.c
>> @@ -70,6 +70,21 @@ VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
>>       return &info;
>>   }
>>   
>> +VIR_MOCK_IMPL_RET_ARGS(libxl_get_physinfo,
>> +                       int,
>> +                       libxl_ctx *, ctx,
>> +                       libxl_physinfo *, physinfo)
>> +{
>> +    memset(physinfo, 0, sizeof(*physinfo));
>> +    physinfo->nr_nodes = 6;
>> +
>> +    /* silence gcc warning about unused function */
>> +    if (0)
>> +        real_libxl_get_physinfo(ctx, physinfo);
>> +
>> +    return 0;
>> +}
>> +
>>   VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
>>                          int, 0,
>>                          libxl_ctx *, ctx,
>> diff --git a/tests/libxlxml2domconfigdata/vnuma-hvm.json b/tests/libxlxml2domconfigdata/vnuma-hvm.json
>> index 2556c82d5f..c90ee823a4 100644
>> --- a/tests/libxlxml2domconfigdata/vnuma-hvm.json
>> +++ b/tests/libxlxml2domconfigdata/vnuma-hvm.json
>> @@ -39,6 +39,7 @@
>>                       41,
>>                       51
>>                   ],
>> +		"pnode": 1,
> 
> These look misaligned... and in fact they are, because you've used TABs.
> Can you please switch to spaces?

Opps. I changed all the offending lines before pushing.

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

Thanks!
Jim