libs/gst/check: Run gst-indent on libcheck.

This commit is contained in:
Edward Hervey 2009-10-12 13:49:35 +02:00
parent 7f68d7a6f8
commit bf3ab71a2b
9 changed files with 825 additions and 704 deletions

View file

@ -106,7 +106,8 @@ rpl_strsignal (int sig)
return signame; return signame;
} }
Suite *suite_create (const char *name) Suite *
suite_create (const char *name)
{ {
Suite *s; Suite *s;
s = emalloc (sizeof (Suite)); /* freed in suite_free */ s = emalloc (sizeof (Suite)); /* freed in suite_free */
@ -118,7 +119,8 @@ Suite *suite_create (const char *name)
return s; return s;
} }
static void suite_free (Suite *s) static void
suite_free (Suite * s)
{ {
List *l; List *l;
if (s == NULL) if (s == NULL)
@ -131,7 +133,8 @@ static void suite_free (Suite *s)
free (s); free (s);
} }
TCase *tcase_create (const char *name) TCase *
tcase_create (const char *name)
{ {
char *env; char *env;
int timeout = DEFAULT_TIMEOUT; int timeout = DEFAULT_TIMEOUT;
@ -160,7 +163,8 @@ TCase *tcase_create (const char *name)
} }
static void tcase_free (TCase *tc) static void
tcase_free (TCase * tc)
{ {
list_apply (tc->tflst, free); list_apply (tc->tflst, free);
list_apply (tc->unch_sflst, free); list_apply (tc->unch_sflst, free);
@ -176,14 +180,17 @@ static void tcase_free (TCase *tc)
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) if (s == NULL || tc == NULL)
return; return;
list_add_end (s->tclst, tc); 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) if (tc == NULL || fn == NULL || name == NULL)
@ -197,7 +204,8 @@ void _tcase_add_test (TCase *tc, TFun fn, const char *name, int _signal, int sta
list_add_end (tc->tflst, tf); list_add_end (tc->tflst, tf);
} }
static Fixture *fixture_create (SFun fun, int ischecked) static Fixture *
fixture_create (SFun fun, int ischecked)
{ {
Fixture *f; Fixture *f;
f = emalloc (sizeof (Fixture)); f = emalloc (sizeof (Fixture));
@ -207,18 +215,20 @@ static Fixture *fixture_create (SFun fun, int ischecked)
return f; 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, static void
int ischecked) tcase_add_fixture (TCase * tc, SFun setup, SFun teardown, int ischecked)
{ {
if (setup) { if (setup) {
if (ischecked) if (ischecked)
@ -236,25 +246,28 @@ static void tcase_add_fixture (TCase *tc, SFun setup, SFun teardown,
} }
} }
void tcase_set_timeout (TCase *tc, int timeout) void
tcase_set_timeout (TCase * tc, int timeout)
{ {
if (timeout >= 0) if (timeout >= 0)
tc->timeout = timeout; 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_ctx_info (CK_CTX_TEST);
send_loc_info (file, line); 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); send_loc_info (file, line);
} }
void _fail_unless (int result, const char *file, void
int line, const char *expr, ...) _fail_unless (int result, const char *file, int line, const char *expr, ...)
{ {
const char *msg; const char *msg;
@ -275,7 +288,8 @@ void _fail_unless (int result, const char *file,
} }
} }
SRunner *srunner_create (Suite *s) SRunner *
srunner_create (Suite * s)
{ {
SRunner *sr = emalloc (sizeof (SRunner)); /* freed in srunner_free */ SRunner *sr = emalloc (sizeof (SRunner)); /* freed in srunner_free */
sr->slst = check_list_create (); sr->slst = check_list_create ();
@ -291,7 +305,8 @@ SRunner *srunner_create (Suite *s)
return sr; return sr;
} }
void srunner_add_suite (SRunner *sr, Suite *s) void
srunner_add_suite (SRunner * sr, Suite * s)
{ {
if (s == NULL) if (s == NULL)
return; return;
@ -299,7 +314,8 @@ void srunner_add_suite (SRunner *sr, Suite *s)
list_add_end (sr->slst, s); list_add_end (sr->slst, s);
} }
void srunner_free (SRunner *sr) void
srunner_free (SRunner * sr)
{ {
List *l; List *l;
TestResult *tr; TestResult *tr;
@ -325,17 +341,20 @@ void srunner_free (SRunner *sr)
free (sr); free (sr);
} }
int srunner_ntests_failed (SRunner *sr) int
srunner_ntests_failed (SRunner * sr)
{ {
return sr->stats->n_failed + sr->stats->n_errors; 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; return sr->stats->n_checked;
} }
TestResult **srunner_failures (SRunner *sr) TestResult **
srunner_failures (SRunner * sr)
{ {
int i = 0; int i = 0;
TestResult **trarray; TestResult **trarray;
@ -352,7 +371,8 @@ TestResult **srunner_failures (SRunner *sr)
return trarray; return trarray;
} }
TestResult **srunner_results (SRunner *sr) TestResult **
srunner_results (SRunner * sr)
{ {
int i = 0; int i = 0;
TestResult **trarray; TestResult **trarray;
@ -367,12 +387,14 @@ TestResult **srunner_results (SRunner *sr)
return trarray; return trarray;
} }
static int non_pass (int val) static int
non_pass (int val)
{ {
return val != CK_PASS; return val != CK_PASS;
} }
TestResult *tr_create(void) TestResult *
tr_create (void)
{ {
TestResult *tr; TestResult *tr;
@ -381,12 +403,14 @@ TestResult *tr_create(void)
return 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->ctx = CK_CTX_INVALID;
tr->line = -1; 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; return tr->msg;
} }
int tr_lno (TestResult *tr) int
tr_lno (TestResult * tr)
{ {
return tr->line; return tr->line;
} }
const char *tr_lfile (TestResult *tr) const char *
tr_lfile (TestResult * tr)
{ {
return tr->file; return tr->file;
} }
int tr_rtype (TestResult *tr) int
tr_rtype (TestResult * tr)
{ {
return tr->rtype; return tr->rtype;
} }
enum ck_result_ctx tr_ctx (TestResult *tr) enum ck_result_ctx
tr_ctx (TestResult * tr)
{ {
return tr->ctx; return tr->ctx;
} }
const char *tr_tcname (TestResult *tr) const char *
tr_tcname (TestResult * tr)
{ {
return tr->tcname; return tr->tcname;
} }
static int _fstat = CK_FORK; 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) if (fstat == CK_FORK || fstat == CK_NOFORK || fstat == CK_FORK_GETENV)
_fstat = fstat; _fstat = fstat;
@ -438,7 +469,8 @@ void set_fork_status (enum fork_status fstat)
eprintf ("Bad status in set_fork_status", __FILE__, __LINE__); 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; return _fstat;
} }

