Replace boost::scoped_ptr with std::unique_ptr.
[cumulus.git] / tests / run-test
1 #!/bin/bash
2 #
3 # Cumulus: Efficient Filesystem Backup to the Cloud
4 # Copyright (C) 2012 The Cumulus Developers
5 # See the AUTHORS file for a list of contributors.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 # Perform a simple Cumulus integration test: create a sample file tree, create
22 # a backup, modify the files, create a new backup, then try restoring and
23 # compare with the original state.
24
25 # Directory containing test scripts
26 TEST_DIR="$(readlink -f "$(dirname "$0")")"
27
28 # Directory containing Cumulus binaries
29 BIN_DIR="$(readlink -f "$TEST_DIR/..")"
30
31 # Directory where temporary files used for the tests can be stored.
32 TMP_DIR="$(readlink -f "$(mktemp -d cumulus-tests.XXXXXX)")"
33
34 # Command to use for running memory leak tests.
35 VALGRIND="valgrind --tool=memcheck --leak-check=full --log-file=$TMP_DIR/valgrind.log"
36
37 # Python interpreter to test with.
38 PYTHON="${PYTHON:-python2}"
39
40 log_action() {
41     echo
42     echo "================================================================"
43     echo "$@"
44 }
45
46 log_action "Starting tests: BIN_DIR=$BIN_DIR TMP_DIR=$TMP_DIR"
47
48 log_action "Initializing local database..."
49 LOCALDB="$TMP_DIR/database"
50 mkdir "$LOCALDB"
51 sqlite3 -init "$BIN_DIR/schema.sql" "$LOCALDB/localdb.sqlite" ".exit"
52
53 log_action "Creating test file system tree..."
54 TREE="$TMP_DIR/tree"
55 mkdir "$TREE"
56 cp "$BIN_DIR"/*.cc "$BIN_DIR"/*.h "$TREE"
57 cp -a "$BIN_DIR/python" "$TREE"
58 "$TEST_DIR"/digest_tree "$TREE" >"$TMP_DIR/digest.1"
59
60 log_action "Running initial backup..."
61 sleep 5
62 BACKUP_DIR="$TMP_DIR/backups"
63 mkdir "$BACKUP_DIR"
64 "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
65     --scheme=test -v "$TREE"
66
67 log_action "Modifying files..."
68 rm "$TREE/"*.h
69 cp -a "$BIN_DIR/third_party" "$TREE"
70 "$TEST_DIR"/digest_tree "$TREE" >"$TMP_DIR/digest.2"
71
72 log_action "Running second backup..."
73 sleep 5
74 $VALGRIND "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
75     --scheme=test -v "$TREE"
76
77 log_action "Restoring snapshots"
78 export LBS_GPG_PASSPHRASE=""
79 snapshots=$("$BIN_DIR"/cumulus-util --store="$BACKUP_DIR" list-snapshots)
80 echo "Available snapshots:" $snapshots
81 i=0
82 for s in $snapshots; do
83     i=$((i + 1))
84     dest="$TMP_DIR/restore-$i"
85     mkdir -p "$dest"
86     "$PYTHON" "$BIN_DIR"/cumulus-util --store="$BACKUP_DIR" \
87         restore-snapshot $s "$dest"
88 done