More refcounting test cases

Original commit message from CVS:
More refcounting test cases
This commit is contained in:
Wim Taymans 2001-05-12 18:03:52 +00:00
parent 1041fcea08
commit 12cfd1842c
6 changed files with 366 additions and 2 deletions

View file

@ -1,11 +1,12 @@
SUBDIRS =
testprogs = object element pad element_pad
testprogs = object element pad element_pad bin
object_SOURCES = object.c mem.c
element_SOURCES = element.c mem.c
pad_SOURCES = pad.c mem.c
element_pad_SOURCES = element_pad.c mem.c
bin_SOURCES = bin.c mem.c
TESTS = $(testprogs)

View file

@ -0,0 +1,139 @@
#include <gst/gst.h>
#define ITERS 100000
#include <stdlib.h>
#include "mem.h"
static GstElement*
create_bin (void)
{
GstElement *bin;
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
gst_element_set_name (element, "test1");
gst_bin_add (GST_BIN (bin), element);
element = gst_element_new ();
gst_element_set_name (element, "test2");
gst_bin_add (GST_BIN (bin), element);
return bin;
}
int
main (int argc, gchar *argv[])
{
GstElement *bin;
long usage1;
gint i, iters;
gst_init (&argc, &argv);
if (argc == 2)
iters = atoi (argv[1]);
else
iters = ITERS;
g_print ("starting test\n");
usage1 = vmsize();
bin = gst_bin_new ("somebin");
gst_object_unref (GST_OBJECT (bin));
g_print ("create/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/unref %d bins %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
g_assert (GST_OBJECT_FLOATING (bin));
gst_object_ref (GST_OBJECT (bin));
gst_object_sink (GST_OBJECT (bin));
g_assert (!GST_OBJECT_FLOATING (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/ref/sink/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_sink (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/ref/sink/unref %d bins %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
g_assert (!GST_OBJECT_DESTROYED (bin));
gst_object_destroy (GST_OBJECT (bin));
g_assert (GST_OBJECT_DESTROYED (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/destroy/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/destroy/unref %d bin %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/ref/unref/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/ref/unref/unref %d bin %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("craete/ref/destroy/unref/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("craete/ref/destroy/unref/unref %d bins %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_element_set_name (bin, "testing123");
gst_object_destroy (GST_OBJECT (bin));
gst_element_set_name (bin, "testing123");
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("craete/ref/destroy/unref/unref %d bins with name %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
for (i=0; i<iters;i++) {
gst_element_set_name (bin, "testing");
}
gst_object_unref (GST_OBJECT (bin));
g_print ("set name %d times %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = create_bin();
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/unref %d bin with children %ld\n", iters, vmsize()-usage1);
g_print ("leaked: %ld\n", vmsize()-usage1);
return (vmsize()-usage1 ? -1 : 0);
}

View file

@ -63,6 +63,48 @@ main (int argc, gchar *argv[])
}
g_print ("create/connect/unref %d elements %ld\n", iters, vmsize()-usage1);
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_element_remove_pad (element, pad);
g_assert (gst_element_get_pad (element, "sink") == NULL);
g_print ("pad removal ok %ld\n", vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_element_remove_pad (element, pad);
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad removal loop %d %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_ref (GST_OBJECT (pad));
gst_element_remove_pad (element, pad);
g_assert (gst_pad_get_parent (pad) == NULL);
gst_object_unref (GST_OBJECT (pad));
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad removal and test loop %d %ld\n", iters, vmsize()-usage1);
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_destroy (GST_OBJECT (element));
g_assert (GST_OBJECT_DESTROYED (element));
g_assert (gst_element_get_pad (element, "sink") == NULL);
gst_object_unref (GST_OBJECT (element));
g_print ("pad destroy/removal ok %ld\n", vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_destroy (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad destroy/removal loop %d %ld\n", iters, vmsize()-usage1);
g_print ("leaked: %ld\n", vmsize()-usage1);
return (vmsize()-usage1 ? -1 : 0);

View file

@ -1,11 +1,12 @@
SUBDIRS =
testprogs = object element pad element_pad
testprogs = object element pad element_pad bin
object_SOURCES = object.c mem.c
element_SOURCES = element.c mem.c
pad_SOURCES = pad.c mem.c
element_pad_SOURCES = element_pad.c mem.c
bin_SOURCES = bin.c mem.c
TESTS = $(testprogs)

139
testsuite/refcounting/bin.c Normal file
View file

@ -0,0 +1,139 @@
#include <gst/gst.h>
#define ITERS 100000
#include <stdlib.h>
#include "mem.h"
static GstElement*
create_bin (void)
{
GstElement *bin;
GstElement *element;
bin = gst_bin_new ("testbin");
element = gst_element_new ();
gst_element_set_name (element, "test1");
gst_bin_add (GST_BIN (bin), element);
element = gst_element_new ();
gst_element_set_name (element, "test2");
gst_bin_add (GST_BIN (bin), element);
return bin;
}
int
main (int argc, gchar *argv[])
{
GstElement *bin;
long usage1;
gint i, iters;
gst_init (&argc, &argv);
if (argc == 2)
iters = atoi (argv[1]);
else
iters = ITERS;
g_print ("starting test\n");
usage1 = vmsize();
bin = gst_bin_new ("somebin");
gst_object_unref (GST_OBJECT (bin));
g_print ("create/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/unref %d bins %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
g_assert (GST_OBJECT_FLOATING (bin));
gst_object_ref (GST_OBJECT (bin));
gst_object_sink (GST_OBJECT (bin));
g_assert (!GST_OBJECT_FLOATING (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/ref/sink/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_sink (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/ref/sink/unref %d bins %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
g_assert (!GST_OBJECT_DESTROYED (bin));
gst_object_destroy (GST_OBJECT (bin));
g_assert (GST_OBJECT_DESTROYED (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/destroy/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/destroy/unref %d bin %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("create/ref/unref/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/ref/unref/unref %d bin %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
g_print ("craete/ref/destroy/unref/unref new bin %ld\n", vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_object_destroy (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("craete/ref/destroy/unref/unref %d bins %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = gst_bin_new ("somebin");
gst_object_ref (GST_OBJECT (bin));
gst_element_set_name (bin, "testing123");
gst_object_destroy (GST_OBJECT (bin));
gst_element_set_name (bin, "testing123");
gst_object_unref (GST_OBJECT (bin));
gst_object_unref (GST_OBJECT (bin));
}
g_print ("craete/ref/destroy/unref/unref %d bins with name %ld\n", iters, vmsize()-usage1);
bin = gst_bin_new ("somebin");
for (i=0; i<iters;i++) {
gst_element_set_name (bin, "testing");
}
gst_object_unref (GST_OBJECT (bin));
g_print ("set name %d times %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters;i++) {
bin = create_bin();
gst_object_unref (GST_OBJECT (bin));
}
g_print ("create/unref %d bin with children %ld\n", iters, vmsize()-usage1);
g_print ("leaked: %ld\n", vmsize()-usage1);
return (vmsize()-usage1 ? -1 : 0);
}

View file

@ -63,6 +63,48 @@ main (int argc, gchar *argv[])
}
g_print ("create/connect/unref %d elements %ld\n", iters, vmsize()-usage1);
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_element_remove_pad (element, pad);
g_assert (gst_element_get_pad (element, "sink") == NULL);
g_print ("pad removal ok %ld\n", vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_element_remove_pad (element, pad);
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad removal loop %d %ld\n", iters, vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_ref (GST_OBJECT (pad));
gst_element_remove_pad (element, pad);
g_assert (gst_pad_get_parent (pad) == NULL);
gst_object_unref (GST_OBJECT (pad));
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad removal and test loop %d %ld\n", iters, vmsize()-usage1);
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_destroy (GST_OBJECT (element));
g_assert (GST_OBJECT_DESTROYED (element));
g_assert (gst_element_get_pad (element, "sink") == NULL);
gst_object_unref (GST_OBJECT (element));
g_print ("pad destroy/removal ok %ld\n", vmsize()-usage1);
for (i=0; i<iters/2; i++) {
element = create_element ("sink", GST_PAD_SINK);
pad = gst_element_get_pad (element, "sink");
gst_object_destroy (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (element));
}
g_print ("pad destroy/removal loop %d %ld\n", iters, vmsize()-usage1);
g_print ("leaked: %ld\n", vmsize()-usage1);
return (vmsize()-usage1 ? -1 : 0);