Implement flag retrieval for new keepalive flag.
[m6w6/libmemcached] / tests / test.c
index 27f7f1b0d32f6c507fccb5743b508617cfbd0161..b177f64fdffdbb8a7d84f401ab5dcbd30691f10f 100644 (file)
@@ -105,6 +105,34 @@ static world_runner_st defualt_runners= {
   _runner_default
 };
 
+static test_return_t _default_callback(void *p)
+{
+  (void)p;
+
+  return TEST_SUCCESS;
+}
+
+static inline void set_default_fn(test_callback_fn *fn)
+{
+  if (*fn == NULL)
+  {
+    *fn= _default_callback;
+  }
+}
+
+static collection_st *init_world(world_st *world)
+{
+  if (! world->runner)
+  {
+    world->runner= &defualt_runners;
+  }
+
+  set_default_fn(&world->collection.startup);
+  set_default_fn(&world->collection.shutdown);
+
+  return world->collections;
+}
+
 
 int main(int argc, char *argv[])
 {
@@ -123,12 +151,7 @@ int main(int argc, char *argv[])
   memset(&world, 0, sizeof(world));
   get_world(&world);
 
-  if (! world.runner)
-  {
-    world.runner= &defualt_runners;
-  }
-
-  collection= world.collections;
+  collection= init_world(&world);
 
   if (world.create)
   {
@@ -161,11 +184,17 @@ int main(int argc, char *argv[])
 
     stats.collection_total++;
 
-    if (world.collection_startup)
+    collection_rc= world.collection.startup(world_ptr);
+
+    if (collection_rc != TEST_SUCCESS)
+      goto skip_pre;
+
+    if (next->pre)
     {
-      collection_rc= world.collection_startup(world_ptr);
+      collection_rc= world.runner->pre(next->pre, world_ptr);
     }
 
+skip_pre:
     switch (collection_rc)
     {
       case TEST_SUCCESS:
@@ -173,12 +202,12 @@ int main(int argc, char *argv[])
         break;
       case TEST_FAILURE:
         fprintf(stderr, "\n%s [ failed ]\n\n", next->name);
-        stats.failed++;
-        continue;
+        stats.collection_failed++;
+        goto cleanup;
       case TEST_SKIPPED:
         fprintf(stderr, "\n%s [ skipping ]\n\n", next->name);
-        stats.skipped++;
-        continue;
+        stats.collection_skipped++;
+        goto cleanup;
       case TEST_MEMORY_ALLOCATION_FAILURE:
       case TEST_MAXIMUM_RETURN:
       default:
@@ -186,6 +215,7 @@ int main(int argc, char *argv[])
         break;
     }
 
+
     for (x= 0; run->name; run++)
     {
       struct timeval start_time, end_time;
@@ -214,6 +244,7 @@ int main(int argc, char *argv[])
 
       // Runner code
       {
+#if 0
         if (next->pre && world.runner->pre)
         {
           return_code= world.runner->pre(next->pre, world_ptr);
@@ -223,16 +254,19 @@ int main(int argc, char *argv[])
             goto error;
           }
         }
+#endif
 
         gettimeofday(&start_time, NULL);
         return_code= world.runner->run(run->test_fn, world_ptr);
         gettimeofday(&end_time, NULL);
         load_time= timedif(end_time, start_time);
 
+#if 0
         if (next->post && world.runner->post)
         {
           (void) world.runner->post(next->post, world_ptr);
         }
+#endif
       }
 
       if (world.test.post_run)
@@ -240,7 +274,6 @@ int main(int argc, char *argv[])
         world.test.post_run(world_ptr);
       }
 
-error:
       stats.total++;
 
       fprintf(stderr, "\t\t\t\t\t");
@@ -280,25 +313,18 @@ error:
       }
     }
 
-    if (failed)
+    if (next->post && world.runner->post)
     {
-      stats.collection_failed++;
-    }
-
-    if (skipped)
-    {
-      stats.collection_skipped++;
+      (void) world.runner->post(next->post, world_ptr);
     }
 
     if (! failed && ! skipped)
     {
       stats.collection_success++;
     }
+cleanup:
 
-    if (world.collection_shutdown)
-    {
-      world.collection_shutdown(world_ptr);
-    }
+    world.collection.shutdown(world_ptr);
   }
 
   if (stats.collection_failed || stats.collection_skipped)