#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];
return 0;
}
-uint8_t version_string_test(void)
+uint8_t version_string_test(memcached_st *memc)
{
const char *version_string;
+
version_string= memcached_lib_version();
+
assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING));
+
return 0;
}
if (rc == MEMCACHED_NOTFOUND)
errors++;
else
+ {
+ WATCHPOINT_ERROR(rc);
assert(0);
+ }
continue;
}
return 0;
}
+/*
+ Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
+*/
+uint8_t user_supplied_bug12(memcached_st *memc)
+{
+ memcached_return rc;
+ uint32_t flags;
+ size_t value_length;
+ char *value;
+ uint64_t number_value;
+
+ value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
+ &value_length, &flags, &rc);
+ assert(value == NULL);
+ assert(rc == MEMCACHED_NOTFOUND);
+
+ rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
+ 1, &number_value);
+
+ assert(value == NULL);
+ assert(rc == MEMCACHED_NOTFOUND);
+
+ rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
+
+ value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
+ &value_length, &flags, &rc);
+ assert(value);
+ assert(rc == MEMCACHED_SUCCESS);
+ free(value);
+
+ rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
+ 1, &number_value);
+ assert(number_value == 2);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ 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;
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;
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);
+
+ return 0;
+}
- (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
+uint8_t generate_buffer_data(memcached_st *memc)
+{
+ int latch= 0;
- for (x= 0; x < GLOBAL_COUNT; x++)
- {
- global_keys[x]= global_pairs[x].key;
- global_keys_length[x]= global_pairs[x].key_length;
- }
+ latch= 1;
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
+ generate_data(memc);
return 0;
}
-#endif
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);
{
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 */
{
{
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 */
{
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;
{
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);
}
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);
}
return MEMCACHED_SUCCESS;
}
+
void my_free(memcached_st *ptr, void *mem)
{
free(mem);
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &my_malloc);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
- assert(test_ptr == (memcached_malloc_function)my_malloc);
+ test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(test_ptr == my_malloc);
}
{
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &my_realloc);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
+ test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
assert(test_ptr == my_realloc);
}
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, my_free);
assert(rc == MEMCACHED_SUCCESS);
- test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
+ test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
assert(test_ptr == my_free);
}
{"user_supplied_bug9", 1, user_supplied_bug9 },
{"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 },
{"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}
};