From: Peter Johnson Date: Wed, 19 Sep 2001 21:56:00 +0000 (-0000) Subject: Autoconfize Check test suite, and make it work even if fork(), wait(), and X-Git-Tag: v0.1.0~317 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bfb25663df179a105fa30b90a87577aaea5a469;p=yasm Autoconfize Check test suite, and make it work even if fork(), wait(), and msg*() aren't available. svn path=/trunk/yasm/; revision=201 --- diff --git a/acconfig.h b/acconfig.h index 1fab28db..50f402f2 100644 --- a/acconfig.h +++ b/acconfig.h @@ -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 */ diff --git a/check/check.c b/check/check.c index 79607d2c..829c95f3 100644 --- a/check/check.c +++ b/check/check.c @@ -16,15 +16,26 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include + +#ifdef STDC_HEADERS +# include +# include +#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; } diff --git a/check/check.h b/check/check.h index 208c8ab8..0f6047ac 100644 --- a/check/check.h +++ b/check/check.h @@ -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); /*! @} */ diff --git a/check/check_log.c b/check/check_log.c index 501c68cb..67bd900d 100644 --- a/check/check_log.c +++ b/check/check_log.c @@ -1,4 +1,11 @@ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include #include #include "list.h" diff --git a/check/check_msg.c b/check/check_msg.c index b87d1870..cba6b83f 100644 --- a/check/check_msg.c +++ b/check/check_msg.c @@ -16,20 +16,41 @@ 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 + +#ifdef STDC_HEADERS #include #include -#include #include -#include -#include -#include +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#ifdef HAVE_SYS_IPC_H +# include +#endif + +#ifdef HAVE_SYS_MSG_H +# include +#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 } diff --git a/check/check_run.c b/check/check_run.c index 96601b4c..8ff0aaa0 100644 --- a/check/check_run.c +++ b/check/check_run.c @@ -16,13 +16,43 @@ 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 +#endif + +#ifdef HAVE_SYS_WAIT_H +# include +#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 +#endif -#include -#include -#include -#include #include -#include + +#ifdef STDC_HEADERS +# include +# include +#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) { diff --git a/check/error.c b/check/error.c index f2227a2b..4a486804 100644 --- a/check/error.c +++ b/check/error.c @@ -1,8 +1,16 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#ifdef STDC_HEADERS #include #include #include -#include #include +#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); diff --git a/check/error.h b/check/error.h index 01c2e136..da089b29 100644 --- a/check/error.h +++ b/check/error.h @@ -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*/ diff --git a/check/list.c b/check/list.c index 5e2d04a1..9fce7edf 100644 --- a/check/list.c +++ b/check/list.c @@ -1,4 +1,11 @@ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef STDC_HEADERS +# include +#endif + #include "list.h" #include "error.h" diff --git a/check/list.h b/check/list.h index 17215a2c..12fa3788 100644 --- a/check/list.h +++ b/check/list.h @@ -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*/ diff --git a/configure.ac b/configure.ac index a0f61022..03227f5b 100644 --- a/configure.ac +++ b/configure.ac @@ -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*) diff --git a/configure.in b/configure.in index a0f61022..03227f5b 100644 --- a/configure.in +++ b/configure.in @@ -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*)