#include "check_msg.h"
#include "check_pack.h"
-struct MsgKey
-{
- int key;
-};
-
typedef struct Pipe
{
int sendfd;
List *plst = NULL;
-static PipeEntry *get_pe_by_key(MsgKey *key);
-static Pipe *get_pipe_by_key(MsgKey *key);
-static MsgKey *get_setup_key (void);
+static PipeEntry *get_pe_by_key(MsgKey key);
+static Pipe *get_pipe_by_key(MsgKey key);
+static MsgKey get_setup_key (void);
static void setup_pipe (Pipe *p);
-static void setup_messaging_with_key (MsgKey *key);
-static void teardown_messaging_with_key (MsgKey *key);
+static void setup_messaging_with_key (MsgKey key);
+static void teardown_messaging_with_key (MsgKey key);
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);
-void send_failure_info (MsgKey *key, const char *msg)
+void send_failure_info (MsgKey key, const char *msg)
{
FailMsg fmsg;
Pipe *p;
ppack (p->sendfd, CK_MSG_FAIL, (CheckMsg *) &fmsg);
}
-void send_loc_info (MsgKey *key, const char * file, int line)
+void send_loc_info (MsgKey key, const char * file, int line)
{
LocMsg lmsg;
Pipe *p;
ppack (p->sendfd, CK_MSG_LOC, (CheckMsg *) &lmsg);
}
-void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx)
+void send_ctx_info (MsgKey key,enum ck_result_ctx ctx)
{
CtxMsg cmsg;
Pipe *p;
ppack (p->sendfd, CK_MSG_CTX, (CheckMsg *) &cmsg);
}
-TestResult *receive_test_result (MsgKey *key, int waserror)
+TestResult *receive_test_result (MsgKey key, int waserror)
{
Pipe *p;
RcvMsg *rmsg;
+ TestResult *result;
p = get_pipe_by_key (key);
if (p == NULL)
close (p->recvfd);
setup_pipe (p);
- return construct_test_result (rmsg, waserror);
+ result = construct_test_result (rmsg, waserror);
+ rcvmsg_free(rmsg);
+ return result;
}
static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx,
if (ctx == CK_CTX_TEST) {
tr->file = rmsg->test_file;
tr->line = rmsg->test_line;
+ rmsg->test_file = NULL;
+ rmsg->test_line = -1;
} else {
tr->file = rmsg->fixture_file;
tr->line = rmsg->fixture_line;
+ rmsg->fixture_file = NULL;
+ rmsg->fixture_line = -1;
}
}
if (rmsg->msg != NULL || waserror) {
tr->ctx = rmsg->lastctx;
tr->msg = rmsg->msg;
+ rmsg->msg = NULL;
tr_set_loc_by_ctx (tr, rmsg->lastctx, rmsg);
} else if (rmsg->lastctx == CK_CTX_SETUP) {
tr->ctx = CK_CTX_SETUP;
setup_messaging_with_key (get_recv_key());
}
-MsgKey *get_send_key (void)
+MsgKey get_send_key (void)
{
- MsgKey *key = emalloc (sizeof (MsgKey));
+ MsgKey key;
if (cur_fork_status () == CK_FORK)
- key->key = getppid ();
+ 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;
- key->key = getpid ();
+ key.key = getpid ();
return key;
}
-static MsgKey *get_setup_key (void)
+static MsgKey get_setup_key (void)
{
return get_recv_key ();
}
setup_messaging_with_key (get_test_key ());
}
-MsgKey *get_test_key (void)
+MsgKey get_test_key (void)
{
- MsgKey *key = emalloc (sizeof (MsgKey));
- key->key = -1;
+ MsgKey key;
+ key.key = -1;
return 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;
for (list_front(plst); !list_at_end(plst); list_advance(plst)) {
PipeEntry *p = list_val(plst);
- if (p->key == key->key) {
+ if (p->key == key.key) {
pe = p;
break;
}
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);
fcntl (p->sendfd, F_SETFL, O_NONBLOCK);
}
-static void setup_messaging_with_key (MsgKey *key)
+static void setup_messaging_with_key (MsgKey key)
{
PipeEntry *pe;
if (pe == NULL) {
pe = emalloc (sizeof (PipeEntry));
pe->cur = 0;
- pe->key = key->key;
+ pe->key = key.key;
list_add_end (plst, pe);
}
if (pe->cur == 0) {
eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__);
}
-static void teardown_messaging_with_key (MsgKey *key)
+static void teardown_messaging_with_key (MsgKey key)
{
PipeEntry *pe = get_pe_by_key (key);
#define CHECK_MSG_NEW_H
+struct MsgKey
+{
+ int key;
+};
+
typedef struct MsgKey MsgKey;
/* Functions implementing messaging during test runs */
-void send_failure_info (MsgKey *key, const char *msg);
-void send_loc_info (MsgKey *key, const char *file, int line);
-void send_ctx_info (MsgKey *key, enum ck_result_ctx ctx);
+void send_failure_info (MsgKey key, const char *msg);
+void send_loc_info (MsgKey key, const char *file, int line);
+void send_ctx_info (MsgKey key, enum ck_result_ctx ctx);
-TestResult *receive_test_result (MsgKey *key, int waserror);
+TestResult *receive_test_result (MsgKey key, int waserror);
void setup_messaging(void);
-MsgKey *get_send_key(void);
-MsgKey *get_recv_key(void);
+MsgKey get_send_key(void);
+MsgKey get_recv_key(void);
void teardown_messaging(void);
/* for testing only */
void setup_test_messaging(void);
-MsgKey *get_test_key(void);
+MsgKey get_test_key(void);
void teardown_test_messaging(void);
#endif /*CHECK_MSG_NEW_H */
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);
typedef int (*pfun) (char **, CheckMsg *);
typedef void (*upfun) (char **, CheckMsg *);
return rmsg;
}
+void rcvmsg_free (RcvMsg *rmsg)
+{
+ if (rmsg->fixture_file!=NULL) free(rmsg->fixture_file);
+ if (rmsg->test_file!=NULL) free(rmsg->test_file);
+ if (rmsg->msg!=NULL) free(rmsg->msg);
+ free(rmsg);
+}
+
static void rcvmsg_update_ctx (RcvMsg *rmsg, enum ck_result_ctx ctx)
{
if (rmsg->lastctx != -1)
int flen = strlen(file);
if (rmsg->lastctx == CK_CTX_TEST) {
+ if (rmsg->test_file!=NULL) free(rmsg->test_file);
rmsg->test_line = line;
rmsg->test_file = emalloc (flen + 1);
strcpy (rmsg->test_file, file);
} else {
+ if (rmsg->fixture_file!=NULL) free(rmsg->fixture_file);
rmsg->fixture_line = line;
rmsg->fixture_file = emalloc (flen + 1);
strcpy (rmsg->fixture_file, file);