1259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens#!/bin/bash
2259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
3259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# Copyright (C) 2009 The Android Open Source Project
4259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens#
5259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# Licensed under the Apache License, Version 2.0 (the "License");
6259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# you may not use this file except in compliance with the License.
7259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# You may obtain a copy of the License at
8259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens#
9259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens#      http://www.apache.org/licenses/LICENSE-2.0
10259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens#
11259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# Unless required by applicable law or agreed to in writing, software
12259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# distributed under the License is distributed on an "AS IS" BASIS,
13259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# See the License for the specific language governing permissions and
15259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# limitations under the License.
16259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
17259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensiterations=150
18259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensfailures=0
19259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensi=0
20259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari StephensLOGDIR="$HOME/backup_tests"
21259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari StephensLOGFILE="$LOGDIR/backup_stress.`date +%s`.log"
22259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensexport BUGREPORT_DIR="$LOGDIR/bugreports"
23259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
24259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens# make sure that we have a place to put logs and bugreports
25259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensmkdir -p $LOGDIR $BUGREPORT_DIR
26259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
27259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensecho "logfile is $LOGFILE"
28259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
29259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens(while (sleep 10); do
30259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    failed=0
31259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    
32259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo
33259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo "Iteration $i at `date`"
34259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo
35259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
36259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    ./test_backup.sh "$@" 2>&1
37259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
38259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    sleep 10
39259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo "Restore at `date`"
40259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo
41259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
42259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    ./test_restore.sh "$@" 2>&1 || failed=1
43259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    
44259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    if [ "$failed" -ne 0 ]; then
45259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        failures=$(($failures+1))
46259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        # Long and verbose so it sticks out
47259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        echo "FAILED iteration $i of $iterations; $failures failures so far"
48259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        echo "FAILED iteration $i of $iterations; $failures failures so far" > /dev/stderr
49259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    else
50259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1))
51259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        printf "Iteration %d:\tPASS; remaining: %d\n" $i $(($iterations - $i - 1)) > /dev/stderr
52259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    fi
53259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
54259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    echo "End $i at `date`"
55259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    
56259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    i=$(($i+1))
57259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    if [ $i -eq $iterations ]; then
58259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        echo "DONE: $iterations iterations with $failures failures."
59259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        echo "DONE: $iterations iterations with $failures failures." > /dev/stderr
60259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        [ "$failures" -eq 0 ] && exit 0
61259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens        exit 1
62259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens    fi
63259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephensdone) > "$LOGFILE"
64259447bc6490f4ec7e04eb5d8bfa1b041650ed53Omari Stephens
65