From d3ce6b811b298072785a0b53d4ee9a2fbf65572a Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 19 Aug 2013 12:40:03 +0100 Subject: [PATCH] Start stubbing out cache_dump --- .gitignore | 1 + Makefile.in | 8 ++++ caching/cache_dump.cc | 60 ++++++++++++++++++++++++ features/cache_dump.feature | 30 ++++++++++++ features/cache_restore.feature | 7 +++ features/step_definitions/cache_steps.rb | 19 ++++++++ 6 files changed, 125 insertions(+) create mode 100644 caching/cache_dump.cc create mode 100644 features/cache_dump.feature diff --git a/.gitignore b/.gitignore index 8ffca90..e06e498 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ thin_repair thin_rmap cache_check +cache_dump cache_restore *.metadata diff --git a/Makefile.in b/Makefile.in index 4110365..0dbb0ba 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,6 +21,7 @@ V=@ PROGRAMS=\ cache_check \ + cache_dump \ cache_restore \ \ thin_check \ @@ -234,6 +235,9 @@ CACHE_CHECK_SOURCE=\ caching/superblock.cc CACHE_CHECK_OBJECTS=$(subst .cc,.o,$(CACHE_CHECK_SOURCE)) +CACHE_DUMP_SOURCE=$(SOURCE) +CACHE_DUMP_OBJECTS=$(subst .cc,.o,$(CACHE_DUMP_SOURCE)) + CACHE_RESTORE_SOURCE=$(SOURCE) CACHE_RESTORE_OBJECTS=$(subst .cc,.o,$(CACHE_RESTORE_SOURCE)) @@ -241,6 +245,10 @@ cache_check: $(CACHE_CHECK_OBJECTS) caching/cache_check.o @echo " [LD] $@" $(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) +cache_dump: $(CACHE_DUMP_OBJECTS) caching/cache_dump.o + @echo " [LD] $@" + $(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT) + cache_restore: $(CACHE_RESTORE_OBJECTS) caching/cache_restore.o @echo " [LD] $@" $(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT) diff --git a/caching/cache_dump.cc b/caching/cache_dump.cc new file mode 100644 index 0000000..7d15a39 --- /dev/null +++ b/caching/cache_dump.cc @@ -0,0 +1,60 @@ +#include +#include +#include + +#include "version.h" + +using namespace std; + +//---------------------------------------------------------------- + +namespace { + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options] {device|file}" << endl + << "Options:" << endl + << " {-h|--help}" << endl + << " {-V|--version}" << endl; + } +} + +//---------------------------------------------------------------- + +int main(int argc, char **argv) +{ + int c; + char const shortopts[] = "hV"; + + option const longopts[] = { + { "help", no_argument, NULL, 'h'}, + { "version", no_argument, NULL, 'V'}, + { NULL, no_argument, NULL, 0 } + }; + + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { + switch(c) { + case 'h': + usage(cout, basename(argv[0])); + return 0; + + case 'V': + cout << THIN_PROVISIONING_TOOLS_VERSION << endl; + return 0; + + default: + usage(cerr, basename(argv[0])); + return 1; + } + } + +#if 0 + if (argc == optind) { + cerr << "No input file provided." << endl; + usage(cerr, basename(argv[0])); + return 1; + } +#endif + + return 0; +} + +//---------------------------------------------------------------- diff --git a/features/cache_dump.feature b/features/cache_dump.feature new file mode 100644 index 0000000..6885bba --- /dev/null +++ b/features/cache_dump.feature @@ -0,0 +1,30 @@ +Feature: cache_dump + Scenario: print version (-V flag) + When I run cache_dump with -V + Then it should pass with version + + Scenario: print version (--version flag) + When I run cache_dump with --version + Then it should pass with version + + Scenario: print help (-h) + When I run cache_dump with -h + Then it should pass with: + + """ + Usage: cache_dump [options] {device|file} + Options: + {-h|--help} + {-V|--version} + """ + + Scenario: print help (--help) + When I run cache_dump with -h + Then it should pass with: + + """ + Usage: cache_dump [options] {device|file} + Options: + {-h|--help} + {-V|--version} + """ diff --git a/features/cache_restore.feature b/features/cache_restore.feature index 4ab9594..3fdea64 100644 --- a/features/cache_restore.feature +++ b/features/cache_restore.feature @@ -46,3 +46,10 @@ Feature: thin_restore """ No output file provided. """ + + Scenario: dump/restore is a noop + Given valid cache metadata + When I dump cache + And I restore cache + And I dump cache + Then cache dumps 1 and 2 should be identical diff --git a/features/step_definitions/cache_steps.rb b/features/step_definitions/cache_steps.rb index d82b923..d61c418 100644 --- a/features/step_definitions/cache_steps.rb +++ b/features/step_definitions/cache_steps.rb @@ -64,3 +64,22 @@ When(/^I run cache_restore with (.*?)$/) do |opts| run_simple("cache_restore #{opts}", false) end +When(/^I run cache_dump with (.*?)$/) do |opts| + run_simple("cache_dump #{opts}", false) +end + +Given(/^valid cache metadata$/) do + pending # express the regexp above with the code you wish you had +end + +When(/^I dump cache$/) do + pending # express the regexp above with the code you wish you had +end + +When(/^I restore cache$/) do + pending # express the regexp above with the code you wish you had +end + +Then(/^cache dumps (\d+) and (\d+) should be identical$/) do |arg1, arg2| + pending # express the regexp above with the code you wish you had +end