Browse Source

Extend tests for hostile and break out stress from hostile.

Brian Aker 12 years ago
parent
commit
27efa8d35f
10 changed files with 215 additions and 24 deletions
  1. 2 4
      Makefile.am
  2. 1 0
      configure.ac
  3. 1 1
      gearmand/gearmand.cc
  4. 2 2
      gearmand/include.am
  5. 18 4
      libgearman/include.am
  6. 2 2
      libhostile/function.c
  7. 6 0
      libhostile/include.am
  8. 50 11
      libhostile/pipe.c
  9. 56 0
      libhostile/t/accept.c
  10. 77 0
      libhostile/t/include.am

+ 2 - 4
Makefile.am

@@ -61,12 +61,10 @@ EXTRA_DIST+= scripts/README.solaris
 test: check
 
 BUILT_SOURCES+= configmake.h
-noinst_HEADERS+= configmake.h
-configmake.h: ${top_srcdir}/Makefile.in
-	@echo "Making $@"
+CLEANFILES+= configmake.h configmake.h-t
+configmake.h: Makefile
 	@rm -f $@-t $@
 	@{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-	  echo '#define PREFIX "$(prefix)"'; \
 	  echo '#define SYSCONFDIR "$(sysconfdir)"'; \
 	  echo '#define GEARMAND_CONFIG "$(sysconfdir)/gearmand.conf"'; \
 	  echo '#define LOCALSTATEDIR "$(localstatedir)"'; \

+ 1 - 0
configure.ac

@@ -117,6 +117,7 @@ AC_CHECK_HEADERS_ONCE([netinet/tcp.h])
 AC_CHECK_HEADERS_ONCE([poll.h])
 AC_CHECK_HEADERS_ONCE([pwd.h])
 AC_CHECK_HEADERS_ONCE([signal.h])
+AC_CHECK_HEADERS_ONCE([spawn.h])
 AC_CHECK_HEADERS_ONCE([stdarg.h])
 AC_CHECK_HEADERS_ONCE([stddef.h])
 AC_CHECK_HEADERS_ONCE([stdint.h])

+ 1 - 1
gearmand/gearmand.cc

@@ -37,7 +37,7 @@
  */
 
 #include "gear_config.h"
-#include <configmake.h>
+#include "configmake.h"
 
 #include <cerrno>
 #include <cstdio>

+ 2 - 2
gearmand/include.am

@@ -33,7 +33,6 @@ gearmand_gearmand_SOURCES+= gearmand/gearmand.cc
 gearmand_gearmand_SOURCES+= util/daemon.cc
 gearmand_gearmand_SOURCES+= util/pidfile.cc
 
-if TARGET_LINUX
 gearmand_hostile_gearmand_CXXFLAGS=
 EXTRA_gearmand_hostile_gearmand_DEPENDENCIES=
 gearmand_hostile_gearmand_LDADD=
@@ -44,12 +43,13 @@ gearmand_hostile_gearmand_CXXFLAGS+= $(gearmand_gearmand_CXXFLAGS)
 EXTRA_gearmand_hostile_gearmand_DEPENDENCIES+= $(EXTRA_gearmand_gearmand_DEPENDENCIES)
 gearmand_hostile_gearmand_LDADD+= @DL_LIB@
 gearmand_hostile_gearmand_LDADD+= libgearman-server/libgearman-server.la
+if TARGET_HOSTILE
 gearmand_hostile_gearmand_LDADD+= libhostile/libhostile.la
+endif
 gearmand_hostile_gearmand_LDFLAGS+= $(gearmand_gearmand_LDFLAGS)
 gearmand_hostile_gearmand_SOURCES+= $(gearmand_gearmand_SOURCES)
 
 noinst_PROGRAMS+=gearmand/hostile_gearmand
-endif
 
 gearmand-valgrind: gearmand/gearmand
 	$(LIBTOOL) --mode=execute valgrind --leak-check=yes gearmand/gearmand

+ 18 - 4
libgearman/include.am

@@ -51,6 +51,7 @@ noinst_HEADERS+= \
 		 libgearman/vector.hpp
 
 noinst_LTLIBRARIES+= libgearman/libgearmancore.la
+
 libgearman_libgearmancore_la_SOURCES= \
 				      libgearman/allocator.cc \
 				      libgearman/backtrace.cc \
@@ -67,9 +68,15 @@ libgearman_libgearmancore_la_SOURCES= \
 
 libgearman_libgearmancore_la_CXXFLAGS= -DBUILDING_LIBGEARMAN
 libgearman_libgearmancore_la_LIBADD= @DL_LIB@
+libgearman_libgearmancore_la_LIBADD+= libhashkit/libhashkit.la
+
+libgearman_libgearman_la_LIBADD=
+libgearman_libgearman_la_SOURCES=
+libgearman_libgearman_la_CXXFLAGS=
+libgearman_libgearman_la_LDFLAGS=
 
 lib_LTLIBRARIES+= libgearman/libgearman.la
-libgearman_libgearman_la_SOURCES= \
+libgearman_libgearman_la_SOURCES+= \
 				  libgearman/actions.cc \
 				  libgearman/aggregator.cc \
 				  libgearman/allocator.cc \
@@ -110,11 +117,10 @@ libgearman_libgearman_la_SOURCES= \
 libgearman_libgearman_la_SOURCES+= libgearman/pipe.cc
 libgearman_libgearman_la_SOURCES+= libgearman/uuid.cc
 
-libgearman_libgearman_la_CXXFLAGS= -DBUILDING_LIBGEARMAN
+libgearman_libgearman_la_CXXFLAGS+= -DBUILDING_LIBGEARMAN
 
-libgearman_libgearman_la_LDFLAGS= -version-info $(GEARMAN_LIBRARY_VERSION)
+libgearman_libgearman_la_LDFLAGS+= -version-info $(GEARMAN_LIBRARY_VERSION)
 
-libgearman_libgearman_la_LIBADD=
 libgearman_libgearman_la_LIBADD+= @LIBUUID_LIB@
 libgearman_libgearman_la_LIBADD+= @DL_LIB@
 libgearman_libgearman_la_LIBADD+= libhashkit/libhashkit.la
@@ -125,3 +131,11 @@ endif
 
 
 DISTCLEANFILES+= config/top.h
+
+# Hostile version 
+
+noinst_LTLIBRARIES+= libgearman/libgearman-hostile.la
+
+libgearman_libgearman_hostile_la_LIBADD= $(libgearman_libgearman_la_LIBADD)
+libgearman_libgearman_hostile_la_SOURCES= $(libgearman_libgearman_la_SOURCES)
+libgearman_libgearman_hostile_la_CXXFLAGS= $(libgearman_libgearman_la_CXXFLAGS)

+ 2 - 2
libhostile/function.c

@@ -46,8 +46,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-int64_t function_cache_index;
-struct function_st function_cache[10];
+static int64_t function_cache_index= 0;
+struct function_st function_cache[20];
 
 void print_function_cache_usage(void)
 {

+ 6 - 0
libhostile/include.am

@@ -9,6 +9,8 @@
 # Included from Top Level Makefile.am
 # All paths should be given relative to the root
 
+# Unit tests
+include libhostile/t/include.am
 
 noinst_LTLIBRARIES+= libhostile/libhostile.la
 
@@ -39,11 +41,15 @@ libhostile_libhostile_la_SOURCES=
 libhostile_libhostile_la_CFLAGS+= -DBUILDING_LIBHOSTILE
 libhostile_libhostile_la_CXXFLAGS+= -DBUILDING_LIBHOSTILE
 
+libhostile_libhostile_la_CFLAGS+= @PTHREAD_CFLAGS@
+libhostile_libhostile_la_CXXFLAGS+= @PTHREAD_CFLAGS@
+
 libhostile_libhostile_la_SOURCES+= libhostile/initialize.c
 
 if TARGET_HOSTILE
 libhostile_libhostile_la_LIBADD+= @DL_LIB@
 libhostile_libhostile_la_LIBADD+= @RT_LIB@
+libhostile_libhostile_la_LIBADD+= @PTHREAD_LIBS@
 
 libhostile_libhostile_la_SOURCES+= libhostile/accept.c
 libhostile_libhostile_la_SOURCES+= libhostile/called.c

+ 50 - 11
libhostile/pipe.c

@@ -40,47 +40,86 @@
 #include <libhostile/initialize.h>
 
 #include <assert.h>
+#include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
 
-static struct function_st __function;
+static struct function_st __function_pipe;
+static struct function_st __function_pipe2;
 
 static pthread_once_t function_lookup_once= PTHREAD_ONCE_INIT;
 static void set_local(void)
 {
-  __function= set_function("pipe", "HOSTILE_PIPE");
-  __function= set_function("pipe2", "HOSTILE_PIPE2");
+  __function_pipe= set_function("pipe", "HOSTILE_PIPE");
+  __function_pipe2= set_function("pipe2", "HOSTILE_PIPE2");
 }
 
-int pipe(int pipefd[2])
+int pipe(int pipefd_arg[2])
 {
   hostile_initialize();
 
   (void) pthread_once(&function_lookup_once, set_local);
 
-  set_called();
-  int ret= __function.function.pipe(pipefd);
-  reset_called();
+  int stored_errno;
+  int ret;
+  {
+    set_called();
 
+    if (pipefd_arg)
+    {
+      int pipefd[2];
+      ret= __function_pipe.function.pipe(pipefd);
+      stored_errno= errno;
+      pipefd_arg[0]= pipefd[0];
+      pipefd_arg[1]= pipefd[1];
+    }
+    else
+    {
+      ret= __function_pipe.function.pipe(NULL);
+      stored_errno= errno;
+    }
+
+    reset_called();
+  }
+
+  errno= stored_errno;
   return ret;
 }
 
 #if defined(HAVE_PIPE2) && HAVE_PIPE2
-int pipe2(int pipefd[2], int flags)
+int pipe2(int pipefd_arg[2], int flags)
 {
   hostile_initialize();
 
   (void) pthread_once(&function_lookup_once, set_local);
 
-  set_called();
-  int ret= __function.function.pipe2(pipefd, flags);
-  reset_called();
+  int stored_errno;
+  int ret;
+  {
+    set_called();
+    if (pipefd_arg)
+    {
+      int pipefd[2];
+      ret= __function_pipe2.function.pipe2(pipefd, flags);
+      stored_errno= errno;
+      pipefd_arg[0]= pipefd[0];
+      pipefd_arg[1]= pipefd[1];
+    }
+    else
+    {
+      ret= __function_pipe2.function.pipe2(pipefd_arg, flags);
+      stored_errno= errno;
+    }
+    reset_called();
+  }
 
+  errno= stored_errno;
   return ret;
 }
 #endif

+ 56 - 0
libhostile/t/accept.c

@@ -0,0 +1,56 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ *  Data Differential's libhostle
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifdef HOSTILE
+# include <libhostile/hostile.h>
+#endif
+
+#include <libtest/yatl_lite.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>          /* See NOTES */
+
+int main(void)
+{
+  TEST_TRUE(accept(-1, NULL, NULL) == -1);
+  TEST_TRUE(errno == EBADF);
+
+  return EXIT_SUCCESS;
+}

+ 77 - 0
libhostile/t/include.am

@@ -0,0 +1,77 @@
+# vim:ft=automake
+# libhostile
+# Copyright (C) 2012 Data Differential
+# All rights reserved.
+#
+# Use and distribution licensed under the BSD license.  See
+# the COPYING file in the parent directory for full text.
+#
+# Included from Top Level Makefile.am
+# All paths should be given relative to the root
+
+# Test accept()
+libhostile_t_accept_SOURCES=
+libhostile_t_accept_LDADD=
+
+libhostile_t_accept_SOURCES+= libhostile/t/accept.c
+check_PROGRAMS+= libhostile/t/accept
+noinst_PROGRAMS+= libhostile/t/accept
+
+libhostile_t_hostile_accept_SOURCES=
+libhostile_t_hostile_accept_LDADD=
+libhostile_t_hostile_accept_CFLAGS= -DHOSTILE
+libhostile_t_hostile_accept_CXXFLAGS= -DHOSTILE
+
+libhostile_t_hostile_accept_SOURCES+= libhostile/t/accept.c
+libhostile_t_hostile_accept_LDADD+= libhostile/libhostile.la
+check_PROGRAMS+= libhostile/t/hostile_accept
+noinst_PROGRAMS+= libhostile/t/hostile_accept
+
+# Test pipe() 
+libhostile_t_pipe_SOURCES=
+libhostile_t_pipe_LDADD=
+
+libhostile_t_pipe_SOURCES+= libhostile/t/pipe.c
+check_PROGRAMS+= libhostile/t/pipe
+noinst_PROGRAMS+= libhostile/t/pipe
+
+libhostile_t_hostile_pipe_SOURCES=
+libhostile_t_hostile_pipe_LDADD=
+libhostile_t_hostile_pipe_CFLAGS=
+libhostile_t_hostile_pipe_CXXFLAGS=
+
+libhostile_t_hostile_pipe_SOURCES+= libhostile/t/pipe.c
+libhostile_t_hostile_pipe_CFLAGS+= -DHOSTILE
+libhostile_t_hostile_pipe_CXXFLAGS+= -DHOSTILE
+libhostile_t_hostile_pipe_LDADD+= libhostile/libhostile.la
+check_PROGRAMS+= libhostile/t/hostile_pipe
+noinst_PROGRAMS+= libhostile/t/hostile_pipe
+
+# Test pipe() 
+libhostile_t_pipe2_SOURCES=
+libhostile_t_pipe2_LDADD=
+
+libhostile_t_pipe2_SOURCES+= libhostile/t/pipe2.c
+check_PROGRAMS+= libhostile/t/pipe2
+noinst_PROGRAMS+= libhostile/t/pipe2
+
+libhostile_t_hostile_pipe2_SOURCES=
+libhostile_t_hostile_pipe2_LDADD=
+libhostile_t_hostile_pipe2_CFLAGS=
+libhostile_t_hostile_pipe2_CXXFLAGS=
+
+libhostile_t_hostile_pipe2_SOURCES+= libhostile/t/pipe2.c
+libhostile_t_hostile_pipe2_CFLAGS+= -DHOSTILE
+libhostile_t_hostile_pipe2_CXXFLAGS+= -DHOSTILE
+libhostile_t_hostile_pipe2_LDADD+= libhostile/libhostile.la
+check_PROGRAMS+= libhostile/t/hostile_pipe2
+noinst_PROGRAMS+= libhostile/t/hostile_pipe2
+
+# Test just the hostile unit tests
+unit_hostile: libhostile/t/hostile_accept libhostile/t/accept libhostile/t/pipe libhostile/t/hostile_pipe libhostile/t/pipe2 libhostile/t/hostile_pipe2
+	@libhostile/t/accept
+	@libhostile/t/pipe
+	@libhostile/t/pipe2
+	@libhostile/t/hostile_accept
+	@libhostile/t/hostile_pipe
+	@libhostile/t/hostile_pipe2

Some files were not shown because too many files changed in this diff