mirror of https://github.com/xemu-project/xemu.git
qtest resource cleanup pull request
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJTBMPKAAoJEJykq7OBq3PIYWkIAJsWLbCVaG352bY4bdhssSbX H7IGS1eLYcJsZu6XLTh1KkesTJNhFzazG5XMagT8/5+Av9kkppnIs0K55G7qP+7R YZR4lA7fEIS7wQivKbh7mcFJjYYlHZRWBx3fmTxWQtn/S9B2bLAcZDuAkHv7oXHH ASCyFtbO23MJmAFBNUlqGU+DSGh0jCKyxJI2O3fgLlccgWkIdc0/5gaaLZbWpaKy HmKKKkp6rISlJRLSUyytjldaZhRuDkUCRa+9fKeHJkGzB1o0zN6MqSloVyhKc73y VrP1riHNOwecoZhpUs4t51/cogbrmuOWEydOwTLNbvtD5MGHGYblVWtY17OgibE= =rwDt -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanha/tags/qtest-monitor-process-pull-request' into staging qtest resource cleanup pull request # gpg: Signature made Wed 19 Feb 2014 14:46:34 GMT using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/qtest-monitor-process-pull-request: qtest: kill QEMU process on g_assert() failure qtest: make QEMU our direct child process qtest: drop unused child_pid field Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
3e890c77cf
|
@ -43,8 +43,8 @@ struct QTestState
|
||||||
int qmp_fd;
|
int qmp_fd;
|
||||||
bool irq_level[MAX_IRQ];
|
bool irq_level[MAX_IRQ];
|
||||||
GString *rx;
|
GString *rx;
|
||||||
int child_pid; /* Child process created to execute QEMU */
|
pid_t qemu_pid; /* our child QEMU process */
|
||||||
pid_t qemu_pid; /* QEMU process spawned by our child */
|
struct sigaction sigact_old; /* restored on exit */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define g_assert_no_errno(ret) do { \
|
#define g_assert_no_errno(ret) do { \
|
||||||
|
@ -89,20 +89,17 @@ static int socket_accept(int sock)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static pid_t read_pid_file(const char *pid_file)
|
static void kill_qemu(QTestState *s)
|
||||||
{
|
{
|
||||||
FILE *f;
|
if (s->qemu_pid != -1) {
|
||||||
char buffer[1024];
|
kill(s->qemu_pid, SIGTERM);
|
||||||
pid_t pid = -1;
|
waitpid(s->qemu_pid, NULL, 0);
|
||||||
|
|
||||||
f = fopen(pid_file, "r");
|
|
||||||
if (f) {
|
|
||||||
if (fgets(buffer, sizeof(buffer), f)) {
|
|
||||||
pid = atoi(buffer);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
return pid;
|
}
|
||||||
|
|
||||||
|
static void sigabrt_handler(int signo)
|
||||||
|
{
|
||||||
|
kill_qemu(global_qtest);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTestState *qtest_init(const char *extra_args)
|
QTestState *qtest_init(const char *extra_args)
|
||||||
|
@ -111,10 +108,9 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
int sock, qmpsock, i;
|
int sock, qmpsock, i;
|
||||||
gchar *socket_path;
|
gchar *socket_path;
|
||||||
gchar *qmp_socket_path;
|
gchar *qmp_socket_path;
|
||||||
gchar *pid_file;
|
|
||||||
gchar *command;
|
gchar *command;
|
||||||
const char *qemu_binary;
|
const char *qemu_binary;
|
||||||
pid_t pid;
|
struct sigaction sigact;
|
||||||
|
|
||||||
qemu_binary = getenv("QTEST_QEMU_BINARY");
|
qemu_binary = getenv("QTEST_QEMU_BINARY");
|
||||||
g_assert(qemu_binary != NULL);
|
g_assert(qemu_binary != NULL);
|
||||||
|
@ -123,22 +119,28 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
|
|
||||||
socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
|
socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
|
||||||
qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
|
qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
|
||||||
pid_file = g_strdup_printf("/tmp/qtest-%d.pid", getpid());
|
|
||||||
|
|
||||||
sock = init_socket(socket_path);
|
sock = init_socket(socket_path);
|
||||||
qmpsock = init_socket(qmp_socket_path);
|
qmpsock = init_socket(qmp_socket_path);
|
||||||
|
|
||||||
pid = fork();
|
/* Catch SIGABRT to clean up on g_assert() failure */
|
||||||
if (pid == 0) {
|
sigact = (struct sigaction){
|
||||||
command = g_strdup_printf("%s "
|
.sa_handler = sigabrt_handler,
|
||||||
|
.sa_flags = SA_RESETHAND,
|
||||||
|
};
|
||||||
|
sigemptyset(&sigact.sa_mask);
|
||||||
|
sigaction(SIGABRT, &sigact, &s->sigact_old);
|
||||||
|
|
||||||
|
s->qemu_pid = fork();
|
||||||
|
if (s->qemu_pid == 0) {
|
||||||
|
command = g_strdup_printf("exec %s "
|
||||||
"-qtest unix:%s,nowait "
|
"-qtest unix:%s,nowait "
|
||||||
"-qtest-log /dev/null "
|
"-qtest-log /dev/null "
|
||||||
"-qmp unix:%s,nowait "
|
"-qmp unix:%s,nowait "
|
||||||
"-pidfile %s "
|
|
||||||
"-machine accel=qtest "
|
"-machine accel=qtest "
|
||||||
"-display none "
|
"-display none "
|
||||||
"%s", qemu_binary, socket_path,
|
"%s", qemu_binary, socket_path,
|
||||||
qmp_socket_path, pid_file,
|
qmp_socket_path,
|
||||||
extra_args ?: "");
|
extra_args ?: "");
|
||||||
execlp("/bin/sh", "sh", "-c", command, NULL);
|
execlp("/bin/sh", "sh", "-c", command, NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -152,7 +154,6 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
g_free(qmp_socket_path);
|
g_free(qmp_socket_path);
|
||||||
|
|
||||||
s->rx = g_string_new("");
|
s->rx = g_string_new("");
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -161,10 +162,6 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
qtest_qmp_discard_response(s, "");
|
qtest_qmp_discard_response(s, "");
|
||||||
qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
|
qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
|
||||||
|
|
||||||
s->qemu_pid = read_pid_file(pid_file);
|
|
||||||
unlink(pid_file);
|
|
||||||
g_free(pid_file);
|
|
||||||
|
|
||||||
if (getenv("QTEST_STOP")) {
|
if (getenv("QTEST_STOP")) {
|
||||||
kill(s->qemu_pid, SIGSTOP);
|
kill(s->qemu_pid, SIGSTOP);
|
||||||
}
|
}
|
||||||
|
@ -174,13 +171,9 @@ QTestState *qtest_init(const char *extra_args)
|
||||||
|
|
||||||
void qtest_quit(QTestState *s)
|
void qtest_quit(QTestState *s)
|
||||||
{
|
{
|
||||||
int status;
|
sigaction(SIGABRT, &s->sigact_old, NULL);
|
||||||
|
|
||||||
if (s->qemu_pid != -1) {
|
|
||||||
kill(s->qemu_pid, SIGTERM);
|
|
||||||
waitpid(s->qemu_pid, &status, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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