Re: gstreamer: tee: split the allocation query test

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: gstreamer: tee: split the allocation query test

Nicolas Dufresne-5
Le lundi 02 octobre 2017 à 14:41 +0000, Stefan Kost a écrit :

> Module: gstreamer
> Branch: master
> Commit: e364d7944ecbab86dea73c0ee3e639e766938d36
> URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=e3
> 64d7944ecbab86dea73c0ee3e639e766938d36
>
> Author: Stefan Sauer <[hidden email]>
> Date:   Mon Oct  2 16:25:00 2017 +0200
>
> tee: split the allocation query test
>
> Split the large allocation_query test into seperate tests. Add a
> setup helper
> to reduce code duplication. Fix the original test that used
> fail_unless instead
> of ck_assert_int_eq and had it accidentially working.
>
> ---
>
>  tests/check/elements/tee.c | 110 ++++++++++++++++++++++++++++++++++-
> ----------
>  1 file changed, 83 insertions(+), 27 deletions(-)
>
> diff --git a/tests/check/elements/tee.c b/tests/check/elements/tee.c
> index de63c1fd1..3d4e7d6e7 100644
> --- a/tests/check/elements/tee.c
> +++ b/tests/check/elements/tee.c
> @@ -762,44 +762,43 @@ allocation_query_fail (GstPad * pad, GstObject
> * parent, GstQuery * query)
>    return FALSE;
>  }
>  
> -GST_START_TEST (test_allocation_query)
> +static void
> +add_sink_pad_and_setup_query_func (GstElement * tee,
> +    GstPadQueryFunction query_func)
> +{
> +  GstPad *sink;
> +  static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE
> ("sink",
> +      GST_PAD_SINK,
> +      GST_PAD_ALWAYS,
> +      GST_STATIC_CAPS_ANY);
> +
> +  sink = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
> "src_%u");
> +  fail_unless (sink != NULL);
> +  gst_pad_set_query_function (sink, query_func);
> +}
> +
> +GST_START_TEST (test_allocation_query_aggregation)
>  {
>    GstElement *tee;
> -  GstPad *sink1, *sink2, *sink3;
>    GstPad *sinkpad, *srcpad;
>    GstCaps *caps;
>    GstQuery *query;
>    guint size, min, max;
>    GstAllocationParams param;
>  
> -  static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE
> ("sink",
> -      GST_PAD_SINK,
> -      GST_PAD_ALWAYS,
> -      GST_STATIC_CAPS_ANY);
> -
> -  caps = gst_caps_new_empty_simple ("test/test");
> -
>    tee = gst_check_setup_element ("tee");
>    fail_unless (tee);
>  
>    sinkpad = gst_element_get_static_pad (tee, "sink");
> +  add_sink_pad_and_setup_query_func (tee, allocation_query1);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query2);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query3);
>  
> -  sink1 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
> "src_%u");
> -  fail_unless (sink1 != NULL);
> -  gst_pad_set_query_function (sink1, allocation_query1);
> -
> -  sink2 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
> "src_%u");
> -  fail_unless (sink2 != NULL);
> -  gst_pad_set_query_function (sink2, allocation_query2);
> -
> -  sink3 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
> "src_%u");
> -  fail_unless (sink3 != NULL);
> -  gst_pad_set_query_function (sink3, allocation_query3);
> -
> +  caps = gst_caps_new_empty_simple ("test/test");
>    query = gst_query_new_allocation (caps, TRUE);
>    fail_unless (gst_pad_query (sinkpad, query));
>  
> -  fail_unless (gst_query_get_n_allocation_pools (query), 1);
> +  ck_assert_int_eq (gst_query_get_n_allocation_pools (query), 1);
>    gst_query_parse_nth_allocation_pool (query, 0, NULL, &size, &min,
> &max);
>    fail_unless (size == 130);
>    /* The tee will allocate one more buffer when multiplexing */
> @@ -816,18 +815,75 @@ GST_START_TEST (test_allocation_query)
>    fail_unless (gst_query_parse_nth_allocation_meta (query, 0, NULL)
> ==
>        GST_PARENT_BUFFER_META_API_TYPE);
>  
> +  /* TODO: what is this testing? move to a new test? */
That is testing the case were you have unlinked pads in your tee and
"allow-not-linked" is not set. In this case, query should fail. The
next one is testing the same, but when "allow-not-linked" is set.

