tests/var/
tmp_chroot
unittests/unittests
+tests/memerror
+tests/memcp
+tests/memdump
+tests/memflush
+tests/memrm
+tests/memstat
+tests/memcat
*
*/
-#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',
OPT_USERNAME,
OPT_PASSWD,
OPT_STAT_ARGS,
+ OPT_QUIET,
OPT_FILE= 'f'
-} memcached_options;
-
-#endif /* CLIENT_OPTIONS */
+};
*
*/
-#include "config.h"
+#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <stdint.h>
-#include <string.h>
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <unistd.h>
#include "generator.h"
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)
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;
}
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);
}
- 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)
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"
{
{(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},
case OPT_FILE:
opt_file= optarg;
break;
+
+ case OPT_QUIET:
+ close_stdio();
+ break;
+
case '?':
/* getopt_long already printed an error message. */
exit(1);
/* 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;
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;
}
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);
}
}
+ 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)
{
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)
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,
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);
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},
{
{(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},
{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;
fprintf(stderr, "Bad value passed via --flag\n");
exit(1);
}
- break;
}
+ break;
+
case OPT_EXPIRE: /* --expire */
{
bool strtol_error;
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);
+ }
}
/* 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;
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);
}
}
- 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},
{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;
{
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);
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);
+ }
}
*/
#include "config.h"
-#include <stdio.h>
#include <inttypes.h>
-#include <string.h>
-#include <unistd.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <getopt.h>
-#include <stdlib.h>
+#include <iostream>
+#include <unistd.h>
+
#include <libmemcached/memcached.h>
#include "utilities.h"
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;
}
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);
+ }
}
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,
}
}
- 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);
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},
{(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);
+ }
}
#include <iostream>
-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;
{
{(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},
{(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);
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);
+ }
}
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();
char *temp;
if ((temp= getenv("MEMCACHED_SERVERS")))
+ {
opt_servers= strdup(temp);
+ }
else
{
std::cerr << "No Servers provided" << std::endl;
}
}
+ 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++;
memcached_free(memc);
if (opt_servers)
+ {
free(opt_servers);
+ }
if (opt_hash)
+ {
free(opt_hash);
+ }
return return_code;
}
{
{(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},
{(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);
+ }
}
#include <sys/time.h>
#include <sys/types.h>
#include <sys/types.h>
+#include <unistd.h>
#include <libmemcached/memcached.h>
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;
{
{(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},
{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:
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 */
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 */
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;
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)
* Brian Aker
* Toru Maesaka
*/
-#include "config.h"
+#include <config.h>
#include <cstdio>
#include <cstring>
#include <ctime>
+#include <iostream>
#include <fcntl.h>
#include <getopt.h>
+#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
{(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},
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;
}
}
};
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);
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);
+ }
}
* Summary:
*
*/
-#include "config.h"
+#include <config.h>
#include <clients/utilities.h>
+
#include <cstdio>
+#include <cstdlib>
#include <cstring>
#include <ctype.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
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)
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.");
}
printf("\n");
- exit(0);
+ exit(EXIT_SUCCESS);
}
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);
}
}
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"
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;
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);
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..
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;
}
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();
all slabs on servers and "grab" the keys.
*/
-#include "common.h"
+#include <libmemcached/common.h>
+
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);
rc= memcached_do(instance, buffer, (size_t)send_length, true);
- unlikely (rc != MEMCACHED_SUCCESS)
+ if (rc != MEMCACHED_SUCCESS)
+ {
goto error;
+ }
while (1)
{
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:
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)
@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);
}
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)
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;
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)
{
}
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)
} \
} while (0)
+#define test_null test_zero
+
#define test_compare_got(__expected, __actual, __hint) \
do \
{ \
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
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
@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
@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
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);
std::vector <char> 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);
}
}
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;
{
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;
{
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},
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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},
+ {"<error>", 0, error_test},
+ {"<bad input>", 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;
+}
+
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+
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;
{
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;
{
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;
{
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;
{
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;
{
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;
{
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;
{
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 },
--- /dev/null
+/* 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+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;
+}
+