gstcheck.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /* GStreamer
  2. *
  3. * Common code for GStreamer unittests
  4. *
  5. * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
  6. * Copyright (C) <2008> Thijs Vermeir <[email protected]>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef __GST_CHECK_H__
  24. #define __GST_CHECK_H__
  25. #include <signal.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <math.h>
  29. #include <gst/check/internal-check.h>
  30. #include <gst/gst.h>
  31. G_BEGIN_DECLS
  32. GST_DEBUG_CATEGORY_EXTERN (check_debug);
  33. #define GST_CAT_DEFAULT check_debug
  34. /* logging function for tests
  35. * a test uses g_message() to log a debug line
  36. * a gst unit test can be run with GST_TEST_DEBUG env var set to see the
  37. * messages
  38. */
  39. extern gboolean _gst_check_threads_running;
  40. extern gboolean _gst_check_raised_critical;
  41. extern gboolean _gst_check_raised_warning;
  42. extern gboolean _gst_check_expecting_log;
  43. /* global variables used in test methods */
  44. extern GList * buffers;
  45. extern GMutex check_mutex;
  46. extern GCond check_cond;
  47. typedef struct
  48. {
  49. const char *name;
  50. int size;
  51. int abi_size;
  52. }
  53. GstCheckABIStruct;
  54. void gst_check_init (int *argc, char **argv[]);
  55. GstFlowReturn gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer);
  56. void gst_check_message_error (GstMessage * message, GstMessageType type,
  57. GQuark domain, gint code);
  58. GstElement *gst_check_setup_element (const gchar * factory);
  59. void gst_check_teardown_element (GstElement * element);
  60. GstPad *gst_check_setup_src_pad (GstElement * element,
  61. GstStaticPadTemplate * tmpl);
  62. GstPad *gst_check_setup_src_pad_from_template (GstElement * element,
  63. GstPadTemplate * tmpl);
  64. GstPad * gst_check_setup_src_pad_by_name (GstElement * element,
  65. GstStaticPadTemplate * tmpl, const gchar *name);
  66. GstPad * gst_check_setup_src_pad_by_name_from_template (GstElement * element,
  67. GstPadTemplate * tmpl, const gchar *name);
  68. GstPad *gst_check_setup_sink_pad (GstElement * element,
  69. GstStaticPadTemplate * tmpl);
  70. GstPad *gst_check_setup_sink_pad_from_template (GstElement * element,
  71. GstPadTemplate * tmpl);
  72. GstPad * gst_check_setup_sink_pad_by_name (GstElement * element,
  73. GstStaticPadTemplate * tmpl, const gchar *name);
  74. GstPad * gst_check_setup_sink_pad_by_name_from_template (GstElement * element,
  75. GstPadTemplate * tmpl, const gchar *name);
  76. void gst_check_teardown_pad_by_name (GstElement * element, const gchar *name);
  77. void gst_check_teardown_src_pad (GstElement * element);
  78. void gst_check_drop_buffers (void);
  79. void gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2);
  80. void gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size);
  81. void gst_check_element_push_buffer_list (const gchar * element_name,
  82. GList * buffer_in, GstCaps * caps_in, GList * buffer_out,
  83. GstCaps * caps_out, GstFlowReturn last_flow_return);
  84. void gst_check_element_push_buffer (const gchar * element_name,
  85. GstBuffer * buffer_in, GstCaps * caps_in, GstBuffer * buffer_out,
  86. GstCaps *caps_out);
  87. void gst_check_teardown_sink_pad (GstElement * element);
  88. void gst_check_abi_list (GstCheckABIStruct list[], gboolean have_abi_sizes);
  89. gint gst_check_run_suite (Suite * suite, const gchar * name,
  90. const gchar * fname);
  91. void gst_check_setup_events (GstPad * srcpad, GstElement * element,
  92. GstCaps * caps, GstFormat format);
  93. void gst_check_setup_events_with_stream_id (GstPad * srcpad,
  94. GstElement * element, GstCaps * caps, GstFormat format,
  95. const gchar * stream_id);
  96. #define fail_unless_message_error(msg, domain, code) \
  97. gst_check_message_error (msg, GST_MESSAGE_ERROR, \
  98. GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code)
  99. #define assert_message_error(m, d, c) fail_unless_message_error(m, d, c)
  100. /**
  101. * GST_START_TEST:
  102. * @__testname: test function name
  103. *
  104. * wrapper for checks START_TEST
  105. */
  106. /**
  107. * GST_END_TEST:
  108. *
  109. * wrapper for checks END_TEST
  110. */
  111. #define GST_START_TEST(__testname) \
  112. static void __testname (int __i__)\
  113. {\
  114. GST_DEBUG ("test start"); \
  115. tcase_fn_start (""# __testname, __FILE__, __LINE__);
  116. #define GST_END_TEST GST_LOG ("cleaning up tasks"); \
  117. gst_task_cleanup_all (); \
  118. END_TEST
  119. /* additional fail macros */
  120. /**
  121. * fail_unless_equals_int:
  122. * @a: a #gint value or expression
  123. * @b: a #gint value or expression
  124. *
  125. * This macro checks that @a and @b are equal and aborts if this is not the
  126. * case, printing both expressions and the values they evaluated to. This
  127. * macro is for use in unit tests.
  128. */
  129. #define fail_unless_equals_int(a, b) \
  130. G_STMT_START { \
  131. int first = a; \
  132. int second = b; \
  133. fail_unless(first == second, \
  134. "'" #a "' (%d) is not equal to '" #b"' (%d)", first, second); \
  135. } G_STMT_END;
  136. /**
  137. * assert_equals_int:
  138. * @a: a #gint value or expression
  139. * @b: a #gint value or expression
  140. *
  141. * This macro checks that @a and @b are equal and aborts if this is not the
  142. * case, printing both expressions and the values they evaluated to. This
  143. * macro is for use in unit tests.
  144. */
  145. #define assert_equals_int(a, b) fail_unless_equals_int(a, b)
  146. /**
  147. * fail_unless_equals_int_hex:
  148. * @a: a #gint value or expression
  149. * @b: a #gint value or expression
  150. *
  151. * This macro checks that @a and @b are equal and aborts if this is not the
  152. * case, printing both expressions and the values they evaluated to in
  153. * hexadecimal format. This macro is for use in unit tests.
  154. *
  155. * Since: 1.2
  156. */
  157. #define fail_unless_equals_int_hex(a, b) \
  158. G_STMT_START { \
  159. int first = a; \
  160. int second = b; \
  161. fail_unless(first == second, \
  162. "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second);\
  163. } G_STMT_END;
  164. /**
  165. * assert_equals_int_hex:
  166. * @a: a #gint value or expression
  167. * @b: a #gint value or expression
  168. *
  169. * This macro checks that @a and @b are equal and aborts if this is not the
  170. * case, printing both expressions and the values they evaluated to in
  171. * hexadecimal format. This macro is for use in unit tests.
  172. *
  173. * Since: 1.2
  174. */
  175. #define assert_equals_int_hex(a, b) fail_unless_equals_int_hex(a, b)
  176. /**
  177. * fail_unless_equals_int64:
  178. * @a: a #gint64 value or expression
  179. * @b: a #gint64 value or expression
  180. *
  181. * This macro checks that @a and @b are equal and aborts if this is not the
  182. * case, printing both expressions and the values they evaluated to. This
  183. * macro is for use in unit tests.
  184. */
  185. #define fail_unless_equals_int64(a, b) \
  186. G_STMT_START { \
  187. gint64 first = a; \
  188. gint64 second = b; \
  189. fail_unless(first == second, \
  190. "'" #a "' (%" G_GINT64_FORMAT") is not equal to '" #b"' (%" \
  191. G_GINT64_FORMAT")", first, second); \
  192. } G_STMT_END;
  193. /**
  194. * assert_equals_int64:
  195. * @a: a #gint64 value or expression
  196. * @b: a #gint64 value or expression
  197. *
  198. * This macro checks that @a and @b are equal and aborts if this is not the
  199. * case, printing both expressions and the values they evaluated to. This
  200. * macro is for use in unit tests.
  201. */
  202. #define assert_equals_int64(a, b) fail_unless_equals_int64(a, b)
  203. /**
  204. * fail_unless_equals_int64_hex:
  205. * @a: a #gint64 value or expression
  206. * @b: a #gint64 value or expression
  207. *
  208. * This macro checks that @a and @b are equal and aborts if this is not the
  209. * case, printing both expressions and the values they evaluated to in
  210. * hexadecimal format. This macro is for use in unit tests.
  211. *
  212. * Since: 1.2
  213. */
  214. #define fail_unless_equals_int64_hex(a, b) \
  215. G_STMT_START { \
  216. gint64 first = a; \
  217. gint64 second = b; \
  218. fail_unless(first == second, \
  219. "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
  220. } G_STMT_END;
  221. /**
  222. * assert_equals_int64_hex:
  223. * @a: a #gint64 value or expression
  224. * @b: a #gint64 value or expression
  225. *
  226. * This macro checks that @a and @b are equal and aborts if this is not the
  227. * case, printing both expressions and the values they evaluated to in
  228. * hexadecimal format. This macro is for use in unit tests.
  229. *
  230. * Since: 1.2
  231. */
  232. #define assert_equals_int64_hex(a,b) fail_unless_equals_int64_hex(a,b)
  233. /**
  234. * fail_unless_equals_uint64:
  235. * @a: a #guint64 value or expression
  236. * @b: a #guint64 value or expression
  237. *
  238. * This macro checks that @a and @b are equal and aborts if this is not the
  239. * case, printing both expressions and the values they evaluated to. This
  240. * macro is for use in unit tests.
  241. */
  242. #define fail_unless_equals_uint64(a, b) \
  243. G_STMT_START { \
  244. guint64 first = a; \
  245. guint64 second = b; \
  246. fail_unless(first == second, \
  247. "'" #a "' (%" G_GUINT64_FORMAT ") is not equal to '" #b"' (%" \
  248. G_GUINT64_FORMAT ")", first, second); \
  249. } G_STMT_END;
  250. /**
  251. * assert_equals_uint64:
  252. * @a: a #guint64 value or expression
  253. * @b: a #guint64 value or expression
  254. *
  255. * This macro checks that @a and @b are equal and aborts if this is not the
  256. * case, printing both expressions and the values they evaluated to. This
  257. * macro is for use in unit tests.
  258. */
  259. #define assert_equals_uint64(a, b) fail_unless_equals_uint64(a, b)
  260. /**
  261. * fail_unless_equals_uint64_hex:
  262. * @a: a #gint64 value or expression
  263. * @b: a #gint64 value or expression
  264. *
  265. * This macro checks that @a and @b are equal and aborts if this is not the
  266. * case, printing both expressions and the values they evaluated to in
  267. * hexadecimal format. This macro is for use in unit tests.
  268. *
  269. * Since: 1.2
  270. */
  271. #define fail_unless_equals_uint64_hex(a, b) \
  272. G_STMT_START { \
  273. guint64 first = a; \
  274. guint64 second = b; \
  275. fail_unless(first == second, \
  276. "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\
  277. } G_STMT_END;
  278. /**
  279. * assert_equals_uint64_hex:
  280. * @a: a #guint64 value or expression
  281. * @b: a #guint64 value or expression
  282. *
  283. * This macro checks that @a and @b are equal and aborts if this is not the
  284. * case, printing both expressions and the values they evaluated to in
  285. * hexadecimal format. This macro is for use in unit tests.
  286. *
  287. * Since: 1.2
  288. */
  289. #define assert_equals_uint64_hex(a,b) fail_unless_equals_uint64_hex(a,b)
  290. /**
  291. * fail_unless_equals_string:
  292. * @a: a string literal or expression
  293. * @b: a string literal or expression
  294. *
  295. * This macro checks that @a and @b are equal (as per strcmp) and aborts if
  296. * this is not the case, printing both expressions and the values they
  297. * evaluated to. This macro is for use in unit tests.
  298. */
  299. #define fail_unless_equals_string(a, b) \
  300. G_STMT_START { \
  301. const gchar * first = a; \
  302. const gchar * second = b; \
  303. fail_unless(g_strcmp0 (first, second) == 0, \
  304. "'" #a "' (%s) is not equal to '" #b"' (%s)", first, second); \
  305. } G_STMT_END;
  306. /**
  307. * assert_equals_string:
  308. * @a: a string literal or expression
  309. * @b: a string literal or expression
  310. *
  311. * This macro checks that @a and @b are equal (as per strcmp) and aborts if
  312. * this is not the case, printing both expressions and the values they
  313. * evaluated to. This macro is for use in unit tests.
  314. */
  315. #define assert_equals_string(a, b) fail_unless_equals_string(a, b)
  316. /**
  317. * fail_unless_equals_float:
  318. * @a: a #gdouble or #gfloat value or expression
  319. * @b: a #gdouble or #gfloat value or expression
  320. *
  321. * This macro checks that @a and @b are (almost) equal and aborts if this
  322. * is not the case, printing both expressions and the values they evaluated
  323. * to. This macro is for use in unit tests.
  324. */
  325. #define fail_unless_equals_float(a, b) \
  326. G_STMT_START { \
  327. double first = a; \
  328. double second = b; \
  329. /* This will only work for 'normal' values and values around 0, \
  330. * which should be good enough for our purposes here */ \
  331. fail_unless(fabs (first - second) < 0.0000001, \
  332. "'" #a "' (%g) is not equal to '" #b "' (%g)", first, second);\
  333. } G_STMT_END;
  334. /**
  335. * assert_equals_float:
  336. * @a: a #gdouble or #gfloat value or expression
  337. * @b: a #gdouble or #gfloat value or expression
  338. *
  339. * This macro checks that @a and @b are (almost) equal and aborts if this
  340. * is not the case, printing both expressions and the values they evaluated
  341. * to. This macro is for use in unit tests.
  342. */
  343. #define assert_equals_float(a, b) fail_unless_equals_float(a, b)
  344. /**
  345. * fail_unless_equals_pointer:
  346. * @a: a pointer value or expression
  347. * @b: a pointer value or expression
  348. *
  349. * This macro checks that @a and @b are equal and aborts if this
  350. * is not the case, printing both expressions and the values they
  351. * evaluated to. This macro is for use in unit tests.
  352. *
  353. * Since: 1.2
  354. */
  355. #define fail_unless_equals_pointer(a, b) \
  356. G_STMT_START { \
  357. gpointer first = a; \
  358. gpointer second = b; \
  359. fail_unless(first == second, \
  360. "'" #a "' (%p) is not equal to '" #b "' (%p)", first, second);\
  361. } G_STMT_END;
  362. /**
  363. * assert_equals_pointer:
  364. * @a: a pointer value or expression
  365. * @b: a pointer value or expression
  366. *
  367. * This macro checks that @a and @b are equal and aborts if this
  368. * is not the case, printing both expressions and the values they
  369. * evaluated to. This macro is for use in unit tests.
  370. *
  371. * Since: 1.2
  372. */
  373. #define assert_equals_pointer(a, b) fail_unless_equals_pointer(a, b)
  374. /***
  375. * thread test macros and variables
  376. */
  377. extern GList *thread_list;
  378. extern GMutex mutex;
  379. extern GCond start_cond; /* used to notify main thread of thread startups */
  380. extern GCond sync_cond; /* used to synchronize all threads and main thread */
  381. #define MAIN_START_THREADS(count, function, data) \
  382. MAIN_INIT(); \
  383. MAIN_START_THREAD_FUNCTIONS(count, function, data); \
  384. MAIN_SYNCHRONIZE();
  385. #define MAIN_INIT() \
  386. G_STMT_START { \
  387. g_mutex_init (&mutex); \
  388. g_cond_init (&start_cond); \
  389. g_cond_init (&sync_cond); \
  390. _gst_check_threads_running = TRUE; \
  391. } G_STMT_END;
  392. #define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
  393. G_STMT_START { \
  394. int i; \
  395. for (i = 0; i < count; ++i) { \
  396. MAIN_START_THREAD_FUNCTION (i, function, data); \
  397. } \
  398. } G_STMT_END;
  399. #define MAIN_START_THREAD_FUNCTION(i, function, data) \
  400. G_STMT_START { \
  401. GThread *thread = NULL; \
  402. GST_DEBUG ("MAIN: creating thread %d", i); \
  403. g_mutex_lock (&mutex); \
  404. thread = g_thread_try_new ("gst-check", \
  405. (GThreadFunc) function, data, NULL); \
  406. /* wait for thread to signal us that it's ready */ \
  407. GST_DEBUG ("MAIN: waiting for thread %d", i); \
  408. g_cond_wait (&start_cond, &mutex); \
  409. g_mutex_unlock (&mutex); \
  410. \
  411. thread_list = g_list_append (thread_list, thread); \
  412. } G_STMT_END;
  413. #define MAIN_SYNCHRONIZE() \
  414. G_STMT_START { \
  415. GST_DEBUG ("MAIN: synchronizing"); \
  416. g_cond_broadcast (&sync_cond); \
  417. GST_DEBUG ("MAIN: synchronized"); \
  418. } G_STMT_END;
  419. #define MAIN_STOP_THREADS() \
  420. G_STMT_START { \
  421. _gst_check_threads_running = FALSE; \
  422. \
  423. /* join all threads */ \
  424. GST_DEBUG ("MAIN: joining"); \
  425. g_list_foreach (thread_list, (GFunc) g_thread_join, NULL); \
  426. g_list_free (thread_list); \
  427. thread_list = NULL; \
  428. g_mutex_clear (&mutex); \
  429. g_cond_clear (&start_cond); \
  430. g_cond_clear (&sync_cond); \
  431. GST_DEBUG ("MAIN: joined"); \
  432. } G_STMT_END;
  433. #define THREAD_START() \
  434. THREAD_STARTED(); \
  435. THREAD_SYNCHRONIZE();
  436. #define THREAD_STARTED() \
  437. G_STMT_START { \
  438. /* signal main thread that we started */ \
  439. GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
  440. g_mutex_lock (&mutex); \
  441. g_cond_signal (&start_cond); \
  442. } G_STMT_END;
  443. #define THREAD_SYNCHRONIZE() \
  444. G_STMT_START { \
  445. /* synchronize everyone */ \
  446. GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
  447. fail_if (g_mutex_trylock (&mutex), \
  448. "bug in unit test, mutex should be locked at this point");\
  449. g_cond_wait (&sync_cond, &mutex); \
  450. GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
  451. g_mutex_unlock (&mutex); \
  452. } G_STMT_END;
  453. #define THREAD_SWITCH() \
  454. G_STMT_START { \
  455. /* a minimal sleep is a context switch */ \
  456. g_usleep (1); \
  457. } G_STMT_END;
  458. #define THREAD_TEST_RUNNING() (_gst_check_threads_running == TRUE)
  459. /* additional assertions */
  460. #define ASSERT_CRITICAL(code) \
  461. G_STMT_START { \
  462. _gst_check_expecting_log = TRUE; \
  463. _gst_check_raised_critical = FALSE; \
  464. code; \
  465. _fail_unless (_gst_check_raised_critical, __FILE__, __LINE__, \
  466. "Expected g_critical, got nothing", NULL); \
  467. _gst_check_expecting_log = FALSE; \
  468. } G_STMT_END
  469. #define ASSERT_WARNING(code) \
  470. G_STMT_START { \
  471. _gst_check_expecting_log = TRUE; \
  472. _gst_check_raised_warning = FALSE; \
  473. code; \
  474. _fail_unless (_gst_check_raised_warning, __FILE__, __LINE__, \
  475. "Expected g_warning, got nothing", NULL); \
  476. _gst_check_expecting_log = FALSE; \
  477. } G_STMT_END
  478. #define ASSERT_OBJECT_REFCOUNT(object, name, value) \
  479. G_STMT_START { \
  480. int rc; \
  481. rc = GST_OBJECT_REFCOUNT_VALUE (object); \
  482. fail_unless (rc == value, \
  483. "%s (%p) refcount is %d instead of %d", \
  484. name, object, rc, value); \
  485. } G_STMT_END
  486. #define ASSERT_OBJECT_REFCOUNT_BETWEEN(object, name, lower, upper) \
  487. G_STMT_START { \
  488. int rc = GST_OBJECT_REFCOUNT_VALUE (object); \
  489. int lo = lower; \
  490. int hi = upper; \
  491. \
  492. fail_unless (rc >= lo, \
  493. "%s (%p) refcount %d is smaller than %d", \
  494. name, object, rc, lo); \
  495. fail_unless (rc <= hi, \
  496. "%s (%p) refcount %d is bigger than %d", \
  497. name, object, rc, hi); \
  498. } G_STMT_END
  499. #define ASSERT_CAPS_REFCOUNT(caps, name, value) \
  500. ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
  501. #define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
  502. ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
  503. #define ASSERT_MINI_OBJECT_REFCOUNT(miniobj, name, value) \
  504. G_STMT_START { \
  505. int rc; \
  506. rc = GST_MINI_OBJECT_REFCOUNT_VALUE (miniobj); \
  507. fail_unless (rc == value, \
  508. name " (%p) refcount is %d instead of %d", miniobj, rc, value); \
  509. } G_STMT_END
  510. #define ASSERT_SET_STATE(element, state, ret) \
  511. fail_unless (gst_element_set_state (element, \
  512. state) == ret, \
  513. "could not change state to " #state);
  514. #define GST_CHECK_MAIN(name) \
  515. int main (int argc, char **argv) \
  516. { \
  517. Suite *s; \
  518. gst_check_init (&argc, &argv); \
  519. s = name ## _suite (); \
  520. return gst_check_run_suite (s, # name, __FILE__); \
  521. }
  522. /* Hack to allow run-time selection of unit tests to run via the
  523. * GST_CHECKS environment variable (test function names globs, comma
  524. * separated), or GST_CHECKS_IGNORE with the same semantics */
  525. gboolean _gst_check_run_test_func (const gchar * func_name);
  526. static inline void
  527. __gst_tcase_add_test (TCase * tc, TFun tf, const char * fname, int signal,
  528. int allowed_exit_value, int start, int end)
  529. {
  530. if (_gst_check_run_test_func (fname)) {
  531. _tcase_add_test (tc, tf, fname, signal, allowed_exit_value, start, end);
  532. }
  533. }
  534. #define _tcase_add_test __gst_tcase_add_test
  535. /* A special variant to add broken tests. These are normally skipped, but can be
  536. * forced to run via GST_CHECKS */
  537. #define tcase_skip_broken_test(chain,test_func) \
  538. G_STMT_START { \
  539. const char *env = g_getenv ("GST_CHECKS"); \
  540. \
  541. if (env != NULL && g_pattern_match_simple (env, G_STRINGIFY (test_func))) { \
  542. tcase_add_test(chain,test_func); \
  543. } else { \
  544. g_printerr ("FIXME: skipping test %s because it's broken\n", G_STRINGIFY (test_func)); \
  545. } \
  546. } G_STMT_END
  547. G_END_DECLS
  548. #endif /* __GST_CHECK_H__ */