mirror of https://gitlab.com/qemu-project/qemu
libqtest: Wait for the right child PID after killing QEMU
When running "make check" with gcov enabled, we get the following message: hw/tmp105.gcda:cannot open data file, assuming not executed The problem happens because: * tmp105-test exits before QEMU exits, because waitpid() at qtest_quit() fails; * waitpid() fails because there's another process already waiting for the QEMU process; * The process that is already waiting for QEMU is the child created by qtest_init() to run system(); * qtest_quit() is incorrectly waiting for the QEMU PID directly instead of the child created by qtest_init(). This fixes the problem by sending SIGTERM to QEMU, but waiting for the child process created by qtest_init() (that exits immediately after QEMU exits). Reported-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
3e7b8f4e6f
commit
6bf0076643
|
@ -39,7 +39,8 @@ struct QTestState
|
||||||
int qmp_fd;
|
int qmp_fd;
|
||||||
bool irq_level[MAX_IRQ];
|
bool irq_level[MAX_IRQ];
|
||||||
GString *rx;
|
GString *rx;
|
||||||
gchar *pid_file;
|
gchar *pid_file; /* QEMU PID file */
|
||||||
|
int child_pid; /* Child process created to execute QEMU */
|
||||||
char *socket_path, *qmp_socket_path;
|
char *socket_path, *qmp_socket_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,6 +145,7 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
|
|
||||||
s->rx = g_string_new("");
|
s->rx = g_string_new("");
|
||||||
s->pid_file = pid_file;
|
s->pid_file = pid_file;
|
||||||
|
s->child_pid = pid;
|
||||||
for (i = 0; i < MAX_IRQ; i++) {
|
for (i = 0; i < MAX_IRQ; i++) {
|
||||||
s->irq_level[i] = false;
|
s->irq_level[i] = false;
|
||||||
}
|
}
|
||||||
|
@ -165,8 +167,9 @@ void qtest_quit(QTestState *s)
|
||||||
|
|
||||||
pid_t pid = qtest_qemu_pid(s);
|
pid_t pid = qtest_qemu_pid(s);
|
||||||
if (pid != -1) {
|
if (pid != -1) {
|
||||||
|
/* kill QEMU, but wait for the child created by us to run system() */
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
waitpid(pid, &status, 0);
|
waitpid(s->child_pid, &status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(s->pid_file);
|
unlink(s->pid_file);
|
||||||
|
|
Loading…
Reference in New Issue