Browse Source

Add new include for usage of yatl, plus yatl_lite.

Brian Aker 12 years ago
parent
commit
a40b8b3467

+ 0 - 1
libhostile/accept.c

@@ -64,7 +64,6 @@ bool libhostile_is_accept(void)
 
   (void) pthread_once(&function_lookup_once, set_local);
 
-  fprintf(stderr, "libhostile_is_accept() %s\n", __function.frequency ? "true" : "false");
   if (__function.frequency)
   {
     return true;

+ 0 - 1
libhostile/connect.c

@@ -82,7 +82,6 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
   {
     if (__function.frequency)
     {
-      fprintf(stderr, "%s:%d connect() %d %d\n", __FILE__, __LINE__, not_until, __function.frequency);
       if (--not_until < 0 && rand() % __function.frequency)
       {
         if (rand() % 1)

+ 3 - 3
libhostile/t/accept.c

@@ -38,7 +38,7 @@
 # include <libhostile/hostile.h>
 #endif
 
-#include <libtest/yatl_lite.h>
+#include <libtest/lite.h>
 
 #include <errno.h>
 #include <stdio.h>
@@ -49,8 +49,8 @@
 
 int main(void)
 {
-  TEST_TRUE(accept(-1, NULL, NULL) == -1);
-  TEST_TRUE(errno == EBADF);
+  ASSERT_TRUE(accept(-1, NULL, NULL) == -1);
+  ASSERT_TRUE(errno == EBADF);
 
   return EXIT_SUCCESS;
 }

+ 6 - 6
libhostile/t/pipe.c

@@ -38,7 +38,7 @@
 # include <libhostile/hostile.h>
 #endif
 
-#include <libtest/yatl_lite.h>
+#include <libtest/lite.h>
 
 #include <errno.h>
 #include <stdio.h>
@@ -50,14 +50,14 @@ int main(void)
 {
   if (valgrind_is_caller() == false)
   {
-    TEST_TRUE(pipe(NULL) == -1);
-    TEST_TRUE(errno == EFAULT);
+    ASSERT_TRUE(pipe(NULL) == -1);
+    ASSERT_TRUE(errno == EFAULT);
   }
 
   int pipefd[2];
-  TEST_TRUE(pipe(pipefd) == 0);
-  TEST_TRUE(close(pipefd[0]) == 0);
-  TEST_TRUE(close(pipefd[1]) == 0);
+  ASSERT_TRUE(pipe(pipefd) == 0);
+  ASSERT_TRUE(close(pipefd[0]) == 0);
+  ASSERT_TRUE(close(pipefd[1]) == 0);
 
   return EXIT_SUCCESS;
 }

+ 16 - 13
libhostile/t/pipe2.c

@@ -40,7 +40,7 @@
 
 #include "gear_config.h"
 
-#include <libtest/yatl_lite.h>
+#include <libtest/lite.h>
 
 #include <errno.h>
 #include <stdio.h>
@@ -50,20 +50,23 @@
 
 int main(void)
 {
-#if defined(HAVE_PIPE2) && HAVE_PIPE2
-  if (valgrind_is_caller() == false)
+#if defined(HAVE_PIPE2)
+  if (HAVE_PIPE2)
   {
-    TEST_TRUE(pipe2(NULL, 0) == -1);
-    TEST_TRUE(errno == EFAULT);
-  }
+    if (valgrind_is_caller() == false)
+    {
+      ASSERT_TRUE(pipe2(NULL, 0) == -1);
+      ASSERT_TRUE(errno == EFAULT);
+    }
 
-  int pipefd[2];
-  TEST_TRUE(pipe2(pipefd, 0) == 0);
-  TEST_TRUE(close(pipefd[0]) == 0);
-  TEST_TRUE(close(pipefd[1]) == 0);
+    int pipefd[2];
+    ASSERT_TRUE(pipe2(pipefd, 0) == 0);
+    ASSERT_TRUE(close(pipefd[0]) == 0);
+    ASSERT_TRUE(close(pipefd[1]) == 0);
 
-  return EXIT_SUCCESS;
-#else
-  return EXIT_SKIP;
+    return EXIT_SUCCESS;
+  }
 #endif
+
+  return EXIT_SKIP;
 }

+ 0 - 10
libtest/comparison.cc

@@ -49,16 +49,6 @@ bool jenkins_is_caller(void)
   return false;
 }
 
-bool valgrind_is_caller(void)
-{
-  if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
-  {
-    return true;
-  }
-
-  return false;
-}
-
 bool gdb_is_caller(void)
 {
   if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "gdb"))

+ 0 - 3
libtest/comparison.hpp

@@ -56,9 +56,6 @@ bool jenkins_is_caller(void);
 LIBTEST_API
 bool gdb_is_caller(void);
 
-LIBTEST_API
-bool valgrind_is_caller(void);
-
 LIBTEST_API
 bool _in_valgrind(const char *file, int line, const char *func);
 

+ 9 - 11
libtest/fatal.cc

@@ -41,21 +41,19 @@
 namespace libtest {
 
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
-fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const char *format, ...) :
+fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) :
   std::runtime_error(func_arg),
   _line(line_arg),
   _file(file_arg),
   _func(func_arg)
   {
     va_list args;
-    va_start(args, format);
-    char last_error[BUFSIZ];
-    int last_error_length= vsnprintf(last_error, sizeof(last_error), format, args);
+    va_start(args, func_arg);
+    const char *format= va_arg(args, const char *);
+    int last_error_length= vsnprintf(0, 0, format, args);
+    _error_message.resize(last_error_length +1);
+    last_error_length= vsnprintf(&_error_message[0], _error_message.size(), format, args);
     va_end(args);
-
-    strncpy(_mesg, last_error, sizeof(_mesg));
-
-    snprintf(_error_message, sizeof(_error_message), "%.*s", last_error_length, last_error);
   }
 
 static bool _disabled= false;