>    srcpad = gst_element_get_request_pad (tee, "src_%u");
>    gst_query_unref (query);
>    query = gst_query_new_allocation (caps, TRUE);
>    fail_if (gst_pad_query (sinkpad, query));
>  
> -  g_object_set (tee, "allow-not-linked", TRUE, NULL);
> +  gst_caps_unref (caps);
>    gst_query_unref (query);
> +  gst_check_teardown_pad_by_name (tee, "src_0");
> +  gst_check_teardown_pad_by_name (tee, "src_1");
> +  gst_check_teardown_pad_by_name (tee, "src_2");
> +  gst_element_release_request_pad (tee, srcpad);
> +  gst_object_unref (srcpad);
> +  gst_object_unref (sinkpad);
> +  gst_check_teardown_element (tee);
> +}
> +
> +GST_END_TEST;
> +
> +
> +GST_START_TEST (test_allocation_query_allow_not_linked)
> +{
> +  GstElement *tee;
> +  GstPad *sinkpad;
> +  GstCaps *caps;
> +  GstQuery *query;
> +
> +  tee = gst_check_setup_element ("tee");
> +  fail_unless (tee);
> +  g_object_set (tee, "allow-not-linked", TRUE, NULL);
> +
> +  sinkpad = gst_element_get_static_pad (tee, "sink");
> +  add_sink_pad_and_setup_query_func (tee, allocation_query1);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query2);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query3);
> +
> +  caps = gst_caps_new_empty_simple ("test/test");
>    query = gst_query_new_allocation (caps, TRUE);
>    fail_unless (gst_pad_query (sinkpad, query));
>  
> -  gst_pad_set_query_function (sink3, allocation_query_fail);
> +  gst_caps_unref (caps);
>    gst_query_unref (query);
> +  gst_check_teardown_pad_by_name (tee, "src_0");
> +  gst_check_teardown_pad_by_name (tee, "src_1");
> +  gst_check_teardown_pad_by_name (tee, "src_2");
> +  gst_object_unref (sinkpad);
> +  gst_check_teardown_element (tee);
> +}
> +
> +GST_END_TEST;
> +
> +
> +GST_START_TEST (test_allocation_query_failure)
> +{
> +  GstElement *tee;
> +  GstPad *sinkpad;
> +  GstCaps *caps;
> +  GstQuery *query;
> +
> +  tee = gst_check_setup_element ("tee");
> +  fail_unless (tee);
> +  g_object_set (tee, "allow-not-linked", TRUE, NULL);
> +
> +  sinkpad = gst_element_get_static_pad (tee, "sink");
> +  add_sink_pad_and_setup_query_func (tee, allocation_query1);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query2);
> +  add_sink_pad_and_setup_query_func (tee, allocation_query_fail);
> +
> +  caps = gst_caps_new_empty_simple ("test/test");
>    query = gst_query_new_allocation (caps, TRUE);
>    fail_if (gst_pad_query (sinkpad, query));
>  
> @@ -836,8 +892,6 @@ GST_START_TEST (test_allocation_query)
>    gst_check_teardown_pad_by_name (tee, "src_0");
>    gst_check_teardown_pad_by_name (tee, "src_1");
>    gst_check_teardown_pad_by_name (tee, "src_2");
> -  gst_element_release_request_pad (tee, srcpad);
> -  gst_object_unref (srcpad);
>    gst_object_unref (sinkpad);
>    gst_check_teardown_element (tee);
>  }
> @@ -862,7 +916,9 @@ tee_suite (void)
>    tcase_add_test (tc_chain, test_flow_aggregation);
>    tcase_add_test (tc_chain, test_request_pads);
>    tcase_add_test (tc_chain, test_allow_not_linked);
> -  tcase_add_test (tc_chain, test_allocation_query);
> +  tcase_add_test (tc_chain, test_allocation_query_aggregation);
> +  tcase_add_test (tc_chain, test_allocation_query_allow_not_linked);
> +  tcase_add_test (tc_chain, test_allocation_query_failure);
>  
>    return s;
>  }
>
> _______________________________________________
> gstreamer-commits mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-commits
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: gstreamer: tee: split the allocation query test

