Added more test cases for command line applications.
authorBrian Aker <brian@gaz>
Thu, 14 Jan 2010 21:37:53 +0000 (13:37 -0800)
committerBrian Aker <brian@gaz>
Thu, 14 Jan 2010 21:37:53 +0000 (13:37 -0800)
clients/memcat.c
clients/memcp.c
clients/memerror.c
clients/memrm.c
docs/memcat.pod
tests/include.am

index 2f46ee901792a7e119dae7be714edf8884c1b4ca..f5f7f8f911d28b2bd5cf4dfeca5c4690e34af021 100644 (file)
@@ -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;
 }
 
 
index 1a3307cf2965616e49acd462dd047d7201429bc2..dd8aba9ac907e9001d6e823374e7cf498520af8f 100644 (file)
@@ -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[])
index 84882520d7fe2879e5adeb69f7c7978d509cc8a2..286ef0e142b6630193b6a96b88032268d8bc6ea9 100644 (file)
@@ -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));
   }
index 0f6ad4537449659371d164a3bab3a844a7c50849..81c5f852bd21a992e718b86acb44e7c6203694c6 100644 (file)
@@ -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;
 }
 
 
index c5ef808b17136b0fd128fca8cba05eddfe68889e..12947c671c99765e64f75b0c2141bd91ee0ef6cd 100644 (file)
@@ -9,7 +9,7 @@ memcat - Copy a set of keys to stdout
 =head1 DESCRIPTION
 
 B<memcat> 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. 
 
index 1f66d701689ec783a7918f85ccfe3281c901b00a..db6f23f6cb70da8db486bd35d92bbeb19a9f1d10 100644 (file)
@@ -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