qemu-discuss
[Top][All Lists]
Advanced

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

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


From: Wink Saville
Subject: Re: [Qemu-discuss] How to use qemu for non-interactive testing
Date: Tue, 22 Dec 2015 03:22:25 +0000

Got it, txs, but hopefully someone will offer an internal mechanism.

On Mon, Dec 21, 2015 at 11:34 AM Jakob Bohm <address@hidden> wrote:
By "manually" I meant that your outer test-automating program or script
would do it by simply sending the appropriate "kill" message/signal,
not that you as a human would have to sit at the console ready to hit
ctrl+C.

For qemu-system-i386 (and qemu-system-x86_64), you can use the same
PC BIOS request used by the Linux kernel when someone runs the "halt"
command line program.  You should be able to find that somewhere in
the Linux kernel source code.

For qemu-i386 (and any of the other non-system qemu interpreters)
simply doing a normal program exit should do the trick.

On 21/12/2015 20:13, Wink Saville wrote:
> Killing it "manually" is trivial usually just "ctrl-a", "x" but I want
> to qemu to exit when my application completes. Following the lead from
> Peter you start qemu with -no-reboot option and then "reset the cpu". So
> for ARM the poweroff is:
>
> void ac_poweroff(void) {
>    volatile ac_u32* pUnlockResetReg = (ac_u32*)0x10000020;
>    volatile ac_u32* pResetReg = (ac_u32*)0x10000040;
>    *pUnlockResetReg = 0xA05F;
>    *pResetReg = 0x106;
> }
>
> So I'm hoping for x86 there would be something similar.
>
> On Mon, Dec 21, 2015 at 9:33 AM Jakob Bohm <address@hidden
> <mailto:address@hidden>> wrote:
>
>     I know that libvirt (which is huge) uses those.  I am not up to date on
>     what the specific monitor and qmp commands are or where to find out.
>
>     So basically, I don't know either.
>
>     Hard killing the qemu process you launched yourself should be pretty
>     trivial using whatever tool/language you used to launch it.
>
>     On 21/12/2015 15:53, Wink Saville wrote:
>      > Can you give me some pointers to implementations that use these
>      > techniques. Txs.
>      >
>      >
>      > On Mon, Dec 21, 2015, 4:02 AM Jakob Bohm <address@hidden
>     <mailto:address@hidden>
>      > <mailto:address@hidden
>     <mailto:address@hidden>>> wrote:
>      >
>      >     There is a monitor and/or qmp command to simulate a "soft"
>      >     press on the power button, which would trigger any OS
>      >     provided clean shut down logic via ACPI/APM.
>      >
>      >     There is a different monitor and/or qmp command to simulate
>      >     a hard power off while still keeping the virtualization
>      >     aspect of e.g. qcow2 files consistent.
>      >
>      >     Finally, there is the option to simply kill the qemu
>      >     process.
>      >
>      >     On 19/12/2015 00:39, Wink Saville wrote:
>      >      > Peter,
>      >      >
>      >      > I ended up using the first technique for VersatilePB and works
>      >     just fine.
>      >      >
>      >      > Now I want to be able "power off" a qemu-system-i386 and I was
>      >      > wondering what you might suggest? I'm hoping there might
>     be something
>      >      > "easy".
>      >      >
>      >      > -- Wink
>      >      >
>      >      > On Mon, Oct 19, 2015 at 1:49 PM Wink Saville
>     <address@hidden <mailto:address@hidden>
>      >     <mailto:address@hidden <mailto:address@hidden>>
>      >      > <mailto:address@hidden <mailto:address@hidden>
>     <mailto:address@hidden <mailto:address@hidden>>>> wrote:
>      >      >
>      >      >     THANKS, I'll give those things a try!
>      >      >
>      >      >
>      >      >     On Mon, Oct 19, 2015, 1:46 PM Peter Maydell
>      >      >     <address@hidden
>     <mailto:address@hidden> <mailto:address@hidden
>     <mailto:address@hidden>>
>      >     <mailto:address@hidden
>     <mailto:address@hidden> <mailto:address@hidden
>     <mailto:address@hidden>>>>
>      >     wrote:
>      >      >
>      >      >         On 19 October 2015 at 20:30, Wink Saville
>      >     <address@hidden <mailto:address@hidden>
>     <mailto:address@hidden <mailto:address@hidden>>
>      >      >         <mailto:address@hidden <mailto:address@hidden>
>     <mailto:address@hidden <mailto: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:
>      >      >
>      >
>     http://infocenter.arm.com/help/topic/com.arm.doc.dui0224i/Caccifgi.html
>      >      >         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:
>      >      >
>      >
>     http://infocenter.arm.com/help/topic/com.arm.doc.dui0471l/pge1358787050566.html
>      >      >         (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.
>      >      >
>      >      >         thanks
>      >      >         -- PMM
>      >      >
>
>
>     Enjoy and Merry Christmas
>
>     Jakob
>     --
>     Jakob Bohm, CIO, Partner, WiseMo A/S. https://www.wisemo.com
>     Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
>     This public discussion message is non-binding and may contain errors.
>     WiseMo - Remote Service Management for PCs, Phones and Embedded
>


Enjoy

Jakob
--
Jakob Bohm, CIO, Partner, WiseMo A/S.  https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded


reply via email to

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