Skip to contentSkip to conversation

tests/boot-serial-test: Allow the HPPA machine to shudown

PATCH In review Philippe Mathieu-Daudé 4 participants 8 messages Jan 23, 2020 – Jan 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/boot-serial-test: Allow the HPPA machine to shudown

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

122 void __VISIBLE __noreturn hlt(void)
123 {
124 if (pdc_debug)
125 printf("HALT initiated from %p\n", __builtin_return_address(0));

 126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
 127     asm volatile("\t.word 0xfffdead0": : :"memory");
 128     while (1);

129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

  $ make check-qtest-hppa
    TEST    check-qtest-hppa: tests/qtest/boot-serial-test
  ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
  ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
  make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1

[*] https://github.com/qemu/seabios-hppa/blob/1630ac7d65/src/parisc/parisc.c#L138

---
I first used:

    shutdown = !strcmp(test->arch, "hppa");

Then remembered we'll have other HPPA machines soon.

Instead of:

    shutdown = !strcmp(test->machine, "hppa");

I find the check on the SeaBIOS specific string more accurate (since someone might add some assembly lines as the other tests).

---
 tests/qtest/boot-serial-test.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
tests/qtest/boot-serial-test.c +13 -1
index 05c7f44457..4e92f292f5 100644
@@ -188,6 +188,17 @@ static void test_machine(const void *data)
     const uint8_t *code = NULL;
     QTestState *qts;
     int ser_fd;
+    bool shutdown;
+
+    /*
+     * This test uses SeaBIOS on HPPA, and expects to read the
+     * "SeaBIOS wants SYSTEM HALT" string. A 'SYSTEM HALT' really
+     * halts the CPU. If SeaBIOS does not use the expected serial
+     * port but another device, we might poll the console
+     * indefinitely while the machine is halted.
+     * Keep using this option for all the other tests.
+     */
+    shutdown = !strcmp(test->expect, "SeaBIOS wants SYSTEM HALT");
 
     ser_fd = mkstemp(serialtmp);
     g_assert(ser_fd != -1);
@@ -215,10 +226,11 @@ static void test_machine(const void *data)
      * Make sure that this test uses tcg if available: It is used as a
      * fast-enough smoketest for that.
      */
-    qts = qtest_initf("%s %s -M %s -no-shutdown "
+    qts = qtest_initf("%s %s -M %s %s "
                       "-chardev file,id=serial0,path=%s "
                       "-serial chardev:serial0 -accel tcg -accel kvm %s",
                       codeparam, code ? codetmp : "", test->machine,
+                      shutdown ? "" : "-no-shutdown",
                       serialtmp, test->extra);
     if (code) {
         unlink(codetmp);
Signature · 1 line
2.21.1
#1 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

122 void __VISIBLE __noreturn hlt(void)
123 {
124 if (pdc_debug)
125 printf("HALT initiated from %p\n", __builtin_return_address(0));

Quoted 7 lines
 126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
 127     asm volatile("\t.word 0xfffdead0": : :"memory");
 128     while (1);

129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

Well, SeaBIOS implements it as the magic QEMU halt instruction,

# These are artificial instructions used by QEMU firmware. # They are allocated from the unassigned instruction space.
halt 1111 1111 1111 1101 1110 1010 1101 0000
reset 1111 1111 1111 1101 1110 1010 1101 0001

followed by an infinite loop, probably to avoid a compiler warning and Just In Case. We really should halt here, unless shutdown is disabled.

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 234

Quoted 7 lines
tests/qtest/boot-serial-test.c +2 -1
-    qts = qtest_initf("%s %s -M %s -no-shutdown "
+    qts = qtest_initf("%s %s -M %s %s "
                       "-chardev file,id=serial0,path=%s "
                       "-serial chardev:serial0 -accel tcg -accel kvm %s",
                       codeparam, code ? codetmp : "", test->machine,
+                      shutdown ? "" : "-no-shutdown",
                       serialtmp, test->extra);

And thus avoiding the -no-shutdown should in fact shutdown.

Are you saying this doesn't happen, or what? I think I got lost with the rest of the message...

r~

#2 lore raw
Quoted 34 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

  122 void __VISIBLE __noreturn hlt(void)
  123 {
  124     if (pdc_debug)
  125         printf("HALT initiated from %p\n",  __builtin_return_address(0));
  126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
  127     asm volatile("\t.word 0xfffdead0": : :"memory");
  128     while (1);
  129 }
Quoted 2 lines

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

Well, SeaBIOS implements it as the magic QEMU halt instruction,

# These are artificial instructions used by QEMU firmware. # They are allocated from the unassigned instruction space.
halt 1111 1111 1111 1101 1110 1010 1101 0000
reset 1111 1111 1111 1101 1110 1010 1101 0001

followed by an infinite loop, probably to avoid a compiler warning and Just In Case. We really should halt here, unless shutdown is disabled.

tests/qtest/boot-serial-test.c static void test_machine(const void *data) · line 234

Quoted 7 lines
tests/qtest/boot-serial-test.c +2 -1
-    qts = qtest_initf("%s %s -M %s -no-shutdown "
+    qts = qtest_initf("%s %s -M %s %s "
                        "-chardev file,id=serial0,path=%s "
                        "-serial chardev:serial0 -accel tcg -accel kvm %s",
                        codeparam, code ? codetmp : "", test->machine,
+                      shutdown ? "" : "-no-shutdown",
                        serialtmp, test->extra);
Quoted 4 lines

And thus avoiding the -no-shutdown should in fact shutdown.

Are you saying this doesn't happen, or what? I think I got lost with the rest of the message...

"If the command-line option "-no-shutdown" has been specified,
qemu will not exit, and a STOP event will eventually follow the SHUTDOWN event"

What I see is the HPPA firmware calling HALT, then QEMU doesn't exit.

The QTest keeps reading the console for "SeaBIOS wants SYSTEM HALT.".
When this string is displayed on the graphic output instead of the serial, the QTest keep reading indefinitely, and the test never succeeds/fails, it is just stuck.

#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

122 void __VISIBLE __noreturn hlt(void)
123 {
124 if (pdc_debug)
125 printf("HALT initiated from %p\n", __builtin_return_address(0));

 126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
 127     asm volatile("\t.word 0xfffdead0": : :"memory");
 128     while (1);

129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Quoted 8 lines

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

  $ make check-qtest-hppa
    TEST    check-qtest-hppa: tests/qtest/boot-serial-test
  ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
  ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
  make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1

The tests are run with -no-shutdown. Why does qemu exit in that case? Sounds like a bug in another place, and not in the boot-serial-test.

Thomas

#4 lore raw
Quoted 22 lines · Thomas Huth
Quoted 21 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

  122 void __VISIBLE __noreturn hlt(void)
  123 {
  124     if (pdc_debug)
  125         printf("HALT initiated from %p\n",  __builtin_return_address(0));
  126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
  127     asm volatile("\t.word 0xfffdead0": : :"memory");
  128     while (1);
  129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

Quoted 7 lines
Quoted 5 lines
   $ make check-qtest-hppa
     TEST    check-qtest-hppa: tests/qtest/boot-serial-test
   ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
   ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
   make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1

The tests are run with -no-shutdown. Why does qemu exit in that case?

Because the HPPA firmware called HALT.

Quoted 1 line

Sounds like a bug in another place, and not in the boot-serial-test.

Yes, the bug is elsewhere, but with the bug the boot-serial-test hangs forever.... No output on the console, qtest waiting indefinitely.

#5 lore raw
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Thomas Huth
Quoted 26 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

  122 void __VISIBLE __noreturn hlt(void)
  123 {
  124     if (pdc_debug)
  125         printf("HALT initiated from %p\n", __builtin_return_address(0)); 126     printf("SeaBIOS wants SYSTEM HALT.\n\n");
  127     asm volatile("\t.word 0xfffdead0": : :"memory");
  128     while (1);
  129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

   $ make check-qtest-hppa
     TEST    check-qtest-hppa: tests/qtest/boot-serial-test
   ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
   ERROR - Bail out! FATAL-ERROR: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sjxoM6Q'
   make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1
Quoted 7 lines
Quoted 1 line

The tests are run with -no-shutdown. Why does qemu exit in that case?

Because the HPPA firmware called HALT.

Quoted 1 line

Sounds like a bug in another place, and not in the boot-serial-test.

Yes, the bug is elsewhere, but with the bug the boot-serial-test hangs forever.... No output on the console, qtest waiting indefinitely.

Richard explained me on IRC what you probably meant, which was not obvious to me at first.

Now I found in check_guest_output():

    /* Poll serial output... */
    while (1) {
        ...
        /* Wait at most 360 seconds.  */
        now = time(NULL);
        if (now - start >= 360) {
            break;
        }
        g_usleep(10000);
    }
$ QTEST_QEMU_BINARY=hppa-softmmu/qemu-system-hppa \
  time tests/qtest/boot-serial-test -k
/hppa/boot-serial/hppa:
** (tests/qtest/boot-serial-test:18604): ERROR **: 22:33:25.010: Failed to find expected string. Please check '/tmp/qtest-boot-serial-sZq7ljM'
Command terminated by signal 5
0.31user 0.66system 6:00.07elapsed 0%CPU

Indeed the test fails after 6min, I guess I didn't expect that much while testing interactively.

So please disregard this patch.

Thanks,

Phil.

#6 lore raw
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Thomas Huth
Quoted 22 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

  122 void __VISIBLE __noreturn hlt(void)
  123 {
  124     if (pdc_debug)
  125         printf("HALT initiated from %p\n", __builtin_return_address(0));
  126     printf("SeaBIOS wants SYSTEM HALT.\n\n"); 127     asm volatile("\t.word 0xfffdead0": : :"memory"); 128     while (1);
  129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

Quoted 8 lines
   $ make check-qtest-hppa
     TEST    check-qtest-hppa: tests/qtest/boot-serial-test
   ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604:
Failed to find expected string. Please check
'/tmp/qtest-boot-serial-sjxoM6Q'
   ERROR - Bail out! FATAL-ERROR: Failed to find expected string.
Please check '/tmp/qtest-boot-serial-sjxoM6Q'
   make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1
Quoted 1 line

The tests are run with -no-shutdown. Why does qemu exit in that case?

Because the HPPA firmware called HALT.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Sounds like a bug in another place, and not in the boot-serial-test.

Yes, the bug is elsewhere, but with the bug the boot-serial-test hangs forever.... No output on the console, qtest waiting indefinitely.

Richard explained me on IRC what you probably meant, which was not obvious to me at first.

I think I also did not really understand what you tried to do here ;-)

The -no-shutdown is required, too, otherwise you could get a race between the test reading the serial output and the termination of QEMU, see commit 7150d34a1d60851d73d6ab6783b12b1d25e68f86, and I think we need that for HPPA, too.

Quoted 21 lines

Now I found in check_guest_output():

    /* Poll serial output... */
    while (1) {
        ...
        /* Wait at most 360 seconds.  */
        now = time(NULL);
        if (now - start >= 360) {
            break;
        }
        g_usleep(10000);
    }

$ QTEST_QEMU_BINARY=hppa-softmmu/qemu-system-hppa \
  time tests/qtest/boot-serial-test -k
/hppa/boot-serial/hppa:
** (tests/qtest/boot-serial-test:18604): ERROR **: 22:33:25.010: Failed
to find expected string. Please check '/tmp/qtest-boot-serial-sZq7ljM'
Command terminated by signal 5
0.31user 0.66system 6:00.07elapsed 0%CPU
Quoted 2 lines

Indeed the test fails after 6min, I guess I didn't expect that much while testing interactively.

Yeah, the huge timeout is ugly, but it is required for very slow hosts, see commit 627fce617868df87b3757375a2a0318ad2beb381.

So if you want to "fix" your problem, I think you could maybe add a check for the QEMU events here instead. Or add a check to see whether the registers of the guest change between iterations to make sure that the guest is still alive (that way you also handle the case that the guest crashed and loops forever in a "branch self" instruction). Or simply continue with the 360s timeout, it's long, but it should trigger only in case of other bugs, so it's maybe not worth the effort to add more logic here.

Thomas

#7 lore raw
Quoted 81 lines · Thomas Huth
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Thomas Huth
Quoted 22 lines · Philippe Mathieu-Daudé

The boot-serial test uses SeaBIOS on HPPA, and expects to read the "SeaBIOS wants SYSTEM HALT" string, see [*]:

  122 void __VISIBLE __noreturn hlt(void)
  123 {
  124     if (pdc_debug)
  125         printf("HALT initiated from %p\n",
__builtin_return_address(0));
  126     printf("SeaBIOS wants SYSTEM HALT.\n\n"); 127     asm volatile("\t.word 0xfffdead0": : :"memory"); 128     while (1);
  129 }

A 'SYSTEM HALT' would really halts the CPU, but SeaBIOS implements it as an infinite loop.

If SeaBIOS does not use the expected serial port but another device, we might poll the console indefinitely while the machine is halted.

Allow the HPPA machine to 'shutdown'. When it does, we'll get a qtest error:

Quoted 8 lines
    $ make check-qtest-hppa
      TEST    check-qtest-hppa: tests/qtest/boot-serial-test
    ** (tests/qtest/boot-serial-test:31924): ERROR **: 01:12:37.604:
Failed to find expected string. Please check
'/tmp/qtest-boot-serial-sjxoM6Q'
    ERROR - Bail out! FATAL-ERROR: Failed to find expected string.
Please check '/tmp/qtest-boot-serial-sjxoM6Q'
    make: *** [tests/Makefile.include:628: check-qtest-hppa] Error 1
Quoted 1 line

The tests are run with -no-shutdown. Why does qemu exit in that case?

Because the HPPA firmware called HALT.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Sounds like a bug in another place, and not in the boot-serial-test.

Yes, the bug is elsewhere, but with the bug the boot-serial-test hangs forever.... No output on the console, qtest waiting indefinitely.

Richard explained me on IRC what you probably meant, which was not obvious to me at first.

I think I also did not really understand what you tried to do here ;-)

The -no-shutdown is required, too, otherwise you could get a race between the test reading the serial output and the termination of QEMU, see commit 7150d34a1d60851d73d6ab6783b12b1d25e68f86, and I think we need that for HPPA, too.

Quoted 21 lines

Now I found in check_guest_output():

    /* Poll serial output... */
    while (1) {
        ...
        /* Wait at most 360 seconds.  */
        now = time(NULL);
        if (now - start >= 360) {
            break;
        }
        g_usleep(10000);
    }

$ QTEST_QEMU_BINARY=hppa-softmmu/qemu-system-hppa \
   time tests/qtest/boot-serial-test -k
/hppa/boot-serial/hppa:
** (tests/qtest/boot-serial-test:18604): ERROR **: 22:33:25.010: Failed
to find expected string. Please check '/tmp/qtest-boot-serial-sZq7ljM'
Command terminated by signal 5
0.31user 0.66system 6:00.07elapsed 0%CPU
Quoted 2 lines

Indeed the test fails after 6min, I guess I didn't expect that much while testing interactively.

Yeah, the huge timeout is ugly, but it is required for very slow hosts, see commit 627fce617868df87b3757375a2a0318ad2beb381.

Quoted 8 lines

So if you want to "fix" your problem, I think you could maybe add a check for the QEMU events here instead. Or add a check to see whether the registers of the guest change between iterations to make sure that the guest is still alive (that way you also handle the case that the guest crashed and loops forever in a "branch self" instruction). Or simply continue with the 360s timeout, it's long, but it should trigger only in case of other bugs, so it's maybe not worth the effort to add more logic here.

Good idea. With QMP it is easy:

{ "execute": "query-status" }

{
    "return": {
        "status": "shutdown",
        "singlestep": false,
        "running": false
    }
}