void send_failure_info(const char *msg)
{
FailMsg fmsg;
- int pipe_fileno = fileno(get_pipe());
fmsg.msg = (char *) msg;
- ppack(pipe_fileno, CK_MSG_FAIL, (CheckMsg *) &fmsg);
+ ppack(get_pipe(), CK_MSG_FAIL, (CheckMsg *) &fmsg);
}
void send_duration_info(int duration)
{
DurationMsg dmsg;
- int pipe_fileno = fileno(get_pipe());
dmsg.duration = duration;
- ppack(pipe_fileno, CK_MSG_DURATION, (CheckMsg *) &dmsg);
+ ppack(get_pipe(), CK_MSG_DURATION, (CheckMsg *) &dmsg);
}
void send_loc_info(const char * file, int line)
{
LocMsg lmsg;
- int pipe_fileno = fileno(get_pipe());
lmsg.file = (char *) file;
lmsg.line = line;
- ppack(pipe_fileno, CK_MSG_LOC, (CheckMsg *) &lmsg);
+ ppack(get_pipe(), CK_MSG_LOC, (CheckMsg *) &lmsg);
}
void send_ctx_info(enum ck_result_ctx ctx)
{
CtxMsg cmsg;
- int pipe_fileno = fileno(get_pipe());
cmsg.ctx = ctx;
- ppack(pipe_fileno, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack(get_pipe(), CK_MSG_CTX, (CheckMsg *) &cmsg);
}
TestResult *receive_test_result (int waserror)
FILE *fp;
RcvMsg *rmsg;
TestResult *result;
- int pipe_fileno;
fp = get_pipe();
if (fp == NULL)
}
rewind(fp);
-
- pipe_fileno = fileno(fp);
- rmsg = punpack (pipe_fileno);
+ rmsg = punpack (fp);
if(rmsg == NULL)
{
static enum ck_msg_type upack_type (char **buf);
static void pack_type (char **buf, enum ck_msg_type type);
-static int read_buf (int fdes, int size, char *buf);
+static int read_buf (FILE* fdes, int size, 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);
}
#endif
-void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg)
+void ppack (FILE* fdes, enum ck_msg_type type, CheckMsg *msg)
{
char *buf;
int n;
pthread_cleanup_push( ppack_cleanup, &ck_mutex_lock );
pthread_mutex_lock(&ck_mutex_lock);
- r = write (fdes, buf, n);
+ r = fwrite(buf, 1, n, fdes);
+ fflush(fdes);
pthread_mutex_unlock(&ck_mutex_lock);
pthread_cleanup_pop(0);
- if (r == -1)
- eprintf ("Error in call to write:", __FILE__, __LINE__ - 2);
+ if (r != n)
+ eprintf ("Error in call to fwrite:", __FILE__, __LINE__ - 2);
free (buf);
}
-static int read_buf (int fdes, int size, char *buf)
+static int read_buf (FILE* fdes, int size, char *buf)
{
int n;
+ n = fread(buf, 1, size, fdes);
- n = read (fdes, buf, size);
- if (n == -1)
- eprintf ("Error in call to read:", __FILE__, __LINE__ - 4);
+ if (ferror(fdes))
+ {
+ eprintf ("Error in call to fread:", __FILE__, __LINE__ - 4);
+ }
return n;
}
}
}
-RcvMsg *punpack (int fdes)
+RcvMsg *punpack (FILE* fdes)
{
int nread, nparse, n;
char *buf;
#include "check_pack.h"
#include "check_error.h"
#include "check_check.h"
+#include "check_msg.h"
static char errm[512];
#if defined(HAVE_FORK) && HAVE_FORK==1
START_TEST(test_ppack)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
CtxMsg cmsg;
LocMsg lmsg;
FailMsg fmsg;
RcvMsg *rmsg;
- int pipe_result;
cmsg.ctx = CK_CTX_TEST;
lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
fmsg.msg = (char *) "oops";
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- 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]);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
+ ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);
+
+ rewind(result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg != NULL,
"Return value from ppack should always be malloc'ed");
START_TEST(test_ppack_noctx)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
LocMsg lmsg;
FailMsg fmsg;
RcvMsg *rmsg;
- int pipe_result;
lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
fmsg.msg = (char *) "oops";
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg);
- ppack (filedes[1], CK_MSG_FAIL, (CheckMsg *) &fmsg);
- close (filedes[1]);
- rmsg = punpack (filedes[0]);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
+ ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);
+
+ rewind(result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg == NULL,
"Result should be NULL with no CTX");
START_TEST(test_ppack_onlyctx)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
CtxMsg cmsg;
RcvMsg *rmsg;
- int pipe_result;
cmsg.ctx = CK_CTX_SETUP;
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg);
- close (filedes[1]);
- rmsg = punpack (filedes[0]);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ rewind(result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg != NULL && rmsg->msg == NULL,
"Result message should be NULL with only CTX");
START_TEST(test_ppack_multictx)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
CtxMsg cmsg;
LocMsg lmsg;
RcvMsg *rmsg;
- int pipe_result;
cmsg.ctx = CK_CTX_SETUP;
lmsg.line = 5;
lmsg.file = (char *) "abc123.c";
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg);
- ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
cmsg.ctx = CK_CTX_TEST;
- ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg);
- ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
cmsg.ctx = CK_CTX_TEARDOWN;
- ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg);
- close (filedes[1]);
- rmsg = punpack (filedes[0]);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ rewind(result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg != NULL && rmsg->test_line == 5,
"Test loc not being preserved on CTX change");
START_TEST(test_ppack_nofail)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
CtxMsg cmsg;
LocMsg lmsg;
RcvMsg *rmsg;
- int pipe_result;
lmsg.file = (char *) "abc123.c";
lmsg.line = 10;
cmsg.ctx = CK_CTX_SETUP;
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- ppack (filedes[1], CK_MSG_CTX, (CheckMsg *) &cmsg);
- ppack (filedes[1], CK_MSG_LOC, (CheckMsg *) &lmsg);
- close (filedes[1]);
- rmsg = punpack (filedes[0]);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
+ rewind (result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg != NULL && rmsg->msg == NULL,
"Failure result should be NULL with no failure message");
START_TEST(test_ppack_big)
{
- int filedes[2];
+ FILE * result_file;
+ char * result_file_name = NULL;
CtxMsg cmsg;
LocMsg lmsg;
FailMsg fmsg;
RcvMsg *rmsg;
- int pipe_result;
cmsg.ctx = CK_CTX_TEST;
lmsg.file = emalloc (BIG_MSG_LEN);
fmsg.msg = emalloc (BIG_MSG_LEN);
memset (fmsg.msg, 'a', BIG_MSG_LEN - 1);
fmsg.msg[BIG_MSG_LEN - 1] = '\0';
- pipe_result = pipe (filedes);
- ck_assert_msg (pipe_result == 0, "Failed to create pipe");
- 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]);
+ result_file = open_tmp_file(&result_file_name);
+ free(result_file_name);
+ ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
+ ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
+ ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);
+ rewind (result_file);
+ rmsg = punpack (result_file);
ck_assert_msg (rmsg != NULL,
"Return value from ppack should always be malloc'ed");