mirror of https://github.com/xemu-project/xemu.git
libqtest: add qtest_kill_qemu()
Tests that manage multiple processes may wish to kill QEMU before destroying the QTestState. Expose a function to do that. The vhost-user-blk-test testcase will need this. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Message-Id: <20210223144653.811468-4-stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
9fb7bb0698
commit
7a23c52376
|
@ -74,6 +74,17 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
|
||||||
*/
|
*/
|
||||||
QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
|
QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qtest_kill_qemu:
|
||||||
|
* @s: #QTestState instance to operate on.
|
||||||
|
*
|
||||||
|
* Kill the QEMU process and wait for it to terminate. It is safe to call this
|
||||||
|
* function multiple times. Normally qtest_quit() is used instead because it
|
||||||
|
* also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
|
||||||
|
* and qtest_quit() will be called later.
|
||||||
|
*/
|
||||||
|
void qtest_kill_qemu(QTestState *s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qtest_quit:
|
* qtest_quit:
|
||||||
* @s: #QTestState instance to operate on.
|
* @s: #QTestState instance to operate on.
|
||||||
|
|
|
@ -133,7 +133,7 @@ void qtest_set_expected_status(QTestState *s, int status)
|
||||||
s->expected_status = status;
|
s->expected_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kill_qemu(QTestState *s)
|
void qtest_kill_qemu(QTestState *s)
|
||||||
{
|
{
|
||||||
pid_t pid = s->qemu_pid;
|
pid_t pid = s->qemu_pid;
|
||||||
int wstatus;
|
int wstatus;
|
||||||
|
@ -143,6 +143,7 @@ static void kill_qemu(QTestState *s)
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
|
TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
|
||||||
assert(pid == s->qemu_pid);
|
assert(pid == s->qemu_pid);
|
||||||
|
s->qemu_pid = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -169,7 +170,7 @@ static void kill_qemu(QTestState *s)
|
||||||
|
|
||||||
static void kill_qemu_hook_func(void *s)
|
static void kill_qemu_hook_func(void *s)
|
||||||
{
|
{
|
||||||
kill_qemu(s);
|
qtest_kill_qemu(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigabrt_handler(int signo)
|
static void sigabrt_handler(int signo)
|
||||||
|
@ -373,7 +374,7 @@ void qtest_quit(QTestState *s)
|
||||||
/* Uninstall SIGABRT handler on last instance */
|
/* Uninstall SIGABRT handler on last instance */
|
||||||
cleanup_sigabrt_handler();
|
cleanup_sigabrt_handler();
|
||||||
|
|
||||||
kill_qemu(s);
|
qtest_kill_qemu(s);
|
||||||
close(s->fd);
|
close(s->fd);
|
||||||
close(s->qmp_fd);
|
close(s->qmp_fd);
|
||||||
g_string_free(s->rx, true);
|
g_string_free(s->rx, true);
|
||||||
|
|
Loading…
Reference in New Issue