Skip to contentSkip to conversation

libqtest: refuse QTEST_QEMU_BINARY=qemu-kvm

PATCH Superseded Stefan Hajnoczi 3 participants 6 messages Apr 12, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libqtest: refuse QTEST_QEMU_BINARY=qemu-kvm

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>
---
 tests/qtest/libqtest.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +10 -0
index 71e359efcd..7caf20f56b 100644
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
         abort();
     }
 
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s "
+                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");
+        abort();
+    }
+
     return end + 1;
 }
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 23 lines · Stefan Hajnoczi

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>
---
  tests/qtest/libqtest.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +0 -0
index 71e359efcd..7caf20f56b 100644

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 919

Quoted 10 lines
tests/qtest/libqtest.c +7 -0
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
          abort();
      }
 
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s "
+                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");

The text is very long ... maybe add some \n to wrap it after 80 columns?
(also not sure whether we really need the second part about the symlink... but I also don't mind leaving it in)

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 920

Quoted 1 line
tests/qtest/libqtest.c +1 -0
+        abort();

Since this can be triggered by the user, I'd rather use exit(1) instead, what do you think?

Thomas

Quoted 6 lines
tests/qtest/libqtest.c +2 -0
+    }
+
      return end + 1;
  }
 
#2 lore raw
Quoted 28 lines · Thomas Huth
Quoted 26 lines · Stefan Hajnoczi

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>
---
  tests/qtest/libqtest.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +0 -0
index 71e359efcd..7caf20f56b 100644
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
          abort();
      }
 
Quoted 11 lines

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 919

Quoted 7 lines
tests/qtest/libqtest.c +7 -0
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s "
+                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");

The text is very long ... maybe add some \n to wrap it after 80 columns? (also not sure whether we really need the second part about the symlink... but I also don't mind leaving it in)

Yeah, anybody who runs into this is doing something weird and can be assumed to be able to figure out how to do what they want with a name of the right form, I think. You'll never see it if you're just running 'make check'.

thanks
-- PMM

#3 lore raw
In reply to Thomas Huth
Quoted 38 lines · Thomas Huth
Quoted 23 lines · Stefan Hajnoczi

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>
---
  tests/qtest/libqtest.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +0 -0
index 71e359efcd..7caf20f56b 100644

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 918

Quoted 9 lines
tests/qtest/libqtest.c +7 -0
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
          abort();
      }
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s "
+                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");

The text is very long ... maybe add some \n to wrap it after 80 columns? (also not sure whether we really need the second part about the symlink... but I also don't mind leaving it in)

Quoted 4 lines

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 920

Quoted 1 line
tests/qtest/libqtest.c +1 -0
+        abort();

Since this can be triggered by the user, I'd rather use exit(1) instead, what do you think?

Sure, but in that case I guess the abort() call above also needs to be changed? It is triggered when the QTEST_QEMU_BINARY path does not contain a hyphen ('-') and it currently aborts.

Stefan

#4 lore raw
Quoted 39 lines · Stefan Hajnoczi
Quoted 38 lines · Thomas Huth
Quoted 23 lines · Stefan Hajnoczi

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>
---
   tests/qtest/libqtest.c | 10 ++++++++++
   1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +0 -0
index 71e359efcd..7caf20f56b 100644

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 918

Quoted 9 lines
tests/qtest/libqtest.c +7 -0
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
           abort();
       }
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s "
+                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");

The text is very long ... maybe add some \n to wrap it after 80 columns? (also not sure whether we really need the second part about the symlink... but I also don't mind leaving it in)

Quoted 8 lines
Quoted 4 lines

tests/qtest/libqtest.c const char *qtest_get_arch(void) · line 920

Quoted 1 line
tests/qtest/libqtest.c +1 -0
+        abort();

Since this can be triggered by the user, I'd rather use exit(1) instead, what do you think?

Sure, but in that case I guess the abort() call above also needs to be changed? It is triggered when the QTEST_QEMU_BINARY path does not contain a hyphen ('-') and it currently aborts.

Drat, you're right, and it was even me who added that :-/ ... if you've got some spare minutes, could you send a patch for that, too, please? (Otherwise I'll do it later)

Thomas

#5 lore raw
Quoted 46 lines · Thomas Huth
Quoted 45 lines · Stefan Hajnoczi
Quoted 44 lines · Thomas Huth
Quoted 29 lines · Stefan Hajnoczi

Some downstreams rename the QEMU binary to "qemu-kvm". This breaks qtest_get_arch(), which attempts to parse the target architecture from the QTEST_QEMU_BINARY environment variable.

Print an error instead of returning the architecture "kvm". Things fail in weird ways when the architecture string is bogus.

Arguably qtests should always be run in a build directory instead of against an installed QEMU. In any case, printing a clear error when this happens is helpful.

Cc Emanuele Giuseppe Esposito <[email protected]>

---
   tests/qtest/libqtest.c | 10 ++++++++++

   1 file changed, 10 insertions(+)
tests/qtest/libqtest.c +3 -0
index 71e359efcd..7caf20f56b 100644
@@ -910,6 +910,16 @@ const char *qtest_get_arch(void)
            abort();
        }
+    if (!strstr(qemu, "-system-")) {
+        fprintf(stderr, "QTEST_QEMU_BINARY must end with 
 *-system-<arch> where "
+                        "'arch' is the target architecture (x86_64, 
Quoted 7 lines

aarch64, "
+                        "etc). If you are using qemu-kvm or another custom "
+                        "name, please create a symlink like ln -s " +                        "path/to/qemu-kvm qemu-system-x86_64 and use that "
+                        "instead.\n");

The text is very long ... maybe add some \n to wrap it after 80 columns? (also not sure whether we really need the second part about the symlink... but I also don't mind leaving it in)

Quoted 1 line

+        abort();

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Since this can be triggered by the user, I'd rather use exit(1) instead, what do you think?

Sure, but in that case I guess the abort() call above also needs to be changed? It is triggered when the QTEST_QEMU_BINARY path does not contain a hyphen ('-') and it currently aborts.

Drat, you're right, and it was even me who added that :-/ ... if you've got some spare minutes, could you send a patch for that, too, please? (Otherwise I'll do it later)

Never mind, I just saw that you've fixed it in v3 already :-)

Thomas