From dcfa47407819f5b2c66b6a62934957898447c6be Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sat, 20 Aug 2005 12:39:05 +0000 Subject: [PATCH] valgrind more tests Original commit message from CVS: valgrind more tests --- ChangeLog | 10 +++++++ check/Makefile.am | 8 +----- check/gst/gstiterator.c | 49 +++++++++++++++++++++----------- check/gst/gstsystemclock.c | 33 +++++++++++---------- check/gst/gsttag.c | 8 ++++++ gst/gstclock.c | 2 +- gst/gstiterator.c | 10 +++---- tests/check/Makefile.am | 8 +----- tests/check/gst/gstiterator.c | 49 +++++++++++++++++++++----------- tests/check/gst/gstsystemclock.c | 33 +++++++++++---------- tests/check/gst/gsttag.c | 8 ++++++ 11 files changed, 130 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index bdf99aa9f6..99e4c750f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-08-20 Thomas Vander Stichele + + * check/Makefile.am: + * check/gst/gstiterator.c: (GST_START_TEST): + * check/gst/gstsystemclock.c: (GST_START_TEST), + (gst_systemclock_suite): + * check/gst/gsttag.c: (GST_START_TEST), (gst_tag_suite): + * gst/gstclock.c: + valgrind more tests + 2005-08-20 Thomas Vander Stichele * check/elements/.cvsignore: diff --git a/check/Makefile.am b/check/Makefile.am index 982a21bed0..9786e7316f 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -75,14 +75,8 @@ gst_libs_controller_LDADD = $(GST_OBJ_LIBS) \ $(top_builddir)/libs/gst/controller/libgstcontroller-@GST_MAJORMINOR@.la # valgrind testing - -# these just need fixing, period +# these just need valgrind fixing, period TESTS_TO_FIX = \ - gst/gstghostpad \ - gst/gstiterator \ - gst/gstmessage \ - gst/gstsystemclock \ - gst/gsttag \ pipelines/cleanup \ pipelines/simple_launch_lines diff --git a/check/gst/gstiterator.c b/check/gst/gstiterator.c index ab640040c9..9357eb739d 100644 --- a/check/gst/gstiterator.c +++ b/check/gst/gstiterator.c @@ -52,25 +52,28 @@ GST_START_TEST (test_manual_iteration) iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); while (1) { res = gst_iterator_next (iter, &item); if (i < NUM_ELEMENTS) { - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == i); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == i); i++; continue; } else { - g_return_if_fail (res == GST_ITERATOR_DONE); + fail_unless (res == GST_ITERATOR_DONE); break; } } + /* clean up */ gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST +GST_END_TEST; + GST_START_TEST (test_resync) { GList *l; @@ -87,35 +90,40 @@ GST_START_TEST (test_resync) iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); while (1) { res = gst_iterator_next (iter, &item); if (i < NUM_ELEMENTS / 2) { - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == i); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == i); i++; continue; } else if (!hacked_list) { /* here's where we test resync */ - g_return_if_fail (res == GST_ITERATOR_OK); + fail_unless (res == GST_ITERATOR_OK); l = g_list_prepend (l, GINT_TO_POINTER (-1)); cookie++; hacked_list = TRUE; continue; } else { - g_return_if_fail (res == GST_ITERATOR_RESYNC); + fail_unless (res == GST_ITERATOR_RESYNC); gst_iterator_resync (iter); res = gst_iterator_next (iter, &item); - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == -1); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == -1); break; } } + /* clean up */ gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST static gboolean + +GST_END_TEST; + +static gboolean add_fold_func (gpointer item, GValue * ret, gpointer user_data) { g_value_set_int (ret, g_value_get_int (ret) + GPOINTER_TO_INT (item)); @@ -135,7 +143,7 @@ GST_START_TEST (test_fold) l = make_list_of_ints (NUM_ELEMENTS); m = g_mutex_new (); iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); expected = 0; for (i = 0; i < NUM_ELEMENTS; i++) @@ -146,10 +154,17 @@ GST_START_TEST (test_fold) res = gst_iterator_fold (iter, add_fold_func, &ret, NULL); - g_return_if_fail (res == GST_ITERATOR_DONE); - g_return_if_fail (g_value_get_int (&ret) == expected); + fail_unless (res == GST_ITERATOR_DONE); + fail_unless (g_value_get_int (&ret) == expected); + + /* clean up */ + gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST Suite * + +GST_END_TEST; + +Suite * gstiterator_suite (void) { Suite *s = suite_create ("GstIterator"); diff --git a/check/gst/gstsystemclock.c b/check/gst/gstsystemclock.c index f9a6a35136..14baaf0a14 100644 --- a/check/gst/gstsystemclock.c +++ b/check/gst/gstsystemclock.c @@ -37,7 +37,7 @@ GST_START_TEST (test_signedness) } GST_END_TEST -#define TIME_UNIT GST_SECOND +#define TIME_UNIT (GST_SECOND / 5) static void gst_clock_debug (GstClock * clock) { @@ -97,14 +97,14 @@ GST_START_TEST (test_single_shot) result = gst_clock_id_wait_async (id, ok_callback, NULL); gst_clock_id_unref (id); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT); g_message ("waiting one second async, with cancel on id %p\n", id); result = gst_clock_id_wait_async (id, error_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (G_USEC_PER_SEC / 2); - g_message ("cancel id %p after 0.5 seconds\n", id); + g_usleep (TIME_UNIT / (2 * 1000)); + g_message ("cancel id %p after half a time unit\n", id); gst_clock_id_unschedule (id); gst_clock_id_unref (id); g_message ("canceled id %p\n", id); @@ -119,13 +119,12 @@ GST_START_TEST (test_single_shot) g_message ("waiting id %p\n", id2); result = gst_clock_id_wait_async (id2, error_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (G_USEC_PER_SEC / 2); - g_message ("cancel id %p after 0.5 seconds\n", id2); + g_usleep (TIME_UNIT / (2 * 1000)); + g_message ("cancel id %p after half a time unit\n", id2); gst_clock_id_unschedule (id2); g_message ("canceled id %p\n", id2); gst_clock_id_unref (id2); - - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); } GST_END_TEST @@ -142,11 +141,11 @@ GST_START_TEST (test_periodic_shot) gst_clock_debug (clock); base = gst_clock_get_time (clock); - /* signal every half a second */ + /* signal every half a time unit */ id = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2); fail_unless (id != NULL, "Could not create periodic id"); - g_message ("waiting one second\n"); + g_message ("waiting one time unit\n"); result = gst_clock_id_wait (id, NULL); gst_clock_debug (clock); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); @@ -159,12 +158,12 @@ GST_START_TEST (test_periodic_shot) g_message ("waiting for the next async %p\n", id); result = gst_clock_id_wait_async (id, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); g_message ("waiting some more for the next async %p\n", id); result = gst_clock_id_wait_async (id, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); id2 = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2); fail_unless (id2 != NULL, "Could not create second periodic id"); @@ -172,7 +171,7 @@ GST_START_TEST (test_periodic_shot) g_message ("waiting some more for another async %p\n", id2); result = gst_clock_id_wait_async (id2, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); g_message ("unschedule %p\n", id); gst_clock_id_unschedule (id); @@ -184,7 +183,10 @@ GST_START_TEST (test_periodic_shot) result = gst_clock_id_wait (id, NULL); fail_unless (result == GST_CLOCK_UNSCHEDULED, "Waiting did not return UNSCHEDULED"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); + + /* clean up */ + gst_clock_id_unref (id); } GST_END_TEST Suite * gst_systemclock_suite (void) @@ -192,9 +194,6 @@ GST_END_TEST Suite * gst_systemclock_suite (void) Suite *s = suite_create ("GstSystemClock"); TCase *tc_chain = tcase_create ("waiting"); - /* increase timeout */ - tcase_set_timeout (tc_chain, 20); - suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_signedness); tcase_add_test (tc_chain, test_single_shot); diff --git a/check/gst/gsttag.c b/check/gst/gsttag.c index a91315db90..2e64fe8bc4 100644 --- a/check/gst/gsttag.c +++ b/check/gst/gsttag.c @@ -171,6 +171,14 @@ GST_START_TEST (test_merge) check_tags (merge, FTAG, FIXED1, NULL); NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP_ALL); check_tags (merge, FTAG, FIXED1, NULL); + + /* clean up */ + if (list) + gst_tag_list_free (list); + if (list2) + gst_tag_list_free (list2); + if (merge) + gst_tag_list_free (merge); } GST_END_TEST Suite * diff --git a/gst/gstclock.c b/gst/gstclock.c index f9322c8e70..ea046984c6 100644 --- a/gst/gstclock.c +++ b/gst/gstclock.c @@ -148,7 +148,7 @@ gst_clock_id_unref (GstClockID id) * @clock: The clockid to get a single shot notification from * @time: the requested time * - * Get an ID from the given clock to trigger a single shot + * Get an ID from the given clock to trigger a single shot * notification at the requested time. The single shot id should be * unreffed after usage. * diff --git a/gst/gstiterator.c b/gst/gstiterator.c index a4d4d61135..19fdf33bf4 100644 --- a/gst/gstiterator.c +++ b/gst/gstiterator.c @@ -55,7 +55,7 @@ gst_iterator_init (GstIterator * it, * * For each item retrieved, the @item function is called with the lock * held. The @free function is called when the iterator is freed. - * + * * Returns: the new #GstIterator. * * MT safe. @@ -130,8 +130,8 @@ gst_list_iterator_free (GstListIterator * it) * @item: function to call for each item * @free: function to call when the iterator is freed * - * Create a new iterator designed for iterating @list. - * + * Create a new iterator designed for iterating @list. + * * Returns: the new #GstIterator for @list. * * MT safe. @@ -263,8 +263,8 @@ gst_iterator_resync (GstIterator * it) * gst_iterator_free: * @it: The #GstIterator to free * - * Free the iterator. - * + * Free the iterator. + * * MT safe. */ void diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 982a21bed0..9786e7316f 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -75,14 +75,8 @@ gst_libs_controller_LDADD = $(GST_OBJ_LIBS) \ $(top_builddir)/libs/gst/controller/libgstcontroller-@GST_MAJORMINOR@.la # valgrind testing - -# these just need fixing, period +# these just need valgrind fixing, period TESTS_TO_FIX = \ - gst/gstghostpad \ - gst/gstiterator \ - gst/gstmessage \ - gst/gstsystemclock \ - gst/gsttag \ pipelines/cleanup \ pipelines/simple_launch_lines diff --git a/tests/check/gst/gstiterator.c b/tests/check/gst/gstiterator.c index ab640040c9..9357eb739d 100644 --- a/tests/check/gst/gstiterator.c +++ b/tests/check/gst/gstiterator.c @@ -52,25 +52,28 @@ GST_START_TEST (test_manual_iteration) iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); while (1) { res = gst_iterator_next (iter, &item); if (i < NUM_ELEMENTS) { - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == i); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == i); i++; continue; } else { - g_return_if_fail (res == GST_ITERATOR_DONE); + fail_unless (res == GST_ITERATOR_DONE); break; } } + /* clean up */ gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST +GST_END_TEST; + GST_START_TEST (test_resync) { GList *l; @@ -87,35 +90,40 @@ GST_START_TEST (test_resync) iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); while (1) { res = gst_iterator_next (iter, &item); if (i < NUM_ELEMENTS / 2) { - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == i); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == i); i++; continue; } else if (!hacked_list) { /* here's where we test resync */ - g_return_if_fail (res == GST_ITERATOR_OK); + fail_unless (res == GST_ITERATOR_OK); l = g_list_prepend (l, GINT_TO_POINTER (-1)); cookie++; hacked_list = TRUE; continue; } else { - g_return_if_fail (res == GST_ITERATOR_RESYNC); + fail_unless (res == GST_ITERATOR_RESYNC); gst_iterator_resync (iter); res = gst_iterator_next (iter, &item); - g_return_if_fail (res == GST_ITERATOR_OK); - g_return_if_fail (GPOINTER_TO_INT (item) == -1); + fail_unless (res == GST_ITERATOR_OK); + fail_unless (GPOINTER_TO_INT (item) == -1); break; } } + /* clean up */ gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST static gboolean + +GST_END_TEST; + +static gboolean add_fold_func (gpointer item, GValue * ret, gpointer user_data) { g_value_set_int (ret, g_value_get_int (ret) + GPOINTER_TO_INT (item)); @@ -135,7 +143,7 @@ GST_START_TEST (test_fold) l = make_list_of_ints (NUM_ELEMENTS); m = g_mutex_new (); iter = gst_iterator_new_list (m, &cookie, &l, NULL, NULL, NULL); - g_return_if_fail (iter != NULL); + fail_unless (iter != NULL); expected = 0; for (i = 0; i < NUM_ELEMENTS; i++) @@ -146,10 +154,17 @@ GST_START_TEST (test_fold) res = gst_iterator_fold (iter, add_fold_func, &ret, NULL); - g_return_if_fail (res == GST_ITERATOR_DONE); - g_return_if_fail (g_value_get_int (&ret) == expected); + fail_unless (res == GST_ITERATOR_DONE); + fail_unless (g_value_get_int (&ret) == expected); + + /* clean up */ + gst_iterator_free (iter); + g_mutex_free (m); } -GST_END_TEST Suite * + +GST_END_TEST; + +Suite * gstiterator_suite (void) { Suite *s = suite_create ("GstIterator"); diff --git a/tests/check/gst/gstsystemclock.c b/tests/check/gst/gstsystemclock.c index f9a6a35136..14baaf0a14 100644 --- a/tests/check/gst/gstsystemclock.c +++ b/tests/check/gst/gstsystemclock.c @@ -37,7 +37,7 @@ GST_START_TEST (test_signedness) } GST_END_TEST -#define TIME_UNIT GST_SECOND +#define TIME_UNIT (GST_SECOND / 5) static void gst_clock_debug (GstClock * clock) { @@ -97,14 +97,14 @@ GST_START_TEST (test_single_shot) result = gst_clock_id_wait_async (id, ok_callback, NULL); gst_clock_id_unref (id); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); id = gst_clock_new_single_shot_id (clock, base + 5 * TIME_UNIT); g_message ("waiting one second async, with cancel on id %p\n", id); result = gst_clock_id_wait_async (id, error_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (G_USEC_PER_SEC / 2); - g_message ("cancel id %p after 0.5 seconds\n", id); + g_usleep (TIME_UNIT / (2 * 1000)); + g_message ("cancel id %p after half a time unit\n", id); gst_clock_id_unschedule (id); gst_clock_id_unref (id); g_message ("canceled id %p\n", id); @@ -119,13 +119,12 @@ GST_START_TEST (test_single_shot) g_message ("waiting id %p\n", id2); result = gst_clock_id_wait_async (id2, error_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (G_USEC_PER_SEC / 2); - g_message ("cancel id %p after 0.5 seconds\n", id2); + g_usleep (TIME_UNIT / (2 * 1000)); + g_message ("cancel id %p after half a time unit\n", id2); gst_clock_id_unschedule (id2); g_message ("canceled id %p\n", id2); gst_clock_id_unref (id2); - - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); } GST_END_TEST @@ -142,11 +141,11 @@ GST_START_TEST (test_periodic_shot) gst_clock_debug (clock); base = gst_clock_get_time (clock); - /* signal every half a second */ + /* signal every half a time unit */ id = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2); fail_unless (id != NULL, "Could not create periodic id"); - g_message ("waiting one second\n"); + g_message ("waiting one time unit\n"); result = gst_clock_id_wait (id, NULL); gst_clock_debug (clock); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); @@ -159,12 +158,12 @@ GST_START_TEST (test_periodic_shot) g_message ("waiting for the next async %p\n", id); result = gst_clock_id_wait_async (id, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); g_message ("waiting some more for the next async %p\n", id); result = gst_clock_id_wait_async (id, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); id2 = gst_clock_new_periodic_id (clock, base + TIME_UNIT, TIME_UNIT / 2); fail_unless (id2 != NULL, "Could not create second periodic id"); @@ -172,7 +171,7 @@ GST_START_TEST (test_periodic_shot) g_message ("waiting some more for another async %p\n", id2); result = gst_clock_id_wait_async (id2, ok_callback, NULL); fail_unless (result == GST_CLOCK_OK, "Waiting did not return OK"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); g_message ("unschedule %p\n", id); gst_clock_id_unschedule (id); @@ -184,7 +183,10 @@ GST_START_TEST (test_periodic_shot) result = gst_clock_id_wait (id, NULL); fail_unless (result == GST_CLOCK_UNSCHEDULED, "Waiting did not return UNSCHEDULED"); - g_usleep (2 * G_USEC_PER_SEC); + g_usleep (TIME_UNIT / (2 * 1000)); + + /* clean up */ + gst_clock_id_unref (id); } GST_END_TEST Suite * gst_systemclock_suite (void) @@ -192,9 +194,6 @@ GST_END_TEST Suite * gst_systemclock_suite (void) Suite *s = suite_create ("GstSystemClock"); TCase *tc_chain = tcase_create ("waiting"); - /* increase timeout */ - tcase_set_timeout (tc_chain, 20); - suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_signedness); tcase_add_test (tc_chain, test_single_shot); diff --git a/tests/check/gst/gsttag.c b/tests/check/gst/gsttag.c index a91315db90..2e64fe8bc4 100644 --- a/tests/check/gst/gsttag.c +++ b/tests/check/gst/gsttag.c @@ -171,6 +171,14 @@ GST_START_TEST (test_merge) check_tags (merge, FTAG, FIXED1, NULL); NEW_LISTS_FIXED (GST_TAG_MERGE_KEEP_ALL); check_tags (merge, FTAG, FIXED1, NULL); + + /* clean up */ + if (list) + gst_tag_list_free (list); + if (list2) + gst_tag_list_free (list2); + if (merge) + gst_tag_list_free (merge); } GST_END_TEST Suite *