Stefan Sauer
On 10/02/2017 07:16 PM, Nicolas Dufresne wrote:
Le lundi 02 octobre 2017 à 14:41 +0000, Stefan Kost a écrit :
Module: gstreamer
Branch: master
Commit: e364d7944ecbab86dea73c0ee3e639e766938d36
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=e3
64d7944ecbab86dea73c0ee3e639e766938d36

Author: Stefan Sauer [hidden email]
Date:   Mon Oct  2 16:25:00 2017 +0200

tee: split the allocation query test

Split the large allocation_query test into seperate tests. Add a
setup helper
to reduce code duplication. Fix the original test that used
fail_unless instead
of ck_assert_int_eq and had it accidentially working.

---

 tests/check/elements/tee.c | 110 ++++++++++++++++++++++++++++++++++-
----------
 1 file changed, 83 insertions(+), 27 deletions(-)

diff --git a/tests/check/elements/tee.c b/tests/check/elements/tee.c
index de63c1fd1..3d4e7d6e7 100644
--- a/tests/check/elements/tee.c
+++ b/tests/check/elements/tee.c
@@ -762,44 +762,43 @@ allocation_query_fail (GstPad * pad, GstObject
* parent, GstQuery * query)
   return FALSE;
 }
 
-GST_START_TEST (test_allocation_query)
+static void
+add_sink_pad_and_setup_query_func (GstElement * tee,
+    GstPadQueryFunction query_func)
+{
+  GstPad *sink;
+  static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE
("sink",
+      GST_PAD_SINK,
+      GST_PAD_ALWAYS,
+      GST_STATIC_CAPS_ANY);
+
+  sink = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
"src_%u");
+  fail_unless (sink != NULL);
+  gst_pad_set_query_function (sink, query_func);
+}
+
+GST_START_TEST (test_allocation_query_aggregation)
 {
   GstElement *tee;
-  GstPad *sink1, *sink2, *sink3;
   GstPad *sinkpad, *srcpad;
   GstCaps *caps;
   GstQuery *query;
   guint size, min, max;
   GstAllocationParams param;
 
-  static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE
("sink",
-      GST_PAD_SINK,
-      GST_PAD_ALWAYS,
-      GST_STATIC_CAPS_ANY);
-
-  caps = gst_caps_new_empty_simple ("test/test");
-
   tee = gst_check_setup_element ("tee");
   fail_unless (tee);
 
   sinkpad = gst_element_get_static_pad (tee, "sink");
+  add_sink_pad_and_setup_query_func (tee, allocation_query1);
+  add_sink_pad_and_setup_query_func (tee, allocation_query2);
+  add_sink_pad_and_setup_query_func (tee, allocation_query3);
 
-  sink1 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
"src_%u");
-  fail_unless (sink1 != NULL);
-  gst_pad_set_query_function (sink1, allocation_query1);
-
-  sink2 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
"src_%u");
-  fail_unless (sink2 != NULL);
-  gst_pad_set_query_function (sink2, allocation_query2);
-
-  sink3 = gst_check_setup_sink_pad_by_name (tee, &sinktemplate,
"src_%u");
-  fail_unless (sink3 != NULL);
-  gst_pad_set_query_function (sink3, allocation_query3);
-
+  caps = gst_caps_new_empty_simple ("test/test");
   query = gst_query_new_allocation (caps, TRUE);
   fail_unless (gst_pad_query (sinkpad, query));
 
-  fail_unless (gst_query_get_n_allocation_pools (query), 1);
+  ck_assert_int_eq (gst_query_get_n_allocation_pools (query), 1);
   gst_query_parse_nth_allocation_pool (query, 0, NULL, &size, &min,
&max);
   fail_unless (size == 130);
   /* The tee will allocate one more buffer when multiplexing */
@@ -816,18 +815,75 @@ GST_START_TEST (test_allocation_query)
   fail_unless (gst_query_parse_nth_allocation_meta (query, 0, NULL)
==
       GST_PARENT_BUFFER_META_API_TYPE);
 
+  /* TODO: what is this testing? move to a new test? */
That is testing the case were you have unlinked pads in your tee and
"allow-not-linked" is not set. In this case, query should fail. The
next one is testing the same, but when "allow-not-linked" is set.

