]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added testsuite for rollback testing
authorArvin Schnell <aschnell@suse.de>
Wed, 16 Feb 2011 16:26:09 +0000 (17:26 +0100)
committerArvin Schnell <aschnell@suse.de>
Wed, 16 Feb 2011 16:26:09 +0000 (17:26 +0100)
15 files changed:
Makefile.am
configure.in
snapper/File.cc
snapper/File.h
snapper/Snapper.cc
snapper/Snapper.h
snapper/Snapshot.h
testsuite-real/.gitignore [new file with mode: 0644]
testsuite-real/CAUTION [new file with mode: 0644]
testsuite-real/Makefile.am [new file with mode: 0644]
testsuite-real/common.cc [new file with mode: 0644]
testsuite-real/common.h [new file with mode: 0644]
testsuite-real/owner1.cc [new file with mode: 0644]
testsuite-real/permissions1.cc [new file with mode: 0644]
testsuite-real/simple1.cc [new file with mode: 0644]

index 22e1bb1fe44d4144e0d01beca997d5183fdd5d7f..e9bd29a65a2a167f981450f742fdc5e09db40e5a 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile.am for snapper
 #
 
-SUBDIRS = snapper examples tools data
+SUBDIRS = snapper examples tools data testsuite-real
 
 AUTOMAKE_OPTIONS = foreign dist-bzip2 no-dist-gzip
 
index 5cfb2eaedd8608e59ea20fe3ca243c2324cac23c..4b845e33883fa59e5af2441343be2f42505ed4b3 100644 (file)
@@ -35,5 +35,6 @@ AC_OUTPUT(
        tools/Makefile
        tools/utils/Makefile
        data/Makefile
+       testsuite-real/Makefile
        package/snapper.spec:snapper.spec.in
 )
index eded5b0524b422b6b99f98eda84939c3bc1cad31..658b2d004eb06abebddb7318925928bb2d7ecd6f 100644 (file)
@@ -444,6 +444,8 @@ namespace snapper
     bool
     Files::doRollback()
     {
+       y2mil("begin rollback");
+
        for (vector<File>::reverse_iterator it = entries.rbegin(); it != entries.rend(); ++it)
        {
            if (it->getRollback())
@@ -466,6 +468,8 @@ namespace snapper
            }
        }
 
+       y2mil("end rollback");
+
        return true;
     }
 
index fe0859c2cbbc08822cc119e56450d2885f81e631..4666cc34f6b0244e3ad92c44f107a39df14b7308 100644 (file)
@@ -132,6 +132,8 @@ namespace snapper
        iterator end() { return entries.end(); }
        const_iterator end() const { return entries.end(); }
 
+       bool empty() const { return entries.empty(); }
+
        iterator find(const string& name);
        const_iterator find(const string& name) const;
 
index 15b33ce44471da900233b530099eb214e6e0cee1..3efd0420a65c44878fb61bfc2d2409225f242ce0 100644 (file)
@@ -78,6 +78,13 @@ namespace snapper
     }
 
 
