Kevin's patch bug13
[m6w6/libmemcached] / tests / function.c
index 514fe3c2fb8673f3977fc49053a353801e48b605..13c09ad14b21a8d8a3c7087f6bb02eaf6615023a 100644 (file)
@@ -26,6 +26,9 @@
 #include "test.h"
 
 #define GLOBAL_COUNT 100000
+#define GLOBAL2_COUNT 1000
+static uint32_t global_count;
+
 static pairs_st *global_pairs;
 static char *global_keys[GLOBAL_COUNT];
 static size_t global_keys_length[GLOBAL_COUNT];
@@ -1144,7 +1147,10 @@ uint8_t user_supplied_bug2(memcached_st *memc)
       if (rc == MEMCACHED_NOTFOUND)
         errors++;
       else
+      {
+        WATCHPOINT_ERROR(rc);
         assert(0);
+      }
 
       continue;
     }
@@ -1640,6 +1646,41 @@ uint8_t user_supplied_bug12(memcached_st *memc)
   return 0;
 }
 
+/*
+  Bug found where command total one more than MEMCACHED_MAX_BUFFER
+  set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
+ */
+uint8_t user_supplied_bug13(memcached_st *memc)
+{
+  char key[] = "key34567890";
+  char *overflow;
+  memcached_return rc;
+  size_t overflowSize;
+
+  char commandFirst[]= "set key34567890 0 0 ";
+  char commandLast[] = " \r\n"; /* first line of command sent to server */
+  size_t commandLength;
+  size_t testSize;
+
+  commandLength = strlen(commandFirst) + strlen(commandLast) + 4; /* 4 is number of characters in size, probably 8196 */
+
+  overflowSize = MEMCACHED_MAX_BUFFER - commandLength;
+
+  for (testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++)
+  {
+    overflow= malloc(testSize);
+    assert(overflow != NULL);
+
+    memset(overflow, 'x', testSize);
+    rc= memcached_set(memc, key, strlen(key),
+                      overflow, testSize, 0, 0);
+    assert(rc == MEMCACHED_SUCCESS);
+    free(overflow);
+  }
+
+  return 0;
+}
+
 uint8_t result_static(memcached_st *memc)
 {
   memcached_result_st result;
@@ -1764,13 +1805,13 @@ uint8_t cleanup_pairs(memcached_st *memc)
   return 0;
 }
 
-uint8_t generate_data(memcached_st *memc)
+uint8_t generate_pairs(memcached_st *memc)
 {
   unsigned long long x;
-  global_pairs= pairs_generate(GLOBAL_COUNT);
-  execute_set(memc, global_pairs, GLOBAL_COUNT);
+  global_pairs= pairs_generate(GLOBAL_COUNT, 400);
+  global_count= GLOBAL_COUNT;
 
-  for (x= 0; x < GLOBAL_COUNT; x++)
+  for (x= 0; x < global_count; x++)
   {
     global_keys[x]= global_pairs[x].key; 
     global_keys_length[x]=  global_pairs[x].key_length;
@@ -1779,34 +1820,38 @@ uint8_t generate_data(memcached_st *memc)
   return 0;
 }
 
-uint8_t generate_buffer_data(memcached_st *memc)
+uint8_t generate_large_pairs(memcached_st *memc)
 {
-  int latch= 0;
+  unsigned long long x;
+  global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10);
+  global_count= GLOBAL2_COUNT;
 
-  latch= 1;
-  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
-  generate_data(memc);
+  for (x= 0; x < global_count; x++)
+  {
+    global_keys[x]= global_pairs[x].key; 
+    global_keys_length[x]=  global_pairs[x].key_length;
+  }
 
   return 0;
 }
 
-#ifdef NOT_DONE
-uint8_t mset_data(memcached_st *memc)
+uint8_t generate_data(memcached_st *memc)
 {
-  unsigned long long x;
-  global_pairs= pairs_generate(GLOBAL_COUNT);
+  execute_set(memc, global_pairs, global_count);
 
-  (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
+  return 0;
+}
 
-  for (x= 0; x < GLOBAL_COUNT; x++)
-  {
-    global_keys[x]= global_pairs[x].key; 
-    global_keys_length[x]=  global_pairs[x].key_length;
-  }
+uint8_t generate_buffer_data(memcached_st *memc)
+{
+  int latch= 0;
+
+  latch= 1;
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
+  generate_data(memc);
 
   return 0;
 }
-#endif
 
 uint8_t get_read(memcached_st *memc)
 {
@@ -1818,7 +1863,7 @@ uint8_t get_read(memcached_st *memc)
     size_t return_value_length;
     uint32_t flags;
 
-    for (x= 0; x < GLOBAL_COUNT; x++)
+    for (x= 0; x < global_count; x++)
     {
       return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
                                   &return_value_length, &flags, &rc);
@@ -1838,7 +1883,7 @@ uint8_t mget_read(memcached_st *memc)
 {
   memcached_return rc;
 
-  rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
+  rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
   assert(rc == MEMCACHED_SUCCESS);
   /* Turn this into a help function */
   {
@@ -1864,7 +1909,7 @@ uint8_t mget_read_result(memcached_st *memc)
 {
   memcached_return rc;
 
-  rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
+  rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
   assert(rc == MEMCACHED_SUCCESS);
   /* Turn this into a help function */
   {
@@ -1891,7 +1936,7 @@ uint8_t mget_read_function(memcached_st *memc)
   unsigned int counter;
   unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *);
 
-  rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
+  rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
   assert(rc == MEMCACHED_SUCCESS);
 
   callbacks[0]= &callback_counter;
@@ -1905,7 +1950,7 @@ uint8_t delete_generate(memcached_st *memc)
 {
   unsigned int x;
 
-  for (x= 0; x < GLOBAL_COUNT; x++)
+  for (x= 0; x < global_count; x++)
   {
     (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
   }
@@ -1921,7 +1966,7 @@ uint8_t delete_buffer_generate(memcached_st *memc)
   latch= 1;
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
 
-  for (x= 0; x < GLOBAL_COUNT; x++)
+  for (x= 0; x < global_count; x++)
   {
     (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
   }
@@ -2274,10 +2319,12 @@ test_st user_tests[] ={
   {"user_supplied_bug10", 1, user_supplied_bug10 },
   {"user_supplied_bug11", 1, user_supplied_bug11 },
   {"user_supplied_bug12", 1, user_supplied_bug12 },
+  {"user_supplied_bug13", 1, user_supplied_bug13 },
   {0, 0, 0}
 };
 
 test_st generate_tests[] ={
+  {"generate_pairs", 1, generate_pairs },
   {"generate_data", 1, generate_data },
   {"get_read", 0, get_read },
   {"delete_generate", 0, delete_generate },
@@ -2288,6 +2335,10 @@ test_st generate_tests[] ={
   {"mget_read_result", 0, mget_read_result },
   {"mget_read_function", 0, mget_read_function },
   {"cleanup", 1, cleanup_pairs },
+  {"generate_large_pairs", 1, generate_large_pairs },
+  {"generate_data", 1, generate_data },
+  {"generate_buffer_data", 1, generate_buffer_data },
+  {"cleanup", 1, cleanup_pairs },
   {0, 0, 0}
 };