Thanks for explaining. I think this is a great example for why we should split tests. If the tests only tests one thing it would be easy to give it an appropriate name.

Stefan


   srcpad = gst_element_get_request_pad (tee, "src_%u");
   gst_query_unref (query);
   query = gst_query_new_allocation (caps, TRUE);
   fail_if (gst_pad_query (sinkpad, query));
 
-  g_object_set (tee, "allow-not-linked", TRUE, NULL);
+  gst_caps_unref (caps);
   gst_query_unref (query);
+  gst_check_teardown_pad_by_name (tee, "src_0");
+  gst_check_teardown_pad_by_name (tee, "src_1");
+  gst_check_teardown_pad_by_name (tee, "src_2");
+  gst_element_release_request_pad (tee, srcpad);
+  gst_object_unref (srcpad);
+  gst_object_unref (sinkpad);
+  gst_check_teardown_element (tee);
+}
+
+GST_END_TEST;
+
+
+GST_START_TEST (test_allocation_query_allow_not_linked)
+{
+  GstElement *tee;
+  GstPad *sinkpad;
+  GstCaps *caps;
+  GstQuery *query;
+
+  tee = gst_check_setup_element ("tee");
+  fail_unless (tee);
+  g_object_set (tee, "allow-not-linked", TRUE, NULL);
+
+  sinkpad = gst_element_get_static_pad (tee, "sink");
+  add_sink_pad_and_setup_query_func (tee, allocation_query1);
+  add_sink_pad_and_setup_query_func (tee, allocation_query2);
+  add_sink_pad_and_setup_query_func (tee, allocation_query3);
+
+  caps = gst_caps_new_empty_simple ("test/test");
   query = gst_query_new_allocation (caps, TRUE);
   fail_unless (gst_pad_query (sinkpad, query));
 
-  gst_pad_set_query_function (sink3, allocation_query_fail);
+  gst_caps_unref (caps);
   gst_query_unref (query);
+  gst_check_teardown_pad_by_name (tee, "src_0");
+  gst_check_teardown_pad_by_name (tee, "src_1");
+  gst_check_teardown_pad_by_name (tee, "src_2");
+  gst_object_unref (sinkpad);
+  gst_check_teardown_element (tee);
+}
+
+GST_END_TEST;
+
+
+GST_START_TEST (test_allocation_query_failure)
+{
+  GstElement *tee;
+  GstPad *sinkpad;
+  GstCaps *caps;
+  GstQuery *query;
+
+  tee = gst_check_setup_element ("tee");
+  fail_unless (tee);
+  g_object_set (tee, "allow-not-linked", TRUE, NULL);
+
+  sinkpad = gst_element_get_static_pad (tee, "sink");
+  add_sink_pad_and_setup_query_func (tee, allocation_query1);
+  add_sink_pad_and_setup_query_func (tee, allocation_query2);
+  add_sink_pad_and_setup_query_func (tee, allocation_query_fail);
+
+  caps = gst_caps_new_empty_simple ("test/test");
   query = gst_query_new_allocation (caps, TRUE);
   fail_if (gst_pad_query (sinkpad, query));
 
@@ -836,8 +892,6 @@ GST_START_TEST (test_allocation_query)
   gst_check_teardown_pad_by_name (tee, "src_0");
   gst_check_teardown_pad_by_name (tee, "src_1");
   gst_check_teardown_pad_by_name (tee, "src_2");
-  gst_element_release_request_pad (tee, srcpad);
-  gst_object_unref (srcpad);
   gst_object_unref (sinkpad);
   gst_check_teardown_element (tee);
 }
@@ -862,7 +916,9 @@ tee_suite (void)
   tcase_add_test (tc_chain, test_flow_aggregation);
   tcase_add_test (tc_chain, test_request_pads);
   tcase_add_test (tc_chain, test_allow_not_linked);
-  tcase_add_test (tc_chain, test_allocation_query);
+  tcase_add_test (tc_chain, test_allocation_query_aggregation);
+  tcase_add_test (tc_chain, test_allocation_query_allow_not_linked);
+  tcase_add_test (tc_chain, test_allocation_query_failure);
 
   return s;
 }

_______________________________________________
gstreamer-commits mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-commits


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel