From: Arvin Schnell Date: Mon, 28 Jan 2013 15:23:38 +0000 (+0100) Subject: - added test program X-Git-Tag: v0.1.3~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e5b72df0598e4c4ef8ff5888860e567ebc49cea;p=thirdparty%2Fsnapper.git - added test program --- diff --git a/Makefile.am b/Makefile.am index 600fed8e..90a75304 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # Makefile.am for snapper # -SUBDIRS = snapper examples dbus server client scripts data doc po testsuite-real +SUBDIRS = snapper examples dbus server client scripts data doc po testsuite-real testsuite-cmp AUTOMAKE_OPTIONS = foreign dist-bzip2 no-dist-gzip diff --git a/configure.in b/configure.in index 5a82335b..18ffbc99 100644 --- a/configure.in +++ b/configure.in @@ -94,5 +94,6 @@ AC_OUTPUT( doc/snapperd.8:doc/snapperd.8.in po/Makefile testsuite-real/Makefile + testsuite-cmp/Makefile package/snapper.spec:snapper.spec.in ) diff --git a/testsuite-cmp/.gitignore b/testsuite-cmp/.gitignore new file mode 100644 index 00000000..1dae17ce --- /dev/null +++ b/testsuite-cmp/.gitignore @@ -0,0 +1,2 @@ +*.o +cmp diff --git a/testsuite-cmp/Makefile.am b/testsuite-cmp/Makefile.am new file mode 100644 index 00000000..718cbd6d --- /dev/null +++ b/testsuite-cmp/Makefile.am @@ -0,0 +1,14 @@ +# +# Makefile.am for snapper/testsuite-cmp +# + +AM_CXXFLAGS = -std=gnu++0x + +INCLUDES = -I$(top_srcdir) + +LDADD = ../snapper/libsnapper.la + +noinst_PROGRAMS = cmp + +cmp_SOURCES = cmp.cc + diff --git a/testsuite-cmp/cmp.cc b/testsuite-cmp/cmp.cc new file mode 100644 index 00000000..44c16f27 --- /dev/null +++ b/testsuite-cmp/cmp.cc @@ -0,0 +1,95 @@ + +#include +#include +#include + +#include "snapper/Log.h" +#include "snapper/AppUtil.h" +#include "snapper/File.h" +#include "snapper/Filesystem.h" +#include "snapper/SnapperTmpl.h" + + +using namespace std; +using namespace snapper; + + +bool +cmp(const string& fstype, const string& subvolume, unsigned int num1, unsigned int num2) +{ + Filesystem* filesystem = Filesystem::create(fstype, subvolume); + + SDir dir1 = filesystem->openSnapshotDir(num1); + SDir dir2 = filesystem->openSnapshotDir(num2); + + vector result1; + + { + StopWatch sw1; + + cmpdirs_cb_t cb1 = [&result1](const string& name, unsigned int status) { + result1.push_back(statusToString(status) + " " + name); + }; + + filesystem->cmpDirs(dir1, dir2, cb1); + + y2mil("stopwatch1 " << sw1); + + sort(result1.begin(), result1.end()); + } + + vector result2; + + { + StopWatch sw2; + + cmpdirs_cb_t cb2 = [&result2](const string& name, unsigned int status) { + result2.push_back(statusToString(status) + " " + name); + }; + + snapper::cmpDirs(dir1, dir2, cb2); + + y2mil("stopwatch2 " << sw2); + + sort(result2.begin(), result2.end()); + } + + if (result1 == result2) + { + cout << fstype << " " << subvolume << " " << num1 << " " << num2 << " results match" << endl; + + return true; + } + else + { + cout << fstype << " " << subvolume << " " << num1 << " " << num2 << " results don't match" << endl; + + std::ofstream fout1("/tmp/result1-" + decString(num1) + "-" + decString(num2)); + for (vector::const_iterator it = result1.begin(); it != result1.end(); ++it) + fout1 << *it << endl; + + std::ofstream fout2("/tmp/result2-" + decString(num1) + "-" + decString(num2)); + for (vector::const_iterator it = result2.begin(); it != result2.end(); ++it) + fout2 << *it << endl; + + return false; + } +} + + +int +main(int argc, char** argv) +{ + if (argc != 5) + { + cerr << "usage: fstype subvolume num1 num2" << endl; + exit(EXIT_FAILURE); + } + + string fstype = argv[1]; + string subvolume = argv[2]; + unsigned int num1 = atoi(argv[3]); + unsigned int num2 = atoi(argv[4]); + + exit(cmp(fstype, subvolume, num1, num2) ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/testsuite-real/Makefile.am b/testsuite-real/Makefile.am index be44b3d0..3f8d7e47 100644 --- a/testsuite-real/Makefile.am +++ b/testsuite-real/Makefile.am @@ -2,7 +2,7 @@ # Makefile.am for snapper/testsuite-real # -CXXFLAGS += -std=gnu++0x +AM_CXXFLAGS = -std=gnu++0x INCLUDES = -I$(top_srcdir)