msg*() aren't available.
svn path=/trunk/yasm/; revision=201
#undef HAVE_LC_MESSAGES
#undef HAVE_STPCPY
+/* combined test for fork/way/msg* */
+#undef USE_FORKWAITMSG
+
@BOTTOM@
#endif /* YASM_CONFIG_H */
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
-#include <stdlib.h>
+
+#ifdef STDC_HEADERS
+# include <string.h>
+# include <stdlib.h>
+#endif
+
#include "error.h"
#include "list.h"
#include "check.h"
#include "check_impl.h"
#include "check_msg.h"
+#ifndef USE_FORKWAITMSG
+extern int nofork_exit_status;
+#endif
Suite *suite_create (char *name)
{
list_add_end (s->tclst, tc);
}
-void _tcase_add_test (TCase *tc, TFun fn, char *name)
+void tcase_add_test_ (TCase *tc, TFun fn, char *name)
{
TF * tf;
if (tc == NULL || fn == NULL || name == NULL)
send_last_loc_msg (msqid, file, line);
}
-void _mark_point (int msqid, char *file, int line)
+void mark_point_ (int msqid, char *file, int line)
{
send_last_loc_msg (msqid, file, line);
}
-void _fail_unless (int msqid, int result, char *file, int line, char * msg)
+int fail_unless_ (int msqid, int result, char *file, int line, char * msg)
{
if (line > MAXLINE)
eprintf ("Line number %d too large to use", line);
send_last_loc_msg (msqid, file, line);
if (!result) {
send_failure_msg (msqid, msg);
+#ifdef USE_FORKWAITMSG
exit(1);
+#else
+ nofork_exit_status = 1;
+ return 1;
+#endif
}
+ return 0;
}
/*! Add a test function to a test case
(macro version) */
-#define tcase_add_test(tc,tf) _tcase_add_test(tc,tf,"" # tf "")
+#define tcase_add_test(tc,tf) tcase_add_test_(tc,tf,"" # tf "")
/*! Add a test function to a test case
(function version -- use this when the macro won't work */
-void _tcase_add_test (TCase *tc, TFun tf, char *fname);
+void tcase_add_test_ (TCase *tc, TFun tf, char *fname);
/*!
/*! Start a unit test with START_TEST(unit_name), end with END_TEST
One must use braces within a START_/END_ pair to declare new variables */
-#define START_TEST(__testname)\
-static void __testname (int __msqid)\
+#define START_TEST(testname__)\
+static void testname__ (int msqid__)\
{\
- tcase_fn_start (__msqid,""# __testname, __FILE__, __LINE__);
+ tcase_fn_start (msqid__,""# testname__, __FILE__, __LINE__);
/*! End a unit test */
#define END_TEST }
/*! Fail the test case unless result is true */
-#define fail_unless(result,msg) _fail_unless(__msqid,result,__FILE__,__LINE__,msg)
+#define fail_unless(result,msg) \
+ if(fail_unless_(msqid__,result,__FILE__,__LINE__,msg)) return;
/*! Non macro version of #fail_unless, with more complicated interface */
-void _fail_unless (int msqid, int result, char *file, int line, char *msg);
+int fail_unless_ (int msqid, int result, char *file, int line, char *msg);
/*! Always fail */
-#define fail(msg) _fail_unless(__msqid,0,__FILE__,__LINE__,msg)
+#define fail(msg) fail_unless_(msqid__,0,__FILE__,__LINE__,msg)
/*! Mark the last point reached in a unit test
(useful for tracking down where a segfault, etc. occurs */
-#define mark_point() _mark_point(__msqid,__FILE__,__LINE__)
+#define mark_point() mark_point_(msqid__,__FILE__,__LINE__)
/*! Non macro version of #mark_point */
-void _mark_point (int msqid, char *file, int line);
+void mark_point_ (int msqid, char *file, int line);
/*! @} */
-#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
#include <stdio.h>
#include <check.h>
#include "list.h"
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <stdio.h>
+
+#ifdef STDC_HEADERS
#include <errno.h>
#include <string.h>
-#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_IPC_H
+# include <sys/ipc.h>
+#endif
+
+#ifdef HAVE_SYS_MSG_H
+# include <sys/msg.h>
+#endif
+
#include "list.h"
#include "error.h"
#include "check.h"
#include "check_impl.h"
#include "check_msg.h"
+#ifndef USE_FORKWAITMSG
+static LastLocMsg *nofork_lastlocmsg;
+static FailureMsg *nofork_failuremsg;
+#endif
+
enum {
LASTLOCMSG = 1,
FAILUREMSG = 2
void send_last_loc_msg (int msqid, char * file, int line)
{
+#ifdef USE_FORKWAITMSG
int rval;
LastLocMsg *rmsg = create_last_loc_msg(file, line);
rval = msgsnd(msqid, (void *) rmsg, CMAXMSG, IPC_NOWAIT);
eprintf ("send_last_loc_msg:Failed to send message, msqid = %d:",msqid);
}
free(rmsg);
+#else
+ nofork_lastlocmsg = create_last_loc_msg(file, line);
+#endif
}
int create_msq (void) {
+#ifdef USE_FORKWAITMSG
int msqid;
msqid = msgget((key_t) 1, 0666 | IPC_CREAT);
if (msqid == -1)
eprintf ("Unable to create message queue:");
return msqid;
+#else
+ return 0;
+#endif
}
void delete_msq (int msqid)
{
+#ifdef USE_FORKWAITMSG
if (msgctl (msqid, IPC_RMID, NULL) == -1)
eprintf ("Failed to free message queue:");
+#endif
}
void send_failure_msg (int msqid, char *msg)
{
+#ifdef USE_FORKWAITMSG
int rval;
FailureMsg *rmsg = create_failure_msg(msg);
if (rval == -1)
eprintf ("send_failure_msg:Failed to send message:");
free(rmsg);
+#else
+ nofork_failuremsg = create_failure_msg(msg);
+#endif
}
LastLocMsg *receive_last_loc_msg (int msqid)
{
+#ifdef USE_FORKWAITMSG
LastLocMsg *rmsg = emalloc(sizeof(LastLocMsg)); /* caller responsible for freeing */
while (1) {
int rval;
}
}
return rmsg;
+#else
+ LastLocMsg *rmsg = nofork_lastlocmsg;
+ nofork_lastlocmsg = NULL;
+ return rmsg;
+#endif
}
FailureMsg *receive_failure_msg (int msqid)
{
+#ifdef USE_FORKWAITMSG
FailureMsg *rmsg = emalloc(sizeof(FailureMsg));
int rval;
rval = msgrcv(msqid, (void *) rmsg, CMAXMSG, FAILUREMSG, IPC_NOWAIT);
eprintf ("receive_failure_msg:Failed to receive message:");
}
return rmsg;
+#else
+ FailureMsg *rmsg = nofork_failuremsg;
+ nofork_failuremsg = NULL;
+ return rmsg;
+#endif
}
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#ifndef WIFSIGNALED
+# define WIFSIGNALED(stat_val) \
+ (((stat_val) & 255) != 255 && \
+ ((stat_val) & 255) != 0)
+#endif
+#ifndef WTERMSIG
+# define WTERMSIG(stat_val) ((stat_val) & 255)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif
+#ifndef WEXITSTATUS
+# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <stdio.h>
-#include <stdarg.h>
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stdarg.h>
+#endif
+
#include "error.h"
#include "list.h"
#include "check.h"
#include "check_msg.h"
#include "check_log.h"
+#ifndef USE_FORKWAITMSG
+int nofork_exit_status;
+#endif
static void srunner_run_tcase (SRunner *sr, TCase *tc);
static void srunner_add_failure (SRunner *sr, TestResult *tf);
static List *srunner_resultlst (SRunner *sr);
+#ifdef USE_FORKWAITMSG
static char *signal_msg (int sig);
+#endif
static char *exit_msg (int exitstatus);
static int non_pass (int val);
static void receive_failure_info (int msqid, int status, TestResult *tr)
{
FailureMsg *fmsg;
-
+#ifdef USE_FORKWAITMSG
if (WIFSIGNALED(status)) {
tr->rtype = CRERROR;
tr->msg = signal_msg (WTERMSIG(status));
} else {
eprintf ("Bad status from wait() call\n");
}
+#else
+ if (status == 0) {
+ tr->rtype = CRPASS;
+ tr->msg = "Test passed";
+ }
+ else {
+ fmsg = receive_failure_msg (msqid);
+ if (fmsg == NULL) { /* implies early exit */
+ tr->rtype = CRERROR;
+ tr->msg = exit_msg (status);
+ }
+ else {
+ tr->rtype = CRFAILURE;
+ tr->msg = emalloc(strlen(fmsg->msg) + 1);
+ strcpy (tr->msg, fmsg->msg);
+ free (fmsg);
+ }
+ }
+#endif
}
static TestResult *receive_result_info (int msqid, int status, char *tcname,
static TestResult *tfun_run (int msqid, char *tcname, TF *tfun)
{
+#ifdef USE_FORKWAITMSG
pid_t pid;
+#endif
int status = 0;
+#ifdef USE_FORKWAITMSG
pid = fork();
if (pid == -1)
eprintf ("Unable to fork:");
_exit(EXIT_SUCCESS);
}
(void) wait(&status);
+#else
+ nofork_exit_status = 0;
+ tfun->fn(msqid);
+ status = nofork_exit_status;
+#endif
return receive_result_info(msqid, status, tcname, tfun->name);
}
return tr->tcname;
}
-
+#ifdef USE_FORKWAITMSG
static char *signal_msg (int signal)
{
char *msg = emalloc (CMAXMSG); /* free'd by caller */
snprintf(msg, CMAXMSG, "Received signal %d", signal);
return msg;
}
+#endif
static char *exit_msg (int exitval)
{
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+
+#ifdef STDC_HEADERS
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include <errno.h>
+#endif
+
#include "error.h"
/*
va_end(args);
/*include system error information if format ends in colon */
+#ifdef HAVE_STRERROR
if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
fprintf(stderr, " %s", strerror(errno));
+#endif
fprintf(stderr, "\n");
exit(2);
-#ifndef ERROR_H
-#define ERROR_H
+#ifndef CHECK_ERROR_H
+#define CHECK_ERROR_H
/*
Check: a unit test framework for C
void *emalloc(size_t n);
void *erealloc(void *, size_t n);
-#endif /*ERROR_H*/
+#endif /*CHECK_ERROR_H*/
-#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
#include "list.h"
#include "error.h"
-#ifndef LIST_H
-#define LIST_H
+#ifndef CHECK_LIST_H
+#define CHECK_LIST_H
/*
Check: a unit test framework for C
/* Free a list, freeing values using a freeing function */
/* void list_vfree (List * lp, void (*fp) (void *)); */
-#endif /*LIST_H*/
+#endif /*CHECK_LIST_H*/
AC_TYPE_SIZE_T
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(memcpy toascii abort strcasecmp stricmp strcmpi)
+AC_CHECK_FUNCS(memcpy toascii abort)
+AC_CHECK_FUNCS(strcasecmp stricmp strcmpi, break)
AC_REPLACE_FUNCS(strdup strtoul)
AC_CHECK_HEADERS(limits.h sys/queue.h sys/cdefs.h)
+# Check for stuff wanted by the test suite. None of this is required.
+if ${check}; then
+ AC_CHECK_FUNCS(fork wait msgctl msgget msgrcv msgsnd strerror)
+ if test "$ac_cv_func_fork" = yes &&
+ test "$ac_cv_func_wait" = yes &&
+ test "$ac_cv_func_msgctl" = yes &&
+ test "$ac_cv_func_msgget" = yes &&
+ test "$ac_cv_func_msgrcv" = yes &&
+ test "$ac_cv_func_msgsnd" = yes; then
+ AC_DEFINE(USE_FORKWAITMSG)
+ fi
+ AC_TYPE_PID_T
+ AC_HEADER_SYS_WAIT
+ AC_CHECK_HEADERS(sys/types.h sys/ipc.h sys/msg.h unistd.h)
+fi
+
# Check for some target-specific stuff
case "$host" in
*-*-sunos4*)
AC_TYPE_SIZE_T
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(memcpy toascii abort strcasecmp stricmp strcmpi)
+AC_CHECK_FUNCS(memcpy toascii abort)
+AC_CHECK_FUNCS(strcasecmp stricmp strcmpi, break)
AC_REPLACE_FUNCS(strdup strtoul)
AC_CHECK_HEADERS(limits.h sys/queue.h sys/cdefs.h)
+# Check for stuff wanted by the test suite. None of this is required.
+if ${check}; then
+ AC_CHECK_FUNCS(fork wait msgctl msgget msgrcv msgsnd strerror)
+ if test "$ac_cv_func_fork" = yes &&
+ test "$ac_cv_func_wait" = yes &&
+ test "$ac_cv_func_msgctl" = yes &&
+ test "$ac_cv_func_msgget" = yes &&
+ test "$ac_cv_func_msgrcv" = yes &&
+ test "$ac_cv_func_msgsnd" = yes; then
+ AC_DEFINE(USE_FORKWAITMSG)
+ fi
+ AC_TYPE_PID_T
+ AC_HEADER_SYS_WAIT
+ AC_CHECK_HEADERS(sys/types.h sys/ipc.h sys/msg.h unistd.h)
+fi
+
# Check for some target-specific stuff
case "$host" in
*-*-sunos4*)