On 21.03.2017 13:39, Andrew Jones wrote: > On Mon, Mar 20, 2017 at 06:12:11PM +0100, Thomas Huth wrote: >> To be able to do simple migration tests with kvm-unit-tests, too, >> add a helper function that does all the necessary work: Start two >> instances of QEMU (source and destination) with QMP sockets for >> sending commands to them, then trigger the migration from one >> instance to the other and finally signal the end of the migration >> to the guest by injecting an NMI. >> This helper function is now used automatically for powerpc tests >> if the test is put into the "migration" group in the unittests.cfg >> file. >> >> Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx> >> --- >> powerpc/run | 2 +- >> scripts/arch-run.bash | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ >> scripts/runtime.bash | 3 +++ >> 3 files changed, 65 insertions(+), 1 deletion(-) >> >> diff --git a/powerpc/run b/powerpc/run >> index 6269abb..d92608e 100755 >> --- a/powerpc/run >> +++ b/powerpc/run >> @@ -46,7 +46,7 @@ M+=",accel=$ACCEL" >> command="$qemu -nodefaults $M -bios $FIRMWARE" >> [ -f "$ENV" ] && command+=" -initrd $ENV" >> command+=" -display none -serial stdio -kernel" >> -command="$(timeout_cmd) $command" >> +command="$(migration_cmd) $(timeout_cmd) $command" >> echo $command "$@" >> >> # powerpc tests currently exit with rtas-poweroff, which exits with 0. >> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash >> index 1610f3b..453ae1c 100644 >> --- a/scripts/arch-run.bash >> +++ b/scripts/arch-run.bash >> @@ -70,3 +70,64 @@ timeout_cmd () >> echo "timeout -k 1s --foreground $TIMEOUT" >> fi >> } >> + >> +qmp () >> +{ > > Let's put the nc probe here, and instead of saying $0 needs nc, we can > say which specific function with $FUNCNAME, i.e. > > command -v nc >/dev/null 2>&1 || (echo "$FUNCNAME needs nc (netcat)"; exit 1) > > We could also cache the results of the probe, if we don't want to do it on > every invocation of qmp() I tried to move the check to the qmp() function, as you suggested, but that does not work as expected: The script then does not terminate anymore! Seems like the shell is waiting for the started QEMU processes to finish first, so I'd have to add some ugly error handling magic in that case to kill the background QEMU processes if nc is not available. I think it is easier if I keep the check at the beginning of run_migration() instead. >> + echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 >> +} >> + >> +run_migration () >> +{ >> + if ! command -v nc >/dev/null 2>&1; then >> + echo "$0 needs nc (netcat)" >> + exit 1 I noticed that I should rather exit with "2" instead of "1" here ... otherwise run_tests.sh does not report a FAIL here. I'll send a new version with the fix... >> + fi Thomas