Update for valgrind failure.
authorBrian Aker <brian@tangent.org>
Sun, 11 Mar 2012 20:04:00 +0000 (13:04 -0700)
committerBrian Aker <brian@tangent.org>
Sun, 11 Mar 2012 20:04:00 +0000 (13:04 -0700)
libtest/cmdline.cc
libtest/include.am
libtest/server.cc
libtest/unittest.cc

index 76b677f47aade5bef8659dbcf02837bd829bdb79..e774113a87f75bc5f8635f1f3312bd02a075d7dc 100644 (file)
@@ -26,6 +26,7 @@ using namespace libtest;
 
 #include <cstdlib>
 #include <cstring>
+#include <cerrno>
 #include <fcntl.h>
 #include <fstream>
 #include <memory>
@@ -352,26 +353,24 @@ void Application::Pipe::reset()
   close(WRITE);
 
   int ret;
-  if ((ret= pipe(_fd)) < 0)
+  if (pipe(_fd) == -1)
   {
-    throw strerror(ret);
+    throw strerror(errno);
   }
   _open[0]= true;
   _open[1]= true;
 
   {
-    ret= fcntl(_fd[0], F_GETFL, 0);
-    if (ret == -1)
+    if ((ret= fcntl(_fd[0], F_GETFL, 0)) == -1)
     {
-      Error << "fcntl(F_GETFL) " << strerror(ret);
-      throw strerror(ret);
+      Error << "fcntl(F_GETFL) " << strerror(errno);
+      throw strerror(errno);
     }
 
-    ret= fcntl(_fd[0], F_SETFL, ret | O_NONBLOCK);
-    if (ret == -1)
+    if ((ret= fcntl(_fd[0], F_SETFL, ret | O_NONBLOCK)) == -1)
     {
-      Error << "fcntl(F_SETFL) " << strerror(ret);
-      throw strerror(ret);
+      Error << "fcntl(F_SETFL) " << strerror(errno);
+      throw strerror(errno);
     }
   }
 }
@@ -407,11 +406,12 @@ void Application::Pipe::close(const close_t& arg)
   if (_open[type])
   {
     int ret;
-    if ((ret= ::close(_fd[type])) < 0)
+    if (::close(_fd[type]) == -1)
     {
-      Error << "close(" << strerror(ret) << ")";
+      Error << "close(" << strerror(errno) << ")";
     }
     _open[type]= false;
+    _fd[type]= -1;
   }
 }
 
@@ -524,21 +524,19 @@ std::string Application::arguments()
 
 void Application::delete_argv()
 {
-  if (built_argv == NULL)
-  {
-    return;
-  }
-
-  for (size_t x= 0; x < _argc; x++)
+  if (built_argv)
   {
-    if (built_argv[x])
+    for (size_t x= 0; x < _argc; x++)
     {
-      ::free(built_argv[x]);
+      if (built_argv[x])
+      {
+        ::free(built_argv[x]);
+      }
     }
+    delete[] built_argv;
+    built_argv= NULL;
+    _argc= 0;
   }
-  delete[] built_argv;
-  built_argv= NULL;
-  _argc= 0;
 }
 
 
index 92dc7d2776f61744852faafaf682619929a5b09d..7cbbb1de57e89c211c3f4d9354f82e227162a741 100644 (file)
@@ -210,7 +210,7 @@ test-unittest: libtest/unittest
        @libtest/unittest
 
 valgrind-unittest: libtest/unittest
-       @$(VALGRIND_COMMAND) libtest/unittest
+       @$(VALGRIND_COMMAND) libtest/unittest TESTS_ENVIRONMENT="valgrind"
 
 gdb-unittest: libtest/unittest
        @$(GDB_COMMAND) libtest/unittest
index 31ea6effab54d2d5d5081efd45c59bb9fdcb5f5f..34d367ef41ad209fc0fe89ada478fbe8d61b258c 100644 (file)
@@ -168,7 +168,7 @@ bool Server::start()
 
   if (Application::SUCCESS !=  (ret= app.wait()))
   {
-    Error << "Application::wait() " << app.print() << " " << ret;
+    Error << "Application::wait() " << _running << " " << ret;
     return false;
   }
 
index 7f0c7404fc2d5ca74997efaf1dc3a0bfcb281809..0272ee7e181a10ba73cbad237287491e789d0c8c 100644 (file)
@@ -379,7 +379,14 @@ static test_return_t application_doesnotexist_BINARY(void *)
 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
     test_compare(Application::FAILURE, true_app.wait());
 #else
-    test_compare(Application::INVALID, true_app.wait());
+    if (getenv("TESTS_ENVIRONMENT") and strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
+    {
+      test_compare(Application::FAILURE, true_app.wait());
+    }
+    else
+    {
+      test_compare(Application::INVALID, true_app.wait());
+    }
 #endif
   }
   test_compare(0, true_app.stdout_result().size());