Skip to contentSkip to conversation

qtest: fix 'expression is always false' build failure in qtest_has_accel()

PATCH Superseded Igor Mammedov 4 participants 5 messages Oct 27, 2021 – Oct 29, 2021 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qtest: fix 'expression is always false' build failure in qtest_has_accel()

If KVM is disabled or not present, qtest library build may fail with:
libqtest.c: In function 'qtest_has_accel':
comparison of unsigned expression < 0 is always false [-Werror=type-limits]
for (i = 0; i < ARRAY_SIZE(targets); i++) {

due to empty 'targets' array.
Fix it by compiling KVM related part only if
CONFIG_KVM_TARGETS is set.

Fixes e741aff0f43343 ("tests: qtest: add qtest_has_accel() to check if tested binary supports accelerator")
---
 tests/qtest/libqtest.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/libqtest.c +4 -0
index 25aeea385b..9833e16f84 100644
@@ -931,6 +931,7 @@ bool qtest_has_accel(const char *accel_name)
         return false;
 #endif
     } else if (g_str_equal(accel_name, "kvm")) {
+#if defined(CONFIG_KVM_TARGETS)
         int i;
         const char *arch = qtest_get_arch();
         const char *targets[] = { CONFIG_KVM_TARGETS };
@@ -942,6 +943,9 @@ bool qtest_has_accel(const char *accel_name)
                 }
             }
         }
+#else
+        return false;
+#endif
     } else {
         /* not implemented */
         g_assert_not_reached();
Signature · 1 line
2.27.0
#1 lore raw
Quoted 25 lines · Igor Mammedov

If KVM is disabled or not present, qtest library build may fail with:
libqtest.c: In function 'qtest_has_accel':
comparison of unsigned expression < 0 is always false [-Werror=type-limits]
for (i = 0; i < ARRAY_SIZE(targets); i++) {

due to empty 'targets' array.
Fix it by compiling KVM related part only if
CONFIG_KVM_TARGETS is set.

Fixes e741aff0f43343 ("tests: qtest: add qtest_has_accel() to check if tested binary supports accelerator")
---
 tests/qtest/libqtest.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/libqtest.c +0 -0
index 25aeea385b..9833e16f84 100644

tests/qtest/libqtest.c bool qtest_has_accel(const char *accel_name) · line 934

Quoted 4 lines
tests/qtest/libqtest.c +1 -0
@@ -931,6 +931,7 @@ bool qtest_has_accel(const char *accel_name)
         return false;
 #endif
     } else if (g_str_equal(accel_name, "kvm")) {
+#if defined(CONFIG_KVM_TARGETS)

Ugh.

        const char *targets[] = { CONFIG_KVM_TARGETS };

are you use CONFIG_KVM_TARGETS is not defined?

Looks like it's defined, just empty.

which is not standard C BTW.

How about we just add an empty string in meson?

meson.build +1 -1
index 2c5b53cbe2..ff85e9c2af 100644
@@ -75,7 +75,7 @@ else
   kvm_targets = []
 endif
 
-kvm_targets_c = ''
+kvm_targets_c = '""'
 if not get_option('kvm').disabled() and targetos == 'linux'
   kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
 endif
Quoted 15 lines
tests/qtest/libqtest.c +3 -0
         int i;
         const char *arch = qtest_get_arch();
         const char *targets[] = { CONFIG_KVM_TARGETS };
@@ -942,6 +943,9 @@ bool qtest_has_accel(const char *accel_name)
                 }
             }
         }
+#else
+        return false;
+#endif
     } else {
         /* not implemented */
         g_assert_not_reached();
Signature · 1 line
2.27.0
#2 lore raw
Quoted 48 lines · Michael S. Tsirkin
Quoted 25 lines · Igor Mammedov

If KVM is disabled or not present, qtest library build may fail with:
libqtest.c: In function 'qtest_has_accel':
comparison of unsigned expression < 0 is always false [-Werror=type-limits]
for (i = 0; i < ARRAY_SIZE(targets); i++) {

due to empty 'targets' array.
Fix it by compiling KVM related part only if
CONFIG_KVM_TARGETS is set.

Fixes e741aff0f43343 ("tests: qtest: add qtest_has_accel() to check if tested binary supports accelerator")
---
 tests/qtest/libqtest.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/libqtest.c +0 -0
index 25aeea385b..9833e16f84 100644

tests/qtest/libqtest.c bool qtest_has_accel(const char *accel_name) · line 934

Quoted 4 lines
tests/qtest/libqtest.c +1 -0
@@ -931,6 +931,7 @@ bool qtest_has_accel(const char *accel_name)
         return false;
 #endif
     } else if (g_str_equal(accel_name, "kvm")) {
+#if defined(CONFIG_KVM_TARGETS)

Ugh.

        const char *targets[] = { CONFIG_KVM_TARGETS };

are you use CONFIG_KVM_TARGETS is not defined?

Looks like it's defined, just empty.

which is not standard C BTW.

How about we just add an empty string in meson?

meson.build +0 -0
index 2c5b53cbe2..ff85e9c2af 100644

meson.build else · line 81

Quoted 8 lines
meson.build +1 -1
@@ -75,7 +75,7 @@ else
   kvm_targets = []
 endif
 
-kvm_targets_c = ''
+kvm_targets_c = '""'
 if not get_option('kvm').disabled() and targetos == 'linux'
   kvm_targets_c = '"' + '" ,"'.join(kvm_targets) + '"'
 endif

This allows Debian buster (gcc 8.3.0) to compile.

Thanks,
Jason

#3 lore raw
In reply to Igor Mammedov
Quoted 10 lines · Igor Mammedov

If KVM is disabled or not present, qtest library build may fail with:
libqtest.c: In function 'qtest_has_accel':
comparison of unsigned expression < 0 is always false [-Werror=type-limits]
for (i = 0; i < ARRAY_SIZE(targets); i++) {

due to empty 'targets' array.
Fix it by compiling KVM related part only if
CONFIG_KVM_TARGETS is set.

Another possibility is to add a trailing NULL to the array and change the loop to "for (i = 0; targets[i]; i++)".

Paolo

#4 lore raw
Quoted 8 lines · On Wed, 27 Oct 2021 17:59:44 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 7 lines · Igor Mammedov

If KVM is disabled or not present, qtest library build may fail with:
libqtest.c: In function 'qtest_has_accel':
comparison of unsigned expression < 0 is always false [-Werror=type-limits]
for (i = 0; i < ARRAY_SIZE(targets); i++) {

Quoted 6 lines
Quoted 3 lines

due to empty 'targets' array.
Fix it by compiling KVM related part only if
CONFIG_KVM_TARGETS is set.

Another possibility is to add a trailing NULL to the array and change the loop to "for (i = 0; targets[i]; i++)".

Thanks,
I've sent v2 with Michael suggested approach,
it seems to me a bit more cleaner.

Quoted 3 lines

Paolo