@@ -90,8 +88,7 @@ void fatal::increment_disabled_counter()
 
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg,
-                           const std::string& instance, const in_port_t port,
-                           const char *format, ...) :
+                           const std::string& instance, const in_port_t port, ...) :
   std::runtime_error(func_arg),
   _port(port),
   _line(line_arg),
@@ -99,7 +96,8 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_
   _func(func_arg)
 {
   va_list args;
-  va_start(args, format);
+  va_start(args, port);
+  const char *format= va_arg(args, const char *);
   char last_error[BUFSIZ];
   (void)vsnprintf(last_error, sizeof(last_error), format, args);
   va_end(args);

+ 14 - 11
libtest/fatal.hpp

@@ -56,16 +56,15 @@ namespace libtest {
 class fatal : std::runtime_error
 {
 public:
-  fatal(const char *file, int line, const char *func, const char *format, ...);
+  fatal(const char *file, int line, const char *func, ...);
 
-  const char* what() const throw()
+  ~fatal() throw()
   {
-    return _error_message;
   }
 
-  const char* mesg() const throw()
+  const char* what() const throw()
   {
-    return _error_message;
+    return &_error_message[0];
   }
 
   // The following are just for unittesting the exception class
@@ -91,8 +90,7 @@ public:
   }
 
 private:
-  char _error_message[BUFSIZ];
-  char _mesg[BUFSIZ];
+  vchar_t _error_message;
   int _line;
   const char*  _file;
   const char* _func;
@@ -101,11 +99,11 @@ private:
 class disconnected : std::runtime_error
 {
 public:
-  disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, const char *format, ...);
+  disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, ...);
 
   const char* what() const throw()
   {
-    return _error_message;
+    return &_error_message[0];
   }
 
   // The following are just for unittesting the exception class
@@ -141,5 +139,10 @@ private:
 
 } // namespace libtest
 
-#define fatal_message(__mesg) throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", __mesg)
-#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", #__assert); }
+#define fatal_message(...) \
+do \
+{ \
+  throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
+} while (0)
+
+#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); }

+ 1 - 1
libtest/framework.cc

@@ -139,7 +139,7 @@ void Framework::exec()
     catch (libtest::fatal& e)
     {
       _failed++;
-      stream::cerr(e.file(), e.line(), e.func()) << e.mesg();
+      stream::cerr(e.file(), e.line(), e.func()) << e.what();
     }
     catch (libtest::disconnected& e)
     {

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