testapp.c (memcached-1.6.8) | : | testapp.c (memcached-1.6.9) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <assert.h> | #include <assert.h> | |||
#include <string.h> | #include <string.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <netinet/in.h> | #include <netinet/in.h> | |||
#include <fcntl.h> | #include <fcntl.h> | |||
#include "config.h" | #include "config.h" | |||
#include "cache.h" | #include "cache.h" | |||
#include "crc32c.h" | ||||
#include "hash.h" | #include "hash.h" | |||
#include "jenkins_hash.h" | #include "jenkins_hash.h" | |||
#include "stats_prefix.h" | #include "stats_prefix.h" | |||
#include "util.h" | #include "util.h" | |||
#include "protocol_binary.h" | #include "protocol_binary.h" | |||
#ifdef TLS | #ifdef TLS | |||
#include <openssl/ssl.h> | #include <openssl/ssl.h> | |||
#endif | #endif | |||
#define TMP_TEMPLATE "/tmp/test_file.XXXXXXX" | #define TMP_TEMPLATE "/tmp/test_file.XXXXXXX" | |||
skipping to change at line 168 | skipping to change at line 169 | |||
cache_destroy(cache); | cache_destroy(cache); | |||
return (ptr == destruct_data) ? TEST_PASS : TEST_FAIL; | return (ptr == destruct_data) ? TEST_PASS : TEST_FAIL; | |||
} | } | |||
static enum test_return cache_reuse_test(void) | static enum test_return cache_reuse_test(void) | |||
{ | { | |||
int ii; | int ii; | |||
cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), | cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), | |||
NULL, NULL); | NULL, NULL); | |||
if (cache == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
char *ptr = cache_alloc(cache); | char *ptr = cache_alloc(cache); | |||
cache_free(cache, ptr); | cache_free(cache, ptr); | |||
for (ii = 0; ii < 100; ++ii) { | for (ii = 0; ii < 100; ++ii) { | |||
char *p = cache_alloc(cache); | char *p = cache_alloc(cache); | |||
assert(p == ptr); | assert(p == ptr); | |||
cache_free(cache, ptr); | cache_free(cache, ptr); | |||
} | } | |||
cache_destroy(cache); | cache_destroy(cache); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return cache_bulkalloc(size_t datasize) | static enum test_return cache_bulkalloc(size_t datasize) | |||
{ | { | |||
cache_t *cache = cache_create("test", datasize, sizeof(char*), | cache_t *cache = cache_create("test", datasize, sizeof(char*), | |||
NULL, NULL); | NULL, NULL); | |||
if (cache == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
#define ITERATIONS 1024 | #define ITERATIONS 1024 | |||
void *ptr[ITERATIONS]; | void *ptr[ITERATIONS]; | |||
for (int ii = 0; ii < ITERATIONS; ++ii) { | for (int ii = 0; ii < ITERATIONS; ++ii) { | |||
ptr[ii] = cache_alloc(cache); | ptr[ii] = cache_alloc(cache); | |||
assert(ptr[ii] != 0); | assert(ptr[ii] != 0); | |||
memset(ptr[ii], 0xff, datasize); | memset(ptr[ii], 0xff, datasize); | |||
} | } | |||
for (int ii = 0; ii < ITERATIONS; ++ii) { | for (int ii = 0; ii < ITERATIONS; ++ii) { | |||
skipping to change at line 217 | skipping to change at line 224 | |||
return ret; | return ret; | |||
} | } | |||
static enum test_return cache_redzone_test(void) | static enum test_return cache_redzone_test(void) | |||
{ | { | |||
#ifndef HAVE_UMEM_H | #ifndef HAVE_UMEM_H | |||
cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), | cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), | |||
NULL, NULL); | NULL, NULL); | |||
if (cache == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
/* Ignore SIGABRT */ | /* Ignore SIGABRT */ | |||
struct sigaction old_action; | struct sigaction old_action; | |||
struct sigaction action = { .sa_handler = SIG_IGN, .sa_flags = 0}; | struct sigaction action = { .sa_handler = SIG_IGN, .sa_flags = 0}; | |||
sigemptyset(&action.sa_mask); | sigemptyset(&action.sa_mask); | |||
sigaction(SIGABRT, &action, &old_action); | sigaction(SIGABRT, &action, &old_action); | |||
/* check memory debug.. */ | /* check memory debug.. */ | |||
char *p = cache_alloc(cache); | char *p = cache_alloc(cache); | |||
char old = *(p - 1); | char old = *(p - 1); | |||
*(p - 1) = 0; | *(p - 1) = 0; | |||
skipping to change at line 303 | skipping to change at line 313 | |||
assert(pfs1 != pfs2); | assert(pfs1 != pfs2); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return test_stats_prefix_record_get(void) { | static enum test_return test_stats_prefix_record_get(void) { | |||
PREFIX_STATS *pfs; | PREFIX_STATS *pfs; | |||
stats_prefix_clear(); | stats_prefix_clear(); | |||
stats_prefix_record_get("abc:123", 7, false); | stats_prefix_record_get("abc:123", 7, false); | |||
pfs = stats_prefix_find("abc:123", 7); | pfs = stats_prefix_find("abc:123", 7); | |||
if (pfs == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
assert(1 == pfs->num_gets); | assert(1 == pfs->num_gets); | |||
assert(0 == pfs->num_hits); | assert(0 == pfs->num_hits); | |||
stats_prefix_record_get("abc:456", 7, false); | stats_prefix_record_get("abc:456", 7, false); | |||
assert(2 == pfs->num_gets); | assert(2 == pfs->num_gets); | |||
assert(0 == pfs->num_hits); | assert(0 == pfs->num_hits); | |||
stats_prefix_record_get("abc:456", 7, true); | stats_prefix_record_get("abc:456", 7, true); | |||
assert(3 == pfs->num_gets); | assert(3 == pfs->num_gets); | |||
assert(1 == pfs->num_hits); | assert(1 == pfs->num_hits); | |||
stats_prefix_record_get("def:", 4, true); | stats_prefix_record_get("def:", 4, true); | |||
assert(3 == pfs->num_gets); | assert(3 == pfs->num_gets); | |||
assert(1 == pfs->num_hits); | assert(1 == pfs->num_hits); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return test_stats_prefix_record_delete(void) { | static enum test_return test_stats_prefix_record_delete(void) { | |||
PREFIX_STATS *pfs; | PREFIX_STATS *pfs; | |||
stats_prefix_clear(); | stats_prefix_clear(); | |||
stats_prefix_record_delete("abc:123", 7); | stats_prefix_record_delete("abc:123", 7); | |||
pfs = stats_prefix_find("abc:123", 7); | pfs = stats_prefix_find("abc:123", 7); | |||
if (pfs == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
assert(0 == pfs->num_gets); | assert(0 == pfs->num_gets); | |||
assert(0 == pfs->num_hits); | assert(0 == pfs->num_hits); | |||
assert(1 == pfs->num_deletes); | assert(1 == pfs->num_deletes); | |||
assert(0 == pfs->num_sets); | assert(0 == pfs->num_sets); | |||
stats_prefix_record_delete("def:", 4); | stats_prefix_record_delete("def:", 4); | |||
assert(1 == pfs->num_deletes); | assert(1 == pfs->num_deletes); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return test_stats_prefix_record_set(void) { | static enum test_return test_stats_prefix_record_set(void) { | |||
PREFIX_STATS *pfs; | PREFIX_STATS *pfs; | |||
stats_prefix_clear(); | stats_prefix_clear(); | |||
stats_prefix_record_set("abc:123", 7); | stats_prefix_record_set("abc:123", 7); | |||
pfs = stats_prefix_find("abc:123", 7); | pfs = stats_prefix_find("abc:123", 7); | |||
if (pfs == NULL) { | ||||
return TEST_FAIL; | ||||
} | ||||
assert(0 == pfs->num_gets); | assert(0 == pfs->num_gets); | |||
assert(0 == pfs->num_hits); | assert(0 == pfs->num_hits); | |||
assert(0 == pfs->num_deletes); | assert(0 == pfs->num_deletes); | |||
assert(1 == pfs->num_sets); | assert(1 == pfs->num_sets); | |||
stats_prefix_record_delete("def:", 4); | stats_prefix_record_delete("def:", 4); | |||
assert(1 == pfs->num_sets); | assert(1 == pfs->num_sets); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return test_stats_prefix_dump(void) { | static enum test_return test_stats_prefix_dump(void) { | |||
skipping to change at line 880 | skipping to change at line 899 | |||
send_ascii_command("stats cachedump 200 0 0\r\n"); | send_ascii_command("stats cachedump 200 0 0\r\n"); | |||
read_ascii_response(buffer, sizeof(buffer)); | read_ascii_response(buffer, sizeof(buffer)); | |||
assert(strncmp(buffer, "CLIENT_ERROR", strlen("CLIENT_ERROR")) == 0); | assert(strncmp(buffer, "CLIENT_ERROR", strlen("CLIENT_ERROR")) == 0); | |||
close_conn(); | close_conn(); | |||
con = connect_server("127.0.0.1", port, false, enable_ssl); | con = connect_server("127.0.0.1", port, false, enable_ssl); | |||
assert(con); | assert(con); | |||
return TEST_PASS; | return TEST_PASS; | |||
} | } | |||
static enum test_return test_crc32c(void) { | ||||
uint32_t crc_hw, crc_sw; | ||||
char buffer[256]; | ||||
for (int x = 0; x < 256; x++) | ||||
buffer[x] = x; | ||||
/* Compare harware to software implementaiton */ | ||||
crc_hw = crc32c(0, buffer, 256); | ||||
crc_sw = crc32c_sw(0, buffer, 256); | ||||
assert(crc_hw == 0x9c44184b); | ||||
assert(crc_sw == 0x9c44184b); | ||||
/* Test that passing a CRC in also works */ | ||||
crc_hw = crc32c(crc_hw, buffer, 256); | ||||
crc_sw = crc32c_sw(crc_sw, buffer, 256); | ||||
assert(crc_hw == 0xae10ee5a); | ||||
assert(crc_sw == 0xae10ee5a); | ||||
/* Test odd offsets/sizes */ | ||||
crc_hw = crc32c(crc_hw, buffer + 1, 256 - 2); | ||||
crc_sw = crc32c_sw(crc_sw, buffer + 1, 256 - 2); | ||||
assert(crc_hw == 0xed37b906); | ||||
assert(crc_sw == 0xed37b906); | ||||
return TEST_PASS; | ||||
} | ||||
static enum test_return test_issue_102(void) { | static enum test_return test_issue_102(void) { | |||
char buffer[4096]; | char buffer[4096]; | |||
memset(buffer, ' ', sizeof(buffer)); | memset(buffer, ' ', sizeof(buffer)); | |||
buffer[sizeof(buffer) - 1] = '\0'; | buffer[sizeof(buffer) - 1] = '\0'; | |||
close_conn(); | close_conn(); | |||
con = connect_server("127.0.0.1", port, false, enable_ssl); | con = connect_server("127.0.0.1", port, false, enable_ssl); | |||
assert(con); | assert(con); | |||
send_ascii_command(buffer); | send_ascii_command(buffer); | |||
skipping to change at line 2275 | skipping to change at line 2322 | |||
{ "stats_prefix_record_set", test_stats_prefix_record_set }, | { "stats_prefix_record_set", test_stats_prefix_record_set }, | |||
{ "stats_prefix_dump", test_stats_prefix_dump }, | { "stats_prefix_dump", test_stats_prefix_dump }, | |||
{ "issue_161", test_issue_161 }, | { "issue_161", test_issue_161 }, | |||
{ "strtol", test_safe_strtol }, | { "strtol", test_safe_strtol }, | |||
{ "strtoll", test_safe_strtoll }, | { "strtoll", test_safe_strtoll }, | |||
{ "strtoul", test_safe_strtoul }, | { "strtoul", test_safe_strtoul }, | |||
{ "strtoull", test_safe_strtoull }, | { "strtoull", test_safe_strtoull }, | |||
{ "issue_44", test_issue_44 }, | { "issue_44", test_issue_44 }, | |||
{ "vperror", test_vperror }, | { "vperror", test_vperror }, | |||
{ "issue_101", test_issue_101 }, | { "issue_101", test_issue_101 }, | |||
{ "crc32c", test_crc32c }, | ||||
/* The following tests all run towards the same server */ | /* The following tests all run towards the same server */ | |||
{ "start_server", start_memcached_server }, | { "start_server", start_memcached_server }, | |||
{ "issue_92", test_issue_92 }, | { "issue_92", test_issue_92 }, | |||
{ "issue_102", test_issue_102 }, | { "issue_102", test_issue_102 }, | |||
{ "binary_noop", test_binary_noop }, | { "binary_noop", test_binary_noop }, | |||
{ "binary_quit", test_binary_quit }, | { "binary_quit", test_binary_quit }, | |||
{ "binary_quitq", test_binary_quitq }, | { "binary_quitq", test_binary_quitq }, | |||
{ "binary_set", test_binary_set }, | { "binary_set", test_binary_set }, | |||
{ "binary_setq", test_binary_setq }, | { "binary_setq", test_binary_setq }, | |||
{ "binary_add", test_binary_add }, | { "binary_add", test_binary_add }, | |||
skipping to change at line 2341 | skipping to change at line 2389 | |||
SSLeay_add_ssl_algorithms(); | SSLeay_add_ssl_algorithms(); | |||
SSL_load_error_strings(); | SSL_load_error_strings(); | |||
enable_ssl = true; | enable_ssl = true; | |||
} | } | |||
#endif | #endif | |||
/* Initialized directly instead of using hash_init to avoid pulling in | /* Initialized directly instead of using hash_init to avoid pulling in | |||
the definition of settings struct from memcached.h */ | the definition of settings struct from memcached.h */ | |||
hash = jenkins_hash; | hash = jenkins_hash; | |||
stats_prefix_init(':'); | stats_prefix_init(':'); | |||
crc32c_init(); | ||||
for (num_cases = 0; testcases[num_cases].description; num_cases++) { | for (num_cases = 0; testcases[num_cases].description; num_cases++) { | |||
/* Just counting */ | /* Just counting */ | |||
} | } | |||
printf("1..%d\n", num_cases); | printf("1..%d\n", num_cases); | |||
for (ii = 0; testcases[ii].description != NULL; ++ii) { | for (ii = 0; testcases[ii].description != NULL; ++ii) { | |||
fflush(stdout); | fflush(stdout); | |||
#ifndef DEBUG | #ifndef DEBUG | |||
/* the test program shouldn't run longer than 10 minutes... */ | /* the test program shouldn't run longer than 10 minutes... */ | |||
End of changes. 10 change blocks. | ||||
0 lines changed or deleted | 50 lines changed or added |