From 6169becad27ef834dfd0f3f207ee890e390c87cd Mon Sep 17 00:00:00 2001 From: neo23 Date: Fri, 12 Apr 2002 09:54:17 +0000 Subject: [PATCH] Removed limitations on line number, message and buffer sizes (bug #478233) by changing the way we send integers over the pipe. Instead of strings, integers are now send as 4 bytes. This allows the pack routine to easily calculate the message size so that we can allocate the needed buffer there. Made a union out of the different Msg structs to clean up the internal API. Also introduced the internal function ck_strdup_printf(), a simple wrapper around sprintf() that allocates enough space to hold the resulting string. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@128 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- check/config.h.in | 9 + check/configure.in | 4 + check/src/Makefile.am | 28 +-- check/src/check.c | 3 - check/src/check_impl.h | 10 +- check/src/check_magic.h | 37 ---- check/src/check_msg.c | 105 ++++++----- check/src/check_pack.c | 278 ++++++++++++++++-------------- check/src/check_pack.h | 16 +- check/src/check_run.c | 28 +-- check/src/check_str.c | 48 +++++- check/src/check_str.h | 2 + check/tests/Makefile.am | 55 +++--- check/tests/check_check_fixture.c | 33 ++-- check/tests/check_check_master.c | 6 +- check/tests/check_check_msg.c | 1 - check/tests/check_check_pack.c | 243 +++++++++++++------------- 17 files changed, 462 insertions(+), 444 deletions(-) delete mode 100644 check/src/check_magic.h diff --git a/check/config.h.in b/check/config.h.in index f5fccbd..f720e7a 100644 --- a/check/config.h.in +++ b/check/config.h.in @@ -21,6 +21,15 @@ /* Define if you have the ANSI C header files. */ #undef STDC_HEADERS +/* The number of bytes in a int. */ +#undef SIZEOF_INT + +/* The number of bytes in a long. */ +#undef SIZEOF_LONG + +/* The number of bytes in a short. */ +#undef SIZEOF_SHORT + /* Define if you have the strerror function. */ #undef HAVE_STRERROR diff --git a/check/configure.in b/check/configure.in index d8553d5..2dc05b1 100644 --- a/check/configure.in +++ b/check/configure.in @@ -51,6 +51,10 @@ AC_C_CONST AC_TYPE_PID_T AC_TYPE_SIZE_T +AC_CHECK_SIZEOF(int) +AC_CHECK_SIZEOF(short) +AC_CHECK_SIZEOF(long) + dnl Checks for library functions. dnl AC_FUNC_FORK dnl AC_FUNC_MALLOC diff --git a/check/src/Makefile.am b/check/src/Makefile.am index 9e38cd1..1c0a8c3 100644 --- a/check/src/Makefile.am +++ b/check/src/Makefile.am @@ -3,15 +3,23 @@ lib_LIBRARIES=libcheck.a include_HEADERS=check.h libcheck_a_SOURCES=\ - check.h check_impl.h check_magic.h check.c check_run.c\ - check_pack.h check_pack.c\ - check_msg.h check_msg.c\ - check_log.h check_log.c\ - check_str.h check_str.c\ - check_print.h check_print.c\ - check_error.h check_error.c\ - list.h list.c + check_impl.h \ + check.h \ + check.c \ + check_run.c \ + check_pack.h \ + check_pack.c \ + check_msg.h \ + check_msg.c \ + check_log.h \ + check_log.c \ + check_str.h \ + check_str.c \ + check_print.h \ + check_print.c \ + check_error.h \ + check_error.c \ + list.h \ + list.c EXTRA_DIST=check.h.in - -CLEANFILES=*.*~ diff --git a/check/src/check.c b/check/src/check.c index 670af51..5c5a852 100644 --- a/check/src/check.c +++ b/check/src/check.c @@ -166,9 +166,6 @@ void _fail_unless (int result, const char *file, int line, const char * msg) if (msg == NULL) eprintf ("_fail_unless() called with NULL msg",__FILE__,__LINE__); - if (line > MAXLINE) - eprintf ("Line number %d too large to use",__FILE__,__LINE__, line); - send_loc_info (get_send_key(), file, line); if (!result) { send_failure_info (get_send_key(), msg); diff --git a/check/src/check_impl.h b/check/src/check_impl.h index f6f0973..280dbad 100644 --- a/check/src/check_impl.h +++ b/check/src/check_impl.h @@ -29,13 +29,9 @@ /* magic values */ -enum { - MAXLINE = 9999 , /* maximum line no */ - CMAXMSG = 100, /* maximum length of a message, including terminating - nul */ - CK_FORK_UNSPECIFIED = -1 /* Unspecified fork status, used only - internally */ -}; +/* Unspecified fork status, used only internally */ +#define CK_FORK_UNSPECIFIED -1 + typedef struct TF { TFun fn; diff --git a/check/src/check_magic.h b/check/src/check_magic.h deleted file mode 100644 index a80428b..0000000 --- a/check/src/check_magic.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Check: a unit test framework for C - * Copyright (C) 2001,2002 Arien Malec - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef CHECK_MAGIC_H -#define CHECK_MAGIC_H - -/* This header should be included by any module that needs - to know Check magic values. -*/ - -/* magic values */ - -enum { - CK_MAXLINE = 9999, /* maximum line no */ - CK_MAXMSG = 100, /* maximum length of a message, including - terminating nul */ - CK_MAXMSGBUF = 200 /* maximum length of a message buffer */ -}; - -#endif /*CHECK_MAGIC_H*/ diff --git a/check/src/check_msg.c b/check/src/check_msg.c index ca7494f..ae7b8e0 100644 --- a/check/src/check_msg.c +++ b/check/src/check_msg.c @@ -66,10 +66,10 @@ void send_failure_info (MsgKey *key, const char *msg) Pipe *p; fmsg.msg = (char *) msg; - p = get_pipe_by_key(key); + p = get_pipe_by_key (key); if (p == NULL) - eprintf("Couldn't find pipe with key %d",__FILE__, __LINE__, key); - ppack(p->sendfd, CK_MSG_FAIL, &fmsg); + eprintf ("Couldn't find pipe with key %d",__FILE__, __LINE__, key); + ppack (p->sendfd, CK_MSG_FAIL, (CheckMsg *) &fmsg); } void send_loc_info (MsgKey *key, const char * file, int line) @@ -79,10 +79,10 @@ void send_loc_info (MsgKey *key, const char * file, int line) lmsg.file = (char *) file; lmsg.line = line; - p = get_pipe_by_key(key); + p = get_pipe_by_key (key); if (p == NULL) - eprintf("Couldn't find pipe with key %d",__FILE__, __LINE__, key); - ppack(p->sendfd, CK_MSG_LOC, &lmsg); + eprintf ("Couldn't find pipe with key %d",__FILE__, __LINE__, key); + ppack (p->sendfd, CK_MSG_LOC, (CheckMsg *) &lmsg); } void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx) @@ -91,11 +91,11 @@ void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx) Pipe *p; cmsg.ctx = ctx; - p = get_pipe_by_key(key); + p = get_pipe_by_key (key); if (p == NULL) - eprintf("Couldn't find pipe with key %d",__FILE__, __LINE__, key); + eprintf ("Couldn't find pipe with key %d",__FILE__, __LINE__, key); - ppack(p->sendfd, CK_MSG_CTX, &cmsg); + ppack (p->sendfd, CK_MSG_CTX, (CheckMsg *) &cmsg); } TestResult *receive_test_result (MsgKey *key, int waserror) @@ -103,13 +103,14 @@ TestResult *receive_test_result (MsgKey *key, int waserror) Pipe *p; RcvMsg *rmsg; - p = get_pipe_by_key(key); + p = get_pipe_by_key (key); if (p == NULL) - eprintf("Couldn't find pipe with key %d",__FILE__, __LINE__, key); - close(p->sendfd); - rmsg = punpack(p->recvfd); - close(p->recvfd); - setup_pipe(p); + eprintf ("Couldn't find pipe with key %d",__FILE__, __LINE__, key); + close (p->sendfd); + rmsg = punpack (p->recvfd); + close (p->recvfd); + setup_pipe (p); + return construct_test_result (rmsg, waserror); } @@ -132,81 +133,81 @@ static TestResult *construct_test_result (RcvMsg *rmsg, int waserror) if (rmsg == NULL) return NULL; - tr = emalloc (sizeof(TestResult)); + tr = emalloc (sizeof (TestResult)); if (rmsg->msg != NULL || waserror) { tr->ctx = rmsg->lastctx; tr->msg = rmsg->msg; - tr_set_loc_by_ctx(tr, rmsg->lastctx, rmsg); + tr_set_loc_by_ctx (tr, rmsg->lastctx, rmsg); } else if (rmsg->lastctx == CK_CTX_SETUP) { tr->ctx = CK_CTX_SETUP; tr->msg = NULL; - tr_set_loc_by_ctx(tr, CK_CTX_SETUP, rmsg); + tr_set_loc_by_ctx (tr, CK_CTX_SETUP, rmsg); } else { tr->ctx = CK_CTX_TEST; tr->msg = NULL; - tr_set_loc_by_ctx(tr, CK_CTX_TEST, rmsg); + tr_set_loc_by_ctx (tr, CK_CTX_TEST, rmsg); } return tr; } -void setup_messaging(void) +void setup_messaging (void) { - setup_messaging_with_key(get_recv_key()); + setup_messaging_with_key (get_recv_key()); } -MsgKey *get_send_key(void) +MsgKey *get_send_key (void) { - MsgKey *key = emalloc(sizeof(MsgKey)); + MsgKey *key = emalloc (sizeof (MsgKey)); - if (cur_fork_status() == CK_FORK) - key->key = getppid(); + if (cur_fork_status () == CK_FORK) + key->key = getppid (); else - key->key = getpid(); + key->key = getpid (); return key; } -MsgKey *get_recv_key(void) +MsgKey *get_recv_key (void) { - MsgKey *key = emalloc(sizeof(MsgKey)); + MsgKey *key = emalloc (sizeof (MsgKey)); - key->key = getpid(); + key->key = getpid (); return key; } static MsgKey *get_setup_key (void) { - return get_recv_key(); + return get_recv_key (); } -void teardown_messaging(void) +void teardown_messaging (void) { - teardown_messaging_with_key(get_setup_key()); + teardown_messaging_with_key (get_setup_key ()); } /* for testing only */ -void setup_test_messaging(void) +void setup_test_messaging (void) { - setup_messaging_with_key(get_test_key()); + setup_messaging_with_key (get_test_key ()); } -MsgKey *get_test_key(void) +MsgKey *get_test_key (void) { - MsgKey *key = emalloc(sizeof(MsgKey)); + MsgKey *key = emalloc (sizeof (MsgKey)); key->key = -1; return key; } -void teardown_test_messaging(void) +void teardown_test_messaging (void) { - teardown_messaging_with_key(get_test_key()); + teardown_messaging_with_key (get_test_key ()); } -static PipeEntry *get_pe_by_key(MsgKey *key) +static PipeEntry *get_pe_by_key (MsgKey *key) { PipeEntry *pe = NULL; @@ -221,10 +222,10 @@ static PipeEntry *get_pe_by_key(MsgKey *key) return pe; } -static Pipe *get_pipe_by_key(MsgKey *key) +static Pipe *get_pipe_by_key (MsgKey *key) { Pipe *pr = NULL; - PipeEntry *pe = get_pe_by_key(key); + PipeEntry *pe = get_pe_by_key (key); if (pe == NULL || pe->cur == 0) eprintf ("No messaging setup", __FILE__, __LINE__); @@ -253,39 +254,37 @@ void setup_messaging_with_key (MsgKey *key) if (plst == NULL) plst = list_create(); - pe = get_pe_by_key(key); + pe = get_pe_by_key (key); if (pe == NULL) { - pe = emalloc(sizeof(PipeEntry)); + pe = emalloc (sizeof (PipeEntry)); pe->cur = 0; pe->key = key->key; - list_add_end(plst, pe); + list_add_end (plst, pe); } if (pe->cur == 0) { - pe->p1 = emalloc(sizeof(Pipe)); + pe->p1 = emalloc (sizeof(Pipe)); pe->cur = 1; setup_pipe (pe->p1); } else if (pe->cur == 1) { pe->cur = 2; - pe->p2 = emalloc(sizeof(Pipe)); + pe->p2 = emalloc (sizeof(Pipe)); setup_pipe (pe->p2); } else - eprintf("Only one nesting of suite runs supported", __FILE__, __LINE__); - + eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__); } void teardown_messaging_with_key (MsgKey *key) { - PipeEntry *pe = get_pe_by_key(key); + PipeEntry *pe = get_pe_by_key (key); if (pe == NULL || pe->cur == 0) - eprintf("Messaging not setup", __FILE__, __LINE__); + eprintf ("Messaging not setup", __FILE__, __LINE__); else if (pe->cur == 1) { pe->cur = 0; - free(pe->p1); + free (pe->p1); } else if (pe->cur == 2) { pe->cur = 1; - free(pe->p2); + free (pe->p2); } - } diff --git a/check/src/check_pack.c b/check/src/check_pack.c index 0ec7c1e..eafc4fc 100644 --- a/check/src/check_pack.c +++ b/check/src/check_pack.c @@ -18,6 +18,8 @@ * Boston, MA 02111-1307, USA. */ +#include "config.h" + #include #include #include @@ -26,69 +28,70 @@ #include "list.h" #include "check_error.h" #include "check.h" -#include "check_magic.h" #include "check_impl.h" #include "check_pack.h" -static void pack_int (char **buf, int val); -static int upack_int (char **buf); -static void pack_str (char **buf, const char *str); -static char *upack_str (char **buf); +/* typedef an unsigned int that has at least 4 bytes */ +#if SIZEOF_INT == 4 +typedef unsigned int ck_uint32; +#elif SIZEOF_SHORT == 4 +typedef unsigned short ck_uint32; +#else +typedef unsigned long ck_uint32; +#endif + + +static void pack_int (char **buf, int val); +static int upack_int (char **buf); +static void pack_str (char **buf, const char *str); +static char *upack_str (char **buf); -static void pack_ctx (char **buf, void *msg); -static void pack_loc (char **buf, void *msg); -static void pack_fail (char **buf, void *msg); -static void upack_ctx (char **buf, void *msg); -static void upack_loc (char **buf, void *msg); -static void upack_fail (char **buf, void *msg); +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 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 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 RcvMsg *rcvmsg_create(void); +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 RcvMsg *rcvmsg_create (void); -typedef void (*pfun) (char **, void *); +typedef int (*pfun) (char **, CheckMsg *); +typedef void (*upfun) (char **, CheckMsg *); static pfun pftab [] = { - pack_ctx, - pack_fail, - pack_loc + (pfun) pack_ctx, + (pfun) pack_fail, + (pfun) pack_loc }; -static pfun upftab [] = { - upack_ctx, - upack_fail, - upack_loc +static upfun upftab [] = { + (upfun) upack_ctx, + (upfun) upack_fail, + (upfun) upack_loc }; -int pack (enum ck_msg_type type, char *buf, void *data) +int pack (enum ck_msg_type type, char **buf, CheckMsg *msg) { - char *obuf; - int nread; - if (buf == NULL) return -1; - if (data == NULL) + if (msg == NULL) return 0; - obuf = buf; - - check_type(type, __FILE__, __LINE__); - pack_type(&buf, type); - - pftab[type] (&buf, data); + check_type (type, __FILE__, __LINE__); - nread = buf - obuf; - return nread; + return pftab[type] (buf, msg); } -int upack (char *buf, void *data, enum ck_msg_type *type) +int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type) { char *obuf; int nread; @@ -100,9 +103,9 @@ int upack (char *buf, void *data, enum ck_msg_type *type) *type = upack_type (&buf); - check_type(*type, __FILE__, __LINE__); + check_type (*type, __FILE__, __LINE__); - upftab[*type] (&buf, data); + upftab[*type] (&buf, msg); nread = buf - obuf; return nread; @@ -110,55 +113,61 @@ int upack (char *buf, void *data, enum ck_msg_type *type) static void pack_int (char **buf, int val) { - int n; - - n = sprintf (*buf, "%d", val); + unsigned char *ubuf = *buf; + ck_uint32 uval = val; + + ubuf[0] = (uval >> 24) & 0xFF; + ubuf[1] = (uval >> 16) & 0xFF; + ubuf[2] = (uval >> 8) & 0xFF; + ubuf[3] = uval & 0xFF; - *buf += n + 1; + *buf += 4; } static int upack_int (char **buf) { - int val; - char *endptr; + unsigned char *ubuf = *buf; + ck_uint32 uval; - val = (int) strtol (*buf, &endptr, 10); + uval = ((ubuf[0] << 24) | (ubuf[1] << 16) | (ubuf[2] << 8) | ubuf[3]); - *buf = endptr + 1; - - return val; + *buf += 4; + + return (int) uval; } static void pack_str (char **buf, const char *val) { int strsz; - int n; if (val == NULL) strsz = 0; else - strsz = strlen (val) + 1; + strsz = strlen (val); + + pack_int (buf, strsz); - pack_int(buf,strsz); if (strsz > 0) { - n = sprintf (*buf, "%s", val); - *buf += n + 1; - } - -} + memcpy (*buf, val, strsz); + *buf += strsz; + } +} static char *upack_str (char **buf) { - char *val = NULL; + char *val; int strsz; - val = emalloc (CK_MAXMSG); - strsz = upack_int (buf); if (strsz > 0) { - strncpy (val, *buf, strsz); + val = emalloc (strsz + 1); + memcpy (val, *buf, strsz); + val[strsz] = 0; *buf += strsz; + } else { + val = emalloc (1); + *val = 0; } return val; @@ -166,80 +175,92 @@ static char *upack_str (char **buf) 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) { - return (enum ck_msg_type) upack_int(buf); + return (enum ck_msg_type) upack_int (buf); } -static void pack_ctx (char **buf, void *msg) +static int pack_ctx (char **buf, CtxMsg *cmsg) { - CtxMsg *cmsg = msg; - pack_int(buf,(int) cmsg->ctx); + char *ptr; + int len; + + len = 4 + 4; + *buf = ptr = emalloc (len); + + pack_type (&ptr, CK_MSG_CTX); + pack_int (&ptr, (int) cmsg->ctx); + + return len; } -static void upack_ctx (char **buf, void *msg) +static void upack_ctx (char **buf, CtxMsg *cmsg) { - CtxMsg *cmsg = msg; - cmsg->ctx = upack_int (buf); - - return; } -static void pack_loc (char **buf, void *msg) +static int pack_loc (char **buf, LocMsg *lmsg) { - LocMsg *lmsg = msg; + char *ptr; + int len; + + len = 4 + 4 + (lmsg->file ? strlen (lmsg->file) : 0) + 4; + *buf = ptr = emalloc (len); - pack_str (buf, lmsg->file); - pack_int (buf, lmsg->line); + pack_type (&ptr, CK_MSG_LOC); + pack_str (&ptr, lmsg->file); + pack_int (&ptr, lmsg->line); + return len; } -static void upack_loc (char **buf, void *msg) +static void upack_loc (char **buf, LocMsg *lmsg) { - - LocMsg *lmsg = msg; - - lmsg->file = upack_str(buf); - lmsg->line = upack_int(buf); - return; + lmsg->file = upack_str (buf); + lmsg->line = upack_int (buf); } -static void pack_fail (char **buf, void *msg) +static int pack_fail (char **buf, FailMsg *fmsg) { - FailMsg *fmsg = msg; - pack_str (buf, fmsg->msg); + char *ptr; + int len; + + len = 4 + 4 + (fmsg->msg ? strlen (fmsg->msg) : 0); + *buf = ptr = emalloc (len); + + pack_type (&ptr, CK_MSG_FAIL); + pack_str (&ptr, fmsg->msg); + + return len; } -static void upack_fail (char **buf, void *msg) +static void upack_fail (char **buf, FailMsg *fmsg) { - FailMsg *fmsg = msg; - fmsg->msg = upack_str(buf); + fmsg->msg = upack_str (buf); } static void check_type (int type, const char *file, int line) { - if (type >= CK_MSG_LAST) + if (type < 0 || type >= CK_MSG_LAST) eprintf ("%s:%d:Bad message type arg", file, line); } -void ppack (int fdes, enum ck_msg_type type, void *data) +void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg) { char *buf; int n; ssize_t r; - buf = emalloc (CK_MAXMSGBUF); - n = pack(type, buf, data); + n = pack (type, &buf, msg); r = write (fdes, buf, n); if (r == -1) - eprintf("Error in ppack:",__FILE__,__LINE__); + eprintf ("Error in ppack:",__FILE__,__LINE__); - free(buf); + free (buf); } static int read_buf (int fdes, char **buf) @@ -253,17 +274,18 @@ static int read_buf (int fdes, char **buf) *buf = emalloc(size); readloc = *buf; while (1) { - n = read(fdes,readloc,size - nread); + n = read (fdes, readloc, size - nread); if (n == 0) break; if (n == -1) - eprintf("Error in read_buf:", __FILE__, __LINE__); + eprintf ("Error in read_buf:", __FILE__, __LINE__); nread += n; size *= grow; - *buf = erealloc(*buf,size); + *buf = erealloc (*buf,size); readloc = *buf + nread; } + return nread; } @@ -271,35 +293,31 @@ static int read_buf (int fdes, char **buf) static int get_result (char *buf, RcvMsg *rmsg) { enum ck_msg_type type; - void *data; + CheckMsg msg; int n; - data = emalloc(CK_MAXMSGBUF); - - n = upack(buf,data,&type); + n = upack (buf, &msg, &type); if (n == -1) - eprintf("Error in upack", __FILE__, __LINE__); + eprintf ("Error in upack", __FILE__, __LINE__); if (type == CK_MSG_CTX) { - CtxMsg *cmsg = data; - rcvmsg_update_ctx(rmsg, cmsg->ctx); + CtxMsg *cmsg = (CtxMsg *) &msg; + rcvmsg_update_ctx (rmsg, cmsg->ctx); } else if (type == CK_MSG_LOC) { - LocMsg *lmsg = data; - rcvmsg_update_loc(rmsg, lmsg->file, lmsg->line); + LocMsg *lmsg = (LocMsg *) &msg; + rcvmsg_update_loc (rmsg, lmsg->file, lmsg->line); + free (lmsg->file); } else if (type == CK_MSG_FAIL) { - FailMsg *fmsg = data; - rmsg->msg = emalloc (strlen(fmsg->msg) + 1); - strcpy(rmsg->msg, fmsg->msg); + FailMsg *fmsg = (FailMsg *) &msg; + rmsg->msg = emalloc (strlen (fmsg->msg) + 1); + strcpy (rmsg->msg, fmsg->msg); + free (fmsg->msg); } else - check_type(type, __FILE__, __LINE__); + check_type (type, __FILE__, __LINE__); - free(data); return n; - } - - static void reset_rcv_test (RcvMsg *rmsg) { rmsg->test_line = -1; @@ -312,22 +330,22 @@ static void reset_rcv_fixture (RcvMsg *rmsg) rmsg->fixture_file = NULL; } -static RcvMsg *rcvmsg_create(void) +static RcvMsg *rcvmsg_create (void) { RcvMsg *rmsg; rmsg = emalloc (sizeof (RcvMsg)); rmsg->lastctx = -1; rmsg->msg = NULL; - reset_rcv_test(rmsg); - reset_rcv_fixture(rmsg); + reset_rcv_test (rmsg); + reset_rcv_fixture (rmsg); return 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 != -1) - reset_rcv_fixture(rmsg); + reset_rcv_fixture (rmsg); rmsg->lastctx = ctx; } @@ -338,16 +356,16 @@ static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line) if (rmsg->lastctx == CK_CTX_TEST) { rmsg->test_line = line; - rmsg->test_file = emalloc(flen + 1); - strcpy(rmsg->test_file, file); + rmsg->test_file = emalloc (flen + 1); + strcpy (rmsg->test_file, file); } else { rmsg->fixture_line = line; - rmsg->fixture_file = emalloc(flen + 1); - strcpy(rmsg->fixture_file, file); + rmsg->fixture_file = emalloc (flen + 1); + strcpy (rmsg->fixture_file, file); } } -RcvMsg *punpack(int fdes) +RcvMsg *punpack (int fdes) { int nread, n; char *buf; @@ -356,15 +374,15 @@ RcvMsg *punpack(int fdes) nread = read_buf (fdes, &buf); obuf = buf; - rmsg = rcvmsg_create(); + rmsg = rcvmsg_create (); while (nread > 0) { - n = get_result(buf, rmsg); + n = get_result (buf, rmsg); nread -= n; buf += n; } - free(obuf); + free (obuf); if (rmsg->lastctx == -1) { free (rmsg); rmsg = NULL; diff --git a/check/src/check_pack.h b/check/src/check_pack.h index d02c73d..dd6c40d 100644 --- a/check/src/check_pack.h +++ b/check/src/check_pack.h @@ -29,7 +29,6 @@ enum ck_msg_type { CK_MSG_LAST }; - typedef struct CtxMsg { enum ck_result_ctx ctx; @@ -46,6 +45,13 @@ typedef struct FailMsg char *msg; } FailMsg; +typedef union +{ + CtxMsg ctx_msg; + FailMsg fail_msg; + LocMsg loc_msg; +} CheckMsg; + typedef struct RcvMsg { enum ck_result_ctx lastctx; @@ -57,11 +63,11 @@ typedef struct RcvMsg } RcvMsg; -int pack (enum ck_msg_type type, char *buf, void *data); -int upack (char *buf, void *data, enum ck_msg_type *type); +int pack (enum ck_msg_type type, char **buf, CheckMsg *msg); +int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type); -void ppack (int fdes, enum ck_msg_type type, void *data); -RcvMsg *punpack(int fdes); +void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg); +RcvMsg *punpack (int fdes); #endif /*CHECK_PACK_H */ diff --git a/check/src/check_run.c b/check/src/check_run.c index 9852382..a5a4ff0 100644 --- a/check/src/check_run.c +++ b/check/src/check_run.c @@ -69,6 +69,8 @@ static char *pass_msg (void); static char *exit_msg (int exitstatus); static int waserror (int status); +#define MSG_LEN 100 + static void srunner_run_init (SRunner *sr, enum print_output print_mode) { set_fork_status(srunner_fork_status(sr)); @@ -323,10 +325,10 @@ static TestResult *tcase_run_tfun_fork (TCase *tc, TF *tfun) if (pid == -1) eprintf ("Unable to fork:",__FILE__,__LINE__); if (pid == 0) { - tcase_run_checked_setup(tc); + tcase_run_checked_setup (tc); tfun->fn(); - tcase_run_checked_teardown(tc); - _exit(EXIT_SUCCESS); + tcase_run_checked_teardown (tc); + _exit (EXIT_SUCCESS); } (void) wait(&status); return receive_result_info_fork (tc->name, status); @@ -334,16 +336,16 @@ static TestResult *tcase_run_tfun_fork (TCase *tc, TF *tfun) static char *signal_msg (int signal) { - char *msg = emalloc (CMAXMSG); /* free'd by caller */ - snprintf(msg, CMAXMSG, "Received signal %d", signal); + char *msg = emalloc (MSG_LEN); /* free'd by caller */ + snprintf (msg, MSG_LEN, "Received signal %d", signal); return msg; } static char *exit_msg (int exitval) { - char *msg = emalloc(CMAXMSG); /* free'd by caller */ - snprintf(msg, CMAXMSG, - "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; } @@ -357,10 +359,10 @@ static char *pass_msg (void) enum fork_status srunner_fork_status (SRunner *sr) { if (sr->fstat == CK_FORK_UNSPECIFIED) { - char *env = getenv("CK_FORK"); + 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; @@ -375,9 +377,9 @@ void srunner_set_fork_status (SRunner *sr, enum fork_status fstat) static int waserror (int status) { - int was_sig = WIFSIGNALED(status); - int was_exit = WIFEXITED(status); - int exit_status = WEXITSTATUS(status); + int was_sig = WIFSIGNALED (status); + int was_exit = WIFEXITED (status); + int exit_status = WEXITSTATUS (status); return (was_sig || (was_exit && exit_status != 0)); } diff --git a/check/src/check_str.c b/check/src/check_str.c index 1d42822..dd22e40 100644 --- a/check/src/check_str.c +++ b/check/src/check_str.c @@ -19,7 +19,10 @@ */ #include +#include + #include + #include "list.h" #include "check_error.h" #include "check_impl.h" @@ -34,12 +37,11 @@ char *tr_str (TestResult *tr) char *rstr; exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) ": ""; - rstr = emalloc(CMAXMSG); - snprintf (rstr, CMAXMSG, "%s:%d:%s:%s: %s%s", - tr->file, tr->line, - tr_type_str(tr), tr->tcname, - exact_msg, tr->msg); + rstr = ck_strdup_printf ("%s:%d:%s:%s: %s%s", + tr->file, tr->line, + tr_type_str(tr), tr->tcname, + exact_msg, tr->msg); return rstr; } @@ -50,14 +52,42 @@ char *sr_stat_str (SRunner *sr) TestStats *ts; ts = sr->stats; - str = emalloc (CMAXMSG); - snprintf (str, CMAXMSG, "%d%%: Checks: %d, Failures: %d, Errors: %d", - percent_passed (ts), ts->n_checked, ts->n_failed, - ts->n_errors); + str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d", + percent_passed (ts), ts->n_checked, ts->n_failed, + ts->n_errors); + return str; } +char *ck_strdup_printf (const char *fmt, ...) +{ + /* Guess we need no more than 100 bytes. */ + int n, size = 100; + char *p; + va_list ap; + + p = emalloc (size); + + while (1) + { + /* Try to print in the allocated space. */ + va_start(ap, fmt); + n = vsnprintf (p, size, fmt, 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 */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + + p = erealloc (p, size); + } +} static const char *tr_type_str (TestResult *tr) { diff --git a/check/src/check_str.h b/check/src/check_str.h index cf8ce07..bef230f 100644 --- a/check/src/check_str.h +++ b/check/src/check_str.h @@ -31,4 +31,6 @@ char *tr_str (TestResult *tr); */ char *sr_stat_str (SRunner *sr); +char *ck_strdup_printf (const char *fmt, ...); + #endif /* CHECK_STR_H */ diff --git a/check/tests/Makefile.am b/check/tests/Makefile.am index 6896214..443700b 100644 --- a/check/tests/Makefile.am +++ b/check/tests/Makefile.am @@ -1,40 +1,37 @@ -TESTS=\ - check_check\ - test_output.sh\ +TESTS = \ + check_check \ + test_output.sh \ test_log_output.sh -noinst_PROGRAMS=\ - check_check\ - check_stress\ - ex_output\ +noinst_PROGRAMS = \ + check_check \ + check_stress \ + ex_output \ ex_log_output -EXTRA_DIST=test_output.sh test_log_output.sh - -check_check_SOURCES= \ - check_check.h\ - check_list.c\ - check_check_sub.c\ - check_check_master.c\ - check_check_msg.c\ - check_check_log.c\ - check_check_limit.c\ - check_check_fork.c\ - check_check_fixture.c\ - check_check_pack.c\ +EXTRA_DIST = test_output.sh test_log_output.sh + +check_check_SOURCES = \ + check_check.h \ + check_list.c \ + check_check_sub.c \ + check_check_master.c \ + check_check_msg.c \ + check_check_log.c \ + check_check_limit.c \ + check_check_fork.c \ + check_check_fixture.c \ + check_check_pack.c \ check_check_main.c -check_stress_SOURCES=\ - check_stress.c +check_stress_SOURCES = check_stress.c -ex_output_SOURCES=\ - ex_output.c +ex_output_SOURCES = ex_output.c -ex_log_output_SOURCES=\ - ex_log_output.c +ex_log_output_SOURCES = ex_log_output.c -INCLUDES= -I$(srcdir)/../src -LDADD= ../src/libcheck.a +INCLUDES = -I$(srcdir)/../src +LDADD = ../src/libcheck.a -CLEANFILES=*.*~ *.log test_logfile \ No newline at end of file +CLEANFILES = *.log test_logfile diff --git a/check/tests/check_check_fixture.c b/check/tests/check_check_fixture.c index 795a882..9cc87bc 100644 --- a/check/tests/check_check_fixture.c +++ b/check/tests/check_check_fixture.c @@ -5,7 +5,8 @@ #include "check_error.h" #include "check_str.h" #include "check_check.h" -#include "check_magic.h" + +static char errm[200]; static void fixture_sub_setup (void) { @@ -59,15 +60,13 @@ START_TEST(test_setup_failure_msg) { TestResult **tra; char *trm; - const char *trmexp = "check_check_fixture.c:12:S:Core: Test failure in fixture"; + const char *trmexp = "check_check_fixture.c:13:S:Core: Test failure in fixture"; tra = srunner_failures(fixture_sr); trm = tr_str(tra[0]); if (strcmp(trm, trmexp) != 0) { - char *errm = emalloc(CK_MAXMSG); - - snprintf(errm,CK_MAXMSG, + snprintf(errm, sizeof(errm), "Bad setup tr msg (%s)", trm); fail (errm); @@ -181,11 +180,9 @@ START_TEST(test_ch_setup_fail) trm = tr_str(srunner_failures(sr)[0]); if (strcmp(trm, - "check_check_fixture.c:127:S:Core: Failed setup") + "check_check_fixture.c:126:S:Core: Failed setup") != 0) { - char *errm = emalloc(CK_MAXMSG); - - snprintf(errm,CK_MAXMSG, + snprintf(errm, sizeof(errm), "Bad failed checked setup tr msg (%s)", trm); fail (errm); @@ -224,12 +221,10 @@ START_TEST(test_ch_setup_sig) trm = tr_str(srunner_failures(sr)[0]); if (strcmp(trm, - "check_check_fixture.c:137:S:Core: " + "check_check_fixture.c:136:S:Core: " "(after this point) Received signal 8") != 0) { - char *errm = emalloc(CK_MAXMSG); - - snprintf(errm,CK_MAXMSG, + snprintf(errm, sizeof(errm), "Msg was (%s)", trm); fail (errm); @@ -268,11 +263,9 @@ START_TEST(test_ch_teardown_fail) trm = tr_str(srunner_failures(sr)[0]); if (strcmp(trm, - "check_check_fixture.c:132:S:Core: Failed teardown") + "check_check_fixture.c:131:S:Core: Failed teardown") != 0) { - char *errm = emalloc(CK_MAXMSG); - - snprintf(errm,CK_MAXMSG, + snprintf(errm, sizeof(errm), "Bad failed checked teardown tr msg (%s)", trm); fail (errm); @@ -312,12 +305,10 @@ START_TEST(test_ch_teardown_sig) trm = tr_str(srunner_failures(sr)[0]); if (strcmp(trm, - "check_check_fixture.c:143:S:Core: " + "check_check_fixture.c:142:S:Core: " "(after this point) Received signal 8") != 0) { - char *errm = emalloc(CK_MAXMSG); - - snprintf(errm,CK_MAXMSG, + snprintf(errm, sizeof(errm), "Bad msg (%s)", trm); fail (errm); diff --git a/check/tests/check_check_master.c b/check/tests/check_check_master.c index 1f1e71f..fa44fac 100644 --- a/check/tests/check_check_master.c +++ b/check/tests/check_check_master.c @@ -7,9 +7,9 @@ TestResult **tr_fail_array; TestResult **tr_all_array; -enum { - MAXSTR = 100 -}; + +#define MAXSTR 100 + START_TEST(test_check_nfailures) { diff --git a/check/tests/check_check_msg.c b/check/tests/check_check_msg.c index fd9bc9a..d570810 100644 --- a/check/tests/check_check_msg.c +++ b/check/tests/check_check_msg.c @@ -2,7 +2,6 @@ #include #include #include "error.h" -#include "check_magic.h" #include "check_msg.h" #include "check_check.h" diff --git a/check/tests/check_check_pack.c b/check/tests/check_check_pack.c index c360715..56b3ed6 100644 --- a/check/tests/check_check_pack.c +++ b/check/tests/check_check_pack.c @@ -3,42 +3,41 @@ #include #include -#include -#include "check_magic.h" +#include "check.h" #include "check_pack.h" #include "check_error.h" #include "check_check.h" +static char errm[512]; + + START_TEST(test_pack_fmsg) { FailMsg *fmsg; char *buf; enum ck_msg_type type; - fmsg = emalloc (sizeof(FailMsg)); - buf = emalloc (CK_MAXMSGBUF); + fmsg = emalloc (sizeof (FailMsg)); fmsg->msg = (char *) "Hello, world!"; - pack (CK_MSG_FAIL, buf, fmsg); + pack (CK_MSG_FAIL, &buf, (CheckMsg *) fmsg); fmsg->msg = (char *) ""; - upack (buf, fmsg, &type); + upack (buf, (CheckMsg *) fmsg, &type); fail_unless (type == CK_MSG_FAIL, "Bad type unpacked for FailMsg"); if (strcmp (fmsg->msg, "Hello, world!") != 0) { - char *msg = emalloc(CK_MAXMSG); - snprintf (msg,CK_MAXMSG, + snprintf (errm, sizeof(errm), "Unpacked string is %s, should be Hello, World!", fmsg->msg); - - fail(msg); + fail (errm); } - free(fmsg->msg); - free(fmsg); - free(buf); + free (fmsg->msg); + free (fmsg); + free (buf); } END_TEST @@ -48,32 +47,29 @@ START_TEST(test_pack_loc) char *buf; enum ck_msg_type type; - lmsg = emalloc (sizeof(LocMsg)); - buf = emalloc (CK_MAXMSGBUF); + lmsg = emalloc (sizeof (LocMsg)); lmsg->file = (char *) "abc123.c"; lmsg->line = 125; - pack (CK_MSG_LOC, buf, lmsg); + pack (CK_MSG_LOC, &buf, (CheckMsg *) lmsg); lmsg->file = NULL; lmsg->line = 0; - upack (buf, lmsg, &type); + upack (buf, (CheckMsg *) lmsg, &type); fail_unless (type == CK_MSG_LOC, "Bad type unpacked for LocMsg"); if (lmsg->line != 125) { - char *errm = emalloc (CK_MAXMSG); - snprintf(errm, CK_MAXMSG, + snprintf (errm, sizeof (errm), "LocMsg line was %d, should be %d", lmsg->line, 125); fail (errm); } if (strcmp (lmsg->file, "abc123.c") != 0) { - char *errm = emalloc (CK_MAXMSG); - snprintf(errm, CK_MAXMSG, - "LocMsg file was %s, should be abc123.c", - lmsg->file); + snprintf (errm, sizeof (errm), + "LocMsg file was %s, should be abc123.c", + lmsg->file); fail (errm); } @@ -90,26 +86,23 @@ START_TEST(test_pack_ctx) enum ck_msg_type type; int npk, nupk; - buf = emalloc (CK_MAXMSGBUF); cmsg.ctx = CK_CTX_SETUP; + npk = pack (CK_MSG_CTX, &buf, (CheckMsg *) &cmsg); - npk = pack (CK_MSG_CTX, buf, &cmsg); cmsg.ctx = CK_CTX_TEARDOWN; - nupk = upack (buf, &cmsg, &type); + nupk = upack (buf, (CheckMsg *) &cmsg, &type); fail_unless (type == CK_MSG_CTX, "Bad type unpacked for CtxMsg"); if (cmsg.ctx != CK_CTX_SETUP) { - char *errm = emalloc (CK_MAXMSG); - snprintf(errm, CK_MAXMSG, + snprintf (errm, sizeof (errm), "CtxMsg ctx got %d, expected %d", cmsg.ctx, CK_CTX_SETUP); fail (errm); } free (buf); - } END_TEST @@ -121,22 +114,20 @@ START_TEST(test_pack_len) int n = 0; enum ck_msg_type type; - buf = emalloc (CK_MAXMSGBUF); cmsg.ctx = CK_CTX_TEST; - n = pack(CK_MSG_CTX,buf,&cmsg); + n = pack (CK_MSG_CTX, &buf, (CheckMsg *) &cmsg); fail_unless (n > 0, "Return val from pack not set correctly"); /* Value below may change with different implementations of pack */ - fail_unless (n == 4, "Return val from pack not correct"); + fail_unless (n == 8, "Return val from pack not correct"); n = 0; - n = upack(buf,&cmsg,&type); - if (n != 4) { - char *msg = emalloc (CK_MAXMSG); - snprintf(msg,CK_MAXMSG, "%d bytes read from upack, should be 4",n); - fail (msg); + n = upack (buf, (CheckMsg *) &cmsg, &type); + if (n != 8) { + snprintf (errm, sizeof (errm), "%d bytes read from upack, should be 8", n); + fail (errm); } - free(buf); + free (buf); } END_TEST @@ -147,10 +138,8 @@ START_TEST(test_pack_ctx_limit) char *buf; cmsg.ctx = -1; - buf = emalloc (CK_MAXMSGBUF); - pack(CK_MSG_CTX,buf,&cmsg); - pack(CK_MSG_CTX,buf,cmsgp); - + pack (CK_MSG_CTX, &buf, (CheckMsg *) &cmsg); + pack (CK_MSG_CTX, &buf, (CheckMsg *) cmsgp); } END_TEST @@ -161,16 +150,19 @@ START_TEST(test_pack_fail_limit) char *buf; enum ck_msg_type type; - buf = emalloc (CK_MAXMSGBUF); fmsg.msg = (char *) ""; - pack(CK_MSG_FAIL,buf,&fmsg); + pack (CK_MSG_FAIL, &buf, (CheckMsg *) &fmsg); fmsg.msg = (char *) "abc"; - upack(buf,&fmsg,&type); - fail_unless (strcmp(fmsg.msg, "") == 0, "Empty string not handled properly"); - free(fmsg.msg); + upack (buf, (CheckMsg *) &fmsg, &type); + free (buf); + fail_unless (strcmp (fmsg.msg, "") == 0, + "Empty string not handled properly"); + + free (fmsg.msg); fmsg.msg = NULL; - pack(CK_MSG_FAIL,buf,&fmsg); - pack(CK_MSG_FAIL,buf,fmsgp); + + pack (CK_MSG_FAIL, &buf, (CheckMsg *) &fmsg); + pack (CK_MSG_FAIL, &buf, (CheckMsg *) fmsgp); } END_TEST @@ -181,18 +173,18 @@ START_TEST(test_pack_loc_limit) char *buf; enum ck_msg_type type; - buf = emalloc (CK_MAXMSGBUF); lmsg.file = (char *) ""; lmsg.line = 0; - pack(CK_MSG_LOC,buf,&lmsg); + pack (CK_MSG_LOC, &buf, (CheckMsg *) &lmsg); lmsg.file = (char *) "abc"; - upack(buf,&lmsg,&type); - fail_unless (strcmp(lmsg.file, "") == 0, + upack (buf, (CheckMsg *) &lmsg, &type); + fail_unless (strcmp (lmsg.file, "") == 0, "Empty string not handled properly"); - free(lmsg.file); + free (lmsg.file); lmsg.file = NULL; - pack(CK_MSG_LOC,buf,&lmsg); - pack(CK_MSG_LOC,buf,lmsgp); + + pack (CK_MSG_LOC, &buf, (CheckMsg *) &lmsg); + pack (CK_MSG_LOC, &buf, (CheckMsg *) lmsgp); } END_TEST @@ -208,12 +200,12 @@ START_TEST(test_ppack) lmsg.file = (char *) "abc123.c"; lmsg.line = 10; fmsg.msg = (char *) "oops"; - pipe(filedes); - ppack(filedes[1],CK_MSG_CTX, &cmsg); - ppack(filedes[1],CK_MSG_LOC, &lmsg); - ppack(filedes[1],CK_MSG_FAIL, &fmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + pipe (filedes); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); + ppack (filedes[1], CK_MSG_FAIL, (CheckMsg *) &fmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg != NULL, "Return value from ppack should always be malloc'ed"); @@ -229,7 +221,7 @@ START_TEST(test_ppack) "Test file not received correctly"); fail_unless (strcmp(rmsg->msg, "oops") == 0, "Failure message not received correctly"); - + free(rmsg); } END_TEST @@ -244,17 +236,17 @@ START_TEST(test_ppack_noctx) lmsg.file = (char *) "abc123.c"; lmsg.line = 10; fmsg.msg = (char *) "oops"; - pipe(filedes); - ppack(filedes[1],CK_MSG_LOC, &lmsg); - ppack(filedes[1],CK_MSG_FAIL, &fmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + pipe (filedes); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); + ppack (filedes[1], CK_MSG_FAIL, (CheckMsg *) &fmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg == NULL, "Result should be NULL with no CTX"); if (rmsg != NULL) - free(rmsg); + free (rmsg); } END_TEST @@ -265,10 +257,10 @@ START_TEST(test_ppack_onlyctx) RcvMsg *rmsg; cmsg.ctx = CK_CTX_SETUP; - pipe(filedes); - ppack(filedes[1],CK_MSG_CTX, &cmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + pipe (filedes); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg->msg == NULL, "Result message should be NULL with only CTX"); @@ -278,7 +270,7 @@ START_TEST(test_ppack_onlyctx) "Result loc line should be -1 with only CTX"); if (rmsg != NULL) - free(rmsg); + free (rmsg); } END_TEST @@ -292,16 +284,16 @@ START_TEST(test_ppack_multictx) cmsg.ctx = CK_CTX_SETUP; lmsg.line = 5; lmsg.file = (char *) "abc123.c"; - pipe(filedes); - ppack(filedes[1],CK_MSG_CTX, &cmsg); - ppack(filedes[1],CK_MSG_LOC, &lmsg); + pipe (filedes); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); cmsg.ctx = CK_CTX_TEST; - ppack(filedes[1],CK_MSG_CTX, &cmsg); - ppack(filedes[1],CK_MSG_LOC, &lmsg); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); cmsg.ctx = CK_CTX_TEARDOWN; - ppack(filedes[1],CK_MSG_CTX, &cmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg->test_line == 5, "Test loc not being preserved on CTX change"); @@ -309,7 +301,7 @@ START_TEST(test_ppack_multictx) fail_unless (rmsg->fixture_line == -1, "Fixture not reset on CTX change"); if (rmsg != NULL) - free(rmsg); + free (rmsg); } END_TEST @@ -323,19 +315,22 @@ START_TEST(test_ppack_nofail) lmsg.file = (char *) "abc123.c"; lmsg.line = 10; cmsg.ctx = CK_CTX_SETUP; - pipe(filedes); - ppack(filedes[1],CK_MSG_CTX, &cmsg); - ppack(filedes[1],CK_MSG_LOC, &lmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + pipe (filedes); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg->msg == NULL, "Failure result should be NULL with no failure message"); if (rmsg != NULL) - free(rmsg); + free (rmsg); } END_TEST + +#define BIG_MSG_LEN 1037 + START_TEST(test_ppack_big) { int filedes[2]; @@ -345,19 +340,19 @@ START_TEST(test_ppack_big) RcvMsg *rmsg; cmsg.ctx = CK_CTX_TEST; - lmsg.file = emalloc(CK_MAXMSG); - memset(lmsg.file,'a',CK_MAXMSG - 1); - lmsg.file[CK_MAXMSG - 1] = '\0'; + lmsg.file = emalloc (BIG_MSG_LEN); + memset (lmsg.file,'a',BIG_MSG_LEN - 1); + lmsg.file[BIG_MSG_LEN - 1] = '\0'; lmsg.line = 10; - fmsg.msg = emalloc(CK_MAXMSG); - memset(fmsg.msg,'a',CK_MAXMSG - 1); - fmsg.msg[CK_MAXMSG - 1] = '\0'; - pipe(filedes); - ppack(filedes[1],CK_MSG_CTX, &cmsg); - ppack(filedes[1],CK_MSG_LOC, &lmsg); - ppack(filedes[1],CK_MSG_FAIL, &fmsg); - close(filedes[1]); - rmsg = punpack(filedes[0]); + fmsg.msg = emalloc (BIG_MSG_LEN); + memset (fmsg.msg, 'a', BIG_MSG_LEN - 1); + fmsg.msg[BIG_MSG_LEN - 1] = '\0'; + pipe (filedes); + ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg); + ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg); + ppack (filedes[1], CK_MSG_FAIL, (CheckMsg *) &fmsg); + close (filedes[1]); + rmsg = punpack (filedes[0]); fail_unless (rmsg != NULL, "Return value from ppack should always be malloc'ed"); @@ -365,12 +360,14 @@ START_TEST(test_ppack_big) "CTX not set correctly in ppack"); fail_unless (rmsg->test_line == 10, "Test line not received correctly"); - fail_unless (strcmp(rmsg->test_file,lmsg.file) == 0, + fail_unless (strcmp (rmsg->test_file, lmsg.file) == 0, "Test file not received correctly"); - fail_unless (strcmp(rmsg->msg, fmsg.msg) == 0, + fail_unless (strcmp (rmsg->msg, fmsg.msg) == 0, "Failure message not received correctly"); - free(rmsg); + free (rmsg); + free (lmsg.file); + free (fmsg.msg); } END_TEST @@ -381,25 +378,25 @@ Suite *make_pack_suite(void) TCase *tc_core; TCase *tc_limit; - s = suite_create("Pack"); - tc_core = tcase_create("Core"); - tc_limit = tcase_create("Limit"); - - suite_add_tcase(s, tc_core); - tcase_add_test(tc_core, test_pack_fmsg); - tcase_add_test(tc_core, test_pack_loc); - tcase_add_test(tc_core, test_pack_ctx); - tcase_add_test(tc_core, test_pack_len); - tcase_add_test(tc_core, test_ppack); - tcase_add_test(tc_core, test_ppack_noctx); - tcase_add_test(tc_core, test_ppack_onlyctx); - tcase_add_test(tc_core, test_ppack_multictx); - tcase_add_test(tc_core, test_ppack_nofail); - suite_add_tcase(s, tc_limit); - tcase_add_test(tc_limit, test_pack_ctx_limit); - tcase_add_test(tc_limit, test_pack_fail_limit); - tcase_add_test(tc_limit, test_pack_loc_limit); - tcase_add_test(tc_limit, test_ppack_big); + s = suite_create ("Pack"); + tc_core = tcase_create ("Core"); + tc_limit = tcase_create ("Limit"); + + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, test_pack_fmsg); + tcase_add_test (tc_core, test_pack_loc); + tcase_add_test (tc_core, test_pack_ctx); + tcase_add_test (tc_core, test_pack_len); + tcase_add_test (tc_core, test_ppack); + tcase_add_test (tc_core, test_ppack_noctx); + tcase_add_test (tc_core, test_ppack_onlyctx); + tcase_add_test (tc_core, test_ppack_multictx); + tcase_add_test (tc_core, test_ppack_nofail); + suite_add_tcase (s, tc_limit); + tcase_add_test (tc_limit, test_pack_ctx_limit); + tcase_add_test (tc_limit, test_pack_fail_limit); + tcase_add_test (tc_limit, test_pack_loc_limit); + tcase_add_test (tc_limit, test_ppack_big); return s; } -- 2.49.0