Merge tpm 2018/09/07 v1

-----BEGIN PGP SIGNATURE-----
 
 iQEcBAABAgAGBQJbkuGuAAoJEHWtZYAqC0IRklMH/A3GvaDrEJvIo3SUlRiznnsH
 GaNa+Mxv//2VNc61xgBW1uGKW55JKHjEDNKbPTHnHOVtyJTUueQEH9N7Lnpq/1uy
 CGdmWnl0C49GxL63rcm+mBWxJckCaMK/r9Y7qGJY8U+Qkt3aqdeP/8NK5QOyKFvF
 OD9z+dDod479PYpDLKxUiPNsJ4P+XngAemBRKLIErHBA1FM3WTjw3gSp6DIJ4033
 vX/aVMfQ9n1GJaURxjoPEtgoE1V3RoNGYwzcflVmJPxBOnlfrz5ATLqD+8RzAdCt
 3mLRuEL75jIBEp1HRa4KRleT4hZyJyS54OpQsMuTQo3+mb6rDVisz0LzIE/oEu0=
 =kLs8
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2018-09-07-1' into staging

Merge tpm 2018/09/07 v1

# gpg: Signature made Fri 07 Sep 2018 21:38:06 BST
# gpg:                using RSA key 75AD65802A0B4211
# gpg: Good signature from "Stefan Berger <stefanb@linux.vnet.ibm.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: B818 B9CA DF90 89C2 D5CE  C66B 75AD 6580 2A0B 4211

* remotes/stefanberger/tags/pull-tpm-2018-09-07-1:
  tests: Fix signalling race condition in TPM tests

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2018-09-24 18:12:54 +01:00
commit 741e1a618b
4 changed files with 13 additions and 1 deletions

View File

@ -151,6 +151,7 @@ int main(int argc, char **argv)
test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
g_mutex_init(&test.data_mutex);
g_cond_init(&test.data_cond);
test.data_cond_signal = false;
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
tpm_emu_test_wait_cond(&test);

View File

@ -23,9 +23,14 @@ void tpm_emu_test_wait_cond(TestState *s)
gint64 end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
g_mutex_lock(&s->data_mutex);
if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
if (!s->data_cond_signal &&
!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) {
g_assert_not_reached();
}
s->data_cond_signal = false;
g_mutex_unlock(&s->data_mutex);
}
@ -72,6 +77,10 @@ void *tpm_emu_ctrl_thread(void *data)
QIOChannel *ioc;
qio_channel_socket_listen_sync(lioc, s->addr, &error_abort);
g_mutex_lock(&s->data_mutex);
s->data_cond_signal = true;
g_mutex_unlock(&s->data_mutex);
g_cond_signal(&s->data_cond);
qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN);

View File

@ -26,6 +26,7 @@ struct tpm_hdr {
typedef struct TestState {
GMutex data_mutex;
GCond data_cond;
bool data_cond_signal;
SocketAddress *addr;
QIOChannel *tpm_ioc;
GThread *emu_tpm_thread;

View File

@ -446,6 +446,7 @@ int main(int argc, char **argv)
test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
g_mutex_init(&test.data_mutex);
g_cond_init(&test.data_cond);
test.data_cond_signal = false;
thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
tpm_emu_test_wait_cond(&test);