[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-discuss] How to use qemu for non-interactive testing

From: Peter Maydell
Subject: Re: [Qemu-discuss] How to use qemu for non-interactive testing
Date: Mon, 19 Oct 2015 21:46:14 +0100

On 19 October 2015 at 20:30, Wink Saville <address@hidden> wrote:
> I would like to use qemu in a test environment where I give a "kernel" image
> to qmeu have it execute it and then when complete have qemu exit. Currently
> when
> executing:
>   $ qemu-system-arm -M versatilepb -m 128M -nographic -kernel test.bin
>   ...
>   Hi
>   $
> After test.bin prints "Hi" via the "Uart in VersatilePB" I have to
> interactively press ctrl-a then press 'x' to have it return to the command
> prompt. Is there a way for test.bin to cause qemu to exit without having to
> type commands in the terminal.

That depends on the machine you're using (in this case versatilepb).
Basically if the guest binary tells the emulated hardware "please
power down" via whatever that hardware's mechanism is, then QEMU
will exit. For versatilepb there isn't any way to do that, but you
can use QEMU's "-no-reboot" option (which turns resets into power
downs) and then tell the emulated hardware to do a reset. For info
on how to do a reset on the versatilepb board see the h/w docs:
You need to write to SYS_LOCKCTL to unlock the register and then
to SYS_RESETCTL to actually request the reset.

Other options you can use:
 * an ARM-specific option is to use the -semihosting command line
option, and then you can use the semihosting ABI to exit.
You need to do an angel_SWIreason_ReportException:
(which is to say, set r0 to 0x18, r1 to 0x20026 and do a
swi 0x123456 in ARM mode or swi 0xab (Thumb mode) or
bkpt 0xab (M profile).
Semihosting also lets you conveniently output to the terminal,
read files or look at the command line, so it's handy for
writing test cases.

 * use the 'expect' utility to script up the "make QEMU exit
when it's printed the result" handling. It's generally nicer
to avoid this, but as a last resort it's nice to have: a
handful of lines of expect scripting are sufficient to do
basic "start this program, then exit when some string appears
in its output" control.

PS: you might prefer '-display none' over '-nographic';
that gives you the serial output to standard output, but
doesn't do the 'monitor on alternate screen, ctrl-a <whatever>'
behaviour. You can just ctrl-c to exit qemu then.
Basically -nographic is a magic combination of a bunch
of options and sometimes you only want one of them.

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]