]> granicus.if.org Git - yasm/commitdiff
Autoconfize Check test suite, and make it work even if fork(), wait(), and
authorPeter Johnson <peter@tortall.net>
Wed, 19 Sep 2001 21:56:00 +0000 (21:56 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 19 Sep 2001 21:56:00 +0000 (21:56 -0000)
msg*() aren't available.

svn path=/trunk/yasm/; revision=201

12 files changed:
acconfig.h
check/check.c
check/check.h
check/check_log.c
check/check_msg.c
check/check_run.c
check/error.c
check/error.h
check/list.c
check/list.h
configure.ac
configure.in

index 1fab28db9c41d0a129c0dccc75a686a0617268dc..50f402f2225d1c7cb26d706873d9153e44aaa73b 100644 (file)
@@ -18,6 +18,9 @@
 #undef HAVE_LC_MESSAGES
 #undef HAVE_STPCPY
 
+/* combined test for fork/way/msg* */
+#undef USE_FORKWAITMSG
+
 @BOTTOM@
 
 #endif /* YASM_CONFIG_H */
index 79607d2c68eef6b164a9d315041e3a636fab37ed..829c95f36ef5df47c9ed3d2503e3f6d0d979c8d1 100644 (file)
   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)
 {
@@ -82,7 +93,7 @@ void suite_add_tcase (Suite *s, TCase *tc)
   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)
@@ -105,12 +116,12 @@ void tcase_fn_start (int msqid, char *fname, char *file, int line)
   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);
@@ -118,6 +129,12 @@ void _fail_unless (int msqid, int result, char *file, int line, char * msg)
   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;
 }
index 208c8ab80e5a0706c9c4eacf8db490e2f17dbc25..0f6047ac1a6c2b6acc74cb2a093b874949ef9efb 100644 (file)
@@ -123,10 +123,10 @@ void suite_add_tcase (Suite *s, TCase *tc);
 
 /*! 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);
 
 /*!
 
@@ -142,29 +142,30 @@ void tcase_fn_start (int msqid, char *fname, char *file, int line);
 
 /*! 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);
 
 /*! @} */
 
index 501c68cb67cce12b5bcc6d332ec44c238c124f03..67bd900d7eb757b8b32f67b600088273729d475b 100644 (file)
@@ -1,4 +1,11 @@
-#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"
index b87d18702f08ee48c60e30ae05fe5d5d6f4b70a7..cba6b83f98638f9cd804d920f61778c0a20729db 100644 (file)
   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
@@ -89,6 +110,7 @@ int last_loc_line (LastLocMsg *msg)
 
 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);
@@ -96,25 +118,35 @@ void send_last_loc_msg (int msqid, char * file, int line)
     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);
@@ -123,10 +155,14 @@ void send_failure_msg (int msqid, char *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;
@@ -138,10 +174,16 @@ LastLocMsg *receive_last_loc_msg (int msqid)
     }
   }
   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);
@@ -151,5 +193,10 @@ FailureMsg *receive_failure_msg (int msqid)
     eprintf ("receive_failure_msg:Failed to receive message:");
   }
   return rmsg;
+#else
+  FailureMsg *rmsg = nofork_failuremsg;
+  nofork_failuremsg = NULL;
+  return rmsg;
+#endif
 }
 
index 96601b4c5851242745be136721e8fd08150908d5..8ff0aaa0311f40b1173c09b0a44d91a641f575b7 100644 (file)
   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"
@@ -30,6 +60,9 @@
 #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);
@@ -41,7 +74,9 @@ static void receive_failure_info (int msqid, int status, TestResult *tr);
 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);
 
@@ -176,7 +211,7 @@ static void receive_last_loc_info (int msqid, TestResult *tr)
 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));
@@ -208,6 +243,25 @@ static void receive_failure_info (int msqid, int status, TestResult *tr)
   } 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,
@@ -224,9 +278,12 @@ 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:");
@@ -235,6 +292,11 @@ static TestResult *tfun_run (int msqid, char *tcname, TF *tfun)
     _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);
 }
 
@@ -313,13 +375,14 @@ char *tr_tcname (TestResult *tr)
   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)
 {
index f2227a2b553b19b2365371166583b0f9d888d232..4a486804c119c3ae23f6cb60b11735fad9e88113 100644 (file)
@@ -1,8 +1,16 @@
+#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"
 
 /*
@@ -34,8 +42,10 @@ void eprintf (char *fmt, ...)
   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);
index 01c2e136c3ac38366d08bc8e34fc01a7fdf0a6a1..da089b29dfc96a2083cfbece5c2432ee3eb2864b 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef ERROR_H
-#define ERROR_H
+#ifndef CHECK_ERROR_H
+#define CHECK_ERROR_H
 
 /*
   Check: a unit test framework for C
@@ -29,4 +29,4 @@ void eprintf (char *fmt, ...);
 void *emalloc(size_t n);
 void *erealloc(void *, size_t n);
 
-#endif /*ERROR_H*/
+#endif /*CHECK_ERROR_H*/
index 5e2d04a13ae82266bacc6e0f47d37a63216002f7..9fce7edfbe412a2a563d846fe29ce20ead059798 100644 (file)
@@ -1,4 +1,11 @@
-#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+#endif
+
 #include "list.h"
 #include "error.h"
 
index 17215a2c654a532c8b00402e51eec0fa01661e9f..12fa378860163a88ebd2150ddc68f348d8dcfea1 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef LIST_H
-#define LIST_H
+#ifndef CHECK_LIST_H
+#define CHECK_LIST_H
 
 /*
   Check: a unit test framework for C
@@ -48,4 +48,4 @@ void list_free (List * lp);
 /* Free a list, freeing values using a freeing function */
 /* void list_vfree (List * lp, void (*fp) (void *)); */
 
-#endif /*LIST_H*/
+#endif /*CHECK_LIST_H*/
index a0f61022de3f395fc6ddbf4cb6f332d808828dcb..03227f5bcff39b7cb67166d5d7e594fe4eeeabba 100644 (file)
@@ -68,11 +68,28 @@ AC_C_CONST
 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*)
index a0f61022de3f395fc6ddbf4cb6f332d808828dcb..03227f5bcff39b7cb67166d5d7e594fe4eeeabba 100644 (file)
@@ -68,11 +68,28 @@ AC_C_CONST
 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*)