1#!/bin/bash
2
3# Copyright (C) 2009 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17iterations=150
18failures=0
19i=0
20LOGDIR="$HOME/backup_tests"
21LOGFILE="$LOGDIR/backup_stress.`date +%s`.log"
22export BUGREPORT_DIR="$LOGDIR/bugreports"
23
24# make sure that we have a place to put logs and bugreports
25mkdir -p $LOGDIR $BUGREPORT_DIR
26
27echo "logfile is $LOGFILE"
28
29(while (sleep 10); do
30    failed=0
31    
32    echo
33    echo "Iteration $i at `date`"
34    echo
35
36    ./test_backup.sh "$@" 2>&1
37
38    sleep 10
39    echo "Restore at `date`"
40    echo
41
42    ./test_restore.sh "$@" 2>&1 || failed=1
43    
44    if [ "$failed" -ne 0 ]; then
45        failures=$(($failures+1))
46        # Long and verbose so it sticks out
47        echo "FAILED iteration $i of $iterations; $failures failures so far"
48        echo "FAILED iteration $i of $iterations; $failures failures so far" > /dev/stderr
49    else
50        printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1))
51        printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1)) > /dev/stderr
52    fi
53
54    echo "End $i at `date`"
55    
56    i=$(($i+1))
57    if [ $i -eq $iterations ]; then
58        echo "DONE: $iterations iterations with $failures failures."
59        echo "DONE: $iterations iterations with $failures failures." > /dev/stderr
60        [ "$failures" -eq 0 ] && exit 0
61        exit 1
62    fi
63done) > "$LOGFILE"
64
65