From: Brian Aker Date: Thu, 14 Jan 2010 21:37:53 +0000 (-0800) Subject: Added more test cases for command line applications. X-Git-Tag: 0.40~103 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3ddd6cf2902491eab9d6ecf6e30b0b324c7a6f1f;p=m6w6%2Flibmemcached Added more test cases for command line applications. --- diff --git a/clients/memcat.c b/clients/memcat.c index 2f46ee90..f5f7f8f9 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -41,6 +41,8 @@ int main(int argc, char *argv[]) memcached_return_t rc; memcached_server_st *servers; + int return_code= 0; + options_parse(argc, argv); if (!opt_servers) @@ -94,6 +96,14 @@ int main(int argc, char *argv[]) if (memc->cached_errno) fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); + + return_code= -1; + break; + } + else // Unknown Issue + { + fprintf(stderr, "memcat: %s not found\n", argv[optind]); + return_code= -1; } optind++; } @@ -105,7 +115,7 @@ int main(int argc, char *argv[]) if (opt_hash) free(opt_hash); - return 0; + return return_code; } diff --git a/clients/memcp.c b/clients/memcp.c index 1a3307cf..dd8aba9a 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -75,6 +75,8 @@ int main(int argc, char *argv[]) memcached_return_t rc; memcached_server_st *servers; + int return_code= 0; + options_parse(argc, argv); memc= memcached_create(NULL); @@ -176,6 +178,8 @@ int main(int argc, char *argv[]) if (memc->cached_errno) fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); + + return_code= -1; } free(file_buffer_ptr); @@ -190,7 +194,7 @@ int main(int argc, char *argv[]) if (opt_hash) free(opt_hash); - return 0; + return return_code; } static void options_parse(int argc, char *argv[]) diff --git a/clients/memerror.c b/clients/memerror.c index 84882520..286ef0e1 100644 --- a/clients/memerror.c +++ b/clients/memerror.c @@ -37,9 +37,9 @@ int main(int argc, char *argv[]) if (argc != 2) return 1; - value= strtol(argv[1], (char **) NULL, 10); + value= strtoul(argv[1], (char **) NULL, 10); - if (value >= MEMCACHED_SUCCESS && value < MEMCACHED_MAXIMUM_RETURN) + if (value < MEMCACHED_MAXIMUM_RETURN) { printf("%s\n", memcached_strerror(NULL, (memcached_return_t)value)); } diff --git a/clients/memrm.c b/clients/memrm.c index 0f6ad453..81c5f852 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -36,6 +36,8 @@ int main(int argc, char *argv[]) memcached_return_t rc; memcached_server_st *servers; + int return_code= 0; + options_parse(argc, argv); if (!opt_servers) @@ -73,6 +75,8 @@ int main(int argc, char *argv[]) if (memc->cached_errno) fprintf(stderr, " system error %s", strerror(memc->cached_errno)); fprintf(stderr, "\n"); + + return_code= -1; } optind++; @@ -85,7 +89,7 @@ int main(int argc, char *argv[]) if (opt_hash) free(opt_hash); - return 0; + return return_code; } diff --git a/docs/memcat.pod b/docs/memcat.pod index c5ef808b..12947c67 100644 --- a/docs/memcat.pod +++ b/docs/memcat.pod @@ -9,7 +9,7 @@ memcat - Copy a set of keys to stdout =head1 DESCRIPTION B outputs to stdout the value a single or mutiple set of keys -stored in a memcached(1) server. +stored in a memcached(1) server. If any key is not found an error is returned. It is similar to the standard UNIX cat(1) utility. diff --git a/tests/include.am b/tests/include.am index 1f66d701..db6f23f6 100644 --- a/tests/include.am +++ b/tests/include.am @@ -75,38 +75,120 @@ tests_testhashkit_SOURCES = tests/hashkit_functions.c tests_testhashkit_LDADD = tests/libtest.la libhashkit/libhashkit.la tests_testhashkit_DEPENDENCIES = $(tests_testhashkit_LDADD) -client-record: - sh tests/t/memcat.test > tests/r/memcat.res - sh tests/t/memcp.test > tests/r/memcp.res - sh tests/t/memrm.test > tests/r/memrm.res - sh tests/t/memslap.test > tests/r/memslap.res - sh tests/t/memstat.test > tests/r/memstat.res - -test: test-docs test-mem test-plus test-hash memcapable +test: test-docs test-plus test-mem test-hash memcapable test-memcat test-memcp test-memrm test-memerror test-memdump test-memflush test-memstat echo "Tests completed" memcapable: clients/memcapable - @MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 + @@MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 @clients/memcapable -p 12555 || echo "Your memcached server does not support all commands" @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" @rm tests/Xumemc.pid -PHONY += clients -clients: - @MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 - export MEMCACHED_SERVERS="localhost:12555" - sh tests/t/memcat.test > tests/r/memcat.cmp - diff tests/r/memcat.res tests/r/memcat.cmp - sh tests/t/memcp.test > tests/r/memcp.cmp - diff tests/r/memcp.res tests/r/memcp.cmp - sh tests/t/memrm.test > tests/r/memrm.cmp - diff tests/r/memrm.res tests/r/memrm.cmp - sh tests/t/memslap.test > tests/r/memslap.cmp - diff tests/r/memslap.res tests/r/memslap.cmp - sh tests/t/memstat.test > tests/r/memstat.cmp - diff tests/r/memstat.res tests/r/memstat.cmp - cat tests/Xumemc.pid | xargs kill - rm tests/Xumemc.pid +test-memcat: clients/memcat clients/memcp + @echo "Testing memcat" + @@MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memcp --servers="localhost:12555" clients/memcp + @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 + +valgrind-memcat: clients/memcat clients/memcp + @echo "Testing memcat" + @@MEMC_BINARY@ -d -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 -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +valgrind-memcp: clients/memcat clients/memcp + @echo "Testing memcp" + @@MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 + @$(VALGRIND_COMMAND) clients/memcp --servers="localhost:12555" clients/memcp clients/memcat clients/memstat + @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 -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 -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" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memflush --servers="localhost:12555" + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +valgrind-memflush: clients/memflush + @echo "Testing memflush" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @$(VALGRIND_COMMAND) clients/memflush --servers="localhost:12555" + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +test-memdump: clients/memdump clients/memcp + @echo "Testing memdump" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memcp --servers="localhost:12555" clients/memcat + @clients/memdump --servers="localhost:12555" > /dev/null + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +valgrind-memdump: clients/memcat clients/memcp + @echo "Testing memdump" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memcp --servers="localhost:12555" clients/memcat + @$(VALGRIND_COMMAND) clients/memdump --servers="localhost:12555" > /dev/null + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +test-memstat: clients/memstat + @echo "Testing memstat" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @clients/memstat --servers="localhost:12555" > /dev/null + @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" + @rm tests/Xumemc.pid + +valgrind-memstat: clients/memstat + @echo "Testing memstat" + @/usr/local/bin/memcached -d -P `pwd`/tests/Xumemc.pid -p 12555 + @$(VALGRIND_COMMAND) clients/memstat --servers="localhost:12555" > /dev/null + @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 + + + + MEMSLAP_COMMAND= clients/memslap $(COLLECTION) $(SUITE) @@ -161,7 +243,7 @@ valgrind-memslap: clients/memslap $(VALGRIND_COMMAND) $(MEMSLAP_COMMAND) PHONY += valgrind -valgrind: tests/testapp tests/testhashkit valgrind-mem valgrind-hash +valgrind: tests/testapp tests/testhashkit valgrind-mem valgrind-hash valgrind-memcat valgrind-memcp valgrind-memrm valgrind-memerror valgrind-memdump valgrind-memflush valgrind-memstat PHONY += cachegrind CLEANFILES += tests/cachegrind.out