ICC fixes.
[awesomized/libmemcached] / tests / test.c
index 8f913869de33c9a812b95eb1bea21c2c08352668..fb501fadc2edcc6d57270c2cd47ce52cdc21a5d8 100644 (file)
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 #include <unistd.h>
 #include <time.h>
 #include <fnmatch.h>
-#include "server.h"
 
 #include "test.h"
 
@@ -32,7 +32,7 @@ static void world_stats_print(world_stats_st *stats)
 
 static long int timedif(struct timeval a, struct timeval b)
 {
-  register int us, s;
+  long us, s;
 
   us = (int)(a.tv_usec - b.tv_usec);
   us /= 1000;
@@ -41,7 +41,7 @@ static long int timedif(struct timeval a, struct timeval b)
   return s + us;
 }
 
-static const char *test_strerror(test_return_t code)
+const char *test_strerror(test_return_t code)
 {
   switch (code) {
   case TEST_SUCCESS:
@@ -57,13 +57,26 @@ static const char *test_strerror(test_return_t code)
     fprintf(stderr, "Unknown return value\n");
     abort();
   }
-
 }
 
 void create_core(void)
 {
-   if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL && fork() == 0)
-     abort();
+  if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL)
+  {
+    pid_t pid= fork();
+
+    if (pid == 0)
+    {
+      abort();
+    }
+    else
+    {
+      while (waitpid(pid, NULL, 0) != pid)
+      {
+        ;
+      }
+    }
+  }
 }
 
 
@@ -111,9 +124,16 @@ int main(int argc, char *argv[])
   collection= world.collections;
 
   if (world.create)
-    world_ptr= world.create();
+  {
+    test_return_t error;
+    world_ptr= world.create(&error);
+    if (error != TEST_SUCCESS)
+      exit(1);
+  }
   else
+  {
     world_ptr= NULL;
+  }
 
   if (argc > 1)
     collection_to_run= argv[1];
@@ -157,7 +177,7 @@ int main(int argc, char *argv[])
       }
 
 
-      if (next->pre)
+      if (next->pre && world.runner->pre)
       {
         return_code= world.runner->pre(next->pre, world_ptr);
 
@@ -172,9 +192,9 @@ int main(int argc, char *argv[])
       gettimeofday(&end_time, NULL);
       load_time= timedif(end_time, start_time);
 
-      if (next->post)
+      if (next->post && world.runner->post)
       {
-        (void) world.runner->pre(next->pre, world_ptr);
+        (void) world.runner->post(next->post, world_ptr);
       }
 
       if (world.post_run)
@@ -221,9 +241,18 @@ error:
   fprintf(stderr, "All tests completed successfully\n\n");
 
   if (world.destroy)
-    world.destroy(world_ptr);
+  {
+    test_return_t error;
+    error= world.destroy(world_ptr);
+
+    if (error != TEST_SUCCESS)
+    {
+      fprintf(stderr, "Failure during shutdown.\n");
+      stats.failed++; // We do this to make our exit code return 1
+    }
+  }
 
   world_stats_print(&stats);
 
-  return 0;
+  return stats.failed == 0 ? 0 : 1;
 }