[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 39/47] qtest: add qtest_add_abrt_handler()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v4 39/47] qtest: add qtest_add_abrt_handler() |
Date: |
Thu, 24 Sep 2015 13:37:41 +0200 |
From: Marc-André Lureau <address@hidden>
Allow a test to add abort handlers, use GHook for all handlers.
There is currently no way to remove a handler, but it could be
later added if needed.
Signed-off-by: Marc-André Lureau <address@hidden>
---
tests/libqtest.c | 37 ++++++++++++++++++++++++-------------
tests/libqtest.h | 2 ++
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index e5188e0..4a3a6ad 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -49,6 +49,7 @@ struct QTestState
struct sigaction sigact_old; /* restored on exit */
};
+static GHookList abrt_hooks;
static GList *qtest_instances;
static struct sigaction sigact_old;
@@ -112,10 +113,7 @@ static void kill_qemu(QTestState *s)
static void sigabrt_handler(int signo)
{
- GList *elem;
- for (elem = qtest_instances; elem; elem = elem->next) {
- kill_qemu(elem->data);
- }
+ g_hook_list_invoke(&abrt_hooks, FALSE);
}
static void setup_sigabrt_handler(void)
@@ -136,6 +134,23 @@ static void cleanup_sigabrt_handler(void)
sigaction(SIGABRT, &sigact_old, NULL);
}
+void qtest_add_abrt_handler(void (*fn), const void *data)
+{
+ GHook *hook;
+
+ /* Only install SIGABRT handler once */
+ if (!abrt_hooks.is_setup) {
+ g_hook_list_init(&abrt_hooks, sizeof(GHook));
+ setup_sigabrt_handler();
+ }
+
+ hook = g_hook_alloc(&abrt_hooks);
+ hook->func = fn;
+ hook->data = (void *)data;
+
+ g_hook_prepend(&abrt_hooks, hook);
+}
+
QTestState *qtest_init(const char *extra_args)
{
QTestState *s;
@@ -156,12 +171,7 @@ QTestState *qtest_init(const char *extra_args)
sock = init_socket(socket_path);
qmpsock = init_socket(qmp_socket_path);
- /* Only install SIGABRT handler once */
- if (!qtest_instances) {
- setup_sigabrt_handler();
- }
-
- qtest_instances = g_list_prepend(qtest_instances, s);
+ qtest_add_abrt_handler(kill_qemu, s);
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
@@ -209,13 +219,14 @@ QTestState *qtest_init(const char *extra_args)
void qtest_quit(QTestState *s)
{
+ qtest_instances = g_list_remove(qtest_instances, s);
+ g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
+
/* Uninstall SIGABRT handler on last instance */
- if (qtest_instances && !qtest_instances->next) {
+ if (!qtest_instances) {
cleanup_sigabrt_handler();
}
- qtest_instances = g_list_remove(qtest_instances, s);
-
kill_qemu(s);
close(s->fd);
close(s->qmp_fd);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index ec42031..f02c07c 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -427,6 +427,8 @@ void qtest_add_data_func(const char *str, const void *data,
void (*fn));
g_free(path); \
} while (0)
+void qtest_add_abrt_handler(void (*fn), const void *data);
+
/**
* qtest_start:
* @args: other arguments to pass to QEMU
--
2.4.3
- [Qemu-devel] [PATCH v4 29/47] ivshmem: error on too many eventfd received, (continued)
- [Qemu-devel] [PATCH v4 29/47] ivshmem: error on too many eventfd received, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 30/47] ivshmem: reset mask on device reset, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 32/47] ivshmem-client: check the number of vectors, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 33/47] ivshmem-server: use a uint16 for client ID, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 34/47] ivshmem-server: fix hugetlbfs support, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 31/47] contrib: add ivshmem client and server, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 35/47] docs: update ivshmem device spec, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 37/47] contrib: remove unnecessary strdup(), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 38/47] msix: implement pba write (but read-only), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 36/47] ivshmem: add check on protocol version in QEMU, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 39/47] qtest: add qtest_add_abrt_handler(),
marcandre . lureau <=
- [Qemu-devel] [PATCH v4 40/47] tests: add ivshmem qtest, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 41/47] ivshmem: do not keep shm_fd open, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 42/47] ivshmem: use strtosz(), marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 44/47] ivshmem: remove EventfdEntry.vector, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 43/47] ivshmem: add hostmem backend, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 45/47] ivshmem: rename MSI eventfd_table, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 46/47] ivshmem: use kvm irqfd for msi notifications, marcandre . lureau, 2015/09/24
- [Qemu-devel] [PATCH v4 47/47] ivshmem: use little-endian int64_t for the protocol, marcandre . lureau, 2015/09/24