View file

@ -30,7 +30,8 @@
/* FIXME: including a colon at the end is a bad way to indicate an error */ /* 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; va_list args;
fflush (stderr); fflush (stderr);
@ -48,7 +49,8 @@ void eprintf (const char *fmt, const char *file, int line, ...)
exit (2); exit (2);
} }
void *emalloc (size_t n) void *
emalloc (size_t n)
{ {
void *p; void *p;
p = malloc (n); p = malloc (n);
@ -57,7 +59,8 @@ void *emalloc (size_t n)
return p; return p;
} }
void *erealloc (void * ptr, size_t n) void *
erealloc (void *ptr, size_t n)
{ {
void *p; void *p;
p = realloc (ptr, n); p = realloc (ptr, n);

View file

@ -27,12 +27,14 @@
#include "check_error.h" #include "check_error.h"
enum { enum
{
LINIT = 1, LINIT = 1,
LGROW = 2 LGROW = 2
}; };
struct List { struct List
{
int n_elts; int n_elts;
int max_elts; int max_elts;
int current; /* pointer to the current node */ int current; /* pointer to the current node */
@ -40,7 +42,8 @@ struct List {
const void **data; const void **data;
}; };
static void maybe_grow (List *lp) static void
maybe_grow (List * lp)
{ {
if (lp->n_elts >= lp->max_elts) { if (lp->n_elts >= lp->max_elts) {
lp->max_elts *= LGROW; lp->max_elts *= LGROW;
@ -48,7 +51,8 @@ static void maybe_grow (List *lp)
} }
} }
List *check_list_create (void) List *
check_list_create (void)
{ {
List *lp; List *lp;
lp = emalloc (sizeof (List)); lp = emalloc (sizeof (List));
@ -59,7 +63,8 @@ List *check_list_create (void)
return lp; return lp;
} }
void list_add_front (List *lp, const void *val) void
list_add_front (List * lp, const void *val)
{ {
if (lp == NULL) if (lp == NULL)
return; return;
@ -71,7 +76,8 @@ void list_add_front (List *lp, const void *val)
lp->data[lp->current] = val; 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) if (lp == NULL)
return; return;
@ -82,7 +88,8 @@ void list_add_end (List *lp, const void *val)
lp->data[lp->current] = val; lp->data[lp->current] = val;
} }
int list_at_end (List *lp) int
list_at_end (List * lp)
{ {
if (lp->current == -1) if (lp->current == -1)
return 1; return 1;
@ -90,7 +97,8 @@ int list_at_end (List *lp)
return (lp->current > lp->last); return (lp->current > lp->last);
} }
void list_front (List *lp) void
list_front (List * lp)
{ {
if (lp->current == -1) if (lp->current == -1)
return; return;
@ -98,7 +106,8 @@ void list_front (List *lp)
} }
void list_free (List *lp) void
list_free (List * lp)
{ {
if (lp == NULL) if (lp == NULL)
return; return;
@ -107,7 +116,8 @@ void list_free (List *lp)
free (lp); free (lp);
} }
void *list_val (List *lp) void *
list_val (List * lp)
{ {
if (lp == NULL) if (lp == NULL)
return NULL; return NULL;
@ -117,7 +127,8 @@ void *list_val (List *lp)
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) if (lp == NULL)
return; return;
@ -127,7 +138,8 @@ void list_advance (List *lp)
} }
void list_apply (List *lp, void (*fp) (void *)) void
list_apply (List * lp, void (*fp) (void *))
{ {
if (lp == NULL || fp == NULL) if (lp == NULL || fp == NULL)
return; return;
@ -136,6 +148,3 @@ void list_apply (List *lp, void (*fp) (void *))
fp (list_val (lp)); fp (list_val (lp));
} }

