2009-07-16 17:39:16 +00:00
|
|
|
/*
|
|
|
|
* Check: a unit test framework for C
|
|
|
|
* Copyright (C) 2001, 2002 Arien Malec
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-07-16 17:39:16 +00:00
|
|
|
*/
|
|
|
|
|
check: Apply GStreamer-specific patches
Reintroduced patches:
* Make sure that fail_if(1) actually fails
from commit 9f99d056a263e71a5e6181224829def906cf0226
New patches due to updated libcheck (based on 0.9.14):
* Checks in m4/check-checks.m4 to cater for new dependencies
* Conditional compile-time compat POSIX fallbacks for libcheck
* Avoid relative paths for libcheck header files
* Make timer_create() usage depend on posix timers, not librt
* Rely on default AX_PTHREAD behavior to allow HAVE_PTHREAD to be used
when checking for types and functions (like clock_gettime())
* Avoid double declaration of clock_gettime() when availabe outside of
librt by making compat clock_gettime() declaration conditional
* check 0.9.9 renamed _fail_unless() and 0.9.12 later renamed it again
to _ck_assert_failed(), so ASSERT_{CRITICAL,WARNING}() now calls this
function
* Remove libcheck fallback infrastructure for malloc(), realloc(),
gettimeofday() and snprintf() since either they appear to be
available or they introduce even more dependencies.
The result is an embedded check in gstreamer that has been tested by
running check tests in core, -base, -good, -bad, -ugly and rtsp-server
on Linux, OSX and Windows.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=727826
2014-11-15 12:26:47 +00:00
|
|
|
#include "libcompat.h"
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2014-11-15 11:53:32 +00:00
|
|
|
#include <math.h>
|
2009-07-16 17:39:16 +00:00
|
|
|
|
2014-12-14 11:54:32 +00:00
|
|
|
#include "internal-check.h"
|
2009-07-16 17:39:16 +00:00
|
|
|
#include "check_error.h"
|
|
|
|
#include "check_list.h"
|
|
|
|
#include "check_impl.h"
|
|
|
|
#include "check_msg.h"
|
|
|
|
|
check: Apply GStreamer-specific patches
Reintroduced patches:
* Make sure that fail_if(1) actually fails
from commit 9f99d056a263e71a5e6181224829def906cf0226
New patches due to updated libcheck (based on 0.9.14):
* Checks in m4/check-checks.m4 to cater for new dependencies
* Conditional compile-time compat POSIX fallbacks for libcheck
* Avoid relative paths for libcheck header files
* Make timer_create() usage depend on posix timers, not librt
* Rely on default AX_PTHREAD behavior to allow HAVE_PTHREAD to be used
when checking for types and functions (like clock_gettime())
* Avoid double declaration of clock_gettime() when availabe outside of
librt by making compat clock_gettime() declaration conditional
* check 0.9.9 renamed _fail_unless() and 0.9.12 later renamed it again
to _ck_assert_failed(), so ASSERT_{CRITICAL,WARNING}() now calls this
function
* Remove libcheck fallback infrastructure for malloc(), realloc(),
gettimeofday() and snprintf() since either they appear to be
available or they introduce even more dependencies.
The result is an embedded check in gstreamer that has been tested by
running check tests in core, -base, -good, -bad, -ugly and rtsp-server
on Linux, OSX and Windows.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=727826
2014-11-15 12:26:47 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h> /* for _POSIX_VERSION */
|
|
|
|
#endif
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
#ifndef DEFAULT_TIMEOUT
|
|
|
|
#define DEFAULT_TIMEOUT 4
|
|
|
|
#endif
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
/*
|
|
|
|
* When a process exits either normally, with exit(), or
|
|
|
|
* by an uncaught signal, The lower 0x377 bits are passed
|
|
|
|
* to the parent. Of those, only the lower 8 bits are
|
|
|
|
* returned by the WEXITSTATUS() macro.
|
|
|
|
*/
|
|
|
|
#define WEXITSTATUS_MASK 0xFF
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
int check_major_version = CHECK_MAJOR_VERSION;
|
|
|
|
int check_minor_version = CHECK_MINOR_VERSION;
|
|
|
|
int check_micro_version = CHECK_MICRO_VERSION;
|
|
|
|
|
|
|
|
static int non_pass (int val);
|
|
|
|
static Fixture *fixture_create (SFun fun, int ischecked);
|
2009-10-12 11:49:35 +00:00
|
|
|
static void tcase_add_fixture (TCase * tc, SFun setup, SFun teardown,
|
|
|
|
int ischecked);
|
|
|
|
static void tr_init (TestResult * tr);
|
|
|
|
static void suite_free (Suite * s);
|
|
|
|
static void tcase_free (TCase * tc);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
Suite *
|
|
|
|
suite_create (const char *name)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
Suite *s;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
s = (Suite *) emalloc (sizeof (Suite)); /* freed in suite_free */
|
2009-07-16 17:39:16 +00:00
|
|
|
if (name == NULL)
|
|
|
|
s->name = "";
|
|
|
|
else
|
|
|
|
s->name = name;
|
2009-10-12 11:49:35 +00:00
|
|
|
s->tclst = check_list_create ();
|
2009-07-16 17:39:16 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
int
|
|
|
|
suite_tcase (Suite * s, const char *tcname)
|
|
|
|
{
|
|
|
|
List *l;
|
|
|
|
TCase *tc;
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
l = s->tclst;
|
|
|
|
for (check_list_front (l); !check_list_at_end (l); check_list_advance (l)) {
|
|
|
|
tc = (TCase *) check_list_val (l);
|
|
|
|
if (strcmp (tcname, tc->name) == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
suite_free (Suite * s)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
List *l;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
l = s->tclst;
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (l); !check_list_at_end (l); check_list_advance (l)) {
|
|
|
|
tcase_free ((TCase *) check_list_val (l));
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_free (s->tclst);
|
2009-10-12 11:49:35 +00:00
|
|
|
free (s);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
TCase *
|
|
|
|
tcase_create (const char *name)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
char *env;
|
2014-11-15 11:53:32 +00:00
|
|
|
double timeout_sec = DEFAULT_TIMEOUT;
|
|
|
|
|
|
|
|
TCase *tc = (TCase *) emalloc (sizeof (TCase)); /*freed in tcase_free */
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (name == NULL)
|
|
|
|
tc->name = "";
|
|
|
|
else
|
|
|
|
tc->name = name;
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
env = getenv ("CK_DEFAULT_TIMEOUT");
|
2009-07-16 17:39:16 +00:00
|
|
|
if (env != NULL) {
|
2014-11-15 11:53:32 +00:00
|
|
|
char *endptr = NULL;
|
|
|
|
double tmp = strtod (env, &endptr);
|
|
|
|
|
|
|
|
if (tmp >= 0 && endptr != env && (*endptr) == '\0') {
|
|
|
|
timeout_sec = tmp;
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-12-17 20:09:48 +00:00
|
|
|
env = getenv ("CK_TIMEOUT_MULTIPLIER");
|
|
|
|
if (env != NULL) {
|
2014-11-15 11:53:32 +00:00
|
|
|
char *endptr = NULL;
|
|
|
|
double tmp = strtod (env, &endptr);
|
|
|
|
|
|
|
|
if (tmp >= 0 && endptr != env && (*endptr) == '\0') {
|
|
|
|
timeout_sec = timeout_sec * tmp;
|
2009-12-17 20:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
tc->timeout.tv_sec = (time_t) floor (timeout_sec);
|
|
|
|
tc->timeout.tv_nsec =
|
|
|
|
(long) ((timeout_sec - floor (timeout_sec)) * (double) NANOS_PER_SECONDS);
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
tc->tflst = check_list_create ();
|
|
|
|
tc->unch_sflst = check_list_create ();
|
|
|
|
tc->ch_sflst = check_list_create ();
|
|
|
|
tc->unch_tflst = check_list_create ();
|
|
|
|
tc->ch_tflst = check_list_create ();
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
tcase_free (TCase * tc)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_apply (tc->tflst, free);
|
|
|
|
check_list_apply (tc->unch_sflst, free);
|
|
|
|
check_list_apply (tc->ch_sflst, free);
|
|
|
|
check_list_apply (tc->unch_tflst, free);
|
|
|
|
check_list_apply (tc->ch_tflst, free);
|
|
|
|
check_list_free (tc->tflst);
|
|
|
|
check_list_free (tc->unch_sflst);
|
|
|
|
check_list_free (tc->ch_sflst);
|
|
|
|
check_list_free (tc->unch_tflst);
|
|
|
|
check_list_free (tc->ch_tflst);
|
2009-10-12 11:49:35 +00:00
|
|
|
|
|
|
|
free (tc);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
suite_add_tcase (Suite * s, TCase * tc)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (s == NULL || tc == NULL)
|
|
|
|
return;
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (s->tclst, tc);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2009-12-17 20:09:48 +00:00
|
|
|
_tcase_add_test (TCase * tc, TFun fn, const char *name, int _signal,
|
|
|
|
int allowed_exit_value, int start, int end)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2009-10-12 11:49:35 +00:00
|
|
|
TF *tf;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (tc == NULL || fn == NULL || name == NULL)
|
|
|
|
return;
|
2014-11-15 11:53:32 +00:00
|
|
|
tf = (TF *) emalloc (sizeof (TF)); /* freed in tcase_free */
|
2009-07-16 17:39:16 +00:00
|
|
|
tf->fn = fn;
|
|
|
|
tf->loop_start = start;
|
|
|
|
tf->loop_end = end;
|
2009-10-12 11:49:35 +00:00
|
|
|
tf->signal = _signal; /* 0 means no signal expected */
|
2014-11-15 11:53:32 +00:00
|
|
|
tf->allowed_exit_value = (WEXITSTATUS_MASK & allowed_exit_value); /* 0 is default successful exit */
|
2009-07-16 17:39:16 +00:00
|
|
|
tf->name = name;
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (tc->tflst, tf);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static Fixture *
|
|
|
|
fixture_create (SFun fun, int ischecked)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
Fixture *f;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
f = (Fixture *) emalloc (sizeof (Fixture));
|
2009-07-16 17:39:16 +00:00
|
|
|
f->fun = fun;
|
|
|
|
f->ischecked = ischecked;
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
tcase_add_unchecked_fixture (TCase * tc, SFun setup, SFun teardown)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2009-10-12 11:49:35 +00:00
|
|
|
tcase_add_fixture (tc, setup, teardown, 0);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
tcase_add_checked_fixture (TCase * tc, SFun setup, SFun teardown)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2009-10-12 11:49:35 +00:00
|
|
|
tcase_add_fixture (tc, setup, teardown, 1);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
tcase_add_fixture (TCase * tc, SFun setup, SFun teardown, int ischecked)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (setup) {
|
|
|
|
if (ischecked)
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (tc->ch_sflst, fixture_create (setup, ischecked));
|
2009-07-16 17:39:16 +00:00
|
|
|
else
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (tc->unch_sflst, fixture_create (setup, ischecked));
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add teardowns at front so they are run in reverse order. */
|
|
|
|
if (teardown) {
|
|
|
|
if (ischecked)
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_front (tc->ch_tflst, fixture_create (teardown, ischecked));
|
2009-07-16 17:39:16 +00:00
|
|
|
else
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_front (tc->unch_tflst,
|
|
|
|
fixture_create (teardown, ischecked));
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2014-11-15 11:53:32 +00:00
|
|
|
tcase_set_timeout (TCase * tc, double timeout)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2014-11-15 11:53:32 +00:00
|
|
|
#if defined(HAVE_FORK)
|
2009-12-17 20:09:48 +00:00
|
|
|
if (timeout >= 0) {
|
|
|
|
char *env = getenv ("CK_TIMEOUT_MULTIPLIER");
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-12-17 20:09:48 +00:00
|
|
|
if (env != NULL) {
|
2014-11-15 11:53:32 +00:00
|
|
|
char *endptr = NULL;
|
|
|
|
double tmp = strtod (env, &endptr);
|
|
|
|
|
|
|
|
if (tmp >= 0 && endptr != env && (*endptr) == '\0') {
|
2009-12-17 20:09:48 +00:00
|
|
|
timeout = timeout * tmp;
|
|
|
|
}
|
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
tc->timeout.tv_sec = (time_t) floor (timeout);
|
|
|
|
tc->timeout.tv_nsec =
|
|
|
|
(long) ((timeout - floor (timeout)) * (double) NANOS_PER_SECONDS);
|
2009-12-17 20:09:48 +00:00
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
#else
|
|
|
|
(void) tc;
|
|
|
|
(void) timeout;
|
|
|
|
eprintf
|
|
|
|
("This version does not support timeouts, as fork is not supported",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
#endif /* HAVE_FORK */
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2009-12-17 20:09:48 +00:00
|
|
|
tcase_fn_start (const char *fname CK_ATTRIBUTE_UNUSED, const char *file,
|
|
|
|
int line)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
send_ctx_info (CK_CTX_TEST);
|
|
|
|
send_loc_info (file, line);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
_mark_point (const char *file, int line)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
send_loc_info (file, line);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2014-11-15 11:53:32 +00:00
|
|
|
_ck_assert_failed (const char *file, int line, const char *expr, ...)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
const char *msg;
|
2014-11-15 11:53:32 +00:00
|
|
|
va_list ap;
|
|
|
|
char buf[BUFSIZ];
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
send_loc_info (file, line);
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
va_start (ap, expr);
|
|
|
|
msg = (const char *) va_arg (ap, char *);
|
|
|
|
|
|
|
|
if (msg == NULL)
|
|
|
|
msg = expr;
|
|
|
|
vsnprintf (buf, BUFSIZ, msg, ap);
|
|
|
|
va_end (ap);
|
|
|
|
send_failure_info (buf);
|
|
|
|
if (cur_fork_status () == CK_FORK) {
|
|
|
|
#if defined(HAVE_FORK) && HAVE_FORK==1
|
|
|
|
_exit (1);
|
|
|
|
#endif /* HAVE_FORK */
|
|
|
|
} else {
|
|
|
|
longjmp (error_jmp_buffer, 1);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
SRunner *
|
|
|
|
srunner_create (Suite * s)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2014-11-15 11:53:32 +00:00
|
|
|
SRunner *sr = (SRunner *) emalloc (sizeof (SRunner)); /* freed in srunner_free */
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
sr->slst = check_list_create ();
|
2009-07-16 17:39:16 +00:00
|
|
|
if (s != NULL)
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (sr->slst, s);
|
|
|
|
sr->stats = (TestStats *) emalloc (sizeof (TestStats)); /* freed in srunner_free */
|
2009-07-16 17:39:16 +00:00
|
|
|
sr->stats->n_checked = sr->stats->n_failed = sr->stats->n_errors = 0;
|
2009-10-12 11:49:35 +00:00
|
|
|
sr->resultlst = check_list_create ();
|
2009-07-16 17:39:16 +00:00
|
|
|
sr->log_fname = NULL;
|
|
|
|
sr->xml_fname = NULL;
|
2014-11-15 11:53:32 +00:00
|
|
|
sr->tap_fname = NULL;
|
2009-07-16 17:39:16 +00:00
|
|
|
sr->loglst = NULL;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_FORK)
|
2009-07-16 17:39:16 +00:00
|
|
|
sr->fstat = CK_FORK_GETENV;
|
2014-11-15 11:53:32 +00:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Overriding the default of running tests in fork mode,
|
|
|
|
* as this system does not have fork()
|
|
|
|
*/
|
|
|
|
sr->fstat = CK_NOFORK;
|
|
|
|
#endif /* HAVE_FORK */
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
srunner_add_suite (SRunner * sr, Suite * s)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_add_end (sr->slst, s);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
srunner_free (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
List *l;
|
|
|
|
TestResult *tr;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (sr == NULL)
|
|
|
|
return;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
free (sr->stats);
|
|
|
|
l = sr->slst;
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (l); !check_list_at_end (l); check_list_advance (l)) {
|
|
|
|
suite_free ((Suite *) check_list_val (l));
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_free (sr->slst);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
l = sr->resultlst;
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (l); !check_list_at_end (l); check_list_advance (l)) {
|
|
|
|
tr = (TestResult *) check_list_val (l);
|
|
|
|
tr_free (tr);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
check_list_free (sr->resultlst);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
free (sr);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
int
|
|
|
|
srunner_ntests_failed (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return sr->stats->n_failed + sr->stats->n_errors;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
int
|
|
|
|
srunner_ntests_run (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return sr->stats->n_checked;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
TestResult **
|
|
|
|
srunner_failures (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
TestResult **trarray;
|
|
|
|
List *rlst;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
trarray =
|
|
|
|
(TestResult **) emalloc (sizeof (trarray[0]) *
|
|
|
|
srunner_ntests_failed (sr));
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
rlst = sr->resultlst;
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (rlst); !check_list_at_end (rlst);
|
|
|
|
check_list_advance (rlst)) {
|
|
|
|
TestResult *tr = (TestResult *) check_list_val (rlst);
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
if (non_pass (tr->rtype))
|
2009-07-16 17:39:16 +00:00
|
|
|
trarray[i++] = tr;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
return trarray;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
TestResult **
|
|
|
|
srunner_results (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
TestResult **trarray;
|
|
|
|
List *rlst;
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
trarray =
|
|
|
|
(TestResult **) emalloc (sizeof (trarray[0]) * srunner_ntests_run (sr));
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
rlst = sr->resultlst;
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (rlst); !check_list_at_end (rlst);
|
|
|
|
check_list_advance (rlst)) {
|
|
|
|
trarray[i++] = (TestResult *) check_list_val (rlst);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
return trarray;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static int
|
|
|
|
non_pass (int val)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return val != CK_PASS;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
TestResult *
|
|
|
|
tr_create (void)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
TestResult *tr;
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
tr = (TestResult *) emalloc (sizeof (TestResult));
|
2009-07-16 17:39:16 +00:00
|
|
|
tr_init (tr);
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
tr_init (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
tr->ctx = CK_CTX_INVALID;
|
|
|
|
tr->line = -1;
|
|
|
|
tr->rtype = CK_TEST_RESULT_INVALID;
|
|
|
|
tr->msg = NULL;
|
|
|
|
tr->file = NULL;
|
|
|
|
tr->tcname = NULL;
|
|
|
|
tr->tname = NULL;
|
2014-11-15 11:53:32 +00:00
|
|
|
tr->duration = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tr_free (TestResult * tr)
|
|
|
|
{
|
|
|
|
free (tr->file);
|
|
|
|
free (tr->msg);
|
|
|
|
free (tr);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
const char *
|
|
|
|
tr_msg (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->msg;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
int
|
|
|
|
tr_lno (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->line;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
const char *
|
|
|
|
tr_lfile (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->file;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
int
|
|
|
|
tr_rtype (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->rtype;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
enum ck_result_ctx
|
|
|
|
tr_ctx (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->ctx;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
const char *
|
|
|
|
tr_tcname (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return tr->tcname;
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
static enum fork_status _fstat = CK_FORK;
|
2009-07-16 17:39:16 +00:00
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
set_fork_status (enum fork_status fstat)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (fstat == CK_FORK || fstat == CK_NOFORK || fstat == CK_FORK_GETENV)
|
|
|
|
_fstat = fstat;
|
|
|
|
else
|
|
|
|
eprintf ("Bad status in set_fork_status", __FILE__, __LINE__);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
enum fork_status
|
|
|
|
cur_fork_status (void)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
return _fstat;
|
|
|
|
}
|
2014-11-15 11:53:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Not all systems support the same clockid_t's. This call checks
|
|
|
|
* if the CLOCK_MONOTONIC clockid_t is valid. If so, that is returned,
|
|
|
|
* otherwise, CLOCK_REALTIME is returned.
|
|
|
|
*
|
|
|
|
* The clockid_t that was found to work on the first call is
|
|
|
|
* cached for subsequent calls.
|
|
|
|
*/
|
|
|
|
clockid_t
|
|
|
|
check_get_clockid ()
|
|
|
|
{
|
|
|
|
static clockid_t clockid = -1;
|
|
|
|
|
|
|
|
if (clockid == -1) {
|
|
|
|
/*
|
|
|
|
* Only check if we have librt available. Otherwise, the clockid
|
|
|
|
* will be ignored anyway, as the clock_gettime() and
|
|
|
|
* timer_create() functions will be re-implemented in libcompat.
|
|
|
|
* Worse, if librt and alarm() are unavailable, this check
|
|
|
|
* will result in an assert(0).
|
|
|
|
*/
|
check: Apply GStreamer-specific patches
Reintroduced patches:
* Make sure that fail_if(1) actually fails
from commit 9f99d056a263e71a5e6181224829def906cf0226
New patches due to updated libcheck (based on 0.9.14):
* Checks in m4/check-checks.m4 to cater for new dependencies
* Conditional compile-time compat POSIX fallbacks for libcheck
* Avoid relative paths for libcheck header files
* Make timer_create() usage depend on posix timers, not librt
* Rely on default AX_PTHREAD behavior to allow HAVE_PTHREAD to be used
when checking for types and functions (like clock_gettime())
* Avoid double declaration of clock_gettime() when availabe outside of
librt by making compat clock_gettime() declaration conditional
* check 0.9.9 renamed _fail_unless() and 0.9.12 later renamed it again
to _ck_assert_failed(), so ASSERT_{CRITICAL,WARNING}() now calls this
function
* Remove libcheck fallback infrastructure for malloc(), realloc(),
gettimeofday() and snprintf() since either they appear to be
available or they introduce even more dependencies.
The result is an embedded check in gstreamer that has been tested by
running check tests in core, -base, -good, -bad, -ugly and rtsp-server
on Linux, OSX and Windows.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=727826
2014-11-15 12:26:47 +00:00
|
|
|
#if defined(HAVE_POSIX_TIMERS) && defined(HAVE_MONOTONIC_CLOCK)
|
2014-11-15 11:53:32 +00:00
|
|
|
timer_t timerid;
|
|
|
|
|
|
|
|
if (timer_create (CLOCK_MONOTONIC, NULL, &timerid) == 0) {
|
|
|
|
timer_delete (timerid);
|
|
|
|
clockid = CLOCK_MONOTONIC;
|
|
|
|
} else {
|
|
|
|
clockid = CLOCK_REALTIME;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
clockid = CLOCK_MONOTONIC;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return clockid;
|
|
|
|
}
|