+    Snapshots::const_iterator
+    Snapper::getSnapshotCurrent() const
+    {
+       return snapshots.getSnapshotCurrent();
+    }
+
+
     Snapshots::iterator
     Snapper::createSingleSnapshot(string description)
     {
index 57c13533aea64ee539e89c826704af65d8cdff0a..863a6d32f29de9603b21d3ce9f4e0f5f04ef2b86 100644 (file)
@@ -54,6 +54,8 @@ namespace snapper
        Snapshots& getSnapshots() { return snapshots; }
        const Snapshots& getSnapshots() const { return snapshots; }
 
+       Snapshots::const_iterator getSnapshotCurrent() const;
+
        Snapshots::iterator createSingleSnapshot(string description);
        Snapshots::iterator createPreSnapshot(string description);
        Snapshots::iterator createPostSnapshot(Snapshots::const_iterator pre);
index 87aed299a9c46b97eb63b2fdbdb20ab7cf989043..4b369ddba2eb1d95685124ad7b2858a450086610 100644 (file)
@@ -113,6 +113,8 @@ namespace snapper
 
        const_iterator findPost(const_iterator pre) const;
 
+       const_iterator getSnapshotCurrent() const { return entries.begin(); }
+
     private:
 
        void initialize();
diff --git a/testsuite-real/.gitignore b/testsuite-real/.gitignore
new file mode 100644 (file)
index 0000000..1012091
--- /dev/null
@@ -0,0 +1,4 @@
+*.o
+simple1
+permissions1
+owner1
diff --git a/testsuite-real/CAUTION b/testsuite-real/CAUTION
new file mode 100644 (file)
index 0000000..c52ea40
--- /dev/null
@@ -0,0 +1,6 @@
+
+CAUTION
+-------
+
+The programs here destroy data on your disks!
+
diff --git a/testsuite-real/Makefile.am b/testsuite-real/Makefile.am
new file mode 100644 (file)
index 0000000..4fefd43
--- /dev/null
@@ -0,0 +1,16 @@
+#
+# Makefile.am for snapper/testsuite-real
+#
+
+INCLUDES = -I$(top_srcdir)
+
+LDADD = ../snapper/libsnapper.la
+
+noinst_PROGRAMS = simple1 permissions1 owner1
+
+simple1_SOURCES = simple1.cc common.h common.cc
+
+permissions1_SOURCES = permissions1.cc common.h common.cc
+
+owner1_SOURCES = owner1.cc common.h common.cc
+
diff --git a/testsuite-real/common.cc b/testsuite-real/common.cc
new file mode 100644 (file)
index 0000000..96dbd6d
--- /dev/null
@@ -0,0 +1,89 @@
+
+#include <stdlib.h>
+#include <glob.h>
+#include <iostream>
+#include <fstream>
+
+#include "common.h"
+
+#include <snapper/Snapper.h>
+#include <snapper/Factory.h>
+#include <snapper/Snapshot.h>
+#include <snapper/File.h>
+
+#include "snapper/AppUtil.h"
+
+
+extern char* program_invocation_short_name;
+
+
+using namespace snapper;
+
+#define ROOTDIR "/test"
+
+Snapper* sh = NULL;
+
+Snapshots::iterator first;
+Snapshots::iterator second;
+
+
+void
+setup()
+{
+    system("/usr/bin/find " ROOTDIR " -mindepth 1 -maxdepth 1 -not -path " ROOTDIR "/snapshots "
+          "-exec rm -r {} \\;");
+
+    initDefaultLogger();
+
+    sh = createSnapper(ROOTDIR);
+}
+
+
+void
+first_snapshot()
+{
+    first = sh->createPreSnapshot("testsuite");
+}
+
+
+void
+second_snapshot()
+{
+    second = sh->createPostSnapshot(first);
+}
+
+
+void
+rollback()
+{
+    sh->setComparison(first, second);
+
+    Files& files = sh->getFiles();
+    for (Files::iterator it = files.begin(); it != files.end(); ++it)
+       it->setRollback(true);
+
+    sh->doRollback();
+}
+
+
+void
+check_first()
+{
+    Snapshots::const_iterator current = sh->getSnapshotCurrent();
+
+    sh->setComparison(first, current);
+
+    const Files& files = sh->getFiles();
+    for (Files::const_iterator it = files.begin(); it != files.end(); ++it)
+       cout << *it << endl;
+
+    check_true(files.empty());
+}
+
+
+void
+run_command(const char* command)
+{
+    string tmp = string("cd " ROOTDIR " ; ") + command;
+    check_zero(system(tmp.c_str()));
+}
diff --git a/testsuite-real/common.h b/testsuite-real/common.h
new file mode 100644 (file)
index 0000000..4e3489a
--- /dev/null
@@ -0,0 +1,44 @@
+
+#include <string>
+
+using namespace std;
+
+
+template <typename Type> void
+check_failure(const char* str, Type actual, Type expected, const char* file,
+             int line, const char* func)
+{
+    std::cerr << file << ":" << line << ": \"" << func << "\"" << std::endl;
+    std::cerr << "check \"" << str << "\"" << " failed. expected " << expected
+             << ", actual " << actual << "." << std::endl;
+
+    exit(EXIT_FAILURE);
+}
+
+
+#define check_true(expr)                                                \
+    do {                                                                \
+        bool actual = (expr);                                           \
+        if (!actual)                                                    \
+            check_failure(#expr, actual, true, __FILE__, __LINE__,      \
+                          __PRETTY_FUNCTION__);                         \
+    } while (0)
+
+
+#define check_zero(expr)                                                \
+    do {                                                                \
+        int actual = (expr);                                            \
+        if (actual != 0)                                                \
+            check_failure(#expr, actual, 0, __FILE__, __LINE__,         \
+                          __PRETTY_FUNCTION__);                         \
+    } while (0)
+
+
+void setup();
+void first_snapshot();
+void second_snapshot();
+void rollback();
+void check_first();
+
+void run_command(const char* command);
+
diff --git a/testsuite-real/owner1.cc b/testsuite-real/owner1.cc
new file mode 100644 (file)
index 0000000..7e62633
--- /dev/null
@@ -0,0 +1,37 @@
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+    setup();
+
+    run_command("mkdir directory");
+    run_command("chown nobody directory");
+
+    run_command("echo test > file");
+    run_command("chown nobody file");
+
+    run_command("ln --symbolic test link");
+    run_command("chown --no-dereference nobody link");
+
+    first_snapshot();
+
+    run_command("rmdir directory");
+    run_command("rm file");
+    run_command("rm link");
+
+    second_snapshot();
+
+    rollback();
+
+    check_first();
+
+    exit(EXIT_SUCCESS);
+}
diff --git a/testsuite-real/permissions1.cc b/testsuite-real/permissions1.cc
new file mode 100644 (file)
index 0000000..e25a254
--- /dev/null
@@ -0,0 +1,38 @@
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+    setup();
+
+    run_command("mkdir --mode a=rwx directory1");
+    run_command("mkdir --mode a=--- directory2");
+
+    run_command("echo test > file1");
+    run_command("chmod a=rwx file1");
+    run_command("echo test > file2");
+    run_command("chmod a=--- file2");
+
+    first_snapshot();
+
+    run_command("rmdir directory1");
+    run_command("rmdir directory2");
+
+    run_command("rm file1");
+    run_command("rm file2");
+
+    second_snapshot();
+
+    rollback();
+
+    check_first();
+
+    exit(EXIT_SUCCESS);
+}
diff --git a/testsuite-real/simple1.cc b/testsuite-real/simple1.cc
new file mode 100644 (file)
index 0000000..578e59f
--- /dev/null
@@ -0,0 +1,36 @@
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "common.h"
+
+using namespace std;
+
+
+int
+main()
+{
+    setup();
+
+    run_command("mkdir directory-pre");
+    run_command("echo test > file-pre");
+    run_command("ln --symbolic test link-pre");
+
+    first_snapshot();
+
+    run_command("rmdir directory-pre");
+    run_command("rm file-pre");
+    run_command("rm link-pre");
+
+    run_command("mkdir directory-post");
+    run_command("echo test > file-post");
+    run_command("ln --symbolic test link-post");
+
+    second_snapshot();
+
+    rollback();
+
+    check_first();
+
+    exit(EXIT_SUCCESS);
+}