aggregator: test cleanup

Remove gst_init() from a few tests. Use _OBJECT variants in logging. Remove
arbitrary extra blank lines. Make push_event() more like push_buffer() - set
the event to NULL and add cleanup to _chain_data_clear().
This commit is contained in:
Stefan Sauer 2017-10-14 12:08:19 +02:00 committed by Tim-Philipp Müller
parent 4808f4836c
commit 9efffd05e2

View file

@ -190,6 +190,8 @@ gst_test_aggregator_plugin_register (void)
VERSION, GST_LICENSE, PACKAGE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); VERSION, GST_LICENSE, PACKAGE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
} }
/* test helpers */
typedef struct typedef struct
{ {
GstEvent *event; GstEvent *event;
@ -259,8 +261,8 @@ push_buffer (gpointer user_data)
start_flow (chain_data); start_flow (chain_data);
GST_DEBUG ("Pushing buffer on pad: %s:%s", GST_INFO_OBJECT (chain_data->sinkpad, "Pushing buffer %" GST_PTR_FORMAT,
GST_DEBUG_PAD_NAME (chain_data->sinkpad)); chain_data->buffer);
flow = gst_pad_push (chain_data->srcpad, chain_data->buffer); flow = gst_pad_push (chain_data->srcpad, chain_data->buffer);
fail_unless (flow == chain_data->expected_result, fail_unless (flow == chain_data->expected_result,
"got flow %s instead of %s on %s:%s", gst_flow_get_name (flow), "got flow %s instead of %s on %s:%s", gst_flow_get_name (flow),
@ -276,14 +278,13 @@ push_event (gpointer user_data)
{ {
ChainData *chain_data = (ChainData *) user_data; ChainData *chain_data = (ChainData *) user_data;
GstTestAggregator *aggregator = (GstTestAggregator *) chain_data->aggregator; GstTestAggregator *aggregator = (GstTestAggregator *) chain_data->aggregator;
GstEventType event_type; GstEventType event_type = GST_EVENT_TYPE (chain_data->event);
start_flow (chain_data); start_flow (chain_data);
GST_INFO_OBJECT (chain_data->srcpad, "Pushing event: %" GST_INFO_OBJECT (chain_data->sinkpad, "Pushing event: %" GST_PTR_FORMAT,
GST_PTR_FORMAT, chain_data->event); chain_data->event);
event_type = GST_EVENT_TYPE (chain_data->event);
switch (event_type) { switch (event_type) {
case GST_EVENT_GAP: case GST_EVENT_GAP:
aggregator->gap_expected = TRUE; aggregator->gap_expected = TRUE;
@ -294,7 +295,7 @@ push_event (gpointer user_data)
fail_unless (gst_pad_push_event (chain_data->srcpad, fail_unless (gst_pad_push_event (chain_data->srcpad,
chain_data->event) == TRUE); chain_data->event) == TRUE);
chain_data->event = NULL;
return NULL; return NULL;
} }
@ -328,7 +329,7 @@ _aggregated_cb (GstPad * pad, GstPadProbeInfo * info, GMainLoop * ml)
} }
static GstPadProbeReturn static GstPadProbeReturn
downstream_probe_cb (GstPad * pad, GstPadProbeInfo * info, TestData * test) _downstream_probe_cb (GstPad * pad, GstPadProbeInfo * info, TestData * test)
{ {
GST_DEBUG ("PROBING "); GST_DEBUG ("PROBING ");
if (info->type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) { if (info->type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) {
@ -344,7 +345,6 @@ downstream_probe_cb (GstPad * pad, GstPadProbeInfo * info, TestData * test)
return GST_PAD_PROBE_OK; return GST_PAD_PROBE_OK;
} }
/* /*
* Not thread safe, will create a new ChainData which contains * Not thread safe, will create a new ChainData which contains
* an activated src pad linked to a requested sink pad of @agg, and * an activated src pad linked to a requested sink pad of @agg, and
@ -372,8 +372,8 @@ _chain_data_init (ChainData * data, GstElement * agg)
static void static void
_chain_data_clear (ChainData * data) _chain_data_clear (ChainData * data)
{ {
if (data->buffer) gst_buffer_replace (&data->buffer, NULL);
gst_buffer_unref (data->buffer); gst_event_replace (&data->event, NULL);
if (data->srcpad) if (data->srcpad)
gst_object_unref (data->srcpad); gst_object_unref (data->srcpad);
if (data->sinkpad) if (data->sinkpad)
@ -396,7 +396,7 @@ _test_data_init (TestData * test, gboolean needs_flushing)
test->ml = g_main_loop_new (NULL, TRUE); test->ml = g_main_loop_new (NULL, TRUE);
test->srcpad = GST_AGGREGATOR (test->aggregator)->srcpad; test->srcpad = GST_AGGREGATOR (test->aggregator)->srcpad;
GST_DEBUG ("Srcpad: %p", test->srcpad); GST_DEBUG_OBJECT (test->srcpad, "Init test data for srcpad");
if (needs_flushing) { if (needs_flushing) {
static gint num_sink_pads = 0; static gint num_sink_pads = 0;
@ -409,13 +409,12 @@ _test_data_init (TestData * test, gboolean needs_flushing)
g_free (pad_name); g_free (pad_name);
fail_unless (gst_pad_link (test->srcpad, test->sinkpad) == GST_PAD_LINK_OK); fail_unless (gst_pad_link (test->srcpad, test->sinkpad) == GST_PAD_LINK_OK);
gst_pad_add_probe (test->srcpad, GST_PAD_PROBE_TYPE_EVENT_FLUSH, gst_pad_add_probe (test->srcpad, GST_PAD_PROBE_TYPE_EVENT_FLUSH,
(GstPadProbeCallback) downstream_probe_cb, test, NULL); (GstPadProbeCallback) _downstream_probe_cb, test, NULL);
} else { } else {
gst_pad_add_probe (test->srcpad, GST_PAD_PROBE_TYPE_BUFFER, gst_pad_add_probe (test->srcpad, GST_PAD_PROBE_TYPE_BUFFER,
(GstPadProbeCallback) _aggregated_cb, test->ml, NULL); (GstPadProbeCallback) _aggregated_cb, test->ml, NULL);
} }
test->timeout_id = test->timeout_id =
g_timeout_add (1000, (GSourceFunc) _aggregate_timeout, test->ml); g_timeout_add (1000, (GSourceFunc) _aggregate_timeout, test->ml);
} }
@ -432,10 +431,11 @@ _test_data_clear (TestData * test)
g_main_loop_unref (test->ml); g_main_loop_unref (test->ml);
} }
/* tests */
GST_START_TEST (test_aggregate) GST_START_TEST (test_aggregate)
{ {
GThread *thread1, *thread2; GThread *thread1, *thread2;
ChainData data1 = { 0, }; ChainData data1 = { 0, };
ChainData data2 = { 0, }; ChainData data2 = { 0, };
TestData test = { 0, }; TestData test = { 0, };
@ -450,7 +450,6 @@ GST_START_TEST (test_aggregate)
g_main_loop_run (test.ml); g_main_loop_run (test.ml);
g_source_remove (test.timeout_id); g_source_remove (test.timeout_id);
/* these will return immediately as when the data is popped the threads are /* these will return immediately as when the data is popped the threads are
* unlocked and will terminate */ * unlocked and will terminate */
g_thread_join (thread1); g_thread_join (thread1);
@ -466,7 +465,6 @@ GST_END_TEST;
GST_START_TEST (test_aggregate_eos) GST_START_TEST (test_aggregate_eos)
{ {
GThread *thread1, *thread2; GThread *thread1, *thread2;
ChainData data1 = { 0, }; ChainData data1 = { 0, };
ChainData data2 = { 0, }; ChainData data2 = { 0, };
TestData test = { 0, }; TestData test = { 0, };
@ -498,7 +496,6 @@ GST_END_TEST;
GST_START_TEST (test_aggregate_gap) GST_START_TEST (test_aggregate_gap)
{ {
GThread *thread; GThread *thread;
ChainData data = { 0, }; ChainData data = { 0, };
TestData test = { 0, }; TestData test = { 0, };
@ -536,7 +533,6 @@ GST_START_TEST (test_linear_pipeline)
GstBus *bus; GstBus *bus;
GstMessage *msg; GstMessage *msg;
GstElement *pipeline, *src, *agg, *sink; GstElement *pipeline, *src, *agg, *sink;
gint count = 0; gint count = 0;
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
@ -576,7 +572,6 @@ GST_START_TEST (test_two_src_pipeline)
GstBus *bus; GstBus *bus;
GstMessage *msg; GstMessage *msg;
GstElement *pipeline, *src, *src1, *agg, *sink; GstElement *pipeline, *src, *src1, *agg, *sink;
gint count = 0; gint count = 0;
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
@ -641,7 +636,6 @@ _test_timeout (gint buffer_wait)
GstMessage *msg; GstMessage *msg;
GstElement *pipeline, *src, *src1, *agg, *sink; GstElement *pipeline, *src, *src1, *agg, *sink;
GstPad *src1pad; GstPad *src1pad;
gint count = 0; gint count = 0;
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
@ -711,7 +705,6 @@ GST_START_TEST (test_flushing_seek)
{ {
GstEvent *event; GstEvent *event;
GThread *thread1, *thread2; GThread *thread1, *thread2;
ChainData data1 = { 0, }; ChainData data1 = { 0, };
ChainData data2 = { 0, }; ChainData data2 = { 0, };
TestData test = { 0, }; TestData test = { 0, };
@ -805,12 +798,9 @@ infinite_seek (guint num_srcs, guint num_seeks, gboolean is_live)
GstBus *bus; GstBus *bus;
GstMessage *message; GstMessage *message;
GstElement *pipeline, *src, *agg, *sink; GstElement *pipeline, *src, *agg, *sink;
gint count = 0, i; gint count = 0, i;
gboolean seek_res, carry_on = TRUE; gboolean seek_res, carry_on = TRUE;
gst_init (NULL, NULL);
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
agg = gst_check_setup_element ("testaggregator"); agg = gst_check_setup_element ("testaggregator");
@ -938,19 +928,15 @@ GST_START_TEST (test_add_remove)
/* Used to notify that we removed the pad from */ /* Used to notify that we removed the pad from */
GCond cond; GCond cond;
GMutex lock; GMutex lock;
GstBus *bus; GstBus *bus;
GstState state; GstState state;
GstMessage *message; GstMessage *message;
gboolean carry_on = TRUE; gboolean carry_on = TRUE;
guint num_iterations = 100; guint num_iterations = 100;
GstPad *pad; GstPad *pad;
GstElement *pipeline, *src, *src1 = NULL, *agg, *sink; GstElement *pipeline, *src, *src1 = NULL, *agg, *sink;
gint count = 0; gint count = 0;
gst_init (NULL, NULL);
g_mutex_init (&lock); g_mutex_init (&lock);
g_cond_init (&cond); g_cond_init (&cond);
@ -1067,7 +1053,6 @@ GST_START_TEST (test_change_state_intensive)
GstBus *bus; GstBus *bus;
GstMessage *message; GstMessage *message;
GstElement *pipeline, *src, *agg, *sink; GstElement *pipeline, *src, *agg, *sink;
gint i, state_i = 0, num_srcs = 3; gint i, state_i = 0, num_srcs = 3;
gboolean carry_on = TRUE, ready = FALSE; gboolean carry_on = TRUE, ready = FALSE;
GstStateChangeReturn state_return; GstStateChangeReturn state_return;
@ -1085,8 +1070,6 @@ GST_START_TEST (test_change_state_intensive)
GST_STATE_PLAYING, GST_STATE_NULL, GST_STATE_PLAYING, GST_STATE_NULL, GST_STATE_PLAYING, GST_STATE_NULL, GST_STATE_PLAYING, GST_STATE_NULL,
}; };
gst_init (NULL, NULL);
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
agg = gst_check_setup_element ("testaggregator"); agg = gst_check_setup_element ("testaggregator");