List:Commits« Previous MessageNext Message »
From:John David Duncan Date:May 16 2011 5:38am
Subject:bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4173)
View as plain text  
#At file:///Users/jdd/bzr-repo/working/cluster-7.2-labs-memcached/ based on revid:john.duncan@stripped

 4173 John David Duncan	2011-05-15
      Improvements to unit-test framework

    modified:
      storage/ndb/memcache/unit/all_tests.h
      storage/ndb/memcache/unit/connpool.cc
      storage/ndb/memcache/unit/harness.cc
=== modified file 'storage/ndb/memcache/unit/all_tests.h'
--- a/storage/ndb/memcache/unit/all_tests.h	2011-03-30 06:54:53 +0000
+++ b/storage/ndb/memcache/unit/all_tests.h	2011-05-16 05:37:57 +0000
@@ -30,13 +30,19 @@
 #define detail(v, fmt, ...) if(v) printf (fmt, ## __VA_ARGS__)
 #define RESULT getNdbError().code
 
+#define REQ_NONE           0
+#define REQ_NDB_CONNECTION 1
+#define REQ_DEMO_TABLE     2
+
 void delete_row(QueryPlan *plan, const char * key, int verbose);
 
 typedef int TESTCASE(QueryPlan *plan, int verbose);
 
 struct test_item {
+  int enabled;
   const char *name;
   TESTCASE *function;
+  int requires;
 };
 
 TESTCASE run_cas_test;
@@ -48,12 +54,18 @@ TESTCASE run_pool_test;
 #ifdef HARNESS
 
 struct test_item all_tests[] = { 
-  { "cas operation", run_cas_test },
-  { "cas bitshifting", test_cas_bitshifts },
-  { "incr operation", run_incr_test }, 
-  { "allocator", run_allocator_test },
-  { "pool", run_pool_test },
-  { NULL, NULL }
+  { 1, "cas operation",   run_cas_test,       REQ_DEMO_TABLE },
+  { 1, "cas bitshifting", test_cas_bitshifts, REQ_NONE },
+  { 1, "incr operation",  run_incr_test,      REQ_DEMO_TABLE }, 
+  { 1, "allocator",       run_allocator_test, REQ_NONE },
+  { 0, "pool",            run_pool_test,      REQ_NDB_CONNECTION },
+  { 0, NULL, NULL, NULL }
+};
+
+
+const char * requirements[3] = 
+{ 
+  "none", "ndb connection", "demo_table" 
 };
 
 #else

