From: Brian Aker Date: Sat, 17 Sep 2011 19:41:48 +0000 (-0700) Subject: Improve tesing of command line apps X-Git-Tag: 0.53~16 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=956d15b5b1f3f3518eb374a3a9e0393e9dacd3b6;p=m6w6%2Flibmemcached Improve tesing of command line apps --- diff --git a/.bzrignore b/.bzrignore index 3a6e517a..da5a7c17 100644 --- a/.bzrignore +++ b/.bzrignore @@ -127,3 +127,10 @@ tests/testudp tests/var/ tmp_chroot unittests/unittests +tests/memerror +tests/memcp +tests/memdump +tests/memflush +tests/memrm +tests/memstat +tests/memcat diff --git a/clients/client_options.h b/clients/client_options.h index 70329051..57aefd2b 100644 --- a/clients/client_options.h +++ b/clients/client_options.h @@ -9,12 +9,11 @@ * */ -#ifndef __CLIENT_OPTIONS_H__ -#define __CLIENT_OPTIONS_H__ +#pragma once typedef struct memcached_help_text_st memcached_help_text_st; -typedef enum { +enum memcached_options { OPT_SERVERS= 's', OPT_VERSION= 'V', OPT_HELP= 'h', @@ -39,7 +38,6 @@ typedef enum { OPT_USERNAME, OPT_PASSWD, OPT_STAT_ARGS, + OPT_QUIET, OPT_FILE= 'f' -} memcached_options; - -#endif /* CLIENT_OPTIONS */ +}; diff --git a/clients/generator.cc b/clients/generator.cc index 80b398b2..011ed3a4 100644 --- a/clients/generator.cc +++ b/clients/generator.cc @@ -9,12 +9,15 @@ * */ -#include "config.h" +#include -#include -#include #include -#include + +#include +#include +#include +#include +#include #include "generator.h" @@ -40,13 +43,11 @@ static void get_random_string(char *buffer, size_t size) void pairs_free(pairs_st *pairs) { - uint32_t x; - - if (! pairs) + if (pairs == NULL) return; /* We free until we hit the null pair we stores during creation */ - for (x= 0; pairs[x].key; x++) + for (uint32_t x= 0; pairs[x].key; x++) { free(pairs[x].key); if (pairs[x].value) @@ -58,27 +59,30 @@ void pairs_free(pairs_st *pairs) pairs_st *pairs_generate(uint64_t number_of, size_t value_length) { - unsigned int x; - pairs_st *pairs; - - pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st)); + pairs_st *pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st)); - if (!pairs) + if (pairs == NULL) + { goto error; + } - for (x= 0; x < number_of; x++) + for (uint64_t x= 0; x < number_of; x++) { pairs[x].key= (char *)calloc(100, sizeof(char)); - if (!pairs[x].key) + + if (pairs[x].key == NULL) goto error; + get_random_string(pairs[x].key, 100); pairs[x].key_length= 100; if (value_length) { pairs[x].value= (char *)calloc(value_length, sizeof(char)); - if (!pairs[x].value) + + if (pairs[x].value == NULL) goto error; + get_random_string(pairs[x].value, value_length); pairs[x].value_length= value_length; } @@ -91,6 +95,6 @@ pairs_st *pairs_generate(uint64_t number_of, size_t value_length) return pairs; error: - fprintf(stderr, "Memory Allocation failure in pairs_generate.\n"); - exit(0); + std::cerr << "Memory Allocation failure in pairs_generate." << std::endl; + exit(EXIT_SUCCESS); } diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 1bb7a88a..2d82f300 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -1973,17 +1973,19 @@ int main(int argc, char **argv) - while ((cmd= getopt(argc, argv, "t:vch:p:PT:?ab")) != EOF) + while ((cmd= getopt(argc, argv, "qt:vch:p:PT:?ab")) != EOF) { switch (cmd) { case 'a': tests.ascii= true; tests.binary= false; break; + case 'b': tests.ascii= false; tests.binary= true; break; + case 't': timeout= atoi(optarg); if (timeout == 0) @@ -1992,18 +1994,29 @@ int main(int argc, char **argv) return EXIT_FAILURE; } break; + case 'v': verbose= true; break; + case 'c': do_core= true; break; + case 'h': hostname= optarg; break; + case 'p': port= optarg; break; + + case 'q': + close_stdio(); + break; + case 'P': prompt= true; break; + case 'T': testname= optarg; break; + default: fprintf(stderr, "Usage: %s [-h hostname] [-p port] [-c] [-v] [-t n] [-P] [-T testname]'\n" "\t-c\tGenerate coredump if a test fails\n" diff --git a/clients/memcat.cc b/clients/memcat.cc index 3e073650..ab482e5d 100644 --- a/clients/memcat.cc +++ b/clients/memcat.cc @@ -192,6 +192,7 @@ void options_parse(int argc, char *argv[]) { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -242,6 +243,11 @@ void options_parse(int argc, char *argv[]) case OPT_FILE: opt_file= optarg; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ exit(1); diff --git a/clients/memcp.cc b/clients/memcp.cc index 22836251..4f4f8e10 100644 --- a/clients/memcp.cc +++ b/clients/memcp.cc @@ -41,7 +41,7 @@ /* Prototypes */ static void options_parse(int argc, char *argv[]); -static int opt_binary=0; +static bool opt_binary= false; static int opt_verbose= 0; static char *opt_servers= NULL; static char *opt_hash= NULL; @@ -80,19 +80,14 @@ static long strtol_wrapper(const char *nptr, int base, bool *error) int main(int argc, char *argv[]) { - memcached_st *memc; - memcached_return_t rc; - memcached_server_st *servers; - - int return_code= 0; options_parse(argc, argv); initialize_sockets(); - memc= memcached_create(NULL); + memcached_st *memc= memcached_create(NULL); process_hash_option(memc, opt_hash); - if (!opt_servers) + if (opt_servers == NULL) { char *temp; @@ -102,15 +97,20 @@ int main(int argc, char *argv[]) } else { - fprintf(stderr, "No Servers provided\n"); - exit(1); + std::cerr << "No Servers provided" << std::endl; + exit(EXIT_FAILURE); } } + memcached_server_st *servers; if (opt_servers) + { servers= memcached_servers_parse(opt_servers); + } else + { servers= memcached_servers_parse(argv[--argc]); + } memcached_server_push(memc, servers); memcached_server_list_free(servers); @@ -135,29 +135,33 @@ int main(int argc, char *argv[]) } } + int exit_code= EXIT_SUCCESS; while (optind < argc) { - struct stat sbuf; - int fd; - char *ptr; - ssize_t read_length; - char *file_buffer_ptr; - - fd= open(argv[optind], O_RDONLY); + int fd= open(argv[optind], O_RDONLY); if (fd < 0) { - fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno)); - optind++; + if (opt_verbose) + { + fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno)); + optind++; + } + exit_code= EXIT_FAILURE; continue; } + struct stat sbuf; (void)fstat(fd, &sbuf); - ptr= rindex(argv[optind], '/'); + char *ptr= rindex(argv[optind], '/'); if (ptr) + { ptr++; + } else + { ptr= argv[optind]; + } if (opt_verbose) { @@ -168,16 +172,18 @@ int main(int argc, char *argv[]) ptr, opt_flags, (unsigned long)opt_expires); } + char *file_buffer_ptr; if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) { fprintf(stderr, "malloc: %s\n", strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } + ssize_t read_length; if ((read_length= read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) { fprintf(stderr, "read: %s\n", strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } if (read_length != sbuf.st_size) @@ -186,6 +192,7 @@ int main(int argc, char *argv[]) exit(1); } + memcached_return_t rc; if (opt_method == OPT_ADD) rc= memcached_add(memc, ptr, strlen(ptr), file_buffer_ptr, (size_t)sbuf.st_size, @@ -207,7 +214,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); - return_code= -1; + exit_code= EXIT_FAILURE; } free(file_buffer_ptr); @@ -222,14 +229,11 @@ int main(int argc, char *argv[]) if (opt_hash) free(opt_hash); - return return_code; + return exit_code; } static void options_parse(int argc, char *argv[]) { - int option_index= 0; - int option_rv; - memcached_programs_help_st help_options[]= { {0}, @@ -239,6 +243,7 @@ static void options_parse(int argc, char *argv[]) { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -254,34 +259,45 @@ static void options_parse(int argc, char *argv[]) {0, 0, 0, 0}, }; + bool opt_version= false; + bool opt_help= false; + int option_index= 0; + while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); - if (option_rv == -1) break; + if (option_rv == -1) + break; switch (option_rv) { case 0: break; case OPT_BINARY: - opt_binary = 1; + opt_binary= true; break; + case OPT_VERBOSE: /* --verbose or -v */ - opt_verbose = OPT_VERBOSE; + opt_verbose= OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ - opt_verbose = OPT_DEBUG; + opt_verbose= OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_FLAG: /* --flag */ { bool strtol_error; @@ -291,8 +307,9 @@ static void options_parse(int argc, char *argv[]) fprintf(stderr, "Bad value passed via --flag\n"); exit(1); } - break; } + break; + case OPT_EXPIRE: /* --expire */ { bool strtol_error; @@ -303,29 +320,53 @@ static void options_parse(int argc, char *argv[]) exit(1); } } + break; + case OPT_SET: opt_method= OPT_SET; break; + case OPT_REPLACE: opt_method= OPT_REPLACE; break; + case OPT_ADD: opt_method= OPT_ADD; break; + case OPT_HASH: opt_hash= strdup(optarg); break; + case OPT_USERNAME: opt_username= optarg; break; + case OPT_PASSWD: opt_passwd= optarg; break; - case '?': + + case OPT_QUIET: + close_stdio(); + break; + + case '?': /* getopt_long already printed an error message. */ exit(1); default: abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memdump.cc b/clients/memdump.cc index 2b7b96fa..fded16f2 100644 --- a/clients/memdump.cc +++ b/clients/memdump.cc @@ -35,7 +35,7 @@ /* Prototypes */ static void options_parse(int argc, char *argv[]); -static int opt_binary=0; +static bool opt_binary=0; static int opt_verbose= 0; static char *opt_servers= NULL; static char *opt_hash= NULL; @@ -43,47 +43,51 @@ static char *opt_username; static char *opt_passwd; /* Print the keys and counter how many were found */ -static memcached_return_t key_printer(const memcached_st *ptr, +static memcached_return_t key_printer(const memcached_st *, const char *key, size_t key_length, - void *context) + void *) { - (void)ptr;(void)context; - printf("%.*s\n", (uint32_t)key_length, key); + std::cout.write(key, key_length); + std::cout << std::endl; return MEMCACHED_SUCCESS; } int main(int argc, char *argv[]) { - memcached_st *memc; - memcached_return_t rc; - memcached_server_st *servers; memcached_dump_fn callbacks[1]; callbacks[0]= &key_printer; options_parse(argc, argv); - memc= memcached_create(NULL); + memcached_st *memc= memcached_create(NULL); process_hash_option(memc, opt_hash); - if (!opt_servers) + if (opt_servers == NULL) { char *temp; if ((temp= getenv("MEMCACHED_SERVERS"))) + { opt_servers= strdup(temp); + } else { - fprintf(stderr, "No Servers provided\n"); - exit(1); + std::cerr << "No Servers provided" << std::endl; + exit(EXIT_FAILURE); } } + memcached_server_st *servers; if (opt_servers) + { servers= memcached_servers_parse(opt_servers); + } else + { servers= memcached_servers_parse(argv[--argc]); + } memcached_server_push(memc, servers); memcached_server_list_free(servers); @@ -108,35 +112,39 @@ int main(int argc, char *argv[]) } } - rc= memcached_dump(memc, callbacks, NULL, 1); + memcached_return_t rc= memcached_dump(memc, callbacks, NULL, 1); - if (rc != MEMCACHED_SUCCESS) + int exit_code= EXIT_SUCCESS; + if (memcached_failed(rc)) { - fprintf(stderr, "memdump: memcache error %s", memcached_strerror(memc, rc)); - if (memcached_last_error_errno(memc)) - fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); - fprintf(stderr, "\n"); + if (opt_verbose) + { + std::cerr << "Failed to dump keys: " << memcached_last_error_message(memc) << std::endl; + } + exit_code= EXIT_FAILURE; } memcached_free(memc); if (opt_servers) + { free(opt_servers); + } if (opt_hash) + { free(opt_hash); + } - return EXIT_SUCCESS; + return exit_code; } static void options_parse(int argc, char *argv[]) { - int option_index= 0; - int option_rv; - static struct option long_options[]= { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -147,9 +155,12 @@ static void options_parse(int argc, char *argv[]) {0, 0, 0, 0} }; + int option_index= 0; + bool opt_version= false; + bool opt_help= false; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; @@ -157,33 +168,47 @@ static void options_parse(int argc, char *argv[]) { case 0: break; + case OPT_BINARY: - opt_binary = 1; + opt_binary= true; break; + case OPT_VERBOSE: /* --verbose or -v */ - opt_verbose = OPT_VERBOSE; + opt_verbose= OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ - opt_verbose = OPT_DEBUG; + opt_verbose= OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_verbose= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL); + opt_help= true; break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_HASH: opt_hash= strdup(optarg); break; + case OPT_USERNAME: opt_username= optarg; break; + case OPT_PASSWD: opt_passwd= optarg; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ exit(1); @@ -191,4 +216,16 @@ static void options_parse(int argc, char *argv[]) abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memerror.cc b/clients/memerror.cc index c30dd2e9..fd4238a5 100644 --- a/clients/memerror.cc +++ b/clients/memerror.cc @@ -10,12 +10,14 @@ */ #include "config.h" -#include #include -#include -#include +#include +#include +#include #include -#include +#include +#include + #include #include "utilities.h" @@ -31,21 +33,22 @@ static int opt_verbose= 0; int main(int argc, char *argv[]) { - unsigned long value; options_parse(argc, argv); if (argc != 2) + { return EXIT_FAILURE; + } - value= strtoul(argv[1], (char **) NULL, 10); + unsigned long value= strtoul(argv[1], (char **) NULL, 10); if (value < MEMCACHED_MAXIMUM_RETURN) { - printf("%s\n", memcached_strerror(NULL, (memcached_return_t)value)); + std::cout << memcached_strerror(NULL, (memcached_return_t)value) << std::endl; } else { - fprintf(stderr, "Unknown Error Code\n"); + std::cerr << memcached_strerror(NULL, MEMCACHED_MAXIMUM_RETURN) << std::endl; return EXIT_FAILURE; } @@ -55,48 +58,70 @@ int main(int argc, char *argv[]) void options_parse(int argc, char *argv[]) { - int option_index= 0; - int option_rv; - - memcached_programs_help_st help_options[]= - { - {0}, - }; - static struct option long_options[]= { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {0, 0, 0, 0}, }; + bool opt_version= false; + bool opt_help= false; + int option_index= 0; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); - if (option_rv == -1) break; + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + if (option_rv == -1) + { + break; + } + switch (option_rv) { case 0: break; + case OPT_VERBOSE: /* --verbose or -v */ opt_verbose = OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ opt_verbose = OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ - exit(1); + exit(EXIT_FAILURE); + default: abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memflush.cc b/clients/memflush.cc index 1ef1bfde..81bb2574 100644 --- a/clients/memflush.cc +++ b/clients/memflush.cc @@ -35,28 +35,26 @@ void options_parse(int argc, char *argv[]); int main(int argc, char *argv[]) { - memcached_st *memc; - memcached_return_t rc; - memcached_server_st *servers; - options_parse(argc, argv); - if (!opt_servers) + if (opt_servers == false) { char *temp; if ((temp= getenv("MEMCACHED_SERVERS"))) + { opt_servers= strdup(temp); + } else { - fprintf(stderr, "No Servers provided\n"); - exit(1); + std::cerr << "No Servers provided" << std::endl; + exit(EXIT_FAILURE); } } - memc= memcached_create(NULL); + memcached_st *memc= memcached_create(NULL); - servers= memcached_servers_parse(opt_servers); + memcached_server_st *servers= memcached_servers_parse(opt_servers); memcached_server_push(memc, servers); memcached_server_list_free(servers); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, @@ -80,14 +78,10 @@ int main(int argc, char *argv[]) } } - rc = memcached_flush(memc, opt_expire); + memcached_return_t rc = memcached_flush(memc, opt_expire); if (rc != MEMCACHED_SUCCESS) { - fprintf(stderr, "memflush: memcache error %s", - memcached_strerror(memc, rc)); - if (memcached_last_error_errno(memc)) - fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); - fprintf(stderr, "\n"); + std::cerr << memcached_last_error_message(memc) << std::endl; } memcached_free(memc); @@ -100,15 +94,11 @@ int main(int argc, char *argv[]) void options_parse(int argc, char *argv[]) { - memcached_programs_help_st help_options[]= - { - {0}, - }; - static struct option long_options[]= { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -118,49 +108,77 @@ void options_parse(int argc, char *argv[]) {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD}, {0, 0, 0, 0}, }; - int option_index= 0; - int option_rv; + bool opt_version= false; + bool opt_help= false; + int option_index= 0; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; switch (option_rv) { case 0: break; + case OPT_BINARY: - opt_binary = 1; + opt_binary= true; break; + case OPT_VERBOSE: /* --verbose or -v */ - opt_verbose = OPT_VERBOSE; + opt_verbose= OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ - opt_verbose = OPT_DEBUG; + opt_verbose= OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_EXPIRE: /* --expire */ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); break; + case OPT_USERNAME: opt_username= optarg; break; + case OPT_PASSWD: opt_passwd= optarg; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ - exit(1); + exit(EXIT_FAILURE); + default: abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, NULL); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memping.cc b/clients/memping.cc index e2253471..bcc07cd3 100644 --- a/clients/memping.cc +++ b/clients/memping.cc @@ -21,7 +21,7 @@ #include -static int opt_binary= 0; +static bool opt_binary= false; static int opt_verbose= 0; static time_t opt_expire= 0; static char *opt_servers= NULL; @@ -88,6 +88,7 @@ void options_parse(int argc, char *argv[]) { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -97,44 +98,61 @@ void options_parse(int argc, char *argv[]) {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD}, {0, 0, 0, 0}, }; - int option_index= 0; - int option_rv; + bool opt_version= false; + bool opt_help= false; + int option_index= 0; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + if (option_rv == -1) break; + switch (option_rv) { case 0: break; + case OPT_BINARY: - opt_binary = 1; + opt_binary= true; break; + case OPT_VERBOSE: /* --verbose or -v */ opt_verbose = OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ opt_verbose = OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ version_command(PROGRAM_NAME); break; + case OPT_HELP: /* --help or -h */ help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_EXPIRE: /* --expire */ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); break; + case OPT_USERNAME: opt_username= optarg; break; + case OPT_PASSWD: opt_passwd= optarg; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ exit(1); @@ -142,4 +160,16 @@ void options_parse(int argc, char *argv[]) abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memrm.cc b/clients/memrm.cc index 73a29de9..cbfcd241 100644 --- a/clients/memrm.cc +++ b/clients/memrm.cc @@ -37,11 +37,8 @@ static void options_parse(int argc, char *argv[]); int main(int argc, char *argv[]) { memcached_st *memc; - memcached_return_t rc; memcached_server_st *servers; - int return_code= 0; - options_parse(argc, argv); initialize_sockets(); @@ -50,7 +47,9 @@ int main(int argc, char *argv[]) char *temp; if ((temp= getenv("MEMCACHED_SERVERS"))) + { opt_servers= strdup(temp); + } else { std::cerr << "No Servers provided" << std::endl; @@ -85,26 +84,39 @@ int main(int argc, char *argv[]) } } + int return_code= EXIT_SUCCESS; + while (optind < argc) { - if (opt_verbose) + memcached_return_t rc= memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire); + + if (rc == MEMCACHED_NOTFOUND) { - std::cout << "key: " << argv[optind] << std::endl; - std::cout << "expires: " << opt_expire << std::endl; + if (opt_verbose) + { + std::cerr << "Could not find key \"" << argv[optind] << "\"" << std::endl; + } } - rc= memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire); - - if (memcached_failed(rc)) + else if (memcached_failed(rc)) { - std::cerr << PROGRAM_NAME << ": " << argv[optind] << ": error " << memcached_strerror(memc, rc) << std::endl; - - if (memcached_last_error_errno(memc)) + if (opt_verbose) { - std::cerr << " system error " << strerror(memcached_last_error_errno(memc)); + std::cerr << "Failed to delete key \"" << argv[optind] << "\" :" << memcached_last_error_message(memc) << std::endl; } - std::cerr << std::endl; - return_code= -1; + return_code= EXIT_FAILURE; + } + else // success + { + if (opt_verbose) + { + std::cout << "Deleted key " << argv[optind]; + if (opt_expire) + { + std::cout << " expires: " << opt_expire << std::endl; + } + std::cout << std::endl; + } } optind++; @@ -113,10 +125,14 @@ int main(int argc, char *argv[]) memcached_free(memc); if (opt_servers) + { free(opt_servers); + } if (opt_hash) + { free(opt_hash); + } return return_code; } @@ -133,6 +149,7 @@ static void options_parse(int argc, char *argv[]) { {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -143,52 +160,86 @@ static void options_parse(int argc, char *argv[]) {(OPTIONSTRING)"password", required_argument, NULL, OPT_PASSWD}, {0, 0, 0, 0}, }; + + bool opt_version= false; + bool opt_help= false; int option_index= 0; - int option_rv; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); - if (option_rv == -1) break; + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + if (option_rv == -1) + { + break; + } + switch (option_rv) { case 0: break; + case OPT_BINARY: opt_binary = 1; break; + case OPT_VERBOSE: /* --verbose or -v */ opt_verbose = OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ opt_verbose = OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_EXPIRE: /* --expire */ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); break; + case OPT_HASH: opt_hash= strdup(optarg); break; + case OPT_USERNAME: opt_username= optarg; break; + case OPT_PASSWD: opt_passwd= optarg; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ - exit(1); + exit(EXIT_SUCCESS); + default: abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + exit(EXIT_SUCCESS); + } } diff --git a/clients/memslap.cc b/clients/memslap.cc index 095cd088..f00ba457 100644 --- a/clients/memslap.cc +++ b/clients/memslap.cc @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -141,7 +142,7 @@ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, unsigned int *actual_loaded); void flush_all(memcached_st *memc); -static int opt_binary= 0; +static bool opt_binary= 0; static int opt_verbose= 0; static int opt_flush= 0; static int opt_non_blocking_io= 0; @@ -360,6 +361,7 @@ void options_parse(int argc, char *argv[]) { {(OPTIONSTRING)"concurrency", required_argument, NULL, OPT_SLAP_CONCURRENCY}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER}, {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG}, {(OPTIONSTRING)"flush", no_argument, &opt_flush, OPT_FLUSH}, @@ -376,13 +378,15 @@ void options_parse(int argc, char *argv[]) {0, 0, 0, 0}, }; + bool opt_help= false; + bool opt_version= false; int option_index= 0; - int option_rv; - while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + int option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + if (option_rv == -1) break; + switch (option_rv) { case 0: @@ -399,11 +403,11 @@ void options_parse(int argc, char *argv[]) break; case OPT_BINARY: - opt_binary = 1; + opt_binary= true; break; case OPT_VERBOSE: /* --verbose or -v */ - opt_verbose = OPT_VERBOSE; + opt_verbose= OPT_VERBOSE; break; case OPT_DEBUG: /* --debug or -d */ @@ -411,11 +415,11 @@ void options_parse(int argc, char *argv[]) break; case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; case OPT_SERVERS: /* --servers or -s */ @@ -423,28 +427,28 @@ void options_parse(int argc, char *argv[]) break; case OPT_SLAP_TEST: - if (!strcmp(optarg, "get")) + if (strcmp(optarg, "get") == 0) { if (opt_udp_io == 1) { fprintf(stderr, "You can not run a get test in UDP mode. UDP mode " "does not currently support get ops.\n"); - exit(1); + exit(EXIT_FAILURE); } opt_test= GET_TEST ; } - else if (!strcmp(optarg, "set")) + else if (strcmp(optarg, "set") == 0) { opt_test= SET_TEST; } - else if (!strcmp(optarg, "mget")) + else if (strcmp(optarg, "mget") == 0) { opt_test= MGET_TEST; } else { fprintf(stderr, "Your test, %s, is not a known test\n", optarg); - exit(1); + exit(EXIT_FAILURE); } break; @@ -460,16 +464,33 @@ void options_parse(int argc, char *argv[]) opt_createial_load= (unsigned int)strtoul(optarg, (char **)NULL, 10); break; + case OPT_QUIET: + close_stdio(); + break; + + case '?': /* getopt_long already printed an error message. */ - exit(1); + exit(EXIT_FAILURE); default: abort(); } } - if ((opt_test == GET_TEST or opt_test == MGET_TEST) && opt_createial_load == 0) + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + exit(EXIT_SUCCESS); + } + + if ((opt_test == GET_TEST or opt_test == MGET_TEST) and opt_createial_load == 0) opt_createial_load= DEFAULT_INITIAL_LOAD; if (opt_execute_number == 0) diff --git a/clients/memstat.cc b/clients/memstat.cc index a3b85108..8036ea18 100644 --- a/clients/memstat.cc +++ b/clients/memstat.cc @@ -11,13 +11,15 @@ * Brian Aker * Toru Maesaka */ -#include "config.h" +#include #include #include #include +#include #include #include +#include #include #include #include @@ -49,6 +51,7 @@ static struct option long_options[]= {(OPTIONSTRING)"args", required_argument, NULL, OPT_STAT_ARGS}, {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"quiet", no_argument, NULL, OPT_QUIET}, {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, @@ -83,17 +86,17 @@ int main(int argc, char *argv[]) options_parse(argc, argv); initialize_sockets(); - if (! opt_servers) + if (opt_servers == false) { char *temp; - if ((temp= getenv("MEMCACHED_SERVERS"))) + { opt_servers= strdup(temp); + } else { - fprintf(stderr, "No Servers provided\n\n"); - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, 0); - exit(1); + std::cerr << "No Servers provided" << std::endl; + return EXIT_FAILURE; } } @@ -307,38 +310,54 @@ static void options_parse(int argc, char *argv[]) }; int option_index= 0; - int option_rv; + bool opt_version= false; + bool opt_help= false; while (1) { - option_rv= getopt_long(argc, argv, "Vhvds:a", long_options, &option_index); - if (option_rv == -1) break; + int option_rv= getopt_long(argc, argv, "Vhvds:a", long_options, &option_index); + + if (option_rv == -1) + break; + switch (option_rv) { case 0: break; + case OPT_VERBOSE: /* --verbose or -v */ opt_verbose = OPT_VERBOSE; break; + case OPT_DEBUG: /* --debug or -d */ opt_verbose = OPT_DEBUG; break; + case OPT_VERSION: /* --version or -V */ - version_command(PROGRAM_NAME); + opt_version= true; break; + case OPT_HELP: /* --help or -h */ - help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + opt_help= true; break; + case OPT_SERVERS: /* --servers or -s */ opt_servers= strdup(optarg); break; + case OPT_STAT_ARGS: stat_args= strdup(optarg); break; + case OPT_ANALYZE: /* --analyze or -a */ opt_analyze= OPT_ANALYZE; analyze_mode= (optarg) ? strdup(optarg) : NULL; break; + + case OPT_QUIET: + close_stdio(); + break; + case '?': /* getopt_long already printed an error message. */ exit(1); @@ -346,4 +365,16 @@ static void options_parse(int argc, char *argv[]) abort(); } } + + if (opt_version) + { + version_command(PROGRAM_NAME); + exit(EXIT_SUCCESS); + } + + if (opt_help) + { + help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options); + exit(EXIT_SUCCESS); + } } diff --git a/clients/utilities.cc b/clients/utilities.cc index 97c30783..4dfc15bb 100644 --- a/clients/utilities.cc +++ b/clients/utilities.cc @@ -8,12 +8,18 @@ * Summary: * */ -#include "config.h" +#include #include + #include +#include #include #include +#include +#include +#include +#include long int timedif(struct timeval a, struct timeval b) @@ -30,9 +36,41 @@ long int timedif(struct timeval a, struct timeval b) void version_command(const char *command_name) { printf("%s v%u.%u\n", command_name, 1U, 0U); - exit(0); + exit(EXIT_SUCCESS); } +void close_stdio(void) +{ + int fd; + if ((fd = open("/dev/null", O_RDWR, 0)) < 0) + { + return; + } + else + { + if (dup2(fd, STDIN_FILENO) < 0) + { + return; + } + + if (dup2(fd, STDOUT_FILENO) < 0) + { + return; + } + + if (dup2(fd, STDERR_FILENO) < 0) + { + return; + } + + if (fd > STDERR_FILENO) + { + close(fd); + } + } +} + + static const char *lookup_help(memcached_options option) { switch (option) @@ -41,6 +79,7 @@ static const char *lookup_help(memcached_options option) case OPT_VERSION: return("Display the version of the application and then exit."); case OPT_HELP: return("Display this message and then exit."); case OPT_VERBOSE: return("Give more details on the progression of the application."); + case OPT_QUIET: return("stderr and stdin will be closed at application startup."); case OPT_DEBUG: return("Provide output only useful for debugging."); case OPT_FLAG: return("Provide flag information for storage operation."); case OPT_EXPIRE: return("Set the expire option for the object."); @@ -91,7 +130,7 @@ void help_command(const char *command_name, const char *description, } printf("\n"); - exit(0); + exit(EXIT_SUCCESS); } void process_hash_option(memcached_st *memc, char *opt_hash) @@ -116,14 +155,14 @@ void process_hash_option(memcached_st *memc, char *opt_hash) else { fprintf(stderr, "hash: type not recognized %s\n", opt_hash); - exit(1); + exit(EXIT_FAILURE); } rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); if (rc != MEMCACHED_SUCCESS) { fprintf(stderr, "hash: memcache error %s\n", memcached_strerror(memc, rc)); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/clients/utilities.h b/clients/utilities.h index 685be6a5..0bac61a7 100644 --- a/clients/utilities.h +++ b/clients/utilities.h @@ -58,6 +58,7 @@ void process_hash_option(memcached_st *memc, char *opt_hash); bool initialize_sasl(memcached_st *memc, char *user, char *password); void shutdown_sasl(void); void initialize_sockets(void); +void close_stdio(void); #ifdef __cplusplus } // extern "C" diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index ea3b6025..7348dabe 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -56,7 +56,6 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, const char *key, size_t key_length, time_t expiration) { - bool to_write; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; memcached_server_write_instance_st instance; @@ -80,7 +79,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); instance= memcached_server_instance_fetch(ptr, server_key); - to_write= (ptr->flags.buffer_requests) ? false : true; + bool to_write= (ptr->flags.buffer_requests) ? false : true; bool no_reply= (ptr->flags.no_reply); @@ -120,7 +119,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, if (instance->minor_version == 0) { - if (no_reply || ! to_write) + if (no_reply or to_write == false) { /* We might get out of sync with the server if we * send this command to a server newer than 1.2.x.. @@ -155,7 +154,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, goto error; } - if (ptr->flags.use_udp && ! to_write) + if (ptr->flags.use_udp and to_write == false) { if (send_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH) return MEMCACHED_WRITE_FAILURE; @@ -170,21 +169,27 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, } if (rc != MEMCACHED_SUCCESS) + { goto error; + } - if (! to_write) + if (to_write == false) { rc= MEMCACHED_BUFFERED; } - else if (!no_reply) + else if (no_reply == false) { rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); if (rc == MEMCACHED_DELETED) + { rc= MEMCACHED_SUCCESS; + } } - if (rc == MEMCACHED_SUCCESS && ptr->delete_trigger) + if (rc == MEMCACHED_SUCCESS and ptr->delete_trigger) + { ptr->delete_trigger(ptr, key, key_length); + } error: LIBMEMCACHED_MEMCACHED_DELETE_END(); diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index ef4a0ce3..dcbe15b8 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -6,25 +6,21 @@ all slabs on servers and "grab" the keys. */ -#include "common.h" +#include + static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) { memcached_return_t rc= MEMCACHED_SUCCESS; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - uint32_t server_key; - uint32_t x; - - unlikely (memcached_server_count(ptr) == 0) - return MEMCACHED_NO_SERVERS; - for (server_key= 0; server_key < memcached_server_count(ptr); server_key++) + for (uint32_t server_key= 0; server_key < memcached_server_count(ptr); server_key++) { memcached_server_write_instance_st instance; instance= memcached_server_instance_fetch(ptr, server_key); /* 256 I BELIEVE is the upper limit of slabs */ - for (x= 0; x < 256; x++) + for (uint32_t x= 0; x < 256; x++) { + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; int send_length; send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats cachedump %u 0 0\r\n", x); @@ -37,8 +33,10 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb rc= memcached_do(instance, buffer, (size_t)send_length, true); - unlikely (rc != MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) + { goto error; + } while (1) { @@ -48,23 +46,29 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb if (rc == MEMCACHED_ITEM) { char *string_ptr, *end_ptr; - char *key; string_ptr= buffer; string_ptr+= 5; /* Move past ITEM */ + for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {} ; - key= string_ptr; + + char *key= string_ptr; key[(size_t)(end_ptr-string_ptr)]= 0; + for (callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++) { rc= (*callback[callback_counter])(ptr, key, (size_t)(end_ptr-string_ptr), context); if (rc != MEMCACHED_SUCCESS) + { break; + } } } else if (rc == MEMCACHED_END) + { break; - else if (rc == MEMCACHED_SERVER_ERROR || rc == MEMCACHED_CLIENT_ERROR) + } + else if (rc == MEMCACHED_SERVER_ERROR or rc == MEMCACHED_CLIENT_ERROR) { /* If we try to request stats cachedump for a slab class that is too big * the server will return an incorrect error message: @@ -77,16 +81,22 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb break; } else + { goto error; + } } } } error: if (rc == MEMCACHED_END) + { return MEMCACHED_SUCCESS; + } else + { return rc; + } } memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) @@ -102,7 +112,9 @@ memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback @todo Fix this so that we just flush, switch to ascii, and then go back to binary. */ if (ptr->flags.binary_protocol) + { return MEMCACHED_FAILURE; + } return ascii_dump(ptr, callback, context, number_of_callbacks); } diff --git a/libmemcached/return.h b/libmemcached/return.h index 378194fd..fa36243f 100644 --- a/libmemcached/return.h +++ b/libmemcached/return.h @@ -115,4 +115,15 @@ static inline bool memcached_failed(memcached_return_t rc) rc != MEMCACHED_VALUE); } +static inline bool memcached_fatal(memcached_return_t rc) +{ + return (rc != MEMCACHED_SUCCESS && + rc != MEMCACHED_END && + rc != MEMCACHED_STORED && + rc != MEMCACHED_STAT && + rc != MEMCACHED_DELETED && + rc != MEMCACHED_BUFFERED && + rc != MEMCACHED_VALUE); +} + #define memcached_continue(__memcached_return_t) ((__memcached_return_t) == MEMCACHED_IN_PROGRESS) diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 421fa006..4dc84c9d 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -35,10 +35,10 @@ bool exec_cmdline(const std::string& executable, const char *args[]) arg_buffer << libtool(); - if (getenv("LIBTEST_TEST_ENVIRONMENT")) + if (getenv("PWD")) { - arg_buffer << getenv("LIBTEST_TEST_ENVIRONMENT"); - arg_buffer << " "; + arg_buffer << getenv("PWD"); + arg_buffer << "/"; } arg_buffer << executable; @@ -47,14 +47,9 @@ bool exec_cmdline(const std::string& executable, const char *args[]) arg_buffer << " " << *ptr; } - if (getenv("LIBTEST_TEST_ENVIRONMENT")) - { - std::cerr << std::endl << arg_buffer.str() << std::endl; - } - else - { +#if 0 arg_buffer << " > /dev/null 2>&1"; - } +#endif if (system(arg_buffer.str().c_str()) == -1) { diff --git a/libtest/test.cc b/libtest/test.cc index 432d8417..80cb8ddd 100644 --- a/libtest/test.cc +++ b/libtest/test.cc @@ -150,7 +150,10 @@ int main(int argc, char *argv[]) } else if (getenv("TEST_COLLECTION")) { - collection_to_run= getenv("TEST_COLLECTION"); + if (strlen(getenv("TEST_COLLECTION"))) + { + collection_to_run= getenv("TEST_COLLECTION"); + } } if (collection_to_run) diff --git a/libtest/test.h b/libtest/test.h index e92d9e23..0f1e1e0a 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -148,6 +148,8 @@ do \ } \ } while (0) +#define test_null test_zero + #define test_compare_got(__expected, __actual, __hint) \ do \ { \ diff --git a/tests/include.am b/tests/include.am index 41cf16df..2bbe5802 100644 --- a/tests/include.am +++ b/tests/include.am @@ -174,12 +174,61 @@ tests_memcapable_LDADD= $(tests_memcapable_DEPENDENCIES) check_PROGRAMS+= tests/memcapable noinst_PROGRAMS+= tests/memcapable +tests_memstat_SOURCES= tests/memstat.cc +tests_memstat_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memstat_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memstat_LDADD= $(tests_memstat_DEPENDENCIES) +check_PROGRAMS+= tests/memstat +noinst_PROGRAMS+= tests/memstat + +tests_memcp_SOURCES= tests/memcp.cc +tests_memcp_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memcp_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memcp_LDADD= $(tests_memcp_DEPENDENCIES) +check_PROGRAMS+= tests/memcp +noinst_PROGRAMS+= tests/memcp + +tests_memflush_SOURCES= tests/memflush.cc +tests_memflush_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memflush_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memflush_LDADD= $(tests_memflush_DEPENDENCIES) +check_PROGRAMS+= tests/memflush +noinst_PROGRAMS+= tests/memflush + +tests_memrm_SOURCES= tests/memrm.cc +tests_memrm_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memrm_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memrm_LDADD= $(tests_memrm_DEPENDENCIES) +check_PROGRAMS+= tests/memrm +noinst_PROGRAMS+= tests/memrm + +tests_memcat_SOURCES= tests/memcat.cc +tests_memcat_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memcat_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memcat_LDADD= $(tests_memcat_DEPENDENCIES) +check_PROGRAMS+= tests/memcat +noinst_PROGRAMS+= tests/memcat + +tests_memerror_SOURCES= tests/memerror.cc +tests_memerror_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memerror_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memerror_LDADD= $(tests_memerror_DEPENDENCIES) +check_PROGRAMS+= tests/memerror +noinst_PROGRAMS+= tests/memerror + tests_memslap_SOURCES= tests/memslap.cc tests_memslap_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) tests_memslap_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) tests_memslap_LDADD= $(tests_memslap_DEPENDENCIES) check_PROGRAMS+= tests/memslap noinst_PROGRAMS+= tests/memslap + +tests_memdump_SOURCES= tests/memdump.cc +tests_memdump_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_memdump_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS) +tests_memdump_LDADD= $(tests_memdump_DEPENDENCIES) +check_PROGRAMS+= tests/memdump +noinst_PROGRAMS+= tests/memdump # Test linking with C application tests_c_test_SOURCES= tests/c_test.c @@ -200,31 +249,9 @@ test: check check-local: $(TEST_DOCS) @echo "Tests completed" -test-x: test-plus test-memcat test-memcp test-memrm test-memerror test-memdump test-memflush test-memstat +test-x: test-plus test-memcp test-memdump test-memflush test-memstat @echo "Tests completed" -test-memcat: clients/memcat clients/memcp - @echo "Testing memcat" - @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 - @clients/memcp --servers="localhost:12555" `pwd`/clients/memcp - @clients/memcat --servers="localhost:12555" memcp > `pwd`/tests/scratch - @clients/memcat --servers="localhost:12555" --file=`pwd`/tests/scratch2 memcp -# @diff clients/memcp tests/scratch - @cat `pwd`/tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" - @rm `pwd`/tests/Xumemc.pid - @rm `pwd`/tests/scratch - @rm `pwd`/tests/scratch2 - -valgrind-memcat: clients/memcat clients/memcp - @echo "Testing memcat" - @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 - @clients/memcp --servers="localhost:12555" clients/memcp - @$(VALGRIND_COMMAND) clients/memcat --servers="localhost:12555" memcp > tests/scratch -# @diff clients/memcp tests/scratch - @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" - @rm tests/Xumemc.pid - @rm tests/scratch - test-memcp: clients/memcp @echo "Testing memcp" @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 @@ -239,22 +266,6 @@ valgrind-memcp: clients/memcat clients/memcp @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" @rm tests/Xumemc.pid -test-memrm: clients/memrm clients/memcp - @echo "Testing memrm" - @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 - @clients/memcp --servers="localhost:12555" clients/memcat - @clients/memrm --servers="localhost:12555" memcat - @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" - @rm tests/Xumemc.pid - -valgrind-memrm: clients/memcat clients/memcp - @echo "Testing memrm" - @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 - @clients/memcp --servers="localhost:12555" clients/memcat - @$(VALGRIND_COMMAND) clients/memrm --servers="localhost:12555" memcat - @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" - @rm tests/Xumemc.pid - test-memflush: clients/memflush @echo "Testing memflush" @$(MEMC_BINARY) -d -u root -P `pwd`/tests/Xumemc.pid -p 12555 @@ -299,14 +310,6 @@ valgrind-memstat: clients/memstat @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" @rm tests/Xumemc.pid -test-memerror: clients/memerror - @echo "Testing memerror" - @clients/memerror 0 > /dev/null - -valgrind-memerror: clients/memerror - @echo "Testing memerror" - @$(VALGRIND_COMMAND) clients/memerror 0 > /dev/null - test-mem: tests/var tests/testapp @tests/testapp diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 46466821..b56c47bc 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -821,10 +821,11 @@ static test_return_t bad_key_test(memcached_st *memc) memcached_st *memc_clone; size_t max_keylen= 0xffff; - // Just skip if we are in binary mode. uint64_t query_id= memcached_query_id(memc); - if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) - return TEST_SKIPPED; + + // Just skip if we are in binary mode. + test_skip(false, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); + test_compare(query_id, memcached_query_id(memc)); // We should not increase the query_id for memcached_behavior_get() memc_clone= memcached_clone(NULL, memc); @@ -890,20 +891,16 @@ static test_return_t bad_key_test(memcached_st *memc) std::vector longkey; longkey.insert(longkey.end(), max_keylen +1, 'a'); - if (longkey.size()) + test_compare(longkey.size(), max_keylen +1); { size_t string_length; - char *string= memcached_get(memc_clone, &longkey[0], max_keylen, - &string_length, &flags, &rc); + test_null(memcached_get(memc_clone, &longkey[0], max_keylen, &string_length, &flags, &rc)); test_compare(MEMCACHED_NOTFOUND, rc); test_zero(string_length); - test_false(string); - string= memcached_get(memc_clone, &longkey[0], max_keylen +1, - &string_length, &flags, &rc); + test_null(memcached_get(memc_clone, &longkey[0], max_keylen +1, &string_length, &flags, &rc)); test_compare(MEMCACHED_BAD_KEY_PROVIDED, rc); test_zero(string_length); - test_false(string); } } diff --git a/tests/memcapable.cc b/tests/memcapable.cc index 7adf7635..60fd00ad 100644 --- a/tests/memcapable.cc +++ b/tests/memcapable.cc @@ -52,11 +52,17 @@ using namespace libtest; static std::string executable; +static test_return_t quiet_test(void *) +{ + const char *args[]= { "-q", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + static test_return_t help_test(void *) { - char buffer[1024]; - snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); - const char *args[]= { buffer, "--help", 0 }; + const char *args[]= { "-q", "--help", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -66,7 +72,7 @@ static test_return_t ascii_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); - const char *args[]= { buffer, " -a ", 0 }; + const char *args[]= { "-q", buffer, " -a ", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -76,13 +82,14 @@ static test_return_t binary_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); - const char *args[]= { buffer, " -b ", 0 }; + const char *args[]= { "-q", buffer, " -b ", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; } test_st memcapable_tests[] ={ + {"--quiet", 0, quiet_test}, {"--help", 0, help_test}, {"-a, ascii", 0, ascii_test}, {"-b, binary", 0, binary_test}, diff --git a/tests/memcat.cc b/tests/memcat.cc new file mode 100644 index 00000000..e8ed3efc --- /dev/null +++ b/tests/memcat.cc @@ -0,0 +1,159 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memcat + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--quiet", "--help", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t cat_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, "foo", 0 }; + + memcached_st *memc= memcached(buffer, strlen(buffer)); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0)); + + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_SUCCESS, rc); + + test_true(exec_cmdline(executable, args)); + + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_SUCCESS, rc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +static test_return_t NOT_FOUND_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, "foo", 0 }; + + memcached_st *memc= memcached(buffer, strlen(buffer)); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); + + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + test_true(exec_cmdline(executable, args)); + + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_st memcat_tests[] ={ + {"--quiet", true, quiet_test }, + {"--help", true, help_test }, + {"cat(FOUND)", true, cat_test }, + {"cat(NOT_FOUND)", true, NOT_FOUND_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memcat", 0, 0, memcat_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memcat" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "clients/memcat"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memcp.cc b/tests/memcp.cc new file mode 100644 index 00000000..c22c4db7 --- /dev/null +++ b/tests/memcp.cc @@ -0,0 +1,117 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memcp + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--quiet", "--help", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t server_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +test_st memcp_tests[] ={ + {"--quiet", true, quiet_test }, + {"--help", true, help_test }, + {"--server_test", true, server_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memcp", 0, 0, memcp_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memcp" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memcp"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memdump.cc b/tests/memdump.cc new file mode 100644 index 00000000..6e5a2aed --- /dev/null +++ b/tests/memdump.cc @@ -0,0 +1,144 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memdump + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--help", "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t server_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { buffer, 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t FOUND_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, 0 }; + + memcached_st *memc= memcached(buffer, strlen(buffer)); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0)); + + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, test_literal_param("foo2"), 0, 0, 0, 0)); + + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_SUCCESS, rc); + + test_true(exec_cmdline(executable, args)); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_st memdump_tests[] ={ + {"--quiet", true, quiet_test }, + {"--help", true, help_test }, + {"--server", true, server_test }, + {"FOUND", true, FOUND_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memdump", 0, 0, memdump_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memdump" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memdump"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memerror.cc b/tests/memerror.cc new file mode 100644 index 00000000..88ddcbad --- /dev/null +++ b/tests/memerror.cc @@ -0,0 +1,112 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memerror + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--quiet", "--help", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t error_test(void *) +{ + const char *args[]= { "--quiet", "MEMCACHED_SUCCESS", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t bad_input_test(void *) +{ + const char *args[]= { "--quiet", "bad input", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +test_st memerror_tests[] ={ + {"--quiet", 0, quiet_test}, + {"--help", 0, help_test}, + {"", 0, error_test}, + {"", 0, bad_input_test}, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memerror", 0, 0, memerror_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st&, test_return_t&) +{ + return NULL; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memerror"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memflush.cc b/tests/memflush.cc new file mode 100644 index 00000000..8f91356c --- /dev/null +++ b/tests/memflush.cc @@ -0,0 +1,117 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memflush + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--quiet", "--help", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t server_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +test_st memflush_tests[] ={ + {"--quiet", true, quiet_test }, + {"--help", true, help_test }, + {"--server", true, server_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memflush", 0, 0, memflush_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memflush" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memflush"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memrm.cc b/tests/memrm.cc new file mode 100644 index 00000000..bf2dc86a --- /dev/null +++ b/tests/memrm.cc @@ -0,0 +1,157 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memrm + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t help_test(void *) +{ + const char *args[]= { "--quiet", "--help", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t rm_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, "foo", 0 }; + + memcached_st *memc= memcached(buffer, strlen(buffer)); + test_true(memc); + + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0)); + + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_SUCCESS, rc); + + test_true(exec_cmdline(executable, args)); + + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +static test_return_t NOT_FOUND_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port())); + const char *args[]= { "--quiet", buffer, "foo", 0 }; + + memcached_st *memc= memcached(buffer, strlen(buffer)); + test_true(memc); + + memcached_return_t rc; + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + test_true(exec_cmdline(executable, args)); + + test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc)); + test_compare(MEMCACHED_NOTFOUND, rc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_st memrm_tests[] ={ + {"--quiet", true, quiet_test }, + {"--help", true, help_test }, + {"rm(FOUND)", true, rm_test }, + {"rm(NOT_FOUND)", true, NOT_FOUND_test }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memrm", 0, 0, memrm_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memrm" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memrm"; + world->collections= collection; + world->_create= world_create; +} + diff --git a/tests/memslap.cc b/tests/memslap.cc index 5063c559..229a920c 100644 --- a/tests/memslap.cc +++ b/tests/memslap.cc @@ -52,9 +52,17 @@ using namespace libtest; static std::string executable; +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + static test_return_t help_test(void *) { - const char *args[]= { "--help", 0 }; + const char *args[]= { "--quiet", "--help", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -64,7 +72,7 @@ static test_return_t server_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, 0 }; + const char *args[]= { "--quiet", buffer, 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -74,7 +82,7 @@ static test_return_t server_concurrency_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -84,7 +92,7 @@ static test_return_t server_concurrency_initial_load_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", "--initial-load=1000", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", "--initial-load=1000", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -94,7 +102,7 @@ static test_return_t server_concurrency_initial_load_execute_number_test(void *) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -104,7 +112,7 @@ static test_return_t server_concurrency_initial_load_execute_number_test_get_tes { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=get", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=get", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -114,7 +122,7 @@ static test_return_t server_concurrency_initial_load_execute_number_test_set_tes { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=set", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=set", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; @@ -124,13 +132,14 @@ static test_return_t server_concurrency_initial_load_execute_number_test_set_non { char buffer[1024]; snprintf(buffer, sizeof(buffer), "--servers=localhost:%d", int(default_port())); - const char *args[]= { buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=set", "--non-blocking", 0 }; + const char *args[]= { "--quiet", buffer, "--concurrency=10", "--initial-load=1000", "--execute-number=10", "--test=set", "--non-blocking", 0 }; test_true(exec_cmdline(executable, args)); return TEST_SUCCESS; } test_st memslap_tests[] ={ + {"--quiet", true, quiet_test }, {"--help", true, help_test }, {"--server_test", true, server_test }, {"--concurrency=10", true, server_concurrency_test }, diff --git a/tests/memstat.cc b/tests/memstat.cc new file mode 100644 index 00000000..44bc77aa --- /dev/null +++ b/tests/memstat.cc @@ -0,0 +1,130 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Test memstat + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* + Test that we are cycling the servers we are creating during testing. +*/ + +#include + +#include +#include + +using namespace libtest; + +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + +static std::string executable; + +static test_return_t quiet_test(void *) +{ + const char *args[]= { "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + + +static test_return_t help_test(void *) +{ + const char *args[]= { "--help", "--quiet", 0 }; + + test_true(exec_cmdline(executable, args)); + + return TEST_SUCCESS; +} + +static test_return_t ascii_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); + const char *args[]= { "--quiet", buffer, " -a ", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +static test_return_t binary_test(void *) +{ + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "-p %d", int(default_port())); + const char *args[]= { "--quiet", buffer, " -b ", 0 }; + + test_true(exec_cmdline(executable, args)); + return TEST_SUCCESS; +} + +test_st memstat_tests[] ={ + {"--quiet", 0, quiet_test}, + {"--help", 0, help_test}, + {"-a, ascii", 0, ascii_test}, + {"-b, binary", 0, binary_test}, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memstat", 0, 0, memstat_tests }, + {0, 0, 0, 0} +}; + +static void *world_create(server_startup_st& servers, test_return_t& error) +{ + if (HAVE_MEMCACHED_BINARY == 0) + { + error= TEST_FATAL; + return NULL; + } + + const char *argv[1]= { "memstat" }; + if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv)) + { + error= TEST_FAILURE; + } + + return &servers; +} + + +void get_world(Framework *world) +{ + executable= "./clients/memstat"; + world->collections= collection; + world->_create= world_create; +} +