mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
libs/gst/check: Run gst-indent on libcheck.
This commit is contained in:
parent
7f68d7a6f8
commit
bf3ab71a2b
9 changed files with 825 additions and 704 deletions
|
@ -41,11 +41,11 @@ int check_micro_version = CHECK_MICRO_VERSION;
|
|||
|
||||
static int non_pass (int val);
|
||||
static Fixture *fixture_create (SFun fun, int ischecked);
|
||||
static void tcase_add_fixture (TCase *tc, SFun setup, SFun teardown,
|
||||
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);
|
||||
static void tr_init (TestResult * tr);
|
||||
static void suite_free (Suite * s);
|
||||
static void tcase_free (TCase * tc);
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
|
@ -58,11 +58,11 @@ static void tcase_free (TCase *tc);
|
|||
|
||||
void *malloc (size_t n);
|
||||
void *realloc (void *p, size_t n);
|
||||
char *strsignal(int sig);
|
||||
char *strsignal (int sig);
|
||||
|
||||
void *rpl_malloc (size_t n);
|
||||
void *rpl_realloc (void *p, size_t n);
|
||||
static const char *rpl_strsignal(int sig);
|
||||
static const char *rpl_strsignal (int sig);
|
||||
|
||||
/* Allocate an N-byte block of memory from the heap. If N is zero,
|
||||
allocate a 1-byte block. */
|
||||
|
@ -102,93 +102,100 @@ rpl_strsignal (int sig)
|
|||
{
|
||||
static char signame[40];
|
||||
|
||||
sprintf(signame, "SIG #%d", sig);
|
||||
sprintf (signame, "SIG #%d", sig);
|
||||
return signame;
|
||||
}
|
||||
|
||||
Suite *suite_create (const char *name)
|
||||
Suite *
|
||||
suite_create (const char *name)
|
||||
{
|
||||
Suite *s;
|
||||
s = emalloc (sizeof(Suite)); /* freed in suite_free */
|
||||
s = emalloc (sizeof (Suite)); /* freed in suite_free */
|
||||
if (name == NULL)
|
||||
s->name = "";
|
||||
else
|
||||
s->name = name;
|
||||
s->tclst = check_list_create();
|
||||
s->tclst = check_list_create ();
|
||||
return s;
|
||||
}
|
||||
|
||||
static void suite_free (Suite *s)
|
||||
static void
|
||||
suite_free (Suite * s)
|
||||
{
|
||||
List *l;
|
||||
if (s == NULL)
|
||||
return;
|
||||
l = s->tclst;
|
||||
for (list_front(l); !list_at_end(l); list_advance (l)) {
|
||||
tcase_free (list_val(l));
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
tcase_free (list_val (l));
|
||||
}
|
||||
list_free (s->tclst);
|
||||
free(s);
|
||||
free (s);
|
||||
}
|
||||
|
||||
TCase *tcase_create (const char *name)
|
||||
TCase *
|
||||
tcase_create (const char *name)
|
||||
{
|
||||
char *env;
|
||||
int timeout = DEFAULT_TIMEOUT;
|
||||
TCase *tc = emalloc (sizeof(TCase)); /*freed in tcase_free */
|
||||
TCase *tc = emalloc (sizeof (TCase)); /*freed in tcase_free */
|
||||
if (name == NULL)
|
||||
tc->name = "";
|
||||
else
|
||||
tc->name = name;
|
||||
|
||||
env = getenv("CK_DEFAULT_TIMEOUT");
|
||||
env = getenv ("CK_DEFAULT_TIMEOUT");
|
||||
if (env != NULL) {
|
||||
int tmp = atoi(env);
|
||||
int tmp = atoi (env);
|
||||
if (tmp >= 0) {
|
||||
timeout = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
tc->timeout = timeout;
|
||||
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();
|
||||
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 ();
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
|
||||
static void tcase_free (TCase *tc)
|
||||
static void
|
||||
tcase_free (TCase * tc)
|
||||
{
|
||||
list_apply (tc->tflst, free);
|
||||
list_apply (tc->unch_sflst, free);
|
||||
list_apply (tc->ch_sflst, free);
|
||||
list_apply (tc->unch_tflst, free);
|
||||
list_apply (tc->ch_tflst, free);
|
||||
list_free(tc->tflst);
|
||||
list_free(tc->unch_sflst);
|
||||
list_free(tc->ch_sflst);
|
||||
list_free(tc->unch_tflst);
|
||||
list_free(tc->ch_tflst);
|
||||
list_free (tc->tflst);
|
||||
list_free (tc->unch_sflst);
|
||||
list_free (tc->ch_sflst);
|
||||
list_free (tc->unch_tflst);
|
||||
list_free (tc->ch_tflst);
|
||||
|
||||
free(tc);
|
||||
free (tc);
|
||||
}
|
||||
|
||||
void suite_add_tcase (Suite *s, TCase *tc)
|
||||
void
|
||||
suite_add_tcase (Suite * s, TCase * tc)
|
||||
{
|
||||
if (s == NULL || tc == NULL)
|
||||
return;
|
||||
list_add_end (s->tclst, tc);
|
||||
}
|
||||
|
||||
void _tcase_add_test (TCase *tc, TFun fn, const char *name, int _signal, int start, int end)
|
||||
void
|
||||
_tcase_add_test (TCase * tc, TFun fn, const char *name, int _signal, int start,
|
||||
int end)
|
||||
{
|
||||
TF * tf;
|
||||
TF *tf;
|
||||
if (tc == NULL || fn == NULL || name == NULL)
|
||||
return;
|
||||
tf = emalloc (sizeof(TF)); /* freed in tcase_free */
|
||||
tf = emalloc (sizeof (TF)); /* freed in tcase_free */
|
||||
tf->fn = fn;
|
||||
tf->loop_start = start;
|
||||
tf->loop_end = end;
|
||||
|
@ -197,64 +204,70 @@ void _tcase_add_test (TCase *tc, TFun fn, const char *name, int _signal, int sta
|
|||
list_add_end (tc->tflst, tf);
|
||||
}
|
||||
|
||||
static Fixture *fixture_create (SFun fun, int ischecked)
|
||||
static Fixture *
|
||||
fixture_create (SFun fun, int ischecked)
|
||||
{
|
||||
Fixture *f;
|
||||
f = emalloc (sizeof(Fixture));
|
||||
f = emalloc (sizeof (Fixture));
|
||||
f->fun = fun;
|
||||
f->ischecked = ischecked;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void tcase_add_unchecked_fixture (TCase *tc, SFun setup, SFun teardown)
|
||||
void
|
||||
tcase_add_unchecked_fixture (TCase * tc, SFun setup, SFun teardown)
|
||||
{
|
||||
tcase_add_fixture(tc,setup,teardown,0);
|
||||
tcase_add_fixture (tc, setup, teardown, 0);
|
||||
}
|
||||
|
||||
void tcase_add_checked_fixture (TCase *tc, SFun setup, SFun teardown)
|
||||
void
|
||||
tcase_add_checked_fixture (TCase * tc, SFun setup, SFun teardown)
|
||||
{
|
||||
tcase_add_fixture (tc,setup,teardown,1);
|
||||
tcase_add_fixture (tc, setup, teardown, 1);
|
||||
}
|
||||
|
||||
static void tcase_add_fixture (TCase *tc, SFun setup, SFun teardown,
|
||||
int ischecked)
|
||||
static void
|
||||
tcase_add_fixture (TCase * tc, SFun setup, SFun teardown, int ischecked)
|
||||
{
|
||||
if (setup) {
|
||||
if (ischecked)
|
||||
list_add_end (tc->ch_sflst, fixture_create(setup, ischecked));
|
||||
list_add_end (tc->ch_sflst, fixture_create (setup, ischecked));
|
||||
else
|
||||
list_add_end (tc->unch_sflst, fixture_create(setup, ischecked));
|
||||
list_add_end (tc->unch_sflst, fixture_create (setup, ischecked));
|
||||
}
|
||||
|
||||
/* Add teardowns at front so they are run in reverse order. */
|
||||
if (teardown) {
|
||||
if (ischecked)
|
||||
list_add_front (tc->ch_tflst, fixture_create(teardown, ischecked));
|
||||
list_add_front (tc->ch_tflst, fixture_create (teardown, ischecked));
|
||||
else
|
||||
list_add_front (tc->unch_tflst, fixture_create(teardown, ischecked));
|
||||
list_add_front (tc->unch_tflst, fixture_create (teardown, ischecked));
|
||||
}
|
||||
}
|
||||
|
||||
void tcase_set_timeout (TCase *tc, int timeout)
|
||||
void
|
||||
tcase_set_timeout (TCase * tc, int timeout)
|
||||
{
|
||||
if (timeout >= 0)
|
||||
tc->timeout = timeout;
|
||||
}
|
||||
|
||||
void tcase_fn_start (const char *fname, const char *file, int line)
|
||||
void
|
||||
tcase_fn_start (const char *fname, const char *file, int line)
|
||||
{
|
||||
send_ctx_info (CK_CTX_TEST);
|
||||
send_loc_info (file, line);
|
||||
}
|
||||
|
||||
void _mark_point (const char *file, int line)
|
||||
void
|
||||
_mark_point (const char *file, int line)
|
||||
{
|
||||
send_loc_info (file, line);
|
||||
}
|
||||
|
||||
void _fail_unless (int result, const char *file,
|
||||
int line, const char *expr, ...)
|
||||
void
|
||||
_fail_unless (int result, const char *file, int line, const char *expr, ...)
|
||||
{
|
||||
const char *msg;
|
||||
|
||||
|
@ -263,27 +276,28 @@ void _fail_unless (int result, const char *file,
|
|||
va_list ap;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
va_start(ap,expr);
|
||||
msg = (const char*)va_arg(ap, char *);
|
||||
va_start (ap, expr);
|
||||
msg = (const char *) va_arg (ap, char *);
|
||||
if (msg == NULL)
|
||||
msg = expr;
|
||||
vsnprintf(buf, BUFSIZ, msg, ap);
|
||||
va_end(ap);
|
||||
vsnprintf (buf, BUFSIZ, msg, ap);
|
||||
va_end (ap);
|
||||
send_failure_info (buf);
|
||||
if (cur_fork_status() == CK_FORK)
|
||||
exit(1);
|
||||
if (cur_fork_status () == CK_FORK)
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
SRunner *srunner_create (Suite *s)
|
||||
SRunner *
|
||||
srunner_create (Suite * s)
|
||||
{
|
||||
SRunner *sr = emalloc (sizeof(SRunner)); /* freed in srunner_free */
|
||||
sr->slst = check_list_create();
|
||||
SRunner *sr = emalloc (sizeof (SRunner)); /* freed in srunner_free */
|
||||
sr->slst = check_list_create ();
|
||||
if (s != NULL)
|
||||
list_add_end(sr->slst, s);
|
||||
sr->stats = emalloc (sizeof(TestStats)); /* freed in srunner_free */
|
||||
list_add_end (sr->slst, s);
|
||||
sr->stats = emalloc (sizeof (TestStats)); /* freed in srunner_free */
|
||||
sr->stats->n_checked = sr->stats->n_failed = sr->stats->n_errors = 0;
|
||||
sr->resultlst = check_list_create();
|
||||
sr->resultlst = check_list_create ();
|
||||
sr->log_fname = NULL;
|
||||
sr->xml_fname = NULL;
|
||||
sr->loglst = NULL;
|
||||
|
@ -291,15 +305,17 @@ SRunner *srunner_create (Suite *s)
|
|||
return sr;
|
||||
}
|
||||
|
||||
void srunner_add_suite (SRunner *sr, Suite *s)
|
||||
void
|
||||
srunner_add_suite (SRunner * sr, Suite * s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return;
|
||||
|
||||
list_add_end(sr->slst, s);
|
||||
list_add_end (sr->slst, s);
|
||||
}
|
||||
|
||||
void srunner_free (SRunner *sr)
|
||||
void
|
||||
srunner_free (SRunner * sr)
|
||||
{
|
||||
List *l;
|
||||
TestResult *tr;
|
||||
|
@ -308,85 +324,93 @@ void srunner_free (SRunner *sr)
|
|||
|
||||
free (sr->stats);
|
||||
l = sr->slst;
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
suite_free(list_val(l));
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
suite_free (list_val (l));
|
||||
}
|
||||
list_free(sr->slst);
|
||||
list_free (sr->slst);
|
||||
|
||||
l = sr->resultlst;
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
tr = list_val(l);
|
||||
free(tr->file);
|
||||
free(tr->msg);
|
||||
free(tr);
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
tr = list_val (l);
|
||||
free (tr->file);
|
||||
free (tr->msg);
|
||||
free (tr);
|
||||
}
|
||||
list_free (sr->resultlst);
|
||||
|
||||
free (sr);
|
||||
}
|
||||
|
||||
int srunner_ntests_failed (SRunner *sr)
|
||||
int
|
||||
srunner_ntests_failed (SRunner * sr)
|
||||
{
|
||||
return sr->stats->n_failed + sr->stats->n_errors;
|
||||
}
|
||||
|
||||
int srunner_ntests_run (SRunner *sr)
|
||||
int
|
||||
srunner_ntests_run (SRunner * sr)
|
||||
{
|
||||
return sr->stats->n_checked;
|
||||
}
|
||||
|
||||
TestResult **srunner_failures (SRunner *sr)
|
||||
TestResult **
|
||||
srunner_failures (SRunner * sr)
|
||||
{
|
||||
int i = 0;
|
||||
TestResult **trarray;
|
||||
List *rlst;
|
||||
trarray = malloc (sizeof(trarray[0]) * srunner_ntests_failed (sr));
|
||||
trarray = malloc (sizeof (trarray[0]) * srunner_ntests_failed (sr));
|
||||
|
||||
rlst = sr->resultlst;
|
||||
for (list_front(rlst); !list_at_end(rlst); list_advance(rlst)) {
|
||||
TestResult *tr = list_val(rlst);
|
||||
if (non_pass(tr->rtype))
|
||||
for (list_front (rlst); !list_at_end (rlst); list_advance (rlst)) {
|
||||
TestResult *tr = list_val (rlst);
|
||||
if (non_pass (tr->rtype))
|
||||
trarray[i++] = tr;
|
||||
|
||||
}
|
||||
return trarray;
|
||||
}
|
||||
|
||||
TestResult **srunner_results (SRunner *sr)
|
||||
TestResult **
|
||||
srunner_results (SRunner * sr)
|
||||
{
|
||||
int i = 0;
|
||||
TestResult **trarray;
|
||||
List *rlst;
|
||||
|
||||
trarray = malloc (sizeof(trarray[0]) * srunner_ntests_run (sr));
|
||||
trarray = malloc (sizeof (trarray[0]) * srunner_ntests_run (sr));
|
||||
|
||||
rlst = sr->resultlst;
|
||||
for (list_front(rlst); !list_at_end(rlst); list_advance(rlst)) {
|
||||
trarray[i++] = list_val(rlst);
|
||||
for (list_front (rlst); !list_at_end (rlst); list_advance (rlst)) {
|
||||
trarray[i++] = list_val (rlst);
|
||||
}
|
||||
return trarray;
|
||||
}
|
||||
|
||||
static int non_pass (int val)
|
||||
static int
|
||||
non_pass (int val)
|
||||
{
|
||||
return val != CK_PASS;
|
||||
}
|
||||
|
||||
TestResult *tr_create(void)
|
||||
TestResult *
|
||||
tr_create (void)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
||||
tr = emalloc (sizeof(TestResult));
|
||||
tr = emalloc (sizeof (TestResult));
|
||||
tr_init (tr);
|
||||
return tr;
|
||||
}
|
||||
|
||||
void tr_reset(TestResult *tr)
|
||||
void
|
||||
tr_reset (TestResult * tr)
|
||||
{
|
||||
tr_init(tr);
|
||||
tr_init (tr);
|
||||
}
|
||||
|
||||
static void tr_init (TestResult *tr)
|
||||
static void
|
||||
tr_init (TestResult * tr)
|
||||
{
|
||||
tr->ctx = CK_CTX_INVALID;
|
||||
tr->line = -1;
|
||||
|
@ -398,39 +422,46 @@ static void tr_init (TestResult *tr)
|
|||
}
|
||||
|
||||
|
||||
const char *tr_msg (TestResult *tr)
|
||||
const char *
|
||||
tr_msg (TestResult * tr)
|
||||
{
|
||||
return tr->msg;
|
||||
}
|
||||
|
||||
int tr_lno (TestResult *tr)
|
||||
int
|
||||
tr_lno (TestResult * tr)
|
||||
{
|
||||
return tr->line;
|
||||
}
|
||||
|
||||
const char *tr_lfile (TestResult *tr)
|
||||
const char *
|
||||
tr_lfile (TestResult * tr)
|
||||
{
|
||||
return tr->file;
|
||||
}
|
||||
|
||||
int tr_rtype (TestResult *tr)
|
||||
int
|
||||
tr_rtype (TestResult * tr)
|
||||
{
|
||||
return tr->rtype;
|
||||
}
|
||||
|
||||
enum ck_result_ctx tr_ctx (TestResult *tr)
|
||||
enum ck_result_ctx
|
||||
tr_ctx (TestResult * tr)
|
||||
{
|
||||
return tr->ctx;
|
||||
}
|
||||
|
||||
const char *tr_tcname (TestResult *tr)
|
||||
const char *
|
||||
tr_tcname (TestResult * tr)
|
||||
{
|
||||
return tr->tcname;
|
||||
}
|
||||
|
||||
static int _fstat = CK_FORK;
|
||||
|
||||
void set_fork_status (enum fork_status fstat)
|
||||
void
|
||||
set_fork_status (enum fork_status fstat)
|
||||
{
|
||||
if (fstat == CK_FORK || fstat == CK_NOFORK || fstat == CK_FORK_GETENV)
|
||||
_fstat = fstat;
|
||||
|
@ -438,7 +469,8 @@ void set_fork_status (enum fork_status fstat)
|
|||
eprintf ("Bad status in set_fork_status", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
enum fork_status cur_fork_status (void)
|
||||
enum fork_status
|
||||
cur_fork_status (void)
|
||||
{
|
||||
return _fstat;
|
||||
}
|
||||
|
|
|
@ -30,38 +30,41 @@
|
|||
|
||||
|
||||
/* FIXME: including a colon at the end is a bad way to indicate an error */
|
||||
void eprintf (const char *fmt, const char *file, int line, ...)
|
||||
void
|
||||
eprintf (const char *fmt, const char *file, int line, ...)
|
||||
{
|
||||
va_list args;
|
||||
fflush(stderr);
|
||||
fflush (stderr);
|
||||
|
||||
fprintf(stderr,"%s:%d: ",file,line);
|
||||
va_start(args, line);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
fprintf (stderr, "%s:%d: ", file, line);
|
||||
va_start (args, line);
|
||||
vfprintf (stderr, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
/*include system error information if format ends in colon */
|
||||
if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
|
||||
fprintf(stderr, " %s", strerror(errno));
|
||||
fprintf(stderr, "\n");
|
||||
if (fmt[0] != '\0' && fmt[strlen (fmt) - 1] == ':')
|
||||
fprintf (stderr, " %s", strerror (errno));
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
exit(2);
|
||||
exit (2);
|
||||
}
|
||||
|
||||
void *emalloc (size_t n)
|
||||
void *
|
||||
emalloc (size_t n)
|
||||
{
|
||||
void *p;
|
||||
p = malloc(n);
|
||||
p = malloc (n);
|
||||
if (p == NULL)
|
||||
eprintf("malloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
|
||||
eprintf ("malloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void *erealloc (void * ptr, size_t n)
|
||||
void *
|
||||
erealloc (void *ptr, size_t n)
|
||||
{
|
||||
void *p;
|
||||
p = realloc (ptr, n);
|
||||
if (p == NULL)
|
||||
eprintf("realloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
|
||||
eprintf ("realloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -27,12 +27,14 @@
|
|||
#include "check_error.h"
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
LINIT = 1,
|
||||
LGROW = 2
|
||||
};
|
||||
|
||||
struct List {
|
||||
struct List
|
||||
{
|
||||
int n_elts;
|
||||
int max_elts;
|
||||
int current; /* pointer to the current node */
|
||||
|
@ -40,49 +42,54 @@ struct List {
|
|||
const void **data;
|
||||
};
|
||||
|
||||
static void maybe_grow (List *lp)
|
||||
static void
|
||||
maybe_grow (List * lp)
|
||||
{
|
||||
if (lp->n_elts >= lp->max_elts) {
|
||||
lp->max_elts *= LGROW;
|
||||
lp->data = erealloc (lp->data, lp->max_elts * sizeof(lp->data[0]));
|
||||
lp->data = erealloc (lp->data, lp->max_elts * sizeof (lp->data[0]));
|
||||
}
|
||||
}
|
||||
|
||||
List *check_list_create (void)
|
||||
List *
|
||||
check_list_create (void)
|
||||
{
|
||||
List *lp;
|
||||
lp = emalloc (sizeof(List));
|
||||
lp = emalloc (sizeof (List));
|
||||
lp->n_elts = 0;
|
||||
lp->max_elts = LINIT;
|
||||
lp->data = emalloc(sizeof(lp->data[0]) * LINIT);
|
||||
lp->data = emalloc (sizeof (lp->data[0]) * LINIT);
|
||||
lp->current = lp->last = -1;
|
||||
return lp;
|
||||
}
|
||||
|
||||
void list_add_front (List *lp, const void *val)
|
||||
void
|
||||
list_add_front (List * lp, const void *val)
|
||||
{
|
||||
if (lp == NULL)
|
||||
return;
|
||||
maybe_grow(lp);
|
||||
memmove(lp->data + 1, lp->data, lp->n_elts * sizeof lp->data[0]);
|
||||
maybe_grow (lp);
|
||||
memmove (lp->data + 1, lp->data, lp->n_elts * sizeof lp->data[0]);
|
||||
lp->last++;
|
||||
lp->n_elts++;
|
||||
lp->current = 0;
|
||||
lp->data[lp->current] = val;
|
||||
}
|
||||
|
||||
void list_add_end (List *lp, const void *val)
|
||||
void
|
||||
list_add_end (List * lp, const void *val)
|
||||
{
|
||||
if (lp == NULL)
|
||||
return;
|
||||
maybe_grow(lp);
|
||||
maybe_grow (lp);
|
||||
lp->last++;
|
||||
lp->n_elts++;
|
||||
lp->current = lp->last;
|
||||
lp->data[lp->current] = val;
|
||||
}
|
||||
|
||||
int list_at_end (List *lp)
|
||||
int
|
||||
list_at_end (List * lp)
|
||||
{
|
||||
if (lp->current == -1)
|
||||
return 1;
|
||||
|
@ -90,7 +97,8 @@ int list_at_end (List *lp)
|
|||
return (lp->current > lp->last);
|
||||
}
|
||||
|
||||
void list_front (List *lp)
|
||||
void
|
||||
list_front (List * lp)
|
||||
{
|
||||
if (lp->current == -1)
|
||||
return;
|
||||
|
@ -98,44 +106,45 @@ void list_front (List *lp)
|
|||
}
|
||||
|
||||
|
||||
void list_free (List *lp)
|
||||
void
|
||||
list_free (List * lp)
|
||||
{
|
||||
if (lp == NULL)
|
||||
return;
|
||||
|
||||
free(lp->data);
|
||||
free (lp->data);
|
||||
free (lp);
|
||||
}
|
||||
|
||||
void *list_val (List *lp)
|
||||
void *
|
||||
list_val (List * lp)
|
||||
{
|
||||
if (lp == NULL)
|
||||
return NULL;
|
||||
if (lp->current == -1 || lp->current > lp->last)
|
||||
return NULL;
|
||||
|
||||
return (void*) lp->data[lp->current];
|
||||
return (void *) lp->data[lp->current];
|
||||
}
|
||||
|
||||
void list_advance (List *lp)
|
||||
void
|
||||
list_advance (List * lp)
|
||||
{
|
||||
if (lp == NULL)
|
||||
return;
|
||||
if (list_at_end(lp))
|
||||
if (list_at_end (lp))
|
||||
return;
|
||||
lp->current++;
|
||||
}
|
||||
|
||||
|
||||
void list_apply (List *lp, void (*fp) (void *))
|
||||
void
|
||||
list_apply (List * lp, void (*fp) (void *))
|
||||
{
|
||||
if (lp == NULL || fp == NULL)
|
||||
return;
|
||||
|
||||
for (list_front(lp); !list_at_end(lp); list_advance(lp))
|
||||
fp (list_val(lp));
|
||||
for (list_front (lp); !list_at_end (lp); list_advance (lp))
|
||||
fp (list_val (lp));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,50 +33,57 @@
|
|||
#include "check_print.h"
|
||||
|
||||
|
||||
static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt);
|
||||
static void srunner_send_evt (SRunner * sr, void *obj, enum cl_event evt);
|
||||
|
||||
void srunner_set_log (SRunner *sr, const char *fname)
|
||||
void
|
||||
srunner_set_log (SRunner * sr, const char *fname)
|
||||
{
|
||||
if (sr->log_fname)
|
||||
return;
|
||||
sr->log_fname = fname;
|
||||
}
|
||||
|
||||
int srunner_has_log (SRunner *sr)
|
||||
int
|
||||
srunner_has_log (SRunner * sr)
|
||||
{
|
||||
return sr->log_fname != NULL;
|
||||
}
|
||||
|
||||
const char *srunner_log_fname (SRunner *sr)
|
||||
const char *
|
||||
srunner_log_fname (SRunner * sr)
|
||||
{
|
||||
return sr->log_fname;
|
||||
}
|
||||
|
||||
|
||||
void srunner_set_xml (SRunner *sr, const char *fname)
|
||||
void
|
||||
srunner_set_xml (SRunner * sr, const char *fname)
|
||||
{
|
||||
if (sr->xml_fname)
|
||||
return;
|
||||
sr->xml_fname = fname;
|
||||
}
|
||||
|
||||
int srunner_has_xml (SRunner *sr)
|
||||
int
|
||||
srunner_has_xml (SRunner * sr)
|
||||
{
|
||||
return sr->xml_fname != NULL;
|
||||
}
|
||||
|
||||
const char *srunner_xml_fname (SRunner *sr)
|
||||
const char *
|
||||
srunner_xml_fname (SRunner * sr)
|
||||
{
|
||||
return sr->xml_fname;
|
||||
}
|
||||
|
||||
void srunner_register_lfun (SRunner *sr, FILE *lfile, int close,
|
||||
void
|
||||
srunner_register_lfun (SRunner * sr, FILE * lfile, int close,
|
||||
LFun lfun, enum print_output printmode)
|
||||
{
|
||||
Log *l = emalloc (sizeof(Log));
|
||||
Log *l = emalloc (sizeof (Log));
|
||||
|
||||
if (printmode == CK_ENV) {
|
||||
printmode = get_env_printmode();
|
||||
printmode = get_env_printmode ();
|
||||
}
|
||||
|
||||
l->lfile = lfile;
|
||||
|
@ -87,52 +94,59 @@ void srunner_register_lfun (SRunner *sr, FILE *lfile, int close,
|
|||
return;
|
||||
}
|
||||
|
||||
void log_srunner_start (SRunner *sr)
|
||||
void
|
||||
log_srunner_start (SRunner * sr)
|
||||
{
|
||||
srunner_send_evt (sr, NULL, CLSTART_SR);
|
||||
}
|
||||
|
||||
void log_srunner_end (SRunner *sr)
|
||||
void
|
||||
log_srunner_end (SRunner * sr)
|
||||
{
|
||||
srunner_send_evt (sr, NULL, CLEND_SR);
|
||||
}
|
||||
|
||||
void log_suite_start (SRunner *sr, Suite *s)
|
||||
void
|
||||
log_suite_start (SRunner * sr, Suite * s)
|
||||
{
|
||||
srunner_send_evt (sr, s, CLSTART_S);
|
||||
}
|
||||
|
||||
void log_suite_end (SRunner *sr, Suite *s)
|
||||
void
|
||||
log_suite_end (SRunner * sr, Suite * s)
|
||||
{
|
||||
srunner_send_evt (sr, s, CLEND_S);
|
||||
}
|
||||
|
||||
void log_test_end (SRunner *sr, TestResult *tr)
|
||||
void
|
||||
log_test_end (SRunner * sr, TestResult * tr)
|
||||
{
|
||||
srunner_send_evt (sr, tr, CLEND_T);
|
||||
}
|
||||
|
||||
static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt)
|
||||
static void
|
||||
srunner_send_evt (SRunner * sr, void *obj, enum cl_event evt)
|
||||
{
|
||||
List *l;
|
||||
Log *lg;
|
||||
l = sr->loglst;
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
lg = list_val(l);
|
||||
fflush(lg->lfile);
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
lg = list_val (l);
|
||||
fflush (lg->lfile);
|
||||
lg->lfun (sr, lg->lfile, lg->mode, obj, evt);
|
||||
fflush(lg->lfile);
|
||||
fflush (lg->lfile);
|
||||
}
|
||||
}
|
||||
|
||||
void stdout_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
||||
void
|
||||
stdout_lfun (SRunner * sr, FILE * file, enum print_output printmode,
|
||||
void *obj, enum cl_event evt)
|
||||
{
|
||||
TestResult *tr;
|
||||
Suite *s;
|
||||
|
||||
if (printmode == CK_ENV) {
|
||||
printmode = get_env_printmode();
|
||||
printmode = get_env_printmode ();
|
||||
}
|
||||
|
||||
switch (evt) {
|
||||
|
@ -142,13 +156,13 @@ void stdout_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
|||
break;
|
||||
case CLSTART_SR:
|
||||
if (printmode > CK_SILENT) {
|
||||
fprintf(file, "Running suite(s):");
|
||||
fprintf (file, "Running suite(s):");
|
||||
}
|
||||
break;
|
||||
case CLSTART_S:
|
||||
s = obj;
|
||||
if (printmode > CK_SILENT) {
|
||||
fprintf(file, " %s\n", s->name);
|
||||
fprintf (file, " %s\n", s->name);
|
||||
}
|
||||
break;
|
||||
case CLEND_SR:
|
||||
|
@ -167,13 +181,14 @@ void stdout_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
|||
tr = obj;
|
||||
break;
|
||||
default:
|
||||
eprintf("Bad event type received in stdout_lfun", __FILE__, __LINE__);
|
||||
eprintf ("Bad event type received in stdout_lfun", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void lfile_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
||||
void
|
||||
lfile_lfun (SRunner * sr, FILE * file, enum print_output printmode,
|
||||
void *obj, enum cl_event evt)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
@ -188,7 +203,7 @@ void lfile_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
|||
break;
|
||||
case CLSTART_S:
|
||||
s = obj;
|
||||
fprintf(file, "Running suite %s\n", s->name);
|
||||
fprintf (file, "Running suite %s\n", s->name);
|
||||
break;
|
||||
case CLEND_SR:
|
||||
fprintf (file, "Results for all suites run:\n");
|
||||
|
@ -199,96 +214,100 @@ void lfile_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
|||
break;
|
||||
case CLEND_T:
|
||||
tr = obj;
|
||||
tr_fprint(file, tr, CK_VERBOSE);
|
||||
tr_fprint (file, tr, CK_VERBOSE);
|
||||
break;
|
||||
default:
|
||||
eprintf("Bad event type received in stdout_lfun", __FILE__, __LINE__);
|
||||
eprintf ("Bad event type received in stdout_lfun", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void xml_lfun (SRunner *sr, FILE *file, enum print_output printmode,
|
||||
void
|
||||
xml_lfun (SRunner * sr, FILE * file, enum print_output printmode,
|
||||
void *obj, enum cl_event evt)
|
||||
{
|
||||
TestResult *tr;
|
||||
Suite *s;
|
||||
static struct timeval inittv, endtv;
|
||||
static char t[sizeof "yyyy-mm-dd hh:mm:ss"] = {0};
|
||||
static char t[sizeof "yyyy-mm-dd hh:mm:ss"] = { 0 };
|
||||
|
||||
if (t[0] == 0)
|
||||
{
|
||||
if (t[0] == 0) {
|
||||
struct tm now;
|
||||
gettimeofday(&inittv, NULL);
|
||||
localtime_r(&(inittv.tv_sec), &now);
|
||||
strftime(t, sizeof("yyyy-mm-dd hh:mm:ss"), "%Y-%m-%d %H:%M:%S", &now);
|
||||
gettimeofday (&inittv, NULL);
|
||||
localtime_r (&(inittv.tv_sec), &now);
|
||||
strftime (t, sizeof ("yyyy-mm-dd hh:mm:ss"), "%Y-%m-%d %H:%M:%S", &now);
|
||||
}
|
||||
|
||||
switch (evt) {
|
||||
case CLINITLOG_SR:
|
||||
fprintf(file, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(file, "<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n");
|
||||
fprintf(file, " <datetime>%s</datetime>\n", t);
|
||||
fprintf (file, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf (file,
|
||||
"<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n");
|
||||
fprintf (file, " <datetime>%s</datetime>\n", t);
|
||||
break;
|
||||
case CLENDLOG_SR:
|
||||
gettimeofday(&endtv, NULL);
|
||||
fprintf(file, " <duration>%f</duration>\n",
|
||||
(endtv.tv_sec + (float)(endtv.tv_usec)/1000000) - \
|
||||
(inittv.tv_sec + (float)(inittv.tv_usec/1000000)));
|
||||
fprintf(file, "</testsuites>\n");
|
||||
gettimeofday (&endtv, NULL);
|
||||
fprintf (file, " <duration>%f</duration>\n",
|
||||
(endtv.tv_sec + (float) (endtv.tv_usec) / 1000000) -
|
||||
(inittv.tv_sec + (float) (inittv.tv_usec / 1000000)));
|
||||
fprintf (file, "</testsuites>\n");
|
||||
break;
|
||||
case CLSTART_SR:
|
||||
break;
|
||||
case CLSTART_S:
|
||||
s = obj;
|
||||
fprintf(file, " <suite>\n");
|
||||
fprintf(file, " <title>%s</title>\n", s->name);
|
||||
fprintf (file, " <suite>\n");
|
||||
fprintf (file, " <title>%s</title>\n", s->name);
|
||||
break;
|
||||
case CLEND_SR:
|
||||
break;
|
||||
case CLEND_S:
|
||||
fprintf(file, " </suite>\n");
|
||||
fprintf (file, " </suite>\n");
|
||||
s = obj;
|
||||
break;
|
||||
case CLEND_T:
|
||||
tr = obj;
|
||||
tr_xmlprint(file, tr, CK_VERBOSE);
|
||||
tr_xmlprint (file, tr, CK_VERBOSE);
|
||||
break;
|
||||
default:
|
||||
eprintf("Bad event type received in xml_lfun", __FILE__, __LINE__);
|
||||
eprintf ("Bad event type received in xml_lfun", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
FILE *srunner_open_lfile (SRunner *sr)
|
||||
FILE *
|
||||
srunner_open_lfile (SRunner * sr)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
if (srunner_has_log (sr)) {
|
||||
f = fopen(sr->log_fname, "w");
|
||||
f = fopen (sr->log_fname, "w");
|
||||
if (f == NULL)
|
||||
eprintf ("Error in call to fopen while opening log file %s:", __FILE__, __LINE__ - 2,
|
||||
sr->log_fname);
|
||||
eprintf ("Error in call to fopen while opening log file %s:", __FILE__,
|
||||
__LINE__ - 2, sr->log_fname);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
FILE *srunner_open_xmlfile (SRunner *sr)
|
||||
FILE *
|
||||
srunner_open_xmlfile (SRunner * sr)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
if (srunner_has_xml (sr)) {
|
||||
f = fopen(sr->xml_fname, "w");
|
||||
f = fopen (sr->xml_fname, "w");
|
||||
if (f == NULL)
|
||||
eprintf ("Error in call to fopen while opening xml file %s:", __FILE__, __LINE__ - 2,
|
||||
sr->xml_fname);
|
||||
eprintf ("Error in call to fopen while opening xml file %s:", __FILE__,
|
||||
__LINE__ - 2, sr->xml_fname);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
void srunner_init_logging (SRunner *sr, enum print_output print_mode)
|
||||
void
|
||||
srunner_init_logging (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
FILE *f;
|
||||
sr->loglst = check_list_create();
|
||||
sr->loglst = check_list_create ();
|
||||
srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode);
|
||||
f = srunner_open_lfile (sr);
|
||||
if (f) {
|
||||
|
@ -301,7 +320,8 @@ void srunner_init_logging (SRunner *sr, enum print_output print_mode)
|
|||
srunner_send_evt (sr, NULL, CLINITLOG_SR);
|
||||
}
|
||||
|
||||
void srunner_end_logging (SRunner *sr)
|
||||
void
|
||||
srunner_end_logging (SRunner * sr)
|
||||
{
|
||||
List *l;
|
||||
int rval;
|
||||
|
@ -309,15 +329,16 @@ void srunner_end_logging (SRunner *sr)
|
|||
srunner_send_evt (sr, NULL, CLENDLOG_SR);
|
||||
|
||||
l = sr->loglst;
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
Log *lg = list_val(l);
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
Log *lg = list_val (l);
|
||||
if (lg->close) {
|
||||
rval = fclose (lg->lfile);
|
||||
if (rval != 0)
|
||||
eprintf ("Error in call to fclose while closing log file:", __FILE__, __LINE__ - 2);
|
||||
eprintf ("Error in call to fclose while closing log file:", __FILE__,
|
||||
__LINE__ - 2);
|
||||
}
|
||||
free (lg);
|
||||
}
|
||||
list_free(l);
|
||||
list_free (l);
|
||||
sr->loglst = NULL;
|
||||
}
|
||||
|
|
|
@ -57,13 +57,14 @@
|
|||
static FILE *send_file1;
|
||||
static FILE *send_file2;
|
||||
|
||||
static FILE * get_pipe(void);
|
||||
static FILE *get_pipe (void);
|
||||
static void setup_pipe (void);
|
||||
static void teardown_pipe (void);
|
||||
static TestResult *construct_test_result (RcvMsg *rmsg, int waserror);
|
||||
static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx,
|
||||
RcvMsg *rmsg);
|
||||
static FILE * get_pipe(void)
|
||||
static TestResult *construct_test_result (RcvMsg * rmsg, int waserror);
|
||||
static void tr_set_loc_by_ctx (TestResult * tr, enum ck_result_ctx ctx,
|
||||
RcvMsg * rmsg);
|
||||
static FILE *
|
||||
get_pipe (void)
|
||||
{
|
||||
if (send_file2 != 0) {
|
||||
return send_file2;
|
||||
|
@ -73,57 +74,61 @@ static FILE * get_pipe(void)
|
|||
return send_file1;
|
||||
}
|
||||
printf ("send_file1=%p,send_file2=%p", send_file1, send_file2);
|
||||
eprintf("No messaging setup", __FILE__, __LINE__);
|
||||
eprintf ("No messaging setup", __FILE__, __LINE__);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void send_failure_info(const char *msg)
|
||||
void
|
||||
send_failure_info (const char *msg)
|
||||
{
|
||||
FailMsg fmsg;
|
||||
|
||||
fmsg.msg = (char *) msg;
|
||||
ppack(fileno(get_pipe()), CK_MSG_FAIL, (CheckMsg *) &fmsg);
|
||||
ppack (fileno (get_pipe ()), CK_MSG_FAIL, (CheckMsg *) & fmsg);
|
||||
}
|
||||
|
||||
void send_loc_info(const char * file, int line)
|
||||
void
|
||||
send_loc_info (const char *file, int line)
|
||||
{
|
||||
LocMsg lmsg;
|
||||
|
||||
lmsg.file = (char *) file;
|
||||
lmsg.line = line;
|
||||
ppack(fileno(get_pipe()), CK_MSG_LOC, (CheckMsg *) &lmsg);
|
||||
ppack (fileno (get_pipe ()), CK_MSG_LOC, (CheckMsg *) & lmsg);
|
||||
}
|
||||
|
||||
void send_ctx_info(enum ck_result_ctx ctx)
|
||||
void
|
||||
send_ctx_info (enum ck_result_ctx ctx)
|
||||
{
|
||||
CtxMsg cmsg;
|
||||
|
||||
cmsg.ctx = ctx;
|
||||
ppack(fileno(get_pipe()), CK_MSG_CTX, (CheckMsg *) &cmsg);
|
||||
ppack (fileno (get_pipe ()), CK_MSG_CTX, (CheckMsg *) & cmsg);
|
||||
}
|
||||
|
||||
TestResult *receive_test_result (int waserror)
|
||||
TestResult *
|
||||
receive_test_result (int waserror)
|
||||
{
|
||||
FILE *fp;
|
||||
RcvMsg *rmsg;
|
||||
TestResult *result;
|
||||
|
||||
fp = get_pipe();
|
||||
fp = get_pipe ();
|
||||
if (fp == NULL)
|
||||
eprintf ("Error in call to get_pipe",__FILE__, __LINE__ - 2);
|
||||
rewind(fp);
|
||||
rmsg = punpack (fileno(fp));
|
||||
teardown_pipe();
|
||||
setup_pipe();
|
||||
eprintf ("Error in call to get_pipe", __FILE__, __LINE__ - 2);
|
||||
rewind (fp);
|
||||
rmsg = punpack (fileno (fp));
|
||||
teardown_pipe ();
|
||||
setup_pipe ();
|
||||
|
||||
result = construct_test_result (rmsg, waserror);
|
||||
rcvmsg_free(rmsg);
|
||||
rcvmsg_free (rmsg);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx,
|
||||
RcvMsg *rmsg)
|
||||
static void
|
||||
tr_set_loc_by_ctx (TestResult * tr, enum ck_result_ctx ctx, RcvMsg * rmsg)
|
||||
{
|
||||
if (ctx == CK_CTX_TEST) {
|
||||
tr->file = rmsg->test_file;
|
||||
|
@ -138,14 +143,15 @@ static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx,
|
|||
}
|
||||
}
|
||||
|
||||
static TestResult *construct_test_result (RcvMsg *rmsg, int waserror)
|
||||
static TestResult *
|
||||
construct_test_result (RcvMsg * rmsg, int waserror)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
||||
if (rmsg == NULL)
|
||||
return NULL;
|
||||
|
||||
tr = tr_create();
|
||||
tr = tr_create ();
|
||||
|
||||
if (rmsg->msg != NULL || waserror) {
|
||||
tr->ctx = (cur_fork_status () == CK_FORK) ? rmsg->lastctx : rmsg->failctx;
|
||||
|
@ -165,37 +171,40 @@ static TestResult *construct_test_result (RcvMsg *rmsg, int waserror)
|
|||
return tr;
|
||||
}
|
||||
|
||||
void setup_messaging(void)
|
||||
void
|
||||
setup_messaging (void)
|
||||
{
|
||||
setup_pipe();
|
||||
setup_pipe ();
|
||||
}
|
||||
|
||||
void teardown_messaging(void)
|
||||
void
|
||||
teardown_messaging (void)
|
||||
{
|
||||
teardown_pipe();
|
||||
teardown_pipe ();
|
||||
}
|
||||
|
||||
static void setup_pipe(void)
|
||||
static void
|
||||
setup_pipe (void)
|
||||
{
|
||||
if (send_file1 != 0) {
|
||||
if (send_file2 != 0)
|
||||
eprintf("Only one nesting of suite runs supported", __FILE__, __LINE__);
|
||||
send_file2 = tmpfile();
|
||||
eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__);
|
||||
send_file2 = tmpfile ();
|
||||
} else {
|
||||
send_file1 = tmpfile();
|
||||
send_file1 = tmpfile ();
|
||||
}
|
||||
}
|
||||
|
||||
static void teardown_pipe(void)
|
||||
static void
|
||||
teardown_pipe (void)
|
||||
{
|
||||
if (send_file2 != 0) {
|
||||
fclose(send_file2);
|
||||
fclose (send_file2);
|
||||
send_file2 = 0;
|
||||
} else if (send_file1 != 0) {
|
||||
fclose(send_file1);
|
||||
fclose (send_file1);
|
||||
send_file1 = 0;
|
||||
} else {
|
||||
eprintf("No messaging setup", __FILE__, __LINE__);
|
||||
eprintf ("No messaging setup", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,40 +45,41 @@ static int upack_int (char **buf);
|
|||
static void pack_str (char **buf, const char *str);
|
||||
static char *upack_str (char **buf);
|
||||
|
||||
static int pack_ctx (char **buf, CtxMsg *cmsg);
|
||||
static int pack_loc (char **buf, LocMsg *lmsg);
|
||||
static int pack_fail (char **buf, FailMsg *fmsg);
|
||||
static void upack_ctx (char **buf, CtxMsg *cmsg);
|
||||
static void upack_loc (char **buf, LocMsg *lmsg);
|
||||
static void upack_fail (char **buf, FailMsg *fmsg);
|
||||
static int pack_ctx (char **buf, CtxMsg * cmsg);
|
||||
static int pack_loc (char **buf, LocMsg * lmsg);
|
||||
static int pack_fail (char **buf, FailMsg * fmsg);
|
||||
static void upack_ctx (char **buf, CtxMsg * cmsg);
|
||||
static void upack_loc (char **buf, LocMsg * lmsg);
|
||||
static void upack_fail (char **buf, FailMsg * fmsg);
|
||||
|
||||
static void check_type (int type, const char *file, int line);
|
||||
static enum ck_msg_type upack_type (char **buf);
|
||||
static void pack_type (char **buf, enum ck_msg_type type);
|
||||
|
||||
static int read_buf (int fdes, char **buf);
|
||||
static int get_result (char *buf, RcvMsg *rmsg);
|
||||
static void rcvmsg_update_ctx (RcvMsg *rmsg, enum ck_result_ctx ctx);
|
||||
static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line);
|
||||
static int get_result (char *buf, RcvMsg * rmsg);
|
||||
static void rcvmsg_update_ctx (RcvMsg * rmsg, enum ck_result_ctx ctx);
|
||||
static void rcvmsg_update_loc (RcvMsg * rmsg, const char *file, int line);
|
||||
static RcvMsg *rcvmsg_create (void);
|
||||
void rcvmsg_free (RcvMsg *rmsg);
|
||||
void rcvmsg_free (RcvMsg * rmsg);
|
||||
|
||||
typedef int (*pfun) (char **, CheckMsg *);
|
||||
typedef void (*upfun) (char **, CheckMsg *);
|
||||
|
||||
static pfun pftab [] = {
|
||||
static pfun pftab[] = {
|
||||
(pfun) pack_ctx,
|
||||
(pfun) pack_fail,
|
||||
(pfun) pack_loc
|
||||
};
|
||||
|
||||
static upfun upftab [] = {
|
||||
static upfun upftab[] = {
|
||||
(upfun) upack_ctx,
|
||||
(upfun) upack_fail,
|
||||
(upfun) upack_loc
|
||||
};
|
||||
|
||||
int pack (enum ck_msg_type type, char **buf, CheckMsg *msg)
|
||||
int
|
||||
pack (enum ck_msg_type type, char **buf, CheckMsg * msg)
|
||||
{
|
||||
if (buf == NULL)
|
||||
return -1;
|
||||
|
@ -90,7 +91,8 @@ int pack (enum ck_msg_type type, char **buf, CheckMsg *msg)
|
|||
return pftab[type] (buf, msg);
|
||||
}
|
||||
|
||||
int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type)
|
||||
int
|
||||
upack (char *buf, CheckMsg * msg, enum ck_msg_type *type)
|
||||
{
|
||||
char *obuf;
|
||||
int nread;
|
||||
|
@ -110,7 +112,8 @@ int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type)
|
|||
return nread;
|
||||
}
|
||||
|
||||
static void pack_int (char **buf, int val)
|
||||
static void
|
||||
pack_int (char **buf, int val)
|
||||
{
|
||||
unsigned char *ubuf = (unsigned char *) *buf;
|
||||
ck_uint32 uval = val;
|
||||
|
@ -123,7 +126,8 @@ static void pack_int (char **buf, int val)
|
|||
*buf += 4;
|
||||
}
|
||||
|
||||
static int upack_int (char **buf)
|
||||
static int
|
||||
upack_int (char **buf)
|
||||
{
|
||||
unsigned char *ubuf = (unsigned char *) *buf;
|
||||
ck_uint32 uval;
|
||||
|
@ -135,7 +139,8 @@ static int upack_int (char **buf)
|
|||
return (int) uval;
|
||||
}
|
||||
|
||||
static void pack_str (char **buf, const char *val)
|
||||
static void
|
||||
pack_str (char **buf, const char *val)
|
||||
{
|
||||
int strsz;
|
||||
|
||||
|
@ -152,7 +157,8 @@ static void pack_str (char **buf, const char *val)
|
|||
}
|
||||
}
|
||||
|
||||
static char *upack_str (char **buf)
|
||||
static char *
|
||||
upack_str (char **buf)
|
||||
{
|
||||
char *val;
|
||||
int strsz;
|
||||
|
@ -172,18 +178,21 @@ static char *upack_str (char **buf)
|
|||
return val;
|
||||
}
|
||||
|
||||
static void pack_type (char **buf, enum ck_msg_type type)
|
||||
static void
|
||||
pack_type (char **buf, enum ck_msg_type type)
|
||||
{
|
||||
pack_int (buf, (int) type);
|
||||
}
|
||||
|
||||
static enum ck_msg_type upack_type (char **buf)
|
||||
static enum ck_msg_type
|
||||
upack_type (char **buf)
|
||||
{
|
||||
return (enum ck_msg_type) upack_int (buf);
|
||||
}
|
||||
|
||||
|
||||
static int pack_ctx (char **buf, CtxMsg *cmsg)
|
||||
static int
|
||||
pack_ctx (char **buf, CtxMsg * cmsg)
|
||||
{
|
||||
char *ptr;
|
||||
int len;
|
||||
|
@ -197,12 +206,14 @@ static int pack_ctx (char **buf, CtxMsg *cmsg)
|
|||
return len;
|
||||
}
|
||||
|
||||
static void upack_ctx (char **buf, CtxMsg *cmsg)
|
||||
static void
|
||||
upack_ctx (char **buf, CtxMsg * cmsg)
|
||||
{
|
||||
cmsg->ctx = upack_int (buf);
|
||||
}
|
||||
|
||||
static int pack_loc (char **buf, LocMsg *lmsg)
|
||||
static int
|
||||
pack_loc (char **buf, LocMsg * lmsg)
|
||||
{
|
||||
char *ptr;
|
||||
int len;
|
||||
|
@ -217,13 +228,15 @@ static int pack_loc (char **buf, LocMsg *lmsg)
|
|||
return len;
|
||||
}
|
||||
|
||||
static void upack_loc (char **buf, LocMsg *lmsg)
|
||||
static void
|
||||
upack_loc (char **buf, LocMsg * lmsg)
|
||||
{
|
||||
lmsg->file = upack_str (buf);
|
||||
lmsg->line = upack_int (buf);
|
||||
}
|
||||
|
||||
static int pack_fail (char **buf, FailMsg *fmsg)
|
||||
static int
|
||||
pack_fail (char **buf, FailMsg * fmsg)
|
||||
{
|
||||
char *ptr;
|
||||
int len;
|
||||
|
@ -237,18 +250,21 @@ static int pack_fail (char **buf, FailMsg *fmsg)
|
|||
return len;
|
||||
}
|
||||
|
||||
static void upack_fail (char **buf, FailMsg *fmsg)
|
||||
static void
|
||||
upack_fail (char **buf, FailMsg * fmsg)
|
||||
{
|
||||
fmsg->msg = upack_str (buf);
|
||||
}
|
||||
|
||||
static void check_type (int type, const char *file, int line)
|
||||
static void
|
||||
check_type (int type, const char *file, int line)
|
||||
{
|
||||
if (type < 0 || type >= CK_MSG_LAST)
|
||||
eprintf ("Bad message type arg", file, line);
|
||||
}
|
||||
|
||||
void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg)
|
||||
void
|
||||
ppack (int fdes, enum ck_msg_type type, CheckMsg * msg)
|
||||
{
|
||||
char *buf;
|
||||
int n;
|
||||
|
@ -262,7 +278,8 @@ void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg)
|
|||
free (buf);
|
||||
}
|
||||
|
||||
static int read_buf (int fdes, char **buf)
|
||||
static int
|
||||
read_buf (int fdes, char **buf)
|
||||
{
|
||||
char *readloc;
|
||||
int n;
|
||||
|
@ -270,7 +287,7 @@ static int read_buf (int fdes, char **buf)
|
|||
int size = 1;
|
||||
int grow = 2;
|
||||
|
||||
*buf = emalloc(size);
|
||||
*buf = emalloc (size);
|
||||
readloc = *buf;
|
||||
while (1) {
|
||||
n = read (fdes, readloc, size - nread);
|
||||
|
@ -281,7 +298,7 @@ static int read_buf (int fdes, char **buf)
|
|||
|
||||
nread += n;
|
||||
size *= grow;
|
||||
*buf = erealloc (*buf,size);
|
||||
*buf = erealloc (*buf, size);
|
||||
readloc = *buf + nread;
|
||||
}
|
||||
|
||||
|
@ -289,7 +306,8 @@ static int read_buf (int fdes, char **buf)
|
|||
}
|
||||
|
||||
|
||||
static int get_result (char *buf, RcvMsg *rmsg)
|
||||
static int
|
||||
get_result (char *buf, RcvMsg * rmsg)
|
||||
{
|
||||
enum ck_msg_type type;
|
||||
CheckMsg msg;
|
||||
|
@ -300,25 +318,21 @@ static int get_result (char *buf, RcvMsg *rmsg)
|
|||
eprintf ("Error in call to upack", __FILE__, __LINE__ - 2);
|
||||
|
||||
if (type == CK_MSG_CTX) {
|
||||
CtxMsg *cmsg = (CtxMsg *) &msg;
|
||||
CtxMsg *cmsg = (CtxMsg *) & msg;
|
||||
rcvmsg_update_ctx (rmsg, cmsg->ctx);
|
||||
} else if (type == CK_MSG_LOC) {
|
||||
LocMsg *lmsg = (LocMsg *) &msg;
|
||||
if (rmsg->failctx == CK_CTX_INVALID)
|
||||
{
|
||||
LocMsg *lmsg = (LocMsg *) & msg;
|
||||
if (rmsg->failctx == CK_CTX_INVALID) {
|
||||
rcvmsg_update_loc (rmsg, lmsg->file, lmsg->line);
|
||||
}
|
||||
free (lmsg->file);
|
||||
} else if (type == CK_MSG_FAIL) {
|
||||
FailMsg *fmsg = (FailMsg *) &msg;
|
||||
if (rmsg->msg == NULL)
|
||||
{
|
||||
FailMsg *fmsg = (FailMsg *) & msg;
|
||||
if (rmsg->msg == NULL) {
|
||||
rmsg->msg = emalloc (strlen (fmsg->msg) + 1);
|
||||
strcpy (rmsg->msg, fmsg->msg);
|
||||
rmsg->failctx = rmsg->lastctx;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Skip subsequent failure messages, only happens for CK_NOFORK */
|
||||
}
|
||||
free (fmsg->msg);
|
||||
|
@ -328,19 +342,22 @@ static int get_result (char *buf, RcvMsg *rmsg)
|
|||
return n;
|
||||
}
|
||||
|
||||
static void reset_rcv_test (RcvMsg *rmsg)
|
||||
static void
|
||||
reset_rcv_test (RcvMsg * rmsg)
|
||||
{
|
||||
rmsg->test_line = -1;
|
||||
rmsg->test_file = NULL;
|
||||
}
|
||||
|
||||
static void reset_rcv_fixture (RcvMsg *rmsg)
|
||||
static void
|
||||
reset_rcv_fixture (RcvMsg * rmsg)
|
||||
{
|
||||
rmsg->fixture_line = -1;
|
||||
rmsg->fixture_file = NULL;
|
||||
}
|
||||
|
||||
static RcvMsg *rcvmsg_create (void)
|
||||
static RcvMsg *
|
||||
rcvmsg_create (void)
|
||||
{
|
||||
RcvMsg *rmsg;
|
||||
|
||||
|
@ -353,42 +370,45 @@ static RcvMsg *rcvmsg_create (void)
|
|||
return rmsg;
|
||||
}
|
||||
|
||||
void rcvmsg_free (RcvMsg *rmsg)
|
||||
void
|
||||
rcvmsg_free (RcvMsg * rmsg)
|
||||
{
|
||||
free(rmsg->fixture_file);
|
||||
free(rmsg->test_file);
|
||||
free(rmsg->msg);
|
||||
free(rmsg);
|
||||
free (rmsg->fixture_file);
|
||||
free (rmsg->test_file);
|
||||
free (rmsg->msg);
|
||||
free (rmsg);
|
||||
}
|
||||
|
||||
static void rcvmsg_update_ctx (RcvMsg *rmsg, enum ck_result_ctx ctx)
|
||||
static void
|
||||
rcvmsg_update_ctx (RcvMsg * rmsg, enum ck_result_ctx ctx)
|
||||
{
|
||||
if (rmsg->lastctx != CK_CTX_INVALID)
|
||||
{
|
||||
free(rmsg->fixture_file);
|
||||
if (rmsg->lastctx != CK_CTX_INVALID) {
|
||||
free (rmsg->fixture_file);
|
||||
reset_rcv_fixture (rmsg);
|
||||
}
|
||||
rmsg->lastctx = ctx;
|
||||
}
|
||||
|
||||
static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line)
|
||||
static void
|
||||
rcvmsg_update_loc (RcvMsg * rmsg, const char *file, int line)
|
||||
{
|
||||
int flen = strlen(file);
|
||||
int flen = strlen (file);
|
||||
|
||||
if (rmsg->lastctx == CK_CTX_TEST) {
|
||||
free(rmsg->test_file);
|
||||
free (rmsg->test_file);
|
||||
rmsg->test_line = line;
|
||||
rmsg->test_file = emalloc (flen + 1);
|
||||
strcpy (rmsg->test_file, file);
|
||||
} else {
|
||||
free(rmsg->fixture_file);
|
||||
free (rmsg->fixture_file);
|
||||
rmsg->fixture_line = line;
|
||||
rmsg->fixture_file = emalloc (flen + 1);
|
||||
strcpy (rmsg->fixture_file, file);
|
||||
}
|
||||
}
|
||||
|
||||
RcvMsg *punpack (int fdes)
|
||||
RcvMsg *
|
||||
punpack (int fdes)
|
||||
{
|
||||
int nread, n;
|
||||
char *buf;
|
||||
|
|
|
@ -31,69 +31,74 @@
|
|||
#include "check_str.h"
|
||||
#include "check_print.h"
|
||||
|
||||
static void srunner_fprint_summary (FILE *file, SRunner *sr,
|
||||
static void srunner_fprint_summary (FILE * file, SRunner * sr,
|
||||
enum print_output print_mode);
|
||||
static void srunner_fprint_results (FILE *file, SRunner *sr,
|
||||
static void srunner_fprint_results (FILE * file, SRunner * sr,
|
||||
enum print_output print_mode);
|
||||
|
||||
|
||||
void srunner_print (SRunner *sr, enum print_output print_mode)
|
||||
void
|
||||
srunner_print (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
srunner_fprint (stdout, sr, print_mode);
|
||||
}
|
||||
|
||||
void srunner_fprint (FILE *file, SRunner *sr, enum print_output print_mode)
|
||||
void
|
||||
srunner_fprint (FILE * file, SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
if (print_mode == CK_ENV) {
|
||||
print_mode = get_env_printmode();
|
||||
print_mode = get_env_printmode ();
|
||||
}
|
||||
|
||||
srunner_fprint_summary (file, sr, print_mode);
|
||||
srunner_fprint_results (file, sr, print_mode);
|
||||
}
|
||||
|
||||
static void srunner_fprint_summary (FILE *file, SRunner *sr,
|
||||
enum print_output print_mode)
|
||||
static void
|
||||
srunner_fprint_summary (FILE * file, SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
if (print_mode >= CK_MINIMAL) {
|
||||
char *str;
|
||||
|
||||
str = sr_stat_str (sr);
|
||||
fprintf (file, "%s\n", str);
|
||||
free(str);
|
||||
free (str);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void srunner_fprint_results (FILE *file, SRunner *sr,
|
||||
enum print_output print_mode)
|
||||
static void
|
||||
srunner_fprint_results (FILE * file, SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
List *resultlst;
|
||||
|
||||
resultlst = sr->resultlst;
|
||||
|
||||
for (list_front(resultlst); !list_at_end(resultlst); list_advance(resultlst)) {
|
||||
TestResult *tr = list_val(resultlst);
|
||||
for (list_front (resultlst); !list_at_end (resultlst);
|
||||
list_advance (resultlst)) {
|
||||
TestResult *tr = list_val (resultlst);
|
||||
tr_fprint (file, tr, print_mode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void tr_fprint (FILE *file, TestResult *tr, enum print_output print_mode)
|
||||
void
|
||||
tr_fprint (FILE * file, TestResult * tr, enum print_output print_mode)
|
||||
{
|
||||
if (print_mode == CK_ENV) {
|
||||
print_mode = get_env_printmode();
|
||||
print_mode = get_env_printmode ();
|
||||
}
|
||||
|
||||
if ((print_mode >= CK_VERBOSE && tr->rtype == CK_PASS) ||
|
||||
(tr->rtype != CK_PASS && print_mode >= CK_NORMAL)) {
|
||||
char *trstr = tr_str (tr);
|
||||
fprintf (file,"%s\n", trstr);
|
||||
free(trstr);
|
||||
fprintf (file, "%s\n", trstr);
|
||||
free (trstr);
|
||||
}
|
||||
}
|
||||
|
||||
void tr_xmlprint (FILE *file, TestResult *tr, enum print_output print_mode)
|
||||
void
|
||||
tr_xmlprint (FILE * file, TestResult * tr, enum print_output print_mode)
|
||||
{
|
||||
char result[10];
|
||||
char *path_name;
|
||||
|
@ -102,13 +107,13 @@ void tr_xmlprint (FILE *file, TestResult *tr, enum print_output print_mode)
|
|||
|
||||
switch (tr->rtype) {
|
||||
case CK_PASS:
|
||||
strcpy(result, "success");
|
||||
strcpy (result, "success");
|
||||
break;
|
||||
case CK_FAILURE:
|
||||
strcpy(result, "failure");
|
||||
strcpy (result, "failure");
|
||||
break;
|
||||
case CK_ERROR:
|
||||
strcpy(result, "error");
|
||||
strcpy (result, "error");
|
||||
break;
|
||||
case CK_TEST_RESULT_INVALID:
|
||||
default:
|
||||
|
@ -116,32 +121,33 @@ void tr_xmlprint (FILE *file, TestResult *tr, enum print_output print_mode)
|
|||
break;
|
||||
}
|
||||
|
||||
slash = strrchr(tr->file, '/');
|
||||
slash = strrchr (tr->file, '/');
|
||||
if (slash == NULL) {
|
||||
path_name = (char*)".";
|
||||
path_name = (char *) ".";
|
||||
file_name = tr->file;
|
||||
} else {
|
||||
path_name = strdup(tr->file);
|
||||
path_name = strdup (tr->file);
|
||||
path_name[slash - tr->file] = 0; /* Terminate the temporary string. */
|
||||
file_name = slash + 1;
|
||||
}
|
||||
|
||||
|
||||
fprintf(file, " <test result=\"%s\">\n", result);
|
||||
fprintf(file, " <path>%s</path>\n", path_name);
|
||||
fprintf(file, " <fn>%s:%d</fn>\n", file_name, tr->line);
|
||||
fprintf(file, " <id>%s</id>\n", tr->tname);
|
||||
fprintf(file, " <iteration>%d</iteration>\n", tr->iter);
|
||||
fprintf(file, " <description>%s</description>\n", tr->tcname);
|
||||
fprintf(file, " <message>%s</message>\n", tr->msg);
|
||||
fprintf(file, " </test>\n");
|
||||
fprintf (file, " <test result=\"%s\">\n", result);
|
||||
fprintf (file, " <path>%s</path>\n", path_name);
|
||||
fprintf (file, " <fn>%s:%d</fn>\n", file_name, tr->line);
|
||||
fprintf (file, " <id>%s</id>\n", tr->tname);
|
||||
fprintf (file, " <iteration>%d</iteration>\n", tr->iter);
|
||||
fprintf (file, " <description>%s</description>\n", tr->tcname);
|
||||
fprintf (file, " <message>%s</message>\n", tr->msg);
|
||||
fprintf (file, " </test>\n");
|
||||
|
||||
if (slash != NULL) {
|
||||
free(path_name);
|
||||
free (path_name);
|
||||
}
|
||||
}
|
||||
|
||||
enum print_output get_env_printmode (void)
|
||||
enum print_output
|
||||
get_env_printmode (void)
|
||||
{
|
||||
char *env = getenv ("CK_VERBOSITY");
|
||||
if (env == NULL)
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
#include "check_msg.h"
|
||||
#include "check_log.h"
|
||||
|
||||
enum rinfo {
|
||||
enum rinfo
|
||||
{
|
||||
CK_R_SIG,
|
||||
CK_R_PASS,
|
||||
CK_R_EXIT,
|
||||
|
@ -45,34 +46,33 @@ enum rinfo {
|
|||
CK_R_FAIL_FIXTURE
|
||||
};
|
||||
|
||||
enum tf_type {
|
||||
enum tf_type
|
||||
{
|
||||
CK_FORK_TEST,
|
||||
CK_NOFORK_TEST,
|
||||
CK_NOFORK_FIXTURE
|
||||
};
|
||||
|
||||
static void srunner_run_init (SRunner *sr, enum print_output print_mode);
|
||||
static void srunner_run_end (SRunner *sr, enum print_output print_mode);
|
||||
static void srunner_iterate_suites (SRunner *sr,
|
||||
enum print_output print_mode);
|
||||
static void srunner_run_tcase (SRunner *sr, TCase *tc);
|
||||
static int srunner_run_unchecked_setup (SRunner *sr, TCase *tc);
|
||||
static void srunner_run_unchecked_teardown (SRunner *sr, TCase *tc);
|
||||
static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc);
|
||||
static void tcase_run_checked_teardown (TCase *tc);
|
||||
static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc);
|
||||
static void srunner_add_failure (SRunner *sr, TestResult *tf);
|
||||
static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tf, int i);
|
||||
static TestResult *tcase_run_tfun_nofork (SRunner *sr, TCase *tc, TF *tf, int i);
|
||||
static void srunner_run_init (SRunner * sr, enum print_output print_mode);
|
||||
static void srunner_run_end (SRunner * sr, enum print_output print_mode);
|
||||
static void srunner_iterate_suites (SRunner * sr, enum print_output print_mode);
|
||||
static void srunner_run_tcase (SRunner * sr, TCase * tc);
|
||||
static int srunner_run_unchecked_setup (SRunner * sr, TCase * tc);
|
||||
static void srunner_run_unchecked_teardown (SRunner * sr, TCase * tc);
|
||||
static TestResult *tcase_run_checked_setup (SRunner * sr, TCase * tc);
|
||||
static void tcase_run_checked_teardown (TCase * tc);
|
||||
static void srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc);
|
||||
static void srunner_add_failure (SRunner * sr, TestResult * tf);
|
||||
static TestResult *tcase_run_tfun_fork (SRunner * sr, TCase * tc, TF * tf,
|
||||
int i);
|
||||
static TestResult *tcase_run_tfun_nofork (SRunner * sr, TCase * tc, TF * tf,
|
||||
int i);
|
||||
static TestResult *receive_result_info_fork (const char *tcname,
|
||||
const char *tname,
|
||||
int iter,
|
||||
int status, int expected_signal);
|
||||
const char *tname, int iter, int status, int expected_signal);
|
||||
static TestResult *receive_result_info_nofork (const char *tcname,
|
||||
const char *tname,
|
||||
int iter);
|
||||
static void set_fork_info (TestResult *tr, int status, int expected_signal);
|
||||
static void set_nofork_info (TestResult *tr);
|
||||
const char *tname, int iter);
|
||||
static void set_fork_info (TestResult * tr, int status, int expected_signal);
|
||||
static void set_nofork_info (TestResult * tr);
|
||||
static char *signal_msg (int sig);
|
||||
static char *signal_error_msg (int signal_received, int signal_expected);
|
||||
static char *pass_msg (void);
|
||||
|
@ -84,38 +84,40 @@ static int waserror (int status, int expected_signal);
|
|||
static int alarm_received;
|
||||
static pid_t group_pid;
|
||||
|
||||
static void sig_handler(int sig_nr)
|
||||
static void
|
||||
sig_handler (int sig_nr)
|
||||
{
|
||||
switch (sig_nr) {
|
||||
case SIGALRM:
|
||||
alarm_received = 1;
|
||||
killpg(group_pid, SIGKILL);
|
||||
killpg (group_pid, SIGKILL);
|
||||
break;
|
||||
default:
|
||||
eprintf("Unhandled signal: %d", __FILE__, __LINE__, sig_nr);
|
||||
eprintf ("Unhandled signal: %d", __FILE__, __LINE__, sig_nr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void srunner_run_init (SRunner *sr, enum print_output print_mode)
|
||||
static void
|
||||
srunner_run_init (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
set_fork_status(srunner_fork_status(sr));
|
||||
setup_messaging();
|
||||
set_fork_status (srunner_fork_status (sr));
|
||||
setup_messaging ();
|
||||
srunner_init_logging (sr, print_mode);
|
||||
log_srunner_start (sr);
|
||||
}
|
||||
|
||||
static void srunner_run_end (SRunner *sr, enum print_output print_mode)
|
||||
static void
|
||||
srunner_run_end (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
log_srunner_end (sr);
|
||||
srunner_end_logging (sr);
|
||||
teardown_messaging();
|
||||
set_fork_status(CK_FORK);
|
||||
teardown_messaging ();
|
||||
set_fork_status (CK_FORK);
|
||||
}
|
||||
|
||||
static void srunner_iterate_suites (SRunner *sr,
|
||||
enum print_output print_mode)
|
||||
|
||||
static void
|
||||
srunner_iterate_suites (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
List *slst;
|
||||
List *tcl;
|
||||
|
@ -123,14 +125,14 @@ static void srunner_iterate_suites (SRunner *sr,
|
|||
|
||||
slst = sr->slst;
|
||||
|
||||
for (list_front(slst); !list_at_end(slst); list_advance(slst)) {
|
||||
Suite *s = list_val(slst);
|
||||
for (list_front (slst); !list_at_end (slst); list_advance (slst)) {
|
||||
Suite *s = list_val (slst);
|
||||
|
||||
log_suite_start (sr, s);
|
||||
|
||||
tcl = s->tclst;
|
||||
|
||||
for (list_front(tcl);!list_at_end (tcl); list_advance (tcl)) {
|
||||
for (list_front (tcl); !list_at_end (tcl); list_advance (tcl)) {
|
||||
tc = list_val (tcl);
|
||||
srunner_run_tcase (sr, tc);
|
||||
}
|
||||
|
@ -139,28 +141,29 @@ static void srunner_iterate_suites (SRunner *sr,
|
|||
}
|
||||
}
|
||||
|
||||
void srunner_run_all (SRunner *sr, enum print_output print_mode)
|
||||
void
|
||||
srunner_run_all (SRunner * sr, enum print_output print_mode)
|
||||
{
|
||||
struct sigaction old_action;
|
||||
struct sigaction new_action;
|
||||
|
||||
if (sr == NULL)
|
||||
return;
|
||||
if (print_mode >= CK_LAST)
|
||||
{
|
||||
if (print_mode >= CK_LAST) {
|
||||
eprintf ("Bad print_mode argument to srunner_run_all: %d",
|
||||
__FILE__, __LINE__, print_mode);
|
||||
}
|
||||
memset(&new_action, 0, sizeof new_action);
|
||||
memset (&new_action, 0, sizeof new_action);
|
||||
new_action.sa_handler = sig_handler;
|
||||
sigaction(SIGALRM, &new_action, &old_action);
|
||||
sigaction (SIGALRM, &new_action, &old_action);
|
||||
srunner_run_init (sr, print_mode);
|
||||
srunner_iterate_suites (sr, print_mode);
|
||||
srunner_run_end (sr, print_mode);
|
||||
sigaction(SIGALRM, &old_action, NULL);
|
||||
sigaction (SIGALRM, &old_action, NULL);
|
||||
}
|
||||
|
||||
static void srunner_add_failure (SRunner *sr, TestResult *tr)
|
||||
static void
|
||||
srunner_add_failure (SRunner * sr, TestResult * tr)
|
||||
{
|
||||
list_add_end (sr->resultlst, tr);
|
||||
sr->stats->n_checked++; /* count checks during setup, test, and teardown */
|
||||
|
@ -171,7 +174,8 @@ static void srunner_add_failure (SRunner *sr, TestResult *tr)
|
|||
|
||||
}
|
||||
|
||||
static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc)
|
||||
static void
|
||||
srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc)
|
||||
{
|
||||
List *tfl;
|
||||
TF *tfun;
|
||||
|
@ -179,13 +183,12 @@ static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc)
|
|||
|
||||
tfl = tc->tflst;
|
||||
|
||||
for (list_front(tfl); !list_at_end (tfl); list_advance (tfl)) {
|
||||
for (list_front (tfl); !list_at_end (tfl); list_advance (tfl)) {
|
||||
int i;
|
||||
tfun = list_val (tfl);
|
||||
|
||||
for (i = tfun->loop_start; i < tfun->loop_end; i++)
|
||||
{
|
||||
switch (srunner_fork_status(sr)) {
|
||||
for (i = tfun->loop_start; i < tfun->loop_end; i++) {
|
||||
switch (srunner_fork_status (sr)) {
|
||||
case CK_FORK:
|
||||
tr = tcase_run_tfun_fork (sr, tc, tfun, i);
|
||||
break;
|
||||
|
@ -193,64 +196,66 @@ static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc)
|
|||
tr = tcase_run_tfun_nofork (sr, tc, tfun, i);
|
||||
break;
|
||||
default:
|
||||
eprintf("Bad fork status in SRunner", __FILE__, __LINE__);
|
||||
eprintf ("Bad fork status in SRunner", __FILE__, __LINE__);
|
||||
}
|
||||
srunner_add_failure (sr, tr);
|
||||
log_test_end(sr, tr);
|
||||
log_test_end (sr, tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int srunner_run_unchecked_setup (SRunner *sr, TCase *tc)
|
||||
static int
|
||||
srunner_run_unchecked_setup (SRunner * sr, TCase * tc)
|
||||
{
|
||||
TestResult *tr;
|
||||
List *l;
|
||||
Fixture *f;
|
||||
int rval = 1;
|
||||
|
||||
set_fork_status(CK_NOFORK);
|
||||
set_fork_status (CK_NOFORK);
|
||||
|
||||
l = tc->unch_sflst;
|
||||
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
send_ctx_info(CK_CTX_SETUP);
|
||||
f = list_val(l);
|
||||
f->fun();
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
send_ctx_info (CK_CTX_SETUP);
|
||||
f = list_val (l);
|
||||
f->fun ();
|
||||
|
||||
tr = receive_result_info_nofork (tc->name, "unchecked_setup", 0);
|
||||
|
||||
if (tr->rtype != CK_PASS) {
|
||||
srunner_add_failure(sr, tr);
|
||||
srunner_add_failure (sr, tr);
|
||||
rval = 0;
|
||||
break;
|
||||
}
|
||||
free(tr->file);
|
||||
free(tr->msg);
|
||||
free(tr);
|
||||
free (tr->file);
|
||||
free (tr->msg);
|
||||
free (tr);
|
||||
}
|
||||
|
||||
set_fork_status(srunner_fork_status(sr));
|
||||
set_fork_status (srunner_fork_status (sr));
|
||||
return rval;
|
||||
}
|
||||
|
||||
static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc)
|
||||
static TestResult *
|
||||
tcase_run_checked_setup (SRunner * sr, TCase * tc)
|
||||
{
|
||||
TestResult *tr = NULL;
|
||||
List *l;
|
||||
Fixture *f;
|
||||
enum fork_status fstat = srunner_fork_status(sr);
|
||||
enum fork_status fstat = srunner_fork_status (sr);
|
||||
|
||||
l = tc->ch_sflst;
|
||||
if (fstat == CK_FORK) {
|
||||
send_ctx_info(CK_CTX_SETUP);
|
||||
send_ctx_info (CK_CTX_SETUP);
|
||||
}
|
||||
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
if (fstat == CK_NOFORK) {
|
||||
send_ctx_info(CK_CTX_SETUP);
|
||||
send_ctx_info (CK_CTX_SETUP);
|
||||
}
|
||||
f = list_val(l);
|
||||
f->fun();
|
||||
f = list_val (l);
|
||||
f->fun ();
|
||||
|
||||
/* Stop the setup and return the failure if nofork mode. */
|
||||
if (fstat == CK_NOFORK) {
|
||||
|
@ -259,9 +264,9 @@ static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc)
|
|||
break;
|
||||
}
|
||||
|
||||
free(tr->file);
|
||||
free(tr->msg);
|
||||
free(tr);
|
||||
free (tr->file);
|
||||
free (tr->msg);
|
||||
free (tr);
|
||||
tr = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -269,122 +274,124 @@ static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc)
|
|||
return tr;
|
||||
}
|
||||
|
||||
static void tcase_run_checked_teardown (TCase *tc)
|
||||
static void
|
||||
tcase_run_checked_teardown (TCase * tc)
|
||||
{
|
||||
List *l;
|
||||
Fixture *f;
|
||||
|
||||
l = tc->ch_tflst;
|
||||
|
||||
send_ctx_info(CK_CTX_TEARDOWN);
|
||||
send_ctx_info (CK_CTX_TEARDOWN);
|
||||
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
f = list_val(l);
|
||||
f->fun();
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
f = list_val (l);
|
||||
f->fun ();
|
||||
}
|
||||
}
|
||||
|
||||
static void srunner_run_unchecked_teardown (SRunner *sr, TCase *tc)
|
||||
static void
|
||||
srunner_run_unchecked_teardown (SRunner * sr, TCase * tc)
|
||||
{
|
||||
List *l;
|
||||
Fixture *f;
|
||||
|
||||
set_fork_status(CK_NOFORK);
|
||||
set_fork_status (CK_NOFORK);
|
||||
l = tc->unch_tflst;
|
||||
|
||||
for (list_front(l); !list_at_end(l); list_advance(l)) {
|
||||
for (list_front (l); !list_at_end (l); list_advance (l)) {
|
||||
|
||||
f = list_val(l);
|
||||
send_ctx_info(CK_CTX_TEARDOWN);
|
||||
f = list_val (l);
|
||||
send_ctx_info (CK_CTX_TEARDOWN);
|
||||
f->fun ();
|
||||
}
|
||||
set_fork_status(srunner_fork_status(sr));
|
||||
set_fork_status (srunner_fork_status (sr));
|
||||
}
|
||||
|
||||
static void srunner_run_tcase (SRunner *sr, TCase *tc)
|
||||
static void
|
||||
srunner_run_tcase (SRunner * sr, TCase * tc)
|
||||
{
|
||||
if (srunner_run_unchecked_setup(sr,tc)) {
|
||||
srunner_iterate_tcase_tfuns(sr,tc);
|
||||
srunner_run_unchecked_teardown(sr, tc);
|
||||
if (srunner_run_unchecked_setup (sr, tc)) {
|
||||
srunner_iterate_tcase_tfuns (sr, tc);
|
||||
srunner_run_unchecked_teardown (sr, tc);
|
||||
}
|
||||
}
|
||||
|
||||
static TestResult *receive_result_info_fork (const char *tcname,
|
||||
const char *tname,
|
||||
int iter,
|
||||
int status, int expected_signal)
|
||||
static TestResult *
|
||||
receive_result_info_fork (const char *tcname,
|
||||
const char *tname, int iter, int status, int expected_signal)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
||||
tr = receive_test_result(waserror(status, expected_signal));
|
||||
tr = receive_test_result (waserror (status, expected_signal));
|
||||
if (tr == NULL)
|
||||
eprintf("Failed to receive test result", __FILE__, __LINE__);
|
||||
eprintf ("Failed to receive test result", __FILE__, __LINE__);
|
||||
tr->tcname = tcname;
|
||||
tr->tname = tname;
|
||||
tr->iter = iter;
|
||||
set_fork_info(tr, status, expected_signal);
|
||||
set_fork_info (tr, status, expected_signal);
|
||||
|
||||
return tr;
|
||||
}
|
||||
|
||||
static TestResult *receive_result_info_nofork (const char *tcname,
|
||||
const char *tname,
|
||||
int iter)
|
||||
static TestResult *
|
||||
receive_result_info_nofork (const char *tcname, const char *tname, int iter)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
||||
tr = receive_test_result(0);
|
||||
tr = receive_test_result (0);
|
||||
if (tr == NULL)
|
||||
eprintf("Failed to receive test result", __FILE__, __LINE__);
|
||||
eprintf ("Failed to receive test result", __FILE__, __LINE__);
|
||||
tr->tcname = tcname;
|
||||
tr->tname = tname;
|
||||
tr->iter = iter;
|
||||
set_nofork_info(tr);
|
||||
set_nofork_info (tr);
|
||||
|
||||
return tr;
|
||||
}
|
||||
|
||||
static void set_fork_info (TestResult *tr, int status, int signal_expected)
|
||||
static void
|
||||
set_fork_info (TestResult * tr, int status, int signal_expected)
|
||||
{
|
||||
int was_sig = WIFSIGNALED(status);
|
||||
int was_exit = WIFEXITED(status);
|
||||
int exit_status = WEXITSTATUS(status);
|
||||
int signal_received = WTERMSIG(status);
|
||||
int was_sig = WIFSIGNALED (status);
|
||||
int was_exit = WIFEXITED (status);
|
||||
int exit_status = WEXITSTATUS (status);
|
||||
int signal_received = WTERMSIG (status);
|
||||
|
||||
if (was_sig) {
|
||||
if (signal_expected == signal_received) {
|
||||
if (alarm_received) {
|
||||
/* Got alarm instead of signal */
|
||||
tr->rtype = CK_ERROR;
|
||||
tr->msg = signal_error_msg(signal_received, signal_expected);
|
||||
tr->msg = signal_error_msg (signal_received, signal_expected);
|
||||
} else {
|
||||
tr->rtype = CK_PASS;
|
||||
tr->msg = pass_msg();
|
||||
tr->msg = pass_msg ();
|
||||
}
|
||||
} else if (signal_expected != 0) {
|
||||
/* signal received, but not the expected one */
|
||||
tr->rtype = CK_ERROR;
|
||||
tr->msg = signal_error_msg(signal_received, signal_expected);
|
||||
tr->msg = signal_error_msg (signal_received, signal_expected);
|
||||
} else {
|
||||
/* signal received and none expected */
|
||||
tr->rtype = CK_ERROR;
|
||||
tr->msg = signal_msg(signal_received);
|
||||
tr->msg = signal_msg (signal_received);
|
||||
}
|
||||
} else if (signal_expected == 0) {
|
||||
if (was_exit && exit_status == 0) {
|
||||
tr->rtype = CK_PASS;
|
||||
tr->msg = pass_msg();
|
||||
tr->msg = pass_msg ();
|
||||
} else if (was_exit && exit_status != 0) {
|
||||
if (tr->msg == NULL) { /* early exit */
|
||||
tr->rtype = CK_ERROR;
|
||||
tr->msg = exit_msg(exit_status);
|
||||
tr->msg = exit_msg (exit_status);
|
||||
} else {
|
||||
tr->rtype = CK_FAILURE;
|
||||
}
|
||||
}
|
||||
} else { /* a signal was expected and none raised */
|
||||
if (was_exit) {
|
||||
tr->msg = exit_msg(exit_status);
|
||||
tr->msg = exit_msg (exit_status);
|
||||
if (exit_status == 0)
|
||||
tr->rtype = CK_FAILURE; /* normal exit status */
|
||||
else
|
||||
|
@ -393,68 +400,73 @@ static void set_fork_info (TestResult *tr, int status, int signal_expected)
|
|||
}
|
||||
}
|
||||
|
||||
static void set_nofork_info (TestResult *tr)
|
||||
static void
|
||||
set_nofork_info (TestResult * tr)
|
||||
{
|
||||
if (tr->msg == NULL) {
|
||||
tr->rtype = CK_PASS;
|
||||
tr->msg = pass_msg();
|
||||
tr->msg = pass_msg ();
|
||||
} else {
|
||||
tr->rtype = CK_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
static TestResult *tcase_run_tfun_nofork (SRunner *sr, TCase *tc, TF *tfun, int i)
|
||||
static TestResult *
|
||||
tcase_run_tfun_nofork (SRunner * sr, TCase * tc, TF * tfun, int i)
|
||||
{
|
||||
TestResult *tr;
|
||||
|
||||
tr = tcase_run_checked_setup(sr, tc);
|
||||
tr = tcase_run_checked_setup (sr, tc);
|
||||
if (tr == NULL) {
|
||||
tfun->fn(i);
|
||||
tcase_run_checked_teardown(tc);
|
||||
return receive_result_info_nofork(tc->name, tfun->name, i);
|
||||
tfun->fn (i);
|
||||
tcase_run_checked_teardown (tc);
|
||||
return receive_result_info_nofork (tc->name, tfun->name, i);
|
||||
}
|
||||
|
||||
return tr;
|
||||
}
|
||||
|
||||
|
||||
static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tfun, int i)
|
||||
static TestResult *
|
||||
tcase_run_tfun_fork (SRunner * sr, TCase * tc, TF * tfun, int i)
|
||||
{
|
||||
pid_t pid_w;
|
||||
pid_t pid;
|
||||
int status = 0;
|
||||
pid = fork();
|
||||
pid = fork ();
|
||||
if (pid == -1)
|
||||
eprintf("Error in call to fork:", __FILE__, __LINE__ - 2);
|
||||
eprintf ("Error in call to fork:", __FILE__, __LINE__ - 2);
|
||||
if (pid == 0) {
|
||||
setpgid(0, 0);
|
||||
group_pid = getpgrp();
|
||||
tcase_run_checked_setup(sr, tc);
|
||||
tfun->fn(i);
|
||||
tcase_run_checked_teardown(tc);
|
||||
exit(EXIT_SUCCESS);
|
||||
setpgid (0, 0);
|
||||
group_pid = getpgrp ();
|
||||
tcase_run_checked_setup (sr, tc);
|
||||
tfun->fn (i);
|
||||
tcase_run_checked_teardown (tc);
|
||||
exit (EXIT_SUCCESS);
|
||||
} else {
|
||||
group_pid = pid;
|
||||
}
|
||||
|
||||
alarm_received = 0;
|
||||
alarm(tc->timeout);
|
||||
alarm (tc->timeout);
|
||||
do {
|
||||
pid_w = waitpid(pid, &status, 0);
|
||||
pid_w = waitpid (pid, &status, 0);
|
||||
} while (pid_w == -1);
|
||||
|
||||
killpg(pid, SIGKILL); /* Kill remaining processes. */
|
||||
killpg (pid, SIGKILL); /* Kill remaining processes. */
|
||||
|
||||
return receive_result_info_fork(tc->name, tfun->name, i, status, tfun->signal);
|
||||
return receive_result_info_fork (tc->name, tfun->name, i, status,
|
||||
tfun->signal);
|
||||
}
|
||||
|
||||
static char *signal_error_msg (int signal_received, int signal_expected)
|
||||
static char *
|
||||
signal_error_msg (int signal_received, int signal_expected)
|
||||
{
|
||||
char *sig_r_str;
|
||||
char *sig_e_str;
|
||||
char *msg = emalloc (MSG_LEN); /* free'd by caller */
|
||||
sig_r_str = strdup(strsignal(signal_received));
|
||||
sig_e_str = strdup(strsignal(signal_expected));
|
||||
sig_r_str = strdup (strsignal (signal_received));
|
||||
sig_e_str = strdup (strsignal (signal_expected));
|
||||
if (alarm_received) {
|
||||
snprintf (msg, MSG_LEN, "Test timeout expired, expected signal %d (%s)",
|
||||
signal_expected, sig_e_str);
|
||||
|
@ -462,45 +474,48 @@ static char *signal_error_msg (int signal_received, int signal_expected)
|
|||
snprintf (msg, MSG_LEN, "Received signal %d (%s), expected %d (%s)",
|
||||
signal_received, sig_r_str, signal_expected, sig_e_str);
|
||||
}
|
||||
free(sig_r_str);
|
||||
free(sig_e_str);
|
||||
free (sig_r_str);
|
||||
free (sig_e_str);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static char *signal_msg (int signal)
|
||||
static char *
|
||||
signal_msg (int signal)
|
||||
{
|
||||
char *msg = emalloc(MSG_LEN); /* free'd by caller */
|
||||
char *msg = emalloc (MSG_LEN); /* free'd by caller */
|
||||
if (alarm_received) {
|
||||
snprintf(msg, MSG_LEN, "Test timeout expired");
|
||||
snprintf (msg, MSG_LEN, "Test timeout expired");
|
||||
} else {
|
||||
snprintf(msg, MSG_LEN, "Received signal %d (%s)",
|
||||
signal, strsignal(signal));
|
||||
snprintf (msg, MSG_LEN, "Received signal %d (%s)",
|
||||
signal, strsignal (signal));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
static char *exit_msg (int exitval)
|
||||
static char *
|
||||
exit_msg (int exitval)
|
||||
{
|
||||
char *msg = emalloc(MSG_LEN); /* free'd by caller */
|
||||
snprintf (msg, MSG_LEN,
|
||||
"Early exit with return value %d", exitval);
|
||||
char *msg = emalloc (MSG_LEN); /* free'd by caller */
|
||||
snprintf (msg, MSG_LEN, "Early exit with return value %d", exitval);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static char *pass_msg (void)
|
||||
static char *
|
||||
pass_msg (void)
|
||||
{
|
||||
char *msg = emalloc(sizeof("Passed"));
|
||||
char *msg = emalloc (sizeof ("Passed"));
|
||||
strcpy (msg, "Passed");
|
||||
return msg;
|
||||
}
|
||||
|
||||
enum fork_status srunner_fork_status (SRunner *sr)
|
||||
enum fork_status
|
||||
srunner_fork_status (SRunner * sr)
|
||||
{
|
||||
if (sr->fstat == CK_FORK_GETENV) {
|
||||
char *env = getenv ("CK_FORK");
|
||||
if (env == NULL)
|
||||
return CK_FORK;
|
||||
if (strcmp (env,"no") == 0)
|
||||
if (strcmp (env, "no") == 0)
|
||||
return CK_NOFORK;
|
||||
else
|
||||
return CK_FORK;
|
||||
|
@ -508,40 +523,44 @@ enum fork_status srunner_fork_status (SRunner *sr)
|
|||
return sr->fstat;
|
||||
}
|
||||
|
||||
void srunner_set_fork_status (SRunner *sr, enum fork_status fstat)
|
||||
void
|
||||
srunner_set_fork_status (SRunner * sr, enum fork_status fstat)
|
||||
{
|
||||
sr->fstat = fstat;
|
||||
}
|
||||
|
||||
pid_t check_fork (void)
|
||||
pid_t
|
||||
check_fork (void)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
pid_t pid = fork ();
|
||||
/* Set the process to a process group to be able to kill it easily. */
|
||||
setpgid(pid, group_pid);
|
||||
setpgid (pid, group_pid);
|
||||
return pid;
|
||||
}
|
||||
|
||||
void check_waitpid_and_exit (pid_t pid)
|
||||
void
|
||||
check_waitpid_and_exit (pid_t pid)
|
||||
{
|
||||
pid_t pid_w;
|
||||
int status;
|
||||
|
||||
if (pid > 0) {
|
||||
do {
|
||||
pid_w = waitpid(pid, &status, 0);
|
||||
pid_w = waitpid (pid, &status, 0);
|
||||
} while (pid_w == -1);
|
||||
if (waserror(status, 0))
|
||||
exit(EXIT_FAILURE);
|
||||
if (waserror (status, 0))
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int waserror (int status, int signal_expected)
|
||||
static int
|
||||
waserror (int status, int signal_expected)
|
||||
{
|
||||
int was_sig = WIFSIGNALED (status);
|
||||
int was_exit = WIFEXITED (status);
|
||||
int exit_status = WEXITSTATUS (status);
|
||||
int signal_received = WTERMSIG(status);
|
||||
int signal_received = WTERMSIG (status);
|
||||
|
||||
return ((was_sig && (signal_received != signal_expected)) ||
|
||||
(was_exit && exit_status != 0));
|
||||
|
|
|
@ -29,25 +29,26 @@
|
|||
#include "check_impl.h"
|
||||
#include "check_str.h"
|
||||
|
||||
static const char *tr_type_str (TestResult *tr);
|
||||
static int percent_passed (TestStats *t);
|
||||
static const char *tr_type_str (TestResult * tr);
|
||||
static int percent_passed (TestStats * t);
|
||||
|
||||
char *tr_str (TestResult *tr)
|
||||
char *
|
||||
tr_str (TestResult * tr)
|
||||
{
|
||||
const char *exact_msg;
|
||||
char *rstr;
|
||||
|
||||
exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) ": "";
|
||||
exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) " : "";
|
||||
|
||||
rstr = ck_strdup_printf ("%s:%d:%s:%s:%s:%d: %s%s",
|
||||
tr->file, tr->line,
|
||||
tr_type_str(tr), tr->tcname, tr->tname, tr->iter,
|
||||
exact_msg, tr->msg);
|
||||
tr_type_str (tr), tr->tcname, tr->tname, tr->iter, exact_msg, tr->msg);
|
||||
|
||||
return rstr;
|
||||
}
|
||||
|
||||
char *sr_stat_str (SRunner *sr)
|
||||
char *
|
||||
sr_stat_str (SRunner * sr)
|
||||
{
|
||||
char *str;
|
||||
TestStats *ts;
|
||||
|
@ -55,13 +56,13 @@ char *sr_stat_str (SRunner *sr)
|
|||
ts = sr->stats;
|
||||
|
||||
str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d",
|
||||
percent_passed (ts), ts->n_checked, ts->n_failed,
|
||||
ts->n_errors);
|
||||
percent_passed (ts), ts->n_checked, ts->n_failed, ts->n_errors);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *ck_strdup_printf (const char *fmt, ...)
|
||||
char *
|
||||
ck_strdup_printf (const char *fmt, ...)
|
||||
{
|
||||
/* Guess we need no more than 100 bytes. */
|
||||
int n, size = 100;
|
||||
|
@ -70,19 +71,18 @@ char *ck_strdup_printf (const char *fmt, ...)
|
|||
|
||||
p = emalloc (size);
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
/* Try to print in the allocated space. */
|
||||
va_start(ap, fmt);
|
||||
va_start (ap, fmt);
|
||||
n = vsnprintf (p, size, fmt, ap);
|
||||
va_end(ap);
|
||||
va_end (ap);
|
||||
/* If that worked, return the string. */
|
||||
if (n > -1 && n < size)
|
||||
return p;
|
||||
|
||||
/* Else try again with more space. */
|
||||
if (n > -1) /* C99 conform vsnprintf() */
|
||||
size = n+1; /* precisely what is needed */
|
||||
size = n + 1; /* precisely what is needed */
|
||||
else /* glibc 2.0 */
|
||||
size *= 2; /* twice the old size */
|
||||
|
||||
|
@ -90,7 +90,8 @@ char *ck_strdup_printf (const char *fmt, ...)
|
|||
}
|
||||
}
|
||||
|
||||
static const char *tr_type_str (TestResult *tr)
|
||||
static const char *
|
||||
tr_type_str (TestResult * tr)
|
||||
{
|
||||
const char *str = NULL;
|
||||
if (tr->ctx == CK_CTX_TEST) {
|
||||
|
@ -106,13 +107,14 @@ static const char *tr_type_str (TestResult *tr)
|
|||
return str;
|
||||
}
|
||||
|
||||
static int percent_passed (TestStats *t)
|
||||
static int
|
||||
percent_passed (TestStats * t)
|
||||
{
|
||||
if (t->n_failed == 0 && t->n_errors == 0)
|
||||
return 100;
|
||||
else if (t->n_checked == 0)
|
||||
return 0;
|
||||
else
|
||||
return (int) ( (float) (t->n_checked - (t->n_failed + t->n_errors)) /
|
||||
return (int) ((float) (t->n_checked - (t->n_failed + t->n_errors)) /
|
||||
(float) t->n_checked * 100);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue