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