[18713] | 1 | #include <gst/gst.h> |
---|
| 2 | |
---|
| 3 | #define ITERS 100000 |
---|
| 4 | #include <stdlib.h> |
---|
| 5 | #include "mem.h" |
---|
| 6 | |
---|
[21447] | 7 | GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
---|
| 8 | GST_PAD_SRC, |
---|
| 9 | GST_PAD_ALWAYS, |
---|
| 10 | GST_STATIC_CAPS_ANY); |
---|
| 11 | |
---|
| 12 | GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
---|
| 13 | GST_PAD_SINK, |
---|
| 14 | GST_PAD_ALWAYS, |
---|
| 15 | GST_STATIC_CAPS_ANY); |
---|
| 16 | |
---|
[21004] | 17 | static GstElement * |
---|
[18713] | 18 | create_thread (void) |
---|
| 19 | { |
---|
| 20 | GstElement *thread; |
---|
| 21 | GstElement *element; |
---|
| 22 | |
---|
| 23 | thread = gst_thread_new ("testthread"); |
---|
| 24 | element = gst_element_new (); |
---|
| 25 | gst_element_set_name (element, "test1"); |
---|
| 26 | gst_bin_add (GST_BIN (thread), element); |
---|
| 27 | element = gst_element_new (); |
---|
| 28 | gst_element_set_name (element, "test2"); |
---|
| 29 | gst_bin_add (GST_BIN (thread), element); |
---|
| 30 | |
---|
| 31 | return thread; |
---|
| 32 | } |
---|
| 33 | |
---|
[21004] | 34 | static GstElement * |
---|
[18713] | 35 | create_thread_ghostpads (void) |
---|
| 36 | { |
---|
| 37 | GstElement *thread; |
---|
| 38 | GstElement *element1, *element2; |
---|
| 39 | |
---|
| 40 | thread = gst_thread_new ("testthread"); |
---|
| 41 | element1 = gst_element_new (); |
---|
| 42 | gst_element_set_name (element1, "test1"); |
---|
[21447] | 43 | gst_element_add_pad (element1, |
---|
| 44 | gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate), |
---|
| 45 | "src1")); |
---|
[18713] | 46 | gst_bin_add (GST_BIN (thread), element1); |
---|
| 47 | element2 = gst_element_new (); |
---|
| 48 | gst_element_set_name (element2, "test2"); |
---|
[21447] | 49 | gst_element_add_pad (element1, |
---|
| 50 | gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate), |
---|
| 51 | "sink1")); |
---|
[18713] | 52 | gst_bin_add (GST_BIN (thread), element2); |
---|
| 53 | gst_element_link (element1, "src1", element2, "sink1"); |
---|
[21004] | 54 | gst_element_add_ghost_pad (thread, gst_element_get_pad (element2, "sink1"), |
---|
| 55 | "sink1"); |
---|
[18713] | 56 | |
---|
| 57 | return thread; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | static void |
---|
| 61 | add_remove_test1 (void) |
---|
| 62 | { |
---|
| 63 | GstElement *thread; |
---|
| 64 | GstElement *element; |
---|
| 65 | |
---|
| 66 | thread = gst_thread_new ("testthread"); |
---|
| 67 | element = gst_element_new (); |
---|
| 68 | gst_element_set_name (element, "test1"); |
---|
| 69 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
| 70 | gst_bin_add (GST_BIN (thread), element); |
---|
| 71 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
| 72 | gst_bin_remove (GST_BIN (thread), element); |
---|
| 73 | |
---|
| 74 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | static void |
---|
| 78 | add_remove_test2 (void) |
---|
| 79 | { |
---|
| 80 | GstElement *thread; |
---|
| 81 | GstElement *element; |
---|
| 82 | |
---|
| 83 | thread = gst_thread_new ("testthread"); |
---|
| 84 | element = gst_element_new (); |
---|
| 85 | gst_element_set_name (element, "test1"); |
---|
| 86 | gst_object_ref (GST_OBJECT (element)); |
---|
| 87 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
| 88 | gst_bin_add (GST_BIN (thread), element); |
---|
| 89 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
| 90 | gst_bin_remove (GST_BIN (thread), element); |
---|
| 91 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
| 92 | g_assert (!GST_OBJECT_DESTROYED (element)); |
---|
| 93 | |
---|
[21004] | 94 | gst_object_unref (GST_OBJECT (element)); |
---|
[18713] | 95 | g_assert (GST_OBJECT_DESTROYED (element)); |
---|
| 96 | gst_object_unref (GST_OBJECT (element)); |
---|
| 97 | |
---|
| 98 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | static void |
---|
| 102 | add_remove_test3 (void) |
---|
| 103 | { |
---|
| 104 | GstElement *thread; |
---|
| 105 | GstElement *element; |
---|
| 106 | |
---|
| 107 | thread = gst_thread_new ("testthread"); |
---|
| 108 | element = gst_element_new (); |
---|
| 109 | gst_element_set_name (element, "test1"); |
---|
| 110 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
| 111 | gst_bin_add (GST_BIN (thread), element); |
---|
| 112 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
| 113 | |
---|
[21004] | 114 | gst_object_unref (GST_OBJECT (element)); |
---|
[18713] | 115 | g_assert (gst_bin_get_by_name (GST_BIN (thread), "test1") == NULL); |
---|
| 116 | |
---|
| 117 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static void |
---|
| 121 | add_remove_test4 (void) |
---|
| 122 | { |
---|
| 123 | GstElement *thread, *thread2; |
---|
| 124 | GstElement *element; |
---|
| 125 | |
---|
| 126 | thread = gst_thread_new ("testthread"); |
---|
| 127 | element = gst_element_new (); |
---|
| 128 | gst_element_set_name (element, "test1"); |
---|
| 129 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
| 130 | gst_bin_add (GST_BIN (thread), element); |
---|
| 131 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
| 132 | |
---|
| 133 | thread2 = create_thread (); |
---|
| 134 | g_assert (GST_OBJECT_FLOATING (thread2)); |
---|
| 135 | gst_bin_add (GST_BIN (thread), thread2); |
---|
| 136 | g_assert (!GST_OBJECT_FLOATING (thread2)); |
---|
| 137 | |
---|
[21004] | 138 | gst_object_unref (GST_OBJECT (thread2)); |
---|
[18713] | 139 | g_assert (gst_bin_get_by_name (GST_BIN (thread), "testthread") == NULL); |
---|
[21004] | 140 | gst_object_unref (GST_OBJECT (element)); |
---|
[18713] | 141 | g_assert (gst_bin_get_by_name (GST_BIN (thread), "test1") == NULL); |
---|
| 142 | |
---|
| 143 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | int |
---|
[21004] | 147 | main (int argc, gchar * argv[]) |
---|
[18713] | 148 | { |
---|
| 149 | GstElement *thread, *element; |
---|
| 150 | long usage1; |
---|
| 151 | gint i, iters; |
---|
| 152 | |
---|
| 153 | gst_init (&argc, &argv); |
---|
| 154 | |
---|
| 155 | if (argc == 2) |
---|
| 156 | iters = atoi (argv[1]); |
---|
| 157 | else |
---|
| 158 | iters = ITERS; |
---|
| 159 | |
---|
| 160 | g_print ("starting test\n"); |
---|
[21004] | 161 | usage1 = vmsize (); |
---|
[18713] | 162 | |
---|
| 163 | thread = gst_thread_new ("somethread"); |
---|
| 164 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 165 | g_print ("create/unref new thread %ld\n", vmsize () - usage1); |
---|
[18713] | 166 | |
---|
[21004] | 167 | for (i = 0; i < iters; i++) { |
---|
[18713] | 168 | thread = gst_thread_new ("somethread"); |
---|
| 169 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 170 | } |
---|
[21004] | 171 | g_print ("create/unref %d threads %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 172 | |
---|
| 173 | thread = gst_thread_new ("somethread"); |
---|
| 174 | g_assert (GST_OBJECT_FLOATING (thread)); |
---|
| 175 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 176 | gst_object_sink (GST_OBJECT (thread)); |
---|
| 177 | g_assert (!GST_OBJECT_FLOATING (thread)); |
---|
| 178 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 179 | g_print ("create/ref/sink/unref new thread %ld\n", vmsize () - usage1); |
---|
[18713] | 180 | |
---|
| 181 | |
---|
[21004] | 182 | for (i = 0; i < iters; i++) { |
---|
[18713] | 183 | thread = gst_thread_new ("somethread"); |
---|
| 184 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 185 | gst_object_sink (GST_OBJECT (thread)); |
---|
| 186 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 187 | } |
---|
[21004] | 188 | g_print ("create/ref/sink/unref %d threads %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 189 | |
---|
| 190 | thread = gst_thread_new ("somethread"); |
---|
| 191 | g_assert (!GST_OBJECT_DESTROYED (thread)); |
---|
[21004] | 192 | gst_object_unref (GST_OBJECT (thread)); |
---|
[18713] | 193 | g_assert (GST_OBJECT_DESTROYED (thread)); |
---|
| 194 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 195 | g_print ("create/destroy/unref new thread %ld\n", vmsize () - usage1); |
---|
| 196 | |
---|
| 197 | for (i = 0; i < iters; i++) { |
---|
[18713] | 198 | thread = gst_thread_new ("somethread"); |
---|
| 199 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 200 | gst_object_unref (GST_OBJECT (thread)); |
---|
[18713] | 201 | } |
---|
[21004] | 202 | g_print ("create/destroy/unref %d thread %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 203 | |
---|
| 204 | thread = gst_thread_new ("somethread"); |
---|
| 205 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 206 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 207 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 208 | g_print ("create/ref/unref/unref new thread %ld\n", vmsize () - usage1); |
---|
| 209 | |
---|
| 210 | for (i = 0; i < iters; i++) { |
---|
[18713] | 211 | thread = gst_thread_new ("somethread"); |
---|
| 212 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 213 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 214 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 215 | } |
---|
[21004] | 216 | g_print ("create/ref/unref/unref %d thread %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 217 | |
---|
| 218 | thread = gst_thread_new ("somethread"); |
---|
| 219 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 220 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 221 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 222 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 223 | g_print ("craete/ref/destroy/unref/unref new thread %ld\n", |
---|
| 224 | vmsize () - usage1); |
---|
| 225 | |
---|
| 226 | for (i = 0; i < iters; i++) { |
---|
[18713] | 227 | thread = gst_thread_new ("somethread"); |
---|
| 228 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 229 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 230 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 231 | gst_object_unref (GST_OBJECT (thread)); |
---|
[18713] | 232 | } |
---|
[21004] | 233 | g_print ("craete/ref/destroy/unref/unref %d threads %ld\n", iters, |
---|
| 234 | vmsize () - usage1); |
---|
[18713] | 235 | |
---|
[21004] | 236 | for (i = 0; i < iters; i++) { |
---|
[18713] | 237 | thread = gst_thread_new ("somethread"); |
---|
| 238 | gst_object_ref (GST_OBJECT (thread)); |
---|
| 239 | gst_element_set_name (thread, "testing123"); |
---|
[21004] | 240 | gst_object_unref (GST_OBJECT (thread)); |
---|
[18713] | 241 | gst_element_set_name (thread, "testing123"); |
---|
| 242 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 243 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 244 | } |
---|
[21004] | 245 | g_print ("craete/ref/destroy/unref/unref %d threads with name %ld\n", iters, |
---|
| 246 | vmsize () - usage1); |
---|
[18713] | 247 | |
---|
| 248 | thread = gst_thread_new ("somethread"); |
---|
[21004] | 249 | for (i = 0; i < iters; i++) { |
---|
[18713] | 250 | gst_element_set_name (thread, "testing"); |
---|
| 251 | } |
---|
| 252 | gst_object_unref (GST_OBJECT (thread)); |
---|
[21004] | 253 | g_print ("set name %d times %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 254 | |
---|
[21004] | 255 | for (i = 0; i < iters; i++) { |
---|
[18713] | 256 | thread = gst_thread_new ("somethread"); |
---|
| 257 | element = gst_element_new (); |
---|
| 258 | gst_element_set_name (element, "test1"); |
---|
| 259 | gst_bin_add (GST_BIN (thread), element); |
---|
| 260 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 261 | } |
---|
[21004] | 262 | g_print ("create/unref %d thread with one element %ld\n", iters, |
---|
| 263 | vmsize () - usage1); |
---|
[18713] | 264 | |
---|
[21004] | 265 | for (i = 0; i < iters; i++) { |
---|
| 266 | thread = create_thread (); |
---|
[18713] | 267 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 268 | } |
---|
[21004] | 269 | g_print ("create/unref %d thread with children %ld\n", iters, |
---|
| 270 | vmsize () - usage1); |
---|
[18713] | 271 | |
---|
[21004] | 272 | for (i = 0; i < iters / 2; i++) { |
---|
| 273 | thread = create_thread_ghostpads (); |
---|
[18713] | 274 | gst_object_unref (GST_OBJECT (thread)); |
---|
| 275 | } |
---|
[21004] | 276 | g_print ("create/unref %d thread with children and ghostpads %ld\n", |
---|
| 277 | iters / 2, vmsize () - usage1); |
---|
[18713] | 278 | |
---|
[21004] | 279 | for (i = 0; i < iters; i++) { |
---|
| 280 | add_remove_test1 (); |
---|
[18713] | 281 | } |
---|
[21004] | 282 | g_print ("add/remove test1 %d in thread %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 283 | |
---|
[21004] | 284 | for (i = 0; i < iters; i++) { |
---|
| 285 | add_remove_test2 (); |
---|
[18713] | 286 | } |
---|
[21004] | 287 | g_print ("add/remove test2 %d in thread %ld\n", iters, vmsize () - usage1); |
---|
[18713] | 288 | |
---|
[21004] | 289 | for (i = 0; i < iters; i++) { |
---|
| 290 | add_remove_test3 (); |
---|
[18713] | 291 | } |
---|
[21004] | 292 | g_print ("add/destroy/remove test3 %d in thread %ld\n", iters, |
---|
| 293 | vmsize () - usage1); |
---|
[18713] | 294 | |
---|
[21004] | 295 | for (i = 0; i < iters; i++) { |
---|
| 296 | add_remove_test4 (); |
---|
[18713] | 297 | } |
---|
[21004] | 298 | g_print ("add/destroy/remove test4 %d in thread %ld\n", iters, |
---|
| 299 | vmsize () - usage1); |
---|
[18713] | 300 | |
---|
[21004] | 301 | g_print ("leaked: %ld\n", vmsize () - usage1); |
---|
[18713] | 302 | |
---|
[21004] | 303 | return (vmsize () - usage1 ? -1 : 0); |
---|
[18713] | 304 | } |
---|