• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Unit test for a deterministic clock for Gstreamer unit tests
3  *
4  * Copyright (C) 2008 Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com>
5  * Copyright (C) 2012 Sebastian Rasmussen <sebastian.rasmussen@axis.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include <gst/check/gstcheck.h>
27 #include <gst/check/gsttestclock.h>
28 
29 typedef struct
30 {
31   GstTestClock *test_clock;
32   GstClockID id;
33   GstClockTime reference;
34 } GtuClockWaitContext;
35 
36 typedef struct
37 {
38   GstClockID clock_id;
39   GstClockTimeDiff jitter;
40 } SyncClockWaitContext;
41 
42 #define assert_pending_id(pending_id, id, type, time) \
43 G_STMT_START { \
44   GstClockEntry *entry = GST_CLOCK_ENTRY (pending_id); \
45   g_assert (entry == (id)); \
46   g_assert (GST_CLOCK_ENTRY_TYPE (entry) == (type)); \
47   g_assert_cmpuint (GST_CLOCK_ENTRY_TIME (entry), ==, (time)); \
48 } G_STMT_END
49 
50 #define assert_processed_id(processed_id, id, type, time) \
51 G_STMT_START { \
52   GstClockEntry *entry = GST_CLOCK_ENTRY (processed_id); \
53   g_assert (entry == (id)); \
54   g_assert (GST_CLOCK_ENTRY_TYPE (entry) == (type)); \
55   g_assert_cmpuint (GST_CLOCK_ENTRY_STATUS (entry), ==, (time)); \
56 } G_STMT_END
57 
58 static gpointer test_wait_pending_single_shot_id_sync_worker (gpointer data);
59 static gpointer test_wait_pending_single_shot_id_async_worker (gpointer data);
60 static gpointer test_wait_pending_periodic_id_waiter_thread (gpointer data);
61 static gboolean test_async_wait_cb (GstClock * clock, GstClockTime time,
62     GstClockID id, gpointer user_data);
63 
64 static GtuClockWaitContext *gst_test_util_wait_for_clock_id_begin (GstTestClock
65     * clock, GstClockID id, GstClockTimeDiff * jitter);
66 static GstClockReturn gst_test_util_wait_for_clock_id_end (GtuClockWaitContext *
67     wait_ctx);
68 static gboolean
69 gst_test_util_clock_wait_context_has_completed (GtuClockWaitContext * wait_ctx);
70 
71 static gpointer
test_wait_pending_single_shot_id_sync_worker(gpointer data)72 test_wait_pending_single_shot_id_sync_worker (gpointer data)
73 {
74   SyncClockWaitContext *ctx = data;
75 
76   gst_clock_id_wait (ctx->clock_id, &ctx->jitter);
77 
78   return NULL;
79 }
80 
81 static gpointer
test_wait_pending_single_shot_id_async_worker(gpointer data)82 test_wait_pending_single_shot_id_async_worker (gpointer data)
83 {
84   GstClockID clock_id = data;
85 
86   g_usleep (G_USEC_PER_SEC / 10);
87   gst_clock_id_wait_async (clock_id, test_async_wait_cb, NULL, NULL);
88 
89   return NULL;
90 }
91 
92 static gpointer
test_wait_pending_periodic_id_waiter_thread(gpointer data)93 test_wait_pending_periodic_id_waiter_thread (gpointer data)
94 {
95   GstClockID clock_id = data;
96   gst_clock_id_wait (clock_id, NULL);
97   return NULL;
98 }
99 
100 static gboolean
test_async_wait_cb(GstClock * clock,GstClockTime time,GstClockID id,gpointer user_data)101 test_async_wait_cb (GstClock * clock,
102     GstClockTime time, GstClockID id, gpointer user_data)
103 {
104 
105   gboolean *wait_complete = user_data;
106 
107   if (wait_complete != NULL)
108     *wait_complete = TRUE;
109 
110   return TRUE;
111 }
112 
113 static GtuClockWaitContext *
gst_test_util_wait_for_clock_id_begin(GstTestClock * test_clock,GstClockID id,GstClockTimeDiff * jitter)114 gst_test_util_wait_for_clock_id_begin (GstTestClock * test_clock, GstClockID id,
115     GstClockTimeDiff * jitter)
116 {
117   GtuClockWaitContext *wait_ctx;
118 
119   wait_ctx = g_slice_new (GtuClockWaitContext);
120   wait_ctx->test_clock = gst_object_ref (test_clock);
121   wait_ctx->reference = gst_clock_get_time (GST_CLOCK (wait_ctx->test_clock));
122   wait_ctx->id = gst_clock_id_ref (id);
123 
124   if (jitter) {
125     GstClockEntry *entry = GST_CLOCK_ENTRY (wait_ctx->id);
126     GstClockTime requested = GST_CLOCK_ENTRY_TIME (entry);
127     GstClockTime reference = wait_ctx->reference;
128 
129     *jitter = GST_CLOCK_DIFF (requested, reference);
130   }
131 
132   if (!gst_test_clock_has_id (wait_ctx->test_clock, wait_ctx->id)) {
133     GstClockClass *klass = GST_CLOCK_GET_CLASS (wait_ctx->test_clock);
134     GstClock *clock = GST_CLOCK (wait_ctx->test_clock);
135     g_assert (klass->wait_async (clock, wait_ctx->id) == GST_CLOCK_OK);
136   }
137 
138   g_assert (gst_test_clock_has_id (wait_ctx->test_clock, wait_ctx->id));
139   g_assert_cmpint (gst_test_clock_peek_id_count (wait_ctx->test_clock), >, 0);
140 
141   return wait_ctx;
142 }
143 
144 static GstClockReturn
gst_test_util_wait_for_clock_id_end(GtuClockWaitContext * wait_ctx)145 gst_test_util_wait_for_clock_id_end (GtuClockWaitContext * wait_ctx)
146 {
147   GstClockReturn status = GST_CLOCK_ERROR;
148   GstClockEntry *entry = GST_CLOCK_ENTRY (wait_ctx->id);
149 
150   if (G_UNLIKELY (GST_CLOCK_ENTRY_STATUS (entry) == GST_CLOCK_UNSCHEDULED)) {
151     status = GST_CLOCK_UNSCHEDULED;
152   } else {
153     GstClockTime requested = GST_CLOCK_ENTRY_TIME (entry);
154     GstClockTimeDiff diff;
155 
156     g_assert (gst_test_clock_has_id (wait_ctx->test_clock, wait_ctx->id));
157 
158     diff = GST_CLOCK_DIFF (requested, wait_ctx->reference);
159 
160     if (diff > 0) {
161       status = GST_CLOCK_EARLY;
162     } else {
163       status = GST_CLOCK_OK;
164     }
165 
166     g_atomic_int_set (&GST_CLOCK_ENTRY_STATUS (entry), status);
167   }
168 
169   if (GST_CLOCK_ENTRY_TYPE (entry) == GST_CLOCK_ENTRY_SINGLE) {
170     GstClockClass *klass = GST_CLOCK_GET_CLASS (wait_ctx->test_clock);
171     GstClock *clock = GST_CLOCK (wait_ctx->test_clock);
172 
173     klass->unschedule (clock, wait_ctx->id);
174     g_assert (!gst_test_clock_has_id (wait_ctx->test_clock, wait_ctx->id));
175   } else {
176     GST_CLOCK_ENTRY_TIME (entry) += GST_CLOCK_ENTRY_INTERVAL (entry);
177     g_assert (gst_test_clock_has_id (wait_ctx->test_clock, wait_ctx->id));
178   }
179 
180   gst_clock_id_unref (wait_ctx->id);
181   gst_object_unref (wait_ctx->test_clock);
182   g_slice_free (GtuClockWaitContext, wait_ctx);
183 
184   return status;
185 }
186 
187 static gboolean
gst_test_util_clock_wait_context_has_completed(GtuClockWaitContext * wait_ctx)188 gst_test_util_clock_wait_context_has_completed (GtuClockWaitContext * wait_ctx)
189 {
190   GstClock *clock = GST_CLOCK (wait_ctx->test_clock);
191   GstClockEntry *entry = GST_CLOCK_ENTRY (wait_ctx->id);
192   GstClockTime requested = GST_CLOCK_ENTRY_TIME (entry);
193   GstClockTime now = gst_clock_get_time (clock);
194 
195   return requested < now;
196 }
197 
GST_START_TEST(test_object_flags)198 GST_START_TEST (test_object_flags)
199 {
200   GstClock *clock = gst_test_clock_new ();
201   g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC));
202   g_assert (GST_OBJECT_FLAG_IS_SET (clock, GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC));
203   g_assert (GST_OBJECT_FLAG_IS_SET (clock,
204           GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC));
205   g_assert (GST_OBJECT_FLAG_IS_SET (clock,
206           GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC));
207   gst_object_unref (clock);
208 }
209 
210 GST_END_TEST;
211 
GST_START_TEST(test_resolution_query)212 GST_START_TEST (test_resolution_query)
213 {
214   GstClock *clock = gst_test_clock_new ();
215   g_assert_cmpuint (gst_clock_get_resolution (clock), ==, 1);
216   gst_object_unref (clock);
217 }
218 
219 GST_END_TEST;
220 
GST_START_TEST(test_start_time)221 GST_START_TEST (test_start_time)
222 {
223   GstClock *clock;
224   guint64 start_time;
225 
226   clock = gst_test_clock_new ();
227   g_assert_cmpuint (gst_clock_get_time (clock), ==, 0);
228   g_object_get (clock, "start-time", &start_time, NULL);
229   g_assert_cmpuint (start_time, ==, 0);
230   gst_object_unref (clock);
231 
232   clock = gst_test_clock_new_with_start_time (GST_SECOND);
233   g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
234   g_object_get (clock, "start-time", &start_time, NULL);
235   g_assert_cmpuint (start_time, ==, GST_SECOND);
236   gst_object_unref (clock);
237 }
238 
239 GST_END_TEST;
240 
GST_START_TEST(test_set_time)241 GST_START_TEST (test_set_time)
242 {
243   GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND);
244   gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND);
245   g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
246   gst_test_clock_set_time (GST_TEST_CLOCK (clock), GST_SECOND + 1);
247   g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND + 1);
248   gst_object_unref (clock);
249 }
250 
251 GST_END_TEST;
252 
GST_START_TEST(test_advance_time)253 GST_START_TEST (test_advance_time)
254 {
255   GstClock *clock = gst_test_clock_new_with_start_time (GST_SECOND);
256   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 0);
257   g_assert_cmpuint (gst_clock_get_time (clock), ==, GST_SECOND);
258   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 42 * GST_MSECOND);
259   g_assert_cmpuint (gst_clock_get_time (clock), ==,
260       GST_SECOND + (42 * GST_MSECOND));
261   gst_object_unref (clock);
262 }
263 
264 GST_END_TEST;
265 
GST_START_TEST(test_wait_synchronous_no_timeout)266 GST_START_TEST (test_wait_synchronous_no_timeout)
267 {
268   GstClock *clock;
269   GstTestClock *test_clock;
270   GstClockID clock_id;
271   GThread *worker_thread;
272   GstClockID pending_id;
273   GstClockID processed_id;
274   SyncClockWaitContext context;
275 
276   clock = gst_test_clock_new_with_start_time (GST_SECOND);
277   test_clock = GST_TEST_CLOCK (clock);
278 
279   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND - 1);
280   context.clock_id = gst_clock_id_ref (clock_id);
281   context.jitter = 0;
282   worker_thread =
283       g_thread_new ("worker_thread",
284       test_wait_pending_single_shot_id_sync_worker, &context);
285   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
286   assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
287       GST_SECOND - 1);
288   gst_clock_id_unref (pending_id);
289   processed_id = gst_test_clock_process_next_clock_id (test_clock);
290   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
291       GST_CLOCK_EARLY);
292   gst_clock_id_unref (processed_id);
293   g_thread_join (worker_thread);
294   g_assert_cmpuint (context.jitter, ==, 1);
295   gst_clock_id_unref (context.clock_id);
296   gst_clock_id_unref (clock_id);
297 
298   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND);
299   context.clock_id = gst_clock_id_ref (clock_id);
300   context.jitter = 0;
301   worker_thread =
302       g_thread_new ("worker_thread",
303       test_wait_pending_single_shot_id_sync_worker, &context);
304   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
305   assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_SINGLE, GST_SECOND);
306   gst_clock_id_unref (pending_id);
307   processed_id = gst_test_clock_process_next_clock_id (test_clock);
308   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
309       GST_CLOCK_OK);
310   gst_clock_id_unref (processed_id);
311   g_thread_join (worker_thread);
312   g_assert_cmpuint (context.jitter, ==, 0);
313   gst_clock_id_unref (context.clock_id);
314   gst_clock_id_unref (clock_id);
315 
316   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND + 1);
317   context.clock_id = gst_clock_id_ref (clock_id);
318   context.jitter = 0;
319   worker_thread =
320       g_thread_new ("worker_thread",
321       test_wait_pending_single_shot_id_sync_worker, &context);
322   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
323   assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
324       GST_SECOND + 1);
325   gst_clock_id_unref (pending_id);
326   processed_id = gst_test_clock_process_next_clock_id (test_clock);
327   g_assert (processed_id == NULL);
328   gst_test_clock_advance_time (test_clock, 1);
329   processed_id = gst_test_clock_process_next_clock_id (test_clock);
330   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
331       GST_CLOCK_OK);
332   gst_clock_id_unref (processed_id);
333   g_thread_join (worker_thread);
334   g_assert_cmpuint (context.jitter, ==, -1);
335   gst_clock_id_unref (context.clock_id);
336   gst_clock_id_unref (clock_id);
337 
338   gst_object_unref (clock);
339 }
340 
341 GST_END_TEST;
342 
GST_START_TEST(test_wait_pending_single_shot_id)343 GST_START_TEST (test_wait_pending_single_shot_id)
344 {
345   GstClock *clock;
346   GstTestClock *test_clock;
347   GstClockID clock_id;
348   GstClockID processed_id;
349   GThread *worker_thread;
350   GstClockID pending_id;
351 
352   clock = gst_test_clock_new_with_start_time (GST_SECOND);
353   test_clock = GST_TEST_CLOCK (clock);
354 
355   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND);
356   gst_clock_id_wait_async (clock_id, test_async_wait_cb, NULL, NULL);
357   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
358   assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_SINGLE, GST_SECOND);
359   gst_clock_id_unref (pending_id);
360   processed_id = gst_test_clock_process_next_clock_id (test_clock);
361   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
362       GST_CLOCK_OK);
363   gst_clock_id_unref (processed_id);
364   gst_clock_id_unref (clock_id);
365 
366   clock_id = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
367   worker_thread =
368       g_thread_new ("worker_thread",
369       test_wait_pending_single_shot_id_async_worker, clock_id);
370   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
371   assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
372       2 * GST_SECOND);
373   gst_clock_id_unref (pending_id);
374   g_thread_join (worker_thread);
375   gst_clock_id_unref (clock_id);
376 
377   clock_id = gst_clock_new_single_shot_id (clock, 3 * GST_SECOND);
378   worker_thread =
379       g_thread_new ("worker_thread",
380       test_wait_pending_single_shot_id_async_worker, clock_id);
381   gst_test_clock_wait_for_next_pending_id (test_clock, NULL);
382   g_thread_join (worker_thread);
383   gst_clock_id_unref (clock_id);
384 
385   gst_object_unref (clock);
386 }
387 
388 GST_END_TEST;
389 
GST_START_TEST(test_wait_pending_periodic_id)390 GST_START_TEST (test_wait_pending_periodic_id)
391 {
392   GstClock *clock;
393   GstTestClock *test_clock;
394   GstClockID clock_id;
395   GstClockID processed_id;
396 
397   clock = gst_test_clock_new_with_start_time (GST_SECOND);
398   test_clock = GST_TEST_CLOCK (clock);
399   clock_id = gst_clock_new_periodic_id (clock, GST_SECOND, GST_MSECOND);
400 
401   {
402     GThread *waiter_thread;
403 
404     waiter_thread =
405         g_thread_new ("waiter_thread",
406         test_wait_pending_periodic_id_waiter_thread, clock_id);
407 
408     gst_test_clock_wait_for_next_pending_id (test_clock, NULL);
409     gst_test_clock_set_time (test_clock, GST_SECOND);
410     processed_id = gst_test_clock_process_next_clock_id (test_clock);
411     assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_PERIODIC,
412         GST_CLOCK_OK);
413     gst_clock_id_unref (processed_id);
414 
415     g_thread_join (waiter_thread);
416   }
417 
418   {
419     guint i;
420     GThread *waiter_thread;
421 
422     for (i = 0; i < 3; i++) {
423       g_assert (!gst_test_clock_peek_next_pending_id (test_clock, NULL));
424       g_usleep (G_USEC_PER_SEC / 10 / 10);
425     }
426 
427     waiter_thread =
428         g_thread_new ("waiter_thread",
429         test_wait_pending_periodic_id_waiter_thread, clock_id);
430 
431     gst_test_clock_wait_for_next_pending_id (test_clock, NULL);
432     gst_clock_id_unschedule (clock_id);
433 
434     g_thread_join (waiter_thread);
435   }
436 
437   gst_clock_id_unref (clock_id);
438   gst_object_unref (clock);
439 }
440 
441 GST_END_TEST;
442 
GST_START_TEST(test_single_shot_sync_past)443 GST_START_TEST (test_single_shot_sync_past)
444 {
445   GstClock *clock;
446   GstTestClock *test_clock;
447   GstClockID clock_id;
448   GstClockTimeDiff jitter;
449   GtuClockWaitContext *wait_ctx;
450 
451   clock = gst_test_clock_new_with_start_time (GST_SECOND);
452   test_clock = GST_TEST_CLOCK (clock);
453 
454   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND - 1);
455   wait_ctx =
456       gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, &jitter);
457   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
458       GST_CLOCK_EARLY);
459   g_assert_cmpint (jitter, ==, 1);
460   gst_clock_id_unref (clock_id);
461 
462   gst_object_unref (clock);
463 }
464 
465 GST_END_TEST;
466 
GST_START_TEST(test_single_shot_sync_present)467 GST_START_TEST (test_single_shot_sync_present)
468 {
469   GstClock *clock;
470   GstTestClock *test_clock;
471   GstClockID clock_id;
472   GstClockTimeDiff jitter;
473   GtuClockWaitContext *wait_ctx;
474 
475   clock = gst_test_clock_new_with_start_time (GST_SECOND);
476   test_clock = GST_TEST_CLOCK (clock);
477 
478   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND);
479   wait_ctx =
480       gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, &jitter);
481   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
482       GST_CLOCK_OK);
483   g_assert_cmpint (jitter, ==, 0);
484   gst_clock_id_unref (clock_id);
485 
486   gst_object_unref (clock);
487 }
488 
489 GST_END_TEST;
490 
GST_START_TEST(test_single_shot_sync_future)491 GST_START_TEST (test_single_shot_sync_future)
492 {
493   GstClock *clock;
494   GstTestClock *test_clock;
495   GstClockID clock_id;
496   GstClockTimeDiff jitter;
497   GtuClockWaitContext *wait_ctx;
498 
499   clock = gst_test_clock_new_with_start_time (GST_SECOND);
500   test_clock = GST_TEST_CLOCK (clock);
501 
502   clock_id = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
503   wait_ctx =
504       gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, &jitter);
505   gst_test_clock_advance_time (test_clock, GST_SECOND);
506   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
507       GST_CLOCK_OK);
508   g_assert_cmpint (jitter, ==, -GST_SECOND);
509   gst_clock_id_unref (clock_id);
510 
511   gst_object_unref (clock);
512 }
513 
514 GST_END_TEST;
515 
GST_START_TEST(test_single_shot_sync_unschedule)516 GST_START_TEST (test_single_shot_sync_unschedule)
517 {
518   GstClock *clock;
519   GstTestClock *test_clock;
520   GstClockID clock_id;
521   GtuClockWaitContext *wait_ctx;
522   gboolean wait_complete = FALSE;
523 
524   clock = gst_test_clock_new_with_start_time (GST_SECOND);
525   test_clock = GST_TEST_CLOCK (clock);
526 
527   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND);
528   gst_clock_id_unschedule (clock_id);
529   /* any wait should timeout immediately */
530   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
531           &wait_complete, NULL) == GST_CLOCK_UNSCHEDULED);
532   g_assert (gst_clock_id_wait (clock_id, NULL) == GST_CLOCK_UNSCHEDULED);
533   gst_clock_id_unref (clock_id);
534 
535   clock_id = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
536   wait_ctx = gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, NULL);
537   gst_clock_id_unschedule (clock_id);
538   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
539       GST_CLOCK_UNSCHEDULED);
540   gst_clock_id_unref (clock_id);
541 
542   gst_object_unref (clock);
543 }
544 
545 GST_END_TEST;
546 
GST_START_TEST(test_single_shot_sync_ordering)547 GST_START_TEST (test_single_shot_sync_ordering)
548 {
549   GstClock *clock;
550   GstTestClock *test_clock;
551   GstClockID clock_id_a, clock_id_b;
552   GtuClockWaitContext *wait_ctx_a, *wait_ctx_b;
553 
554   clock = gst_test_clock_new_with_start_time (GST_SECOND);
555   test_clock = GST_TEST_CLOCK (clock);
556 
557   clock_id_a = gst_clock_new_single_shot_id (clock, 3 * GST_SECOND);
558   wait_ctx_a =
559       gst_test_util_wait_for_clock_id_begin (test_clock, clock_id_a, NULL);
560 
561   gst_test_clock_advance_time (test_clock, GST_SECOND);
562 
563   clock_id_b = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
564   wait_ctx_b =
565       gst_test_util_wait_for_clock_id_begin (test_clock, clock_id_b, NULL);
566 
567   gst_test_clock_advance_time (test_clock, GST_SECOND);
568 
569   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx_b),
570       GST_CLOCK_OK);
571   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx_a),
572       GST_CLOCK_OK);
573 
574   gst_clock_id_unref (clock_id_b);
575   gst_clock_id_unref (clock_id_a);
576 
577   gst_object_unref (clock);
578 }
579 
580 GST_END_TEST;
581 
GST_START_TEST(test_single_shot_sync_ordering_parallel)582 GST_START_TEST (test_single_shot_sync_ordering_parallel)
583 {
584   GstClock *clock;
585   GstTestClock *test_clock;
586   GstClockID clock_id_a, clock_id_b;
587   GtuClockWaitContext *wait_ctx_a, *wait_ctx_b;
588 
589   clock = gst_test_clock_new_with_start_time (GST_SECOND);
590   test_clock = GST_TEST_CLOCK (clock);
591 
592   clock_id_a = gst_clock_new_single_shot_id (clock, 3 * GST_SECOND);
593   clock_id_b = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
594   wait_ctx_a = gst_test_util_wait_for_clock_id_begin (test_clock, clock_id_a,
595       NULL);
596   wait_ctx_b = gst_test_util_wait_for_clock_id_begin (test_clock, clock_id_b,
597       NULL);
598 
599   g_assert_cmpuint (gst_test_clock_get_next_entry_time (test_clock), ==,
600       2 * GST_SECOND);
601   gst_test_clock_advance_time (test_clock, GST_SECOND);
602   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx_b),
603       GST_CLOCK_OK);
604 
605   g_assert_cmpuint (gst_test_clock_get_next_entry_time (test_clock), ==,
606       3 * GST_SECOND);
607   gst_test_clock_advance_time (test_clock, GST_SECOND);
608   fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx_a),
609       GST_CLOCK_OK);
610 
611   gst_clock_id_unref (clock_id_b);
612   gst_clock_id_unref (clock_id_a);
613 
614   gst_object_unref (clock);
615 }
616 
617 GST_END_TEST;
618 
GST_START_TEST(test_single_shot_sync_simultaneous_no_timeout)619 GST_START_TEST (test_single_shot_sync_simultaneous_no_timeout)
620 {
621   GstClock *clock;
622   GstTestClock *test_clock;
623   GstClockID clock_id_a;
624   GstClockID clock_id_b;
625   SyncClockWaitContext context_a;
626   SyncClockWaitContext context_b;
627   GThread *worker_thread_a;
628   GThread *worker_thread_b;
629   GstClockID processed_id;
630   GstClockID pending_id;
631 
632   clock = gst_test_clock_new_with_start_time (GST_SECOND);
633   test_clock = GST_TEST_CLOCK (clock);
634 
635   clock_id_a = gst_clock_new_single_shot_id (clock, 5 * GST_SECOND);
636   clock_id_b = gst_clock_new_single_shot_id (clock, 6 * GST_SECOND);
637 
638   context_a.clock_id = gst_clock_id_ref (clock_id_a);
639   context_a.jitter = 0;
640   context_b.clock_id = gst_clock_id_ref (clock_id_b);
641   context_b.jitter = 0;
642 
643   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 0, NULL);
644 
645   worker_thread_b =
646       g_thread_new ("worker_thread_b",
647       test_wait_pending_single_shot_id_sync_worker, &context_b);
648 
649   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 1, NULL);
650   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
651   assert_pending_id (pending_id, clock_id_b, GST_CLOCK_ENTRY_SINGLE,
652       6 * GST_SECOND);
653   gst_clock_id_unref (pending_id);
654 
655   worker_thread_a =
656       g_thread_new ("worker_thread_a",
657       test_wait_pending_single_shot_id_sync_worker, &context_a);
658 
659   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 2, NULL);
660   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
661   assert_pending_id (pending_id, clock_id_a, GST_CLOCK_ENTRY_SINGLE,
662       5 * GST_SECOND);
663   gst_clock_id_unref (pending_id);
664 
665   g_assert_cmpuint (gst_test_clock_get_next_entry_time (test_clock), ==,
666       5 * GST_SECOND);
667   gst_test_clock_advance_time (test_clock, 5 * GST_SECOND);
668   processed_id = gst_test_clock_process_next_clock_id (test_clock);
669   assert_processed_id (processed_id, clock_id_a, GST_CLOCK_ENTRY_SINGLE,
670       GST_CLOCK_OK);
671   gst_clock_id_unref (processed_id);
672 
673   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 1, NULL);
674   gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
675   assert_pending_id (pending_id, clock_id_b, GST_CLOCK_ENTRY_SINGLE,
676       6 * GST_SECOND);
677   gst_clock_id_unref (pending_id);
678 
679   g_assert_cmpuint (gst_test_clock_get_next_entry_time (test_clock), ==,
680       6 * GST_SECOND);
681   gst_test_clock_advance_time (test_clock, 6 * GST_SECOND);
682   processed_id = gst_test_clock_process_next_clock_id (test_clock);
683   assert_processed_id (processed_id, clock_id_b, GST_CLOCK_ENTRY_SINGLE,
684       GST_CLOCK_OK);
685   gst_clock_id_unref (processed_id);
686 
687   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 0, NULL);
688 
689   g_thread_join (worker_thread_a);
690   g_thread_join (worker_thread_b);
691 
692   g_assert_cmpuint (context_a.jitter, ==, -4 * GST_SECOND);
693   g_assert_cmpuint (context_b.jitter, ==, -5 * GST_SECOND);
694 
695   gst_clock_id_unref (context_a.clock_id);
696   gst_clock_id_unref (context_b.clock_id);
697 
698   gst_clock_id_unref (clock_id_a);
699   gst_clock_id_unref (clock_id_b);
700 
701   gst_object_unref (clock);
702 }
703 
704 GST_END_TEST;
705 
GST_START_TEST(test_processing_multiple_ids)706 GST_START_TEST (test_processing_multiple_ids)
707 {
708   GstClock *clock;
709   GstTestClock *test_clock;
710   GstClockID clock_id_a;
711   GstClockID clock_id_b;
712   SyncClockWaitContext context_a;
713   SyncClockWaitContext context_b;
714   GThread *worker_thread_a;
715   GThread *worker_thread_b;
716   GList *pending_list = NULL;
717 
718   clock = gst_test_clock_new_with_start_time (GST_SECOND);
719   test_clock = GST_TEST_CLOCK (clock);
720 
721   /* register a wait for 5 seconds */
722   clock_id_a = gst_clock_new_single_shot_id (clock, 5 * GST_SECOND);
723   context_a.clock_id = gst_clock_id_ref (clock_id_a);
724   context_a.jitter = 0;
725   worker_thread_a =
726       g_thread_new ("worker_thread_a",
727       test_wait_pending_single_shot_id_sync_worker, &context_a);
728 
729   /* register another wait for 6 seconds */
730   clock_id_b = gst_clock_new_single_shot_id (clock, 6 * GST_SECOND);
731   context_b.clock_id = gst_clock_id_ref (clock_id_b);
732   context_b.jitter = 0;
733   worker_thread_b =
734       g_thread_new ("worker_thread_b",
735       test_wait_pending_single_shot_id_sync_worker, &context_b);
736 
737   /* wait for two waits */
738   gst_test_clock_wait_for_multiple_pending_ids (test_clock, 2, &pending_list);
739 
740   /* assert they are correct */
741   assert_pending_id (pending_list->data, clock_id_a, GST_CLOCK_ENTRY_SINGLE,
742       5 * GST_SECOND);
743   assert_pending_id (pending_list->next->data, clock_id_b,
744       GST_CLOCK_ENTRY_SINGLE, 6 * GST_SECOND);
745 
746   /* verify we are waiting for 6 seconds as the latest time */
747   fail_unless_equals_int64 (6 * GST_SECOND,
748       gst_test_clock_id_list_get_latest_time (pending_list));
749 
750   /* process both ID's at the same time */
751   gst_test_clock_process_id_list (test_clock, pending_list);
752   g_list_free_full (pending_list, (GDestroyNotify) gst_clock_id_unref);
753 
754   g_thread_join (worker_thread_a);
755   g_thread_join (worker_thread_b);
756 
757   fail_unless_equals_int64 (-4 * GST_SECOND, context_a.jitter);
758   fail_unless_equals_int64 (-5 * GST_SECOND, context_b.jitter);
759 
760   gst_clock_id_unref (context_a.clock_id);
761   gst_clock_id_unref (context_b.clock_id);
762 
763   gst_clock_id_unref (clock_id_a);
764   gst_clock_id_unref (clock_id_b);
765 
766   gst_object_unref (clock);
767 }
768 
769 GST_END_TEST;
770 
GST_START_TEST(test_single_shot_async_past)771 GST_START_TEST (test_single_shot_async_past)
772 {
773   GstClock *clock;
774   GstClockID clock_id;
775   GstClockID processed_id;
776   gboolean wait_complete = FALSE;
777 
778   clock = gst_test_clock_new_with_start_time (GST_SECOND);
779   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND - 1);
780   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
781           &wait_complete, NULL) == GST_CLOCK_OK);
782   g_assert (!wait_complete);
783   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
784   g_assert (wait_complete);
785   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
786       GST_CLOCK_EARLY);
787   gst_clock_id_unref (processed_id);
788   gst_clock_id_unref (clock_id);
789   gst_object_unref (clock);
790 }
791 
792 GST_END_TEST;
793 
GST_START_TEST(test_single_shot_async_present)794 GST_START_TEST (test_single_shot_async_present)
795 {
796   GstClock *clock;
797   GstClockID clock_id;
798   GstClockID processed_id;
799   gboolean wait_complete = FALSE;
800 
801   clock = gst_test_clock_new_with_start_time (GST_SECOND);
802   clock_id = gst_clock_new_single_shot_id (clock, GST_SECOND);
803   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
804           &wait_complete, NULL) == GST_CLOCK_OK);
805   g_assert (!wait_complete);
806   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
807   g_assert (wait_complete);
808   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
809       GST_CLOCK_OK);
810   gst_clock_id_unref (processed_id);
811   gst_clock_id_unref (clock_id);
812   gst_object_unref (clock);
813 }
814 
815 GST_END_TEST;
816 
GST_START_TEST(test_single_shot_async_future)817 GST_START_TEST (test_single_shot_async_future)
818 {
819   GstClock *clock;
820   GstClockID clock_id;
821   GstClockID processed_id;
822   gboolean wait_complete = FALSE;
823 
824   clock = gst_test_clock_new_with_start_time (GST_SECOND);
825   clock_id = gst_clock_new_single_shot_id (clock, 2 * GST_SECOND);
826   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
827           &wait_complete, NULL) == GST_CLOCK_OK);
828   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
829   g_assert (processed_id == NULL);
830   g_assert (!wait_complete);
831   g_assert (GST_CLOCK_ENTRY_STATUS (GST_CLOCK_ENTRY (clock_id))
832       == GST_CLOCK_OK);
833 
834   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), GST_SECOND - 1);
835   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
836   g_assert (processed_id == NULL);
837   g_assert (!wait_complete);
838   g_assert (GST_CLOCK_ENTRY_STATUS (GST_CLOCK_ENTRY (clock_id))
839       == GST_CLOCK_OK);
840 
841   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 1);
842   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
843   g_assert (wait_complete);
844   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_SINGLE,
845       GST_CLOCK_OK);
846   gst_clock_id_unref (processed_id);
847   g_assert (GST_CLOCK_ENTRY_STATUS (GST_CLOCK_ENTRY (clock_id))
848       == GST_CLOCK_OK);
849 
850   gst_clock_id_unref (clock_id);
851   gst_object_unref (clock);
852 }
853 
854 GST_END_TEST;
855 
GST_START_TEST(test_single_shot_async_unschedule)856 GST_START_TEST (test_single_shot_async_unschedule)
857 {
858   GstClock *clock;
859   GstClockID clock_id;
860   gboolean wait_complete = FALSE;
861 
862   clock = gst_test_clock_new_with_start_time (GST_SECOND);
863 
864   clock_id = gst_clock_new_single_shot_id (clock, 3 * GST_SECOND);
865   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
866           &wait_complete, NULL) == GST_CLOCK_OK);
867 
868   gst_clock_id_unschedule (clock_id);
869 
870   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 2 * GST_SECOND);
871   g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock))
872       == NULL);
873   g_assert (!wait_complete);
874 
875   gst_clock_id_unref (clock_id);
876   gst_object_unref (clock);
877 }
878 
879 GST_END_TEST;
880 
GST_START_TEST(test_periodic_sync)881 GST_START_TEST (test_periodic_sync)
882 {
883   GstClock *clock;
884   GstTestClock *test_clock;
885   GstClockID clock_id;
886   guint i;
887   const GstClockTime interval = 4 * GST_MSECOND;
888 
889   clock = gst_test_clock_new ();
890   test_clock = GST_TEST_CLOCK (clock);
891 
892   clock_id = gst_clock_new_periodic_id (clock, GST_SECOND, interval);
893 
894   for (i = 0; i < 3; i++) {
895     GtuClockWaitContext *wait_ctx;
896     GstClockID pending_id;
897     guint j;
898 
899     wait_ctx =
900         gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, NULL);
901 
902     gst_test_clock_wait_for_next_pending_id (test_clock, &pending_id);
903     assert_pending_id (pending_id, clock_id, GST_CLOCK_ENTRY_PERIODIC,
904         GST_SECOND + (i * interval));
905     gst_clock_id_unref (pending_id);
906 
907     for (j = 0; j < 10; j++) {
908       g_usleep (G_USEC_PER_SEC / 10 / 10);
909       g_assert (!gst_test_util_clock_wait_context_has_completed (wait_ctx));
910     }
911 
912     if (i == 0)
913       gst_test_clock_advance_time (test_clock, GST_SECOND);
914     else
915       gst_test_clock_advance_time (test_clock, interval);
916 
917     fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
918         GST_CLOCK_OK);
919   }
920 
921   gst_clock_id_unref (clock_id);
922   gst_object_unref (clock);
923 }
924 
925 GST_END_TEST;
926 
GST_START_TEST(test_periodic_async)927 GST_START_TEST (test_periodic_async)
928 {
929   GstClock *clock;
930   GstClockID clock_id;
931   GstClockID processed_id;
932   gboolean wait_complete = FALSE;
933   const GstClockTime interval = 4 * GST_MSECOND;
934 
935   clock = gst_test_clock_new ();
936   clock_id = gst_clock_new_periodic_id (clock, gst_clock_get_time (clock),
937       interval);
938   g_assert (gst_clock_id_wait_async (clock_id, test_async_wait_cb,
939           &wait_complete, NULL) == GST_CLOCK_OK);
940 
941   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
942   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_PERIODIC,
943       GST_CLOCK_OK);
944   gst_clock_id_unref (processed_id);
945 
946   g_assert (wait_complete);
947   wait_complete = FALSE;
948 
949   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), interval - 1);
950   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
951   g_assert (processed_id == NULL);
952   g_assert (!wait_complete);
953 
954   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 1);
955   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
956   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_PERIODIC,
957       GST_CLOCK_OK);
958   gst_clock_id_unref (processed_id);
959   g_assert (wait_complete);
960   wait_complete = FALSE;
961 
962   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), interval - 1);
963   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
964   g_assert (processed_id == NULL);
965   g_assert (!wait_complete);
966 
967   gst_test_clock_advance_time (GST_TEST_CLOCK (clock), 1);
968   processed_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (clock));
969   assert_processed_id (processed_id, clock_id, GST_CLOCK_ENTRY_PERIODIC,
970       GST_CLOCK_OK);
971   gst_clock_id_unref (processed_id);
972   g_assert (wait_complete);
973   wait_complete = FALSE;
974 
975   gst_clock_id_unref (clock_id);
976   gst_object_unref (clock);
977 }
978 
979 GST_END_TEST;
980 
GST_START_TEST(test_periodic_uniqueness)981 GST_START_TEST (test_periodic_uniqueness)
982 {
983   GstClock *clock;
984   GstTestClock *test_clock;
985   GstClockID clock_id;
986   guint i;
987   const GstClockTime interval = 4 * GST_MSECOND;
988 
989   clock = gst_test_clock_new ();
990   test_clock = GST_TEST_CLOCK (clock);
991 
992   clock_id = gst_clock_new_periodic_id (clock, 0, interval);
993 
994   for (i = 0; i < 3; i++) {
995     GtuClockWaitContext *wait_ctx;
996     guint j;
997 
998     wait_ctx =
999         gst_test_util_wait_for_clock_id_begin (test_clock, clock_id, NULL);
1000 
1001     for (j = 0; j < 10; j++) {
1002       g_usleep (G_USEC_PER_SEC / 10 / 10);
1003       g_assert_cmpuint (gst_test_clock_peek_id_count (test_clock), ==, 1);
1004     }
1005 
1006     gst_test_clock_advance_time (test_clock, interval);
1007     fail_unless_equals_int (gst_test_util_wait_for_clock_id_end (wait_ctx),
1008         GST_CLOCK_OK);
1009   }
1010 
1011   gst_clock_id_unref (clock_id);
1012   gst_object_unref (clock);
1013 }
1014 
1015 GST_END_TEST;
1016 
GST_START_TEST(test_crank)1017 GST_START_TEST (test_crank)
1018 {
1019   GstClock *clock;
1020   GstTestClock *test_clock;
1021   GstClockID clock_id;
1022   SyncClockWaitContext context;
1023   GThread *worker_thread;
1024 
1025   clock = gst_test_clock_new_with_start_time (GST_SECOND);
1026   test_clock = GST_TEST_CLOCK (clock);
1027 
1028   /* register a wait for 5 seconds */
1029   clock_id = gst_clock_new_single_shot_id (clock, 5 * GST_SECOND);
1030   context.clock_id = gst_clock_id_ref (clock_id);
1031   context.jitter = 0;
1032   worker_thread =
1033       g_thread_new ("worker_thread_a",
1034       test_wait_pending_single_shot_id_sync_worker, &context);
1035 
1036   /* crank */
1037   gst_test_clock_crank (test_clock);
1038 
1039   /* the clock should have advanced and the wait released */
1040   g_thread_join (worker_thread);
1041 
1042   /* 4 seconds was spent waiting for the clock */
1043   fail_unless_equals_int64 (-4 * GST_SECOND, context.jitter);
1044 
1045   /* and the clock is now at 5 seconds */
1046   fail_unless_equals_int64 (5 * GST_SECOND, gst_clock_get_time (clock));
1047 
1048   gst_clock_id_unref (context.clock_id);
1049   gst_clock_id_unref (clock_id);
1050   gst_object_unref (clock);
1051 }
1052 
1053 GST_END_TEST;
1054 
GST_START_TEST(test_late_crank)1055 GST_START_TEST (test_late_crank)
1056 {
1057   GstClock *clock;
1058   GstTestClock *test_clock;
1059   GstClockID clock_id;
1060   SyncClockWaitContext context;
1061   GThread *worker_thread;
1062 
1063   clock = gst_test_clock_new_with_start_time (GST_SECOND);
1064   test_clock = GST_TEST_CLOCK (clock);
1065 
1066   /* register a wait for 5 seconds */
1067   clock_id = gst_clock_new_single_shot_id (clock, 5 * GST_SECOND);
1068   context.clock_id = gst_clock_id_ref (clock_id);
1069   context.jitter = 0;
1070 
1071   /* crank the clock while the pending clock id is in the past */
1072   gst_test_clock_set_time (test_clock, 6 * GST_SECOND);
1073   worker_thread =
1074       g_thread_new ("worker_thread_a",
1075       test_wait_pending_single_shot_id_sync_worker, &context);
1076   gst_test_clock_crank (test_clock);
1077 
1078   /* the clock should have advanced and the wait released */
1079   g_thread_join (worker_thread);
1080 
1081   /* the pending entry was schedule 1 second before waiting */
1082   fail_unless_equals_int64 (1 * GST_SECOND, context.jitter);
1083 
1084   /* and the clock is still 5 seconds as configured */
1085   fail_unless_equals_int64 (6 * GST_SECOND, gst_clock_get_time (clock));
1086 
1087   gst_clock_id_unref (context.clock_id);
1088   gst_clock_id_unref (clock_id);
1089   gst_object_unref (clock);
1090 }
1091 
1092 GST_END_TEST;
1093 
1094 static Suite *
gst_test_clock_suite(void)1095 gst_test_clock_suite (void)
1096 {
1097   Suite *s = suite_create ("GstTestClock");
1098   TCase *tc_chain = tcase_create ("testclock");
1099 
1100   suite_add_tcase (s, tc_chain);
1101 
1102   tcase_add_test (tc_chain, test_object_flags);
1103   tcase_add_test (tc_chain, test_resolution_query);
1104   tcase_add_test (tc_chain, test_start_time);
1105   tcase_add_test (tc_chain, test_set_time);
1106   tcase_add_test (tc_chain, test_advance_time);
1107   tcase_add_test (tc_chain, test_wait_synchronous_no_timeout);
1108   tcase_add_test (tc_chain, test_wait_pending_single_shot_id);
1109   tcase_add_test (tc_chain, test_wait_pending_periodic_id);
1110   tcase_add_test (tc_chain, test_single_shot_sync_simultaneous_no_timeout);
1111   tcase_add_test (tc_chain, test_processing_multiple_ids);
1112   tcase_add_test (tc_chain, test_single_shot_sync_past);
1113   tcase_add_test (tc_chain, test_single_shot_sync_present);
1114   tcase_add_test (tc_chain, test_single_shot_sync_future);
1115   tcase_add_test (tc_chain, test_single_shot_sync_unschedule);
1116   tcase_add_test (tc_chain, test_single_shot_sync_ordering);
1117   tcase_add_test (tc_chain, test_single_shot_sync_ordering_parallel);
1118   tcase_add_test (tc_chain, test_single_shot_async_past);
1119   tcase_add_test (tc_chain, test_single_shot_async_present);
1120   tcase_add_test (tc_chain, test_single_shot_async_future);
1121   tcase_add_test (tc_chain, test_single_shot_async_unschedule);
1122   tcase_add_test (tc_chain, test_periodic_sync);
1123   tcase_add_test (tc_chain, test_periodic_async);
1124   tcase_add_test (tc_chain, test_periodic_uniqueness);
1125   tcase_add_test (tc_chain, test_crank);
1126   tcase_add_test (tc_chain, test_late_crank);
1127 
1128   return s;
1129 }
1130 
1131 GST_CHECK_MAIN (gst_test_clock);
1132