summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2020-10-31 01:23:36 +1100
committerTim-Philipp Müller <tim@centricular.com>2020-10-31 12:31:26 +0000
commit284187d536ecb9508ecd0a8da29514c58d1a50bb (patch)
treee5d9ff0e02710a31886ff50bc5ad6a8f811bc639
parentf69670351db0e2c5bd734d478167d44c7abaeed8 (diff)
downloadgstreamer-plugins-bad-284187d536ecb9508ecd0a8da29514c58d1a50bb.tar.gz
dtls: Catch bus errors and fail instead of hanging.
If the DTLS elements fail, they post a bus error and don't signal any key negotiation. Catch the bus error and fail the test early instead of letting it hang and time out. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1746>
-rw-r--r--tests/check/elements/dtls.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/check/elements/dtls.c b/tests/check/elements/dtls.c
index 203e9cfc1..74149d211 100644
--- a/tests/check/elements/dtls.c
+++ b/tests/check/elements/dtls.c
@@ -51,6 +51,20 @@ GST_END_TEST;
static GMutex key_lock;
static GCond key_cond;
static int key_count;
+static gboolean errored;
+
+static GstBusSyncReply
+bus_msg_handler (GstBus * bus, GstMessage * message, gpointer user_data)
+{
+ if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
+ g_mutex_lock (&key_lock);
+ errored = TRUE;
+ g_cond_broadcast (&key_cond);
+ g_mutex_unlock (&key_lock);
+ }
+
+ return GST_BUS_PASS;
+}
static void
_on_key_received (GstElement * element, gpointer user_data)
@@ -65,8 +79,16 @@ static void
_wait_for_key_count_to_reach (int n)
{
g_mutex_lock (&key_lock);
- while (key_count < n)
+ while (key_count < n) {
g_cond_wait (&key_cond, &key_lock);
+
+ /* Check if any errors were posted */
+ if (errored) {
+ g_mutex_unlock (&key_lock);
+ fail ("DTLS element posted an error");
+ g_mutex_lock (&key_lock);
+ }
+ }
g_mutex_unlock (&key_lock);
}
@@ -80,6 +102,7 @@ GST_START_TEST (test_data_transfer)
GstElement *s_enc, *s_dec, *c_enc, *c_dec, *s_bin, *c_bin;
GstPad *target, *ghost;
GstBuffer *buffer, *buf2;
+ GstBus *bus;
/* setup a server and client for dtls negotiation */
s_bin = gst_bin_new (NULL);
@@ -150,6 +173,14 @@ GST_START_TEST (test_data_transfer)
gst_harness_set_src_caps_str (server, "application/data");
gst_harness_set_src_caps_str (client, "application/data");
+ bus = gst_bus_new ();
+ gst_bus_set_sync_handler (bus, bus_msg_handler, NULL, NULL);
+
+ gst_element_set_bus (s_bin, bus);
+ gst_element_set_bus (c_bin, bus);
+
+ gst_object_unref (bus);
+
_wait_for_key_count_to_reach (4);
buffer = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, data,