aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Suvorova <jusual@mail.ru>2019-01-17 19:16:38 +0300
committerPeter Maydell <peter.maydell@linaro.org>2019-01-18 14:17:38 +0000
commit2a0ed2804e2c77a1c4e255f05ab739618e05c85d (patch)
tree106f7c9a1a97ff4f8c17557b8fe27a1a694a7868
parent15dbd6fd3ca8927c2231c1edd941156aedcb70eb (diff)
tests/libqtest: Introduce qtest_init_with_serial()pull-target-arm-20190118
Run qtest with a socket that connects QEMU chardev and test code. Signed-off-by: Julia Suvorova <jusual@mail.ru> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 20190117161640.5496-2-jusual@mail.ru Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--tests/libqtest.c26
-rw-r--r--tests/libqtest.h11
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 55750dd68d..1f99ea6384 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -315,6 +315,32 @@ QTestState *qtest_initf(const char *fmt, ...)
return s;
}
+QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
+{
+ int sock_fd_init;
+ char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
+ QTestState *qts;
+
+ g_assert(mkdtemp(sock_dir));
+ sock_path = g_strdup_printf("%s/sock", sock_dir);
+
+ sock_fd_init = init_socket(sock_path);
+
+ qts = qtest_initf("-chardev socket,id=s0,path=%s,nowait "
+ "-serial chardev:s0 %s",
+ sock_path, extra_args);
+
+ *sock_fd = socket_accept(sock_fd_init);
+
+ unlink(sock_path);
+ g_free(sock_path);
+ rmdir(sock_dir);
+
+ g_assert(*sock_fd >= 0);
+
+ return qts;
+}
+
void qtest_quit(QTestState *s)
{
g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 7ea94139b0..5937f91912 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -63,6 +63,17 @@ QTestState *qtest_init(const char *extra_args);
QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
/**
+ * qtest_init_with_serial:
+ * @extra_args: other arguments to pass to QEMU. CAUTION: these
+ * arguments are subject to word splitting and shell evaluation.
+ * @sock_fd: pointer to store the socket file descriptor for
+ * connection with serial.
+ *
+ * Returns: #QTestState instance.
+ */
+QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
+
+/**
* qtest_quit:
* @s: #QTestState instance to operate on.
*