Start work on tests for Cumulus.
[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 log_action() {
35     echo
36     echo "================================================================"
37     echo "$@"
38 }
39
40 log_action "Starting tests: BIN_DIR=$BIN_DIR TMP_DIR=$TMP_DIR"
41
42 log_action "Initializing local database..."
43 LOCALDB="$TMP_DIR/database"
44 mkdir "$LOCALDB"
45 sqlite3 -init "$BIN_DIR/schema.sql" "$LOCALDB/localdb.sqlite" ".exit"
46
47 log_action "Creating test file system tree..."
48 TREE="$TMP_DIR/tree"
49 mkdir "$TREE"
50 cp "$BIN_DIR"/*.cc "$BIN_DIR"/*.h "$TREE"
51 cp -a "$BIN_DIR/python" "$TREE"
52 "$TEST_DIR"/digest_tree "$TREE" >"$TMP_DIR/digest.1"
53
54 log_action "Running initial backup..."
55 sleep 5
56 BACKUP_DIR="$TMP_DIR/backups"
57 mkdir "$BACKUP_DIR"
58 "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
59     --scheme=test -v "$TREE"
60
61 log_action "Modifying files..."
62 rm "$TREE/"*.h
63 cp -a "$BIN_DIR/third_party" "$TREE"
64
65 log_action "Running second backup..."
66 sleep 5
67 BACKUP_DIR="$TMP_DIR/backups"
68 mkdir "$BACKUP_DIR"
69 "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
70     --scheme=test -v "$TREE"