View file

@ -35,42 +35,49 @@
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) if (sr->log_fname)
return; return;
sr->log_fname = fname; sr->log_fname = fname;
} }
int srunner_has_log (SRunner *sr) int
srunner_has_log (SRunner * sr)
{ {
return sr->log_fname != NULL; return sr->log_fname != NULL;
} }
const char *srunner_log_fname (SRunner *sr) const char *
srunner_log_fname (SRunner * sr)
{ {
return sr->log_fname; 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) if (sr->xml_fname)
return; return;
sr->xml_fname = fname; sr->xml_fname = fname;
} }
int srunner_has_xml (SRunner *sr) int
srunner_has_xml (SRunner * sr)
{ {
return sr->xml_fname != NULL; return sr->xml_fname != NULL;
} }
const char *srunner_xml_fname (SRunner *sr) const char *
srunner_xml_fname (SRunner * sr)
{ {
return sr->xml_fname; 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) LFun lfun, enum print_output printmode)
{ {
Log *l = emalloc (sizeof (Log)); Log *l = emalloc (sizeof (Log));
@ -87,32 +94,38 @@ void srunner_register_lfun (SRunner *sr, FILE *lfile, int close,
return; return;
} }
void log_srunner_start (SRunner *sr) void
log_srunner_start (SRunner * sr)
{ {
srunner_send_evt (sr, NULL, CLSTART_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); 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); 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); 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); 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; List *l;
Log *lg; Log *lg;
@ -125,7 +138,8 @@ static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt)
} }
} }
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) void *obj, enum cl_event evt)
{ {
TestResult *tr; TestResult *tr;
@ -173,7 +187,8 @@ void stdout_lfun (SRunner *sr, FILE *file, enum print_output printmode,
} }
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) void *obj, enum cl_event evt)
{ {
TestResult *tr; TestResult *tr;
@ -208,7 +223,8 @@ void lfile_lfun (SRunner *sr, FILE *file, enum print_output printmode,
} }
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) void *obj, enum cl_event evt)
{ {
TestResult *tr; TestResult *tr;
@ -216,8 +232,7 @@ void xml_lfun (SRunner *sr, FILE *file, enum print_output printmode,
static struct timeval inittv, endtv; 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; struct tm now;
gettimeofday (&inittv, NULL); gettimeofday (&inittv, NULL);
localtime_r (&(inittv.tv_sec), &now); localtime_r (&(inittv.tv_sec), &now);
@ -227,13 +242,14 @@ void xml_lfun (SRunner *sr, FILE *file, enum print_output printmode,
switch (evt) { switch (evt) {
case CLINITLOG_SR: case CLINITLOG_SR:
fprintf (file, "<?xml version=\"1.0\"?>\n"); fprintf (file, "<?xml version=\"1.0\"?>\n");
fprintf(file, "<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n"); fprintf (file,
"<testsuites xmlns=\"http://check.sourceforge.net/ns\">\n");
fprintf (file, " <datetime>%s</datetime>\n", t); fprintf (file, " <datetime>%s</datetime>\n", t);
break; break;
case CLENDLOG_SR: case CLENDLOG_SR:
gettimeofday (&endtv, NULL); gettimeofday (&endtv, NULL);
fprintf (file, " <duration>%f</duration>\n", fprintf (file, " <duration>%f</duration>\n",
(endtv.tv_sec + (float)(endtv.tv_usec)/1000000) - \ (endtv.tv_sec + (float) (endtv.tv_usec) / 1000000) -
(inittv.tv_sec + (float) (inittv.tv_usec / 1000000))); (inittv.tv_sec + (float) (inittv.tv_usec / 1000000)));
fprintf (file, "</testsuites>\n"); fprintf (file, "</testsuites>\n");
break; break;
@ -261,31 +277,34 @@ void xml_lfun (SRunner *sr, FILE *file, enum print_output printmode,
} }
FILE *srunner_open_lfile (SRunner *sr) FILE *
srunner_open_lfile (SRunner * sr)
{ {
FILE *f = NULL; FILE *f = NULL;
if (srunner_has_log (sr)) { if (srunner_has_log (sr)) {
f = fopen (sr->log_fname, "w"); f = fopen (sr->log_fname, "w");
if (f == NULL) if (f == NULL)
eprintf ("Error in call to fopen while opening log file %s:", __FILE__, __LINE__ - 2, eprintf ("Error in call to fopen while opening log file %s:", __FILE__,
sr->log_fname); __LINE__ - 2, sr->log_fname);
} }
return f; return f;
} }
FILE *srunner_open_xmlfile (SRunner *sr) FILE *
srunner_open_xmlfile (SRunner * sr)
{ {
FILE *f = NULL; FILE *f = NULL;
if (srunner_has_xml (sr)) { if (srunner_has_xml (sr)) {
f = fopen (sr->xml_fname, "w"); f = fopen (sr->xml_fname, "w");
if (f == NULL) if (f == NULL)
eprintf ("Error in call to fopen while opening xml file %s:", __FILE__, __LINE__ - 2, eprintf ("Error in call to fopen while opening xml file %s:", __FILE__,
sr->xml_fname); __LINE__ - 2, sr->xml_fname);
} }
return f; 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; FILE *f;
sr->loglst = check_list_create (); sr->loglst = check_list_create ();
@ -301,7 +320,8 @@ void srunner_init_logging (SRunner *sr, enum print_output print_mode)
srunner_send_evt (sr, NULL, CLINITLOG_SR); srunner_send_evt (sr, NULL, CLINITLOG_SR);
} }
void srunner_end_logging (SRunner *sr) void
srunner_end_logging (SRunner * sr)
{ {
List *l; List *l;
int rval; int rval;
@ -314,7 +334,8 @@ void srunner_end_logging (SRunner *sr)
if (lg->close) { if (lg->close) {
rval = fclose (lg->lfile); rval = fclose (lg->lfile);
if (rval != 0) 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); free (lg);
} }

View file

@ -63,7 +63,8 @@ static void teardown_pipe (void);
static TestResult *construct_test_result (RcvMsg * rmsg, int waserror); static TestResult *construct_test_result (RcvMsg * rmsg, int waserror);
static void tr_set_loc_by_ctx (TestResult * tr, enum ck_result_ctx ctx, static void tr_set_loc_by_ctx (TestResult * tr, enum ck_result_ctx ctx,
RcvMsg * rmsg); RcvMsg * rmsg);
static FILE * get_pipe(void) static FILE *
get_pipe (void)
{ {
if (send_file2 != 0) { if (send_file2 != 0) {
return send_file2; return send_file2;
@ -78,7 +79,8 @@ static FILE * get_pipe(void)
return NULL; return NULL;
} }
void send_failure_info(const char *msg) void
send_failure_info (const char *msg)
{ {
FailMsg fmsg; FailMsg fmsg;
@ -86,7 +88,8 @@ void send_failure_info(const 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; LocMsg lmsg;
@ -95,7 +98,8 @@ void send_loc_info(const char * file, int 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; CtxMsg cmsg;
@ -103,7 +107,8 @@ void send_ctx_info(enum ck_result_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; FILE *fp;
RcvMsg *rmsg; RcvMsg *rmsg;
@ -122,8 +127,8 @@ TestResult *receive_test_result (int waserror)
return result; return result;
} }
static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx, static void
RcvMsg *rmsg) tr_set_loc_by_ctx (TestResult * tr, enum ck_result_ctx ctx, RcvMsg * rmsg)
{ {
if (ctx == CK_CTX_TEST) { if (ctx == CK_CTX_TEST) {
tr->file = rmsg->test_file; tr->file = rmsg->test_file;
@ -138,7 +143,8 @@ 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; TestResult *tr;
@ -165,17 +171,20 @@ static TestResult *construct_test_result (RcvMsg *rmsg, int waserror)
return tr; 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_file1 != 0) {
if (send_file2 != 0) if (send_file2 != 0)
@ -186,7 +195,8 @@ static void setup_pipe(void)
} }
} }
static void teardown_pipe(void) static void
teardown_pipe (void)
{ {
if (send_file2 != 0) { if (send_file2 != 0) {
fclose (send_file2); fclose (send_file2);
@ -198,4 +208,3 @@ static void teardown_pipe(void)
eprintf ("No messaging setup", __FILE__, __LINE__); eprintf ("No messaging setup", __FILE__, __LINE__);
} }
} }

View file

@ -78,7 +78,8 @@ static upfun upftab [] = {
(upfun) upack_loc (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) if (buf == NULL)
return -1; return -1;
@ -90,7 +91,8 @@ int pack (enum ck_msg_type type, char **buf, CheckMsg *msg)
return pftab[type] (buf, 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; char *obuf;
int nread; int nread;
@ -110,7 +112,8 @@ int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type)
return nread; return nread;
} }
static void pack_int (char **buf, int val) static void
pack_int (char **buf, int val)
{ {
unsigned char *ubuf = (unsigned char *) *buf; unsigned char *ubuf = (unsigned char *) *buf;
ck_uint32 uval = val; ck_uint32 uval = val;
@ -123,7 +126,8 @@ static void pack_int (char **buf, int val)
*buf += 4; *buf += 4;
} }
static int upack_int (char **buf) static int
upack_int (char **buf)
{ {
unsigned char *ubuf = (unsigned char *) *buf; unsigned char *ubuf = (unsigned char *) *buf;
ck_uint32 uval; ck_uint32 uval;
@ -135,7 +139,8 @@ static int upack_int (char **buf)
return (int) uval; return (int) uval;
} }
static void pack_str (char **buf, const char *val) static void
pack_str (char **buf, const char *val)
{ {
int strsz; 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; char *val;
int strsz; int strsz;
@ -172,18 +178,21 @@ static char *upack_str (char **buf)
return val; 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); 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); 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; char *ptr;
int len; int len;
@ -197,12 +206,14 @@ static int pack_ctx (char **buf, CtxMsg *cmsg)
return len; return len;
} }
static void upack_ctx (char **buf, CtxMsg *cmsg) static void
upack_ctx (char **buf, CtxMsg * cmsg)
{ {
cmsg->ctx = upack_int (buf); cmsg->ctx = upack_int (buf);
} }
static int pack_loc (char **buf, LocMsg *lmsg) static int
pack_loc (char **buf, LocMsg * lmsg)
{ {
char *ptr; char *ptr;
int len; int len;
@ -217,13 +228,15 @@ static int pack_loc (char **buf, LocMsg *lmsg)
return len; return len;
} }
static void upack_loc (char **buf, LocMsg *lmsg) static void
upack_loc (char **buf, LocMsg * lmsg)
{ {
lmsg->file = upack_str (buf); lmsg->file = upack_str (buf);
lmsg->line = upack_int (buf); lmsg->line = upack_int (buf);
} }
static int pack_fail (char **buf, FailMsg *fmsg) static int
pack_fail (char **buf, FailMsg * fmsg)
{ {
char *ptr; char *ptr;
int len; int len;
@ -237,18 +250,21 @@ static int pack_fail (char **buf, FailMsg *fmsg)
return len; return len;
} }
static void upack_fail (char **buf, FailMsg *fmsg) static void
upack_fail (char **buf, FailMsg * fmsg)
{ {
fmsg->msg = upack_str (buf); 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) if (type < 0 || type >= CK_MSG_LAST)
eprintf ("Bad message type arg", file, line); 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; char *buf;
int n; int n;
@ -262,7 +278,8 @@ void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg)
free (buf); free (buf);
} }
static int read_buf (int fdes, char **buf) static int
read_buf (int fdes, char **buf)
{ {
char *readloc; char *readloc;
int n; int n;
@ -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; enum ck_msg_type type;
CheckMsg msg; CheckMsg msg;
@ -304,21 +322,17 @@ static int get_result (char *buf, RcvMsg *rmsg)
rcvmsg_update_ctx (rmsg, cmsg->ctx); rcvmsg_update_ctx (rmsg, cmsg->ctx);
} else if (type == CK_MSG_LOC) { } else if (type == CK_MSG_LOC) {
LocMsg *lmsg = (LocMsg *) & msg; LocMsg *lmsg = (LocMsg *) & msg;
if (rmsg->failctx == CK_CTX_INVALID) if (rmsg->failctx == CK_CTX_INVALID) {
{
rcvmsg_update_loc (rmsg, lmsg->file, lmsg->line); rcvmsg_update_loc (rmsg, lmsg->file, lmsg->line);
} }
free (lmsg->file); free (lmsg->file);
} else if (type == CK_MSG_FAIL) { } else if (type == CK_MSG_FAIL) {
FailMsg *fmsg = (FailMsg *) & msg; FailMsg *fmsg = (FailMsg *) & msg;
if (rmsg->msg == NULL) if (rmsg->msg == NULL) {
{
rmsg->msg = emalloc (strlen (fmsg->msg) + 1); rmsg->msg = emalloc (strlen (fmsg->msg) + 1);
strcpy (rmsg->msg, fmsg->msg); strcpy (rmsg->msg, fmsg->msg);
rmsg->failctx = rmsg->lastctx; rmsg->failctx = rmsg->lastctx;
} } else {
else
{
/* Skip subsequent failure messages, only happens for CK_NOFORK */ /* Skip subsequent failure messages, only happens for CK_NOFORK */
} }
free (fmsg->msg); free (fmsg->msg);
@ -328,19 +342,22 @@ static int get_result (char *buf, RcvMsg *rmsg)
return n; return n;
} }
static void reset_rcv_test (RcvMsg *rmsg) static void
reset_rcv_test (RcvMsg * rmsg)
{ {
rmsg->test_line = -1; rmsg->test_line = -1;
rmsg->test_file = NULL; rmsg->test_file = NULL;
} }
static void reset_rcv_fixture (RcvMsg *rmsg) static void
reset_rcv_fixture (RcvMsg * rmsg)
{ {
rmsg->fixture_line = -1; rmsg->fixture_line = -1;
rmsg->fixture_file = NULL; rmsg->fixture_file = NULL;
} }
static RcvMsg *rcvmsg_create (void) static RcvMsg *
rcvmsg_create (void)
{ {
RcvMsg *rmsg; RcvMsg *rmsg;
@ -353,7 +370,8 @@ static RcvMsg *rcvmsg_create (void)
return rmsg; return rmsg;
} }
void rcvmsg_free (RcvMsg *rmsg) void
rcvmsg_free (RcvMsg * rmsg)
{ {
free (rmsg->fixture_file); free (rmsg->fixture_file);
free (rmsg->test_file); free (rmsg->test_file);
@ -361,17 +379,18 @@ void rcvmsg_free (RcvMsg *rmsg)
free (rmsg); 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)
{ {
if (rmsg->lastctx != CK_CTX_INVALID) {
free (rmsg->fixture_file); free (rmsg->fixture_file);
reset_rcv_fixture (rmsg); reset_rcv_fixture (rmsg);
} }
rmsg->lastctx = ctx; 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);
@ -388,7 +407,8 @@ static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line)
} }
} }
RcvMsg *punpack (int fdes) RcvMsg *
punpack (int fdes)
{ {
int nread, n; int nread, n;
char *buf; char *buf;

View file

@ -37,12 +37,14 @@ static void srunner_fprint_results (FILE *file, SRunner *sr,
enum print_output print_mode); 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); 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) { if (print_mode == CK_ENV) {
print_mode = get_env_printmode (); print_mode = get_env_printmode ();
@ -52,8 +54,8 @@ void srunner_fprint (FILE *file, SRunner *sr, enum print_output print_mode)
srunner_fprint_results (file, sr, print_mode); srunner_fprint_results (file, sr, print_mode);
} }
static void srunner_fprint_summary (FILE *file, SRunner *sr, static void
enum print_output print_mode) srunner_fprint_summary (FILE * file, SRunner * sr, enum print_output print_mode)
{ {
if (print_mode >= CK_MINIMAL) { if (print_mode >= CK_MINIMAL) {
char *str; char *str;
@ -65,21 +67,23 @@ static void srunner_fprint_summary (FILE *file, SRunner *sr,
return; return;
} }
static void srunner_fprint_results (FILE *file, SRunner *sr, static void
enum print_output print_mode) srunner_fprint_results (FILE * file, SRunner * sr, enum print_output print_mode)
{ {
List *resultlst; List *resultlst;
resultlst = sr->resultlst; resultlst = sr->resultlst;
for (list_front(resultlst); !list_at_end(resultlst); list_advance(resultlst)) { for (list_front (resultlst); !list_at_end (resultlst);
list_advance (resultlst)) {
TestResult *tr = list_val (resultlst); TestResult *tr = list_val (resultlst);
tr_fprint (file, tr, print_mode); tr_fprint (file, tr, print_mode);
} }
return; 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) { if (print_mode == CK_ENV) {
print_mode = get_env_printmode (); print_mode = get_env_printmode ();
@ -93,7 +97,8 @@ void tr_fprint (FILE *file, TestResult *tr, enum print_output print_mode)
} }
} }
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 result[10];
char *path_name; char *path_name;
@ -141,7 +146,8 @@ void tr_xmlprint (FILE *file, TestResult *tr, enum print_output print_mode)
} }
} }
enum print_output get_env_printmode (void) enum print_output
get_env_printmode (void)
{ {
char *env = getenv ("CK_VERBOSITY"); char *env = getenv ("CK_VERBOSITY");
if (env == NULL) if (env == NULL)

View file

@ -37,7 +37,8 @@
#include "check_msg.h" #include "check_msg.h"
#include "check_log.h" #include "check_log.h"
enum rinfo { enum rinfo
{
CK_R_SIG, CK_R_SIG,
CK_R_PASS, CK_R_PASS,
CK_R_EXIT, CK_R_EXIT,
@ -45,7 +46,8 @@ enum rinfo {
CK_R_FAIL_FIXTURE CK_R_FAIL_FIXTURE
}; };
enum tf_type { enum tf_type
{
CK_FORK_TEST, CK_FORK_TEST,
CK_NOFORK_TEST, CK_NOFORK_TEST,
CK_NOFORK_FIXTURE CK_NOFORK_FIXTURE
@ -53,8 +55,7 @@ enum tf_type {
static void srunner_run_init (SRunner * sr, enum print_output print_mode); 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_run_end (SRunner * sr, enum print_output print_mode);
static void srunner_iterate_suites (SRunner *sr, static void srunner_iterate_suites (SRunner * sr, enum print_output print_mode);
enum print_output print_mode);
static void srunner_run_tcase (SRunner * sr, TCase * tc); static void srunner_run_tcase (SRunner * sr, TCase * tc);
static int srunner_run_unchecked_setup (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 void srunner_run_unchecked_teardown (SRunner * sr, TCase * tc);
@ -62,15 +63,14 @@ static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc);
static void tcase_run_checked_teardown (TCase * tc); static void tcase_run_checked_teardown (TCase * tc);
static void srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc); static void srunner_iterate_tcase_tfuns (SRunner * sr, TCase * tc);
static void srunner_add_failure (SRunner * sr, TestResult * tf); 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_fork (SRunner * sr, TCase * tc, TF * tf,
static TestResult *tcase_run_tfun_nofork (SRunner *sr, TCase *tc, TF *tf, int i); 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, static TestResult *receive_result_info_fork (const char *tcname,
const char *tname, const char *tname, int iter, int status, int expected_signal);
int iter,
int status, int expected_signal);
static TestResult *receive_result_info_nofork (const char *tcname, static TestResult *receive_result_info_nofork (const char *tcname,
const char *tname, const char *tname, int iter);
int iter);
static void set_fork_info (TestResult * tr, int status, int expected_signal); static void set_fork_info (TestResult * tr, int status, int expected_signal);
static void set_nofork_info (TestResult * tr); static void set_nofork_info (TestResult * tr);
static char *signal_msg (int sig); static char *signal_msg (int sig);
@ -84,7 +84,8 @@ static int waserror (int status, int expected_signal);
static int alarm_received; static int alarm_received;
static pid_t group_pid; static pid_t group_pid;
static void sig_handler(int sig_nr) static void
sig_handler (int sig_nr)
{ {
switch (sig_nr) { switch (sig_nr) {
case SIGALRM: case SIGALRM:
@ -97,7 +98,8 @@ static void sig_handler(int sig_nr)
} }
} }
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)); set_fork_status (srunner_fork_status (sr));
setup_messaging (); setup_messaging ();
@ -105,7 +107,8 @@ static void srunner_run_init (SRunner *sr, enum print_output print_mode)
log_srunner_start (sr); 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); log_srunner_end (sr);
srunner_end_logging (sr); srunner_end_logging (sr);
@ -113,9 +116,8 @@ static void srunner_run_end (SRunner *sr, enum print_output print_mode)
set_fork_status (CK_FORK); set_fork_status (CK_FORK);
} }
static void srunner_iterate_suites (SRunner *sr, static void
enum print_output print_mode) srunner_iterate_suites (SRunner * sr, enum print_output print_mode)
{ {
List *slst; List *slst;
List *tcl; List *tcl;
@ -139,15 +141,15 @@ 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 old_action;
struct sigaction new_action; struct sigaction new_action;
if (sr == NULL) if (sr == NULL)
return; return;
if (print_mode >= CK_LAST) if (print_mode >= CK_LAST) {
{
eprintf ("Bad print_mode argument to srunner_run_all: %d", eprintf ("Bad print_mode argument to srunner_run_all: %d",
__FILE__, __LINE__, print_mode); __FILE__, __LINE__, print_mode);
} }
@ -160,7 +162,8 @@ void srunner_run_all (SRunner *sr, enum print_output 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); list_add_end (sr->resultlst, tr);
sr->stats->n_checked++; /* count checks during setup, test, and teardown */ 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; List *tfl;
TF *tfun; TF *tfun;
@ -183,8 +187,7 @@ static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc)
int i; int i;
tfun = list_val (tfl); tfun = list_val (tfl);
for (i = tfun->loop_start; i < tfun->loop_end; i++) for (i = tfun->loop_start; i < tfun->loop_end; i++) {
{
switch (srunner_fork_status (sr)) { switch (srunner_fork_status (sr)) {
case CK_FORK: case CK_FORK:
tr = tcase_run_tfun_fork (sr, tc, tfun, i); tr = tcase_run_tfun_fork (sr, tc, tfun, i);
@ -201,7 +204,8 @@ static void srunner_iterate_tcase_tfuns (SRunner *sr, TCase *tc)
} }
} }
static int srunner_run_unchecked_setup (SRunner *sr, TCase *tc) static int
srunner_run_unchecked_setup (SRunner * sr, TCase * tc)
{ {
TestResult *tr; TestResult *tr;
List *l; List *l;
@ -233,7 +237,8 @@ static int srunner_run_unchecked_setup (SRunner *sr, TCase *tc)
return rval; 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; TestResult *tr = NULL;
List *l; List *l;
@ -269,7 +274,8 @@ static TestResult * tcase_run_checked_setup (SRunner *sr, TCase *tc)
return tr; return tr;
} }
static void tcase_run_checked_teardown (TCase *tc) static void
tcase_run_checked_teardown (TCase * tc)
{ {
List *l; List *l;
Fixture *f; Fixture *f;
@ -284,7 +290,8 @@ static void tcase_run_checked_teardown (TCase *tc)
} }
} }
static void srunner_run_unchecked_teardown (SRunner *sr, TCase *tc) static void
srunner_run_unchecked_teardown (SRunner * sr, TCase * tc)
{ {
List *l; List *l;
Fixture *f; Fixture *f;
@ -301,7 +308,8 @@ static void srunner_run_unchecked_teardown (SRunner *sr, TCase *tc)
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)) { if (srunner_run_unchecked_setup (sr, tc)) {
srunner_iterate_tcase_tfuns (sr, tc); srunner_iterate_tcase_tfuns (sr, tc);
@ -309,10 +317,9 @@ static void srunner_run_tcase (SRunner *sr, TCase *tc)
} }
} }
static TestResult *receive_result_info_fork (const char *tcname, static TestResult *
const char *tname, receive_result_info_fork (const char *tcname,
int iter, const char *tname, int iter, int status, int expected_signal)
int status, int expected_signal)
{ {
TestResult *tr; TestResult *tr;
@ -327,9 +334,8 @@ static TestResult *receive_result_info_fork (const char *tcname,
return tr; return tr;
} }
static TestResult *receive_result_info_nofork (const char *tcname, static TestResult *
const char *tname, receive_result_info_nofork (const char *tcname, const char *tname, int iter)
int iter)
{ {
TestResult *tr; TestResult *tr;
@ -344,7 +350,8 @@ static TestResult *receive_result_info_nofork (const char *tcname,
return 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_sig = WIFSIGNALED (status);
int was_exit = WIFEXITED (status); int was_exit = WIFEXITED (status);
@ -393,7 +400,8 @@ 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) { if (tr->msg == NULL) {
tr->rtype = CK_PASS; tr->rtype = CK_PASS;
@ -403,7 +411,8 @@ static void set_nofork_info (TestResult *tr)
} }
} }
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; TestResult *tr;
@ -418,7 +427,8 @@ static TestResult *tcase_run_tfun_nofork (SRunner *sr, TCase *tc, TF *tfun, int
} }
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_w;
pid_t pid; pid_t pid;
@ -445,10 +455,12 @@ static TestResult *tcase_run_tfun_fork (SRunner *sr, TCase *tc, TF *tfun, int i)
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_r_str;
char *sig_e_str; char *sig_e_str;
@ -467,7 +479,8 @@ static char *signal_error_msg (int signal_received, int signal_expected)
return msg; 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) { if (alarm_received) {
@ -479,22 +492,24 @@ static char *signal_msg (int signal)
return msg; return msg;
} }
static char *exit_msg (int exitval) static char *
exit_msg (int exitval)
{ {
char *msg = emalloc (MSG_LEN); /* free'd by caller */ char *msg = emalloc (MSG_LEN); /* free'd by caller */
snprintf (msg, MSG_LEN, snprintf (msg, MSG_LEN, "Early exit with return value %d", exitval);
"Early exit with return value %d", exitval);
return msg; 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"); strcpy (msg, "Passed");
return msg; return msg;
} }
enum fork_status srunner_fork_status (SRunner *sr) enum fork_status
srunner_fork_status (SRunner * sr)
{ {
if (sr->fstat == CK_FORK_GETENV) { if (sr->fstat == CK_FORK_GETENV) {
char *env = getenv ("CK_FORK"); char *env = getenv ("CK_FORK");
@ -508,12 +523,14 @@ enum fork_status srunner_fork_status (SRunner *sr)
return sr->fstat; 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; 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. */ /* Set the process to a process group to be able to kill it easily. */
@ -521,7 +538,8 @@ pid_t check_fork (void)
return pid; return pid;
} }
void check_waitpid_and_exit (pid_t pid) void
check_waitpid_and_exit (pid_t pid)
{ {
pid_t pid_w; pid_t pid_w;
int status; int status;
@ -536,7 +554,8 @@ void check_waitpid_and_exit (pid_t pid)
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_sig = WIFSIGNALED (status);
int was_exit = WIFEXITED (status); int was_exit = WIFEXITED (status);

View file

@ -32,7 +32,8 @@
static const char *tr_type_str (TestResult * tr); static const char *tr_type_str (TestResult * tr);
static int percent_passed (TestStats * t); static int percent_passed (TestStats * t);
char *tr_str (TestResult *tr) char *
tr_str (TestResult * tr)
{ {
const char *exact_msg; const char *exact_msg;
char *rstr; char *rstr;
@ -41,13 +42,13 @@ char *tr_str (TestResult *tr)
rstr = ck_strdup_printf ("%s:%d:%s:%s:%s:%d: %s%s", rstr = ck_strdup_printf ("%s:%d:%s:%s:%s:%d: %s%s",
tr->file, tr->line, tr->file, tr->line,
tr_type_str(tr), tr->tcname, tr->tname, tr->iter, tr_type_str (tr), tr->tcname, tr->tname, tr->iter, exact_msg, tr->msg);
exact_msg, tr->msg);
return rstr; return rstr;
} }
char *sr_stat_str (SRunner *sr) char *
sr_stat_str (SRunner * sr)
{ {
char *str; char *str;
TestStats *ts; TestStats *ts;
@ -55,13 +56,13 @@ char *sr_stat_str (SRunner *sr)
ts = sr->stats; ts = sr->stats;
str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d", str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d",
percent_passed (ts), ts->n_checked, ts->n_failed, percent_passed (ts), ts->n_checked, ts->n_failed, ts->n_errors);
ts->n_errors);
return str; return str;
} }
char *ck_strdup_printf (const char *fmt, ...) char *
ck_strdup_printf (const char *fmt, ...)
{ {
/* Guess we need no more than 100 bytes. */ /* Guess we need no more than 100 bytes. */
int n, size = 100; int n, size = 100;
@ -70,8 +71,7 @@ char *ck_strdup_printf (const char *fmt, ...)
p = emalloc (size); p = emalloc (size);
while (1) while (1) {
{
/* Try to print in the allocated space. */ /* Try to print in the allocated space. */
va_start (ap, fmt); va_start (ap, fmt);
n = vsnprintf (p, size, fmt, ap); n = vsnprintf (p, size, fmt, ap);
@ -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; const char *str = NULL;
if (tr->ctx == CK_CTX_TEST) { if (tr->ctx == CK_CTX_TEST) {
@ -106,7 +107,8 @@ static const char *tr_type_str (TestResult *tr)
return str; return str;
} }
static int percent_passed (TestStats *t) static int
percent_passed (TestStats * t)
{ {
if (t->n_failed == 0 && t->n_errors == 0) if (t->n_failed == 0 && t->n_errors == 0)
return 100; return 100;