]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added test program
authorArvin Schnell <aschnell@suse.de>
Mon, 28 Jan 2013 15:23:38 +0000 (16:23 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 28 Jan 2013 15:24:13 +0000 (16:24 +0100)
Makefile.am
configure.in
testsuite-cmp/.gitignore [new file with mode: 0644]
testsuite-cmp/Makefile.am [new file with mode: 0644]
testsuite-cmp/cmp.cc [new file with mode: 0644]
testsuite-real/Makefile.am

index 600fed8e6ca9756a31ab9322f32401e3b0213613..90a753047792b8f27c7ebce08f838393c8f51966 100644 (file)
@@ -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
 
index 5a82335b70ebfa7fd6eed043ad32fa55d912dc00..18ffbc990f53c75a77f735e3b13efb49d8133096 100644 (file)
@@ -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 (file)
index 0000000..1dae17c
--- /dev/null
@@ -0,0 +1,2 @@
+*.o
+cmp
diff --git a/testsuite-cmp/Makefile.am b/testsuite-cmp/Makefile.am
new file mode 100644 (file)
index 0000000..718cbd6
--- /dev/null
@@ -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 (file)
index 0000000..44c16f2
--- /dev/null
@@ -0,0 +1,95 @@
+
+#include <algorithm>
+#include <iostream>
+#include <fstream>
+
+#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<string> 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<string> 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<string>::const_iterator it = result1.begin(); it != result1.end(); ++it)
+           fout1 << *it << endl;
+
+       std::ofstream fout2("/tmp/result2-" + decString(num1) + "-" + decString(num2));
+       for (vector<string>::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);
+}
index be44b3d08c35a1666d133dc043c747fea38dccaf..3f8d7e4731ce2862030f0669ea7231974a1fea89 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile.am for snapper/testsuite-real
 #
 
-CXXFLAGS += -std=gnu++0x
+AM_CXXFLAGS = -std=gnu++0x
 
 INCLUDES = -I$(top_srcdir)