mirror of
https://github.com/mii443/qemu.git
synced 2025-09-03 23:59:38 +00:00
Merge tag 'pull-tpm-2023-01-17-1' of https://github.com/stefanberger/qemu-tpm into staging
Merge tpm 2023/01/17 v1 # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCAAdFiEEuBi5yt+QicLVzsZrda1lgCoLQhEFAmPGjawACgkQda1lgCoL # QhHOgQf/QxWxhydyj2679bnznCgJXOXKQ1C+MkFvk0ekPJT+bZDwKoohAH3JgbxT # zp3UeMmtqS9JQDcGF6PdIldp4DB7uH+InvVkFFZeD1LN0X6nYHEgZ3Q1obSbf8ut # TGlB6+4TM6ehtk9owDuzlm7/5OFLmEGvGjdVgzZKtwzXGWUKVO7AzzRQBj4QnKq/ # w8cSlZAlF+lJI3IsnCh8EIAdL3SP8dub3yfYJDepbht7IwfkUWPOWBFOSUpo5quX # r1rLKWtjQRsoGDe4iRNrLQu+sgj9npZwj7aYotarJauYBW8qd3jdD4OtiBYj2OMU # LvEIqwNyITivKnapEnDEJV74umzArw== # =lIgU # -----END PGP SIGNATURE----- # gpg: Signature made Tue 17 Jan 2023 11:59:40 GMT # gpg: using RSA key B818B9CADF9089C2D5CEC66B75AD65802A0B4211 # gpg: Good signature from "Stefan Berger <stefanb@linux.vnet.ibm.com>" [unknown] # 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: B818 B9CA DF90 89C2 D5CE C66B 75AD 6580 2A0B 4211 * tag 'pull-tpm-2023-01-17-1' of https://github.com/stefanberger/qemu-tpm: tests/qtest/tpm-emu: Avoid hangs using abort handlers closing channels tests/qtest: Poll on waitpid() for a while before sending SIGKILL Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@ -49,6 +49,8 @@
|
|||||||
# define DEV_NULL "nul"
|
# define DEV_NULL "nul"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define WAITPID_TIMEOUT 30
|
||||||
|
|
||||||
typedef void (*QTestSendFn)(QTestState *s, const char *buf);
|
typedef void (*QTestSendFn)(QTestState *s, const char *buf);
|
||||||
typedef void (*ExternalSendFn)(void *s, const char *buf);
|
typedef void (*ExternalSendFn)(void *s, const char *buf);
|
||||||
typedef GString* (*QTestRecvFn)(QTestState *);
|
typedef GString* (*QTestRecvFn)(QTestState *);
|
||||||
@ -202,8 +204,24 @@ void qtest_wait_qemu(QTestState *s)
|
|||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
uint64_t end;
|
||||||
|
|
||||||
|
/* poll for a while until sending SIGKILL */
|
||||||
|
end = g_get_monotonic_time() + WAITPID_TIMEOUT * G_TIME_SPAN_SECOND;
|
||||||
|
|
||||||
|
do {
|
||||||
|
pid = waitpid(s->qemu_pid, &s->wstatus, WNOHANG);
|
||||||
|
if (pid != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_usleep(100 * 1000);
|
||||||
|
} while (g_get_monotonic_time() < end);
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
kill(s->qemu_pid, SIGKILL);
|
||||||
pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0));
|
pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0));
|
||||||
|
}
|
||||||
|
|
||||||
assert(pid == s->qemu_pid);
|
assert(pid == s->qemu_pid);
|
||||||
#else
|
#else
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
|
@ -36,11 +36,18 @@ void tpm_emu_test_wait_cond(TPMTestState *s)
|
|||||||
g_mutex_unlock(&s->data_mutex);
|
g_mutex_unlock(&s->data_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tpm_emu_close_ioc(void *ioc)
|
||||||
|
{
|
||||||
|
qio_channel_close(ioc, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void *tpm_emu_tpm_thread(void *data)
|
static void *tpm_emu_tpm_thread(void *data)
|
||||||
{
|
{
|
||||||
TPMTestState *s = data;
|
TPMTestState *s = data;
|
||||||
QIOChannel *ioc = s->tpm_ioc;
|
QIOChannel *ioc = s->tpm_ioc;
|
||||||
|
|
||||||
|
qtest_add_abrt_handler(tpm_emu_close_ioc, ioc);
|
||||||
|
|
||||||
s->tpm_msg = g_new(struct tpm_hdr, 1);
|
s->tpm_msg = g_new(struct tpm_hdr, 1);
|
||||||
while (true) {
|
while (true) {
|
||||||
int minhlen = sizeof(s->tpm_msg->tag) + sizeof(s->tpm_msg->len);
|
int minhlen = sizeof(s->tpm_msg->tag) + sizeof(s->tpm_msg->len);
|
||||||
@ -77,6 +84,7 @@ static void *tpm_emu_tpm_thread(void *data)
|
|||||||
&error_abort);
|
&error_abort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qtest_remove_abrt_handler(ioc);
|
||||||
g_free(s->tpm_msg);
|
g_free(s->tpm_msg);
|
||||||
s->tpm_msg = NULL;
|
s->tpm_msg = NULL;
|
||||||
object_unref(OBJECT(s->tpm_ioc));
|
object_unref(OBJECT(s->tpm_ioc));
|
||||||
@ -99,6 +107,7 @@ void *tpm_emu_ctrl_thread(void *data)
|
|||||||
qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN);
|
qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN);
|
||||||
ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort));
|
ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort));
|
||||||
g_assert(ioc);
|
g_assert(ioc);
|
||||||
|
qtest_add_abrt_handler(tpm_emu_close_ioc, ioc);
|
||||||
|
|
||||||
{
|
{
|
||||||
uint32_t cmd = 0;
|
uint32_t cmd = 0;
|
||||||
@ -190,6 +199,7 @@ void *tpm_emu_ctrl_thread(void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qtest_remove_abrt_handler(ioc);
|
||||||
object_unref(OBJECT(ioc));
|
object_unref(OBJECT(ioc));
|
||||||
object_unref(OBJECT(lioc));
|
object_unref(OBJECT(lioc));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user