diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/backup/test_backup.sh | 33 | ||||
-rwxr-xr-x | tests/backup/test_backup_common.sh | 33 | ||||
-rwxr-xr-x | tests/backup/test_restore.sh | 80 |
3 files changed, 96 insertions, 50 deletions
diff --git a/tests/backup/test_backup.sh b/tests/backup/test_backup.sh index f50d03f..10b809d 100755 --- a/tests/backup/test_backup.sh +++ b/tests/backup/test_backup.sh @@ -14,39 +14,32 @@ # See the License for the specific language governing permissions and # limitations under the License. +# uncomment for debugging +#export DRY_RUN="echo" +source test_backup_common.sh -ADB_OPTS="$@" +# wipe prior backup data for packages +b_pkgs=$(a shell dumpsys backup | \ + ruby -ne 'print($1+" ") if $_ =~ /^\s*ApplicationInfo\S+ (.+?)\}/') -#FIXME: what was this for? -#adb kill-server - -b_pkgs=$(adb $ADB_OPTS shell dumpsys backup | \ - ruby -ne 'print($1+" ") if $_ =~ /^\s*ApplicationInfo\{\S+ (.+?)\}/') - -# wipe prior backup data for packages, including the metadata package @pm@ -for pkg in $b_pkgs '@pm@'; do - adb $ADB_OPTS shell bmgr wipe "$pkg" +for pkg in $b_pkgs; do + a shell bmgr wipe "$pkg" done -# who knows? echo 'Waiting 5 seconds for things to settle...' sleep 5 # run adb as root so we can poke at com.android.backuptest's data -root_status=$(adb $ADB_OPTS root) -if [ "x$root_status" != "xadbd is already running as root" ]; then - sleep 2 - adb $ADB_OPTS 'wait-for-device' -fi +adb_root # show commands as we go set -x # set the transport -adb $ADB_OPTS shell bmgr transport com.google.android.backup/.BackupTransportService +a shell bmgr transport com.google.android.backup/.BackupTransportService # load up the three files -adb $ADB_OPTS shell \ +a shell \ "rm /data/data/com.android.backuptest/files/file.txt ; \ rm /data/data/com.android.backuptest/files/another_file.txt ; \ rm /data/data/com.android.backuptest/files/empty.txt ; \ @@ -63,8 +56,8 @@ adb $ADB_OPTS shell \ # echo -n 3 > /data/data/com.android.backuptest/files/3.txt ; \ # say that the data has changed -adb $ADB_OPTS shell bmgr backup com.android.backuptest +a shell bmgr backup com.android.backuptest # run the backup -adb $ADB_OPTS shell bmgr run +a shell bmgr run diff --git a/tests/backup/test_backup_common.sh b/tests/backup/test_backup_common.sh new file mode 100755 index 0000000..31e4ddd --- /dev/null +++ b/tests/backup/test_backup_common.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export ADB_OPTS="$@" + +# run adb with options +function a { $DRY_RUN adb $ADB_OPTS "$@"; } + +# restart adb as root and wait for it to come back again +function adb_root +{ + root_status=$(a root) + if [ "x$root_status" != "xadbd is already running as root" ]; then + echo -n "Restarting adb as root..." + sleep 2 + a 'wait-for-device' + echo done. + fi +} + diff --git a/tests/backup/test_restore.sh b/tests/backup/test_restore.sh index 44b3a28..4506c16 100755 --- a/tests/backup/test_restore.sh +++ b/tests/backup/test_restore.sh @@ -14,76 +14,96 @@ # See the License for the specific language governing permissions and # limitations under the License. +# uncomment for debugging +#export DRY_RUN="echo" +source test_backup_common.sh -ADB_OPTS="$@" +BUGREPORT_DIR="$HOME/backup/bugreports" function check_file { - data=$(adb $ADB_OPTS shell cat /data/data/com.android.backuptest/$1) + data=$(a shell cat /data/data/com.android.backuptest/$1) if [ "$data" = "$2" ] ; then echo "$1 has correct value [$2]" + return 0 else echo $1 is INCORRECT echo " value: [$data]" echo " expected: [$2]" + return 1 + fi +} + +function check_exists +{ + # return 0 if file exists, 1 otherwise + data=$(a shell "ls $@ 2> /dev/null >/dev/null && echo -n exists") + if [ "$data" = "exists" ]; then + return 0 + else + return 1 fi } # run adb as root so we can poke at com.android.backuptest's data -root_status=$(adb $ADB_OPTS root) -if [ "x$root_status" != "xadbd is already running as root" ]; then - echo -n "Restarting adb as root..." - sleep 2 - adb $ADB_OPTS 'wait-for-device' - echo done. -fi +adb_root # delete the old data echo --- Previous files -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" -adb $ADB_OPTS shell "rm /data/data/com.android.backuptest/files/*" +a shell "ls -l /data/data/com.android.backuptest/files" +a shell "rm /data/data/com.android.backuptest/files/*" echo --- Previous shared_prefs -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" -adb $ADB_OPTS shell "rm /data/data/com.android.backuptest/shared_prefs/*" +a shell "ls -l /data/data/com.android.backuptest/shared_prefs" +a shell "rm /data/data/com.android.backuptest/shared_prefs/*" echo --- Erased files and shared_prefs -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" +a shell "ls -l /data/data/com.android.backuptest/files" +a shell "ls -l /data/data/com.android.backuptest/shared_prefs" echo --- echo echo -echo # FIXME: there's probably a smarter way to do this # FIXME: if we can get the android ID, that's probably the safest thing to do # pick the most recent set and restore from it -restore_set=$(adb $ADB_OPTS shell bmgr list sets | head -n1 | awk '{print $1}') +restore_set=$(a shell bmgr list sets | head -n1 | awk '{print $1}') # run the restore -printf "Restoring from set %d (hex: 0x%x)\n" $restore_set $restore_set -adb $ADB_OPTS shell bmgr restore $restore_set +echo "Restoring from set [$restore_set]" +a shell bmgr restore "$restore_set" echo echo -echo # check the results -check_file files/file.txt "first file" -check_file files/another_file.txt "asdf" -#check_file files/3.txt "3" -check_file files/empty.txt "" -check_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>' +export need_bug=0 + +# make sure files have the expected contents +check_file files/file.txt "first file" || need_bug=1 +check_file files/another_file.txt "asdf" || need_bug=1 +#check_file files/3.txt "3" || need_bug=1 +check_file files/empty.txt "" || need_bug=1 +check_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>' || need_bug=1 + +# make sure that missing files weren't somehow created +check_exists files/file_doesnt_exist.txt && need_bug=1 +check_exists files/no_files_here.txt && need_bug=1 + +if [ \( "$need_bug" -ne 0 \) -a -d "$BUGREPORT_DIR" ]; then + dev_id=$(a get-serialno) + filename="${dev_id}_`date +%s`" + echo "Grabbing bugreport; filename is $filename" + a bugreport > "$BUGREPORT_DIR/$filename.txt" +fi -echo -echo echo echo --- Restored files -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" +a shell "ls -l /data/data/com.android.backuptest/files" echo --- Restored shared_prefs -adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" +a shell "ls -l /data/data/com.android.backuptest/shared_prefs" echo --- echo echo "Last 3 timestamps in 3.txt:" -adb $ADB_OPTS shell cat /data/data/com.android.backuptest/files/3.txt | tail -n 3 +a shell cat /data/data/com.android.backuptest/files/3.txt | tail -n 3 |