Thread: Thread test improvement

Thread test improvement

From
Bruce Momjian
Date:
With Peter's help, I have changed the way I do thread testing from
configure to be much cleaner.  Patch attached and applied.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.348
diff -c -c -r1.348 configure
*** configure    26 Apr 2004 19:08:56 -0000    1.348
--- configure    27 Apr 2004 19:46:33 -0000
***************
*** 17876,17881 ****
--- 17876,17940 ----
  done


+ # Thread testing
+
+ # We have to run the thread test near the end so we have all our symbols
+ # defined.  Cross compiling throws a warning.
+ #
+ if test "$enable_thread_safety" = yes; then
+ echo "$as_me:$LINENO: checking thread safety of required library functions" >&5
+ echo $ECHO_N "checking thread safety of required library functions... $ECHO_C" >&6
+
+ _CFLAGS="$CFLAGS"
+ _LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS -DIN_CONFIGURE"
+ LIBS="$LIBS $PTHREAD_LIBS"
+ if test "$cross_compiling" = yes; then
+   echo "$as_me:$LINENO: result: maybe" >&5
+ echo "${ECHO_T}maybe" >&6
+   { echo "$as_me:$LINENO: WARNING:
+ *** Skipping thread test program because of cross-compile build.
+ *** Run the program in src/tools/thread on the target matchine.
+ " >&5
+ echo "$as_me: WARNING:
+ *** Skipping thread test program because of cross-compile build.
+ *** Run the program in src/tools/thread on the target matchine.
+ " >&2;}
+ else
+   cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+ #include "src/tools/thread/thread_test.c"
+ _ACEOF
+ rm -f conftest$ac_exeext
+ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+   (eval $ac_link) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   echo "$as_me:$LINENO: result: yes" >&5
+ echo "${ECHO_T}yes" >&6
+ else
+   echo "$as_me: program exited with status $ac_status" >&5
+ echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ ( exit $ac_status )
+ echo "$as_me:$LINENO: result: no" >&5
+ echo "${ECHO_T}no" >&6
+   { { echo "$as_me:$LINENO: error: Thread test program failed.  Your platform is not thread-safe.  See 'config.log"
>&5
+ echo "$as_me: error: Thread test program failed.  Your platform is not thread-safe.  See 'config.log" >&2;}
+    { (exit 1); exit 1; }; }
+ fi
+ rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+ fi
+ CFLAGS="$_CFLAGS"
+ LIBS="$_LIBS"
+ fi

  # prepare build tree if outside source tree
  # Note 1: test -ef might not exist, but it's more reliable than `pwd`.
***************
*** 19112,19216 ****
    $ac_cs_success || { (exit 1); exit 1; }
  fi

-
- # Check for gmake.
- for ac_prog in gmake make
- do
-   # Extract the first word of "$ac_prog", so it can be a program name with args.
- set dummy $ac_prog; ac_word=$2
- echo "$as_me:$LINENO: checking for $ac_word" >&5
- echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
- if test "${ac_cv_prog_MAKE+set}" = set; then
-   echo $ECHO_N "(cached) $ECHO_C" >&6
- else
-   if test -n "$MAKE"; then
-   ac_cv_prog_MAKE="$MAKE" # Let the user override the test.
- else
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
- for as_dir in $PATH
- do
-   IFS=$as_save_IFS
-   test -z "$as_dir" && as_dir=.
-   for ac_exec_ext in '' $ac_executable_extensions; do
-   if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-     ac_cv_prog_MAKE="$ac_prog"
-     echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
-     break 2
-   fi
- done
- done
-
- fi
- fi
- MAKE=$ac_cv_prog_MAKE
- if test -n "$MAKE"; then
-   echo "$as_me:$LINENO: result: $MAKE" >&5
- echo "${ECHO_T}$MAKE" >&6
- else
-   echo "$as_me:$LINENO: result: no" >&5
- echo "${ECHO_T}no" >&6
- fi
-
-   test -n "$MAKE" && break
- done
-
- if ! $MAKE -v | grep 'GNU Make' >/dev/null
- then    rm -f $srcdir/src/Makefile.global
-     echo "$as_me:$LINENO: checking Can not find GNU Make.  It is required." >&5
- echo $ECHO_N "checking Can not find GNU Make.  It is required.... $ECHO_C" >&6
- fi
-
- # Thread testing
-
- # We have to run the thread test here because it is an external program
- # that has to be runable separately for cross-compiling.
- #
- if test "$enable_thread_safety" = yes; then
- if test cross_compiling != yes; then
- #
- # Clean, compile, run, and clean thread test directory.
- # If test fails for any reason, remove Makefile.global so the user can't
- # compile (to simulate a configure failure).
- #
- echo "$as_me:$LINENO: checking thread safety of required library functions" >&5
- echo $ECHO_N "checking thread safety of required library functions... $ECHO_C" >&6
- if ! $MAKE -C src/tools/thread clean >&5
- then    rm -f src/Makefile.global
-     { { echo "$as_me:$LINENO: error: Can not clean thread test directory." >&5
- echo "$as_me: error: Can not clean thread test directory." >&2;}
-    { (exit 1); exit 1; }; }
- fi
- if ! $MAKE -C src/tools/thread >&5
- then    rm -f src/Makefile.global
-     { { echo "$as_me:$LINENO: error: Can not build thread test proram." >&5
- echo "$as_me: error: Can not build thread test proram." >&2;}
-    { (exit 1); exit 1; }; }
- fi
- if ! src/tools/thread/thread_test >&5
- then    rm -f src/Makefile.global
-     echo "no"
-     echo
-     src/tools/thread/thread_test
-     echo
-     { { echo "$as_me:$LINENO: error: Thread test program failed.  Your platform is not thread-safe." >&5
- echo "$as_me: error: Thread test program failed.  Your platform is not thread-safe." >&2;}
-    { (exit 1); exit 1; }; }
- fi
- if ! $MAKE -C src/tools/thread clean >&5
- then    rm -f src/Makefile.global
-     { { echo "$as_me:$LINENO: error: Can not clean thread test directory." >&5
- echo "$as_me: error: Can not clean thread test directory." >&2;}
-    { (exit 1); exit 1; }; }
- fi
- echo "yes"
- else
- { echo "$as_me:$LINENO: WARNING:
- *** Skipping thread test program because of cross-compile build.
- *** Run the program in src/tools/thread on the target matchine.
- " >&5
- echo "$as_me: WARNING:
- *** Skipping thread test program because of cross-compile build.
- *** Run the program in src/tools/thread on the target matchine.
- " >&2;}
- fi
- fi
--- 19171,19173 ----
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.336
diff -c -c -r1.336 configure.in
*** configure.in    26 Apr 2004 19:08:57 -0000    1.336
--- configure.in    27 Apr 2004 19:46:35 -0000
***************
*** 1176,1181 ****
--- 1176,1205 ----
  PGAC_PATH_COLLATEINDEX
  AC_CHECK_PROGS(SGMLSPL, sgmlspl)

+ # Thread testing
+
+ # We have to run the thread test near the end so we have all our symbols
+ # defined.  Cross compiling throws a warning.
+ #
+ if test "$enable_thread_safety" = yes; then
+ AC_MSG_CHECKING([thread safety of required library functions])
+
+ _CFLAGS="$CFLAGS"
+ _LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS -DIN_CONFIGURE"
+ LIBS="$LIBS $PTHREAD_LIBS"
+ AC_TRY_RUN([#include "src/tools/thread/thread_test.c"],
+   [AC_MSG_RESULT(yes)],
+   [AC_MSG_RESULT(no)
+   AC_MSG_ERROR([Thread test program failed.  Your platform is not thread-safe.  See 'config.log])],
+   [AC_MSG_RESULT(maybe)
+   AC_MSG_WARN([
+ *** Skipping thread test program because of cross-compile build.
+ *** Run the program in src/tools/thread on the target matchine.
+ ])])
+ CFLAGS="$_CFLAGS"
+ LIBS="$_LIBS"
+ fi

  # prepare build tree if outside source tree
  # Note 1: test -ef might not exist, but it's more reliable than `pwd`.
***************
*** 1214,1265 ****
  ])

  AC_OUTPUT
-
- # Check for gmake.
- AC_CHECK_PROGS(MAKE, gmake make)
- if ! $MAKE -v | grep 'GNU Make' >/dev/null
- then    rm -f $srcdir/src/Makefile.global
-     AC_MSG_CHECKING([Can not find GNU Make.  It is required.])
- fi
-
- # Thread testing
-
- # We have to run the thread test here because it is an external program
- # that has to be runable separately for cross-compiling.
- #
- if test "$enable_thread_safety" = yes; then
- if test cross_compiling != yes; then
- #
- # Clean, compile, run, and clean thread test directory.
- # If test fails for any reason, remove Makefile.global so the user can't
- # compile (to simulate a configure failure).
- #
- AC_MSG_CHECKING([thread safety of required library functions])
- if ! $MAKE -C src/tools/thread clean >&5
- then    rm -f src/Makefile.global
-     AC_MSG_ERROR([Can not clean thread test directory.])
- fi
- if ! $MAKE -C src/tools/thread >&5
- then    rm -f src/Makefile.global
-     AC_MSG_ERROR([Can not build thread test proram.])
- fi
- if ! src/tools/thread/thread_test >&5
- then    rm -f src/Makefile.global
-     echo "no"
-     echo
-     src/tools/thread/thread_test
-     echo
-     AC_MSG_ERROR([Thread test program failed.  Your platform is not thread-safe.])
- fi
- if ! $MAKE -C src/tools/thread clean >&5
- then    rm -f src/Makefile.global
-     AC_MSG_ERROR([Can not clean thread test directory.])
- fi
- echo "yes"
- else
- AC_MSG_WARN([
- *** Skipping thread test program because of cross-compile build.
- *** Run the program in src/tools/thread on the target matchine.
- ])
- fi
- fi
--- 1238,1240 ----
Index: src/tools/thread/thread_test.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/tools/thread/thread_test.c,v
retrieving revision 1.28
diff -c -c -r1.28 thread_test.c
*** src/tools/thread/thread_test.c    27 Apr 2004 18:40:50 -0000    1.28
--- src/tools/thread/thread_test.c    27 Apr 2004 19:46:42 -0000
***************
*** 20,26 ****
--- 20,41 ----
   *-------------------------------------------------------------------------
   */

+ #ifndef IN_CONFIGURE
  #include "postgres.h"
+ #else
+ /* From src/include/c.h" */
+ #ifndef bool
+ typedef char bool;
+ #endif
+
+ #ifndef true
+ #define true    ((bool) 1)
+ #endif
+
+ #ifndef false
+ #define false    ((bool) 0)
+ #endif
+ #endif

  #include <stdio.h>
  #include <stdlib.h>
***************
*** 32,38 ****
  #include <fcntl.h>
  #include <errno.h>

! #ifndef ENABLE_THREAD_SAFETY
  int
  main(int argc, char *argv[])
  {
--- 47,53 ----
  #include <fcntl.h>
  #include <errno.h>

! #if !defined(ENABLE_THREAD_SAFETY) && !defined(IN_CONFIGURE)
  int
  main(int argc, char *argv[])
  {
***************
*** 96,101 ****
--- 111,122 ----
          return 1;
      }

+ #ifdef IN_CONFIGURE
+     /* Send stdout to 'config.log' */
+     close(1);
+     dup(5);
+ #endif
+
      /* Make temp filenames, might not have strdup() */
      temp_filename_1 = malloc(strlen(TEMP_FILENAME_1) + 1);
      strcpy(temp_filename_1, TEMP_FILENAME_1);
***************
*** 339,343 ****
      pthread_mutex_lock(&init_mutex);    /* wait for parent to test */
      pthread_mutex_unlock(&init_mutex);
  }
! #endif /* !ENABLE_THREAD_SAFETY */
!
--- 360,363 ----
      pthread_mutex_lock(&init_mutex);    /* wait for parent to test */
      pthread_mutex_unlock(&init_mutex);
  }
! #endif /* !ENABLE_THREAD_SAFETY && !IN_CONFIGURE */