=== modified file 'storage/ndb/memcache/unit/connpool.cc'
--- a/storage/ndb/memcache/unit/connpool.cc	2011-03-30 06:54:53 +0000
+++ b/storage/ndb/memcache/unit/connpool.cc	2011-05-16 05:37:57 +0000
@@ -28,7 +28,6 @@ int run_pool_test(QueryPlan *plan, int v
   int r;
   Ndb_cluster_connection &main_conn = plan->db->get_ndb_cluster_connection();  
 
-
   /* The pooled connection */  
   Ndb_cluster_connection * nc = new Ndb_cluster_connection(connect_string, & main_conn);
   

=== modified file 'storage/ndb/memcache/unit/harness.cc'
--- a/storage/ndb/memcache/unit/harness.cc	2011-04-19 01:16:36 +0000
+++ b/storage/ndb/memcache/unit/harness.cc	2011-05-16 05:37:57 +0000
@@ -26,10 +26,9 @@
 #define HARNESS 1
 #include "all_tests.h"
 
-/***  usage:  ./run_unit_tests [connectstring] [test-id] 
-      These tests require a running cluster. 
+/***  These tests require a running cluster. 
       Some of them require the ndbmemcache.demo_table to exist.  
-      If test-id is supplied, run one test verbosely;
+      If a particular test-id is supplied, run one test verbosely;
       otherwise run all tests and indicate pass or fail.
 ***/      
 
@@ -39,32 +38,43 @@ extern EXTENSION_LOGGER_DESCRIPTOR *logg
                        
 Ndb_cluster_connection * connect(const char *);
 
+int list_tests(void);
+int usage(char *);
+
 int main(int argc, char *argv[]) {
+  connect_string = NULL;
   int test_number = -1;
   char * test_name = 0;
-  if(argc > 1) connect_string = argv[1];
-  if(argc > 2) {
-    test_number = atoi(argv[2]);
-    if(test_number) test_number -= 1;
-    else test_name = argv[2];
-  }
-  
-  ndb_init();
-  DEBUG_INIT(NULL, 0);
-
-  printf("Connecting to cluster (%s)\n", connect_string);
-
-  Ndb_cluster_connection * conn = connect(connect_string);
-  Ndb *db = new Ndb(conn);
-  db->init(4);
-  
-  TableSpec spec("ndbmemcache.demo_table", "mkey", "string_value");
-  spec.cas_column = "cas_value";
-  spec.math_column = "math_value";
-  QueryPlan plan(db, &spec);
-
+  int optc;
+  int req_level;
   int npass = 0, nfail = 0;
 
+  Ndb_cluster_connection * conn = NULL;
+  QueryPlan *plan = NULL;
+  Ndb *db = NULL;
+  
+  /* Options */
+  while((optc = getopt(argc, argv, "hlc:t:")) != -1) {
+    switch(optc) {
+      case 'c':
+        connect_string = optarg;
+        break;
+      case 't':
+        test_number = atoi(optarg);
+        if(test_number > 0) test_number -= 1;
+        else test_name = optarg;
+        break;
+      case 'l':
+        return list_tests();
+        break;
+      case 'h':
+      default:
+        return usage(argv[0]);
+        break;
+    } 
+  }
+    
+  /* If a test name was given, find it by number */
   if(test_name) {
     for(int i = 0; all_tests[i].name; i++) {
       if(! strcmp(test_name, all_tests[i].name)) {
@@ -77,24 +87,78 @@ int main(int argc, char *argv[]) {
       exit(1);
     }  
   }
+  
+  /* Determine requirements level for this test */
+  if(test_number >= 0)
+    req_level = all_tests[test_number].requires;
+  else
+    req_level = REQ_DEMO_TABLE;  // highest level
 
-  if(test_number > -1) {
+  ndb_init();
+  DEBUG_INIT(NULL, 0);
+  
+  if(req_level >= REQ_NDB_CONNECTION) { 
+    printf("Connecting to cluster (%s)\n", connect_string);
+    conn = connect(connect_string);
+    db = new Ndb(conn);
+    db->init(4);
+  }
+  
+  if(req_level >= REQ_DEMO_TABLE) {    
+    TableSpec spec("ndbmemcache.demo_table", "mkey", "string_value");
+    spec.cas_column = "cas_value";
+    spec.math_column = "math_value";
+    plan = new QueryPlan(db, &spec);
+  }
+
+  if(test_number >= 0) {   /* Run a particular test */
     printf("%s\n", all_tests[test_number].name);
-    int r = all_tests[test_number].function(& plan, 1);  //verbose
+    int r = all_tests[test_number].function(plan, 1);  //verbose
     printf(" %s\n", r ? "[PASS]" : "[FAIL]");
     if(r) npass++; 
     else nfail++;  
   }
-  else {
+  else {                  /* Run all tests */
     for(int i = 0; all_tests[i].name; i++) {
-      printf("%-30s", all_tests[i].name);
-      int r = all_tests[i].function(& plan, 0);   // quiet
-      printf(" %s\n", r ? "[PASS]" : "[FAIL]");
-      if(r) npass++; 
-      else nfail++;
+      if(all_tests[i].enabled) {
+        printf("%-30s", all_tests[i].name);
+        int r = all_tests[i].function(plan, 0);   // quiet
+        printf(" %s\n", r ? "[PASS]" : "[FAIL]");
+        if(r) npass++; 
+        else nfail++;
+      }
     }
-  printf("\nTotals:  %d pass        ...    %d fail\n", npass, nfail);
+    printf("\nTotals:  %d pass        ...    %d fail\n", npass, nfail);
   }
+  
+  exit((nfail > 0));
+}
+
+
+int list_tests() {
+  printf("\n");
+  printf("No. %-30s %-20s %-10s\n", "Name", "Requires","Enabled");
+  printf("----------------------------------------------------------------\n");
+  for(int i = 0; all_tests[i].name; i++)
+    printf("%d   %-30s %-20s %-10s\n", i+1, all_tests[i].name,
+           requirements[all_tests[i].requires],
+           all_tests[i].enabled ? "Yes" : "No");
+  printf("\n");
+  return 0;
+}
+
+
+int usage(char *prog) {
+  printf("\n");
+  printf("usage %s [options]\n", prog);
+  printf("options: \n");
+  printf("  -c connectstring  : specify NDB connect-string\n");
+  printf("  -t test-id        : run a particular test by number or name\n");
+  printf("  -l                : list tests\n");
+  printf("  -h                : help\n");
+  printf("\n");
+  
+  return 0;
 }
 
 


Attachment: [text/bzr-bundle] bzr/john.duncan@oracle.com-20110516053757-9zjelwc0vs2135it.bundle
Thread
bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4173) John David Duncan16 May