Debian Codegraph @

tests/backup/test_restore.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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
17 # uncomment for debugging
18 #export DRY_RUN="echo"
19 source test_backup_common.shscip-shell source . . `test_backup_common.sh`.
20
21 [scip-shell system . . `[`. -z "$BUGREPORT_DIR" ] && BUGREPORT_DIR="$HOME/backup/bugreports"
22
23 function check_filescip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_file().
24 {
25 data=$(a shell cat /data/data/com.android.backuptest/$1)
26 if [scip-shell system . . `[`. "$data" = "$2" ] ; then
27 echoscip-shell system . . echo. "$1 has correct value [$2]"
28 return 0
29 else
30 echoscip-shell system . . echo. $1 is INCORRECT
31 echoscip-shell system . . echo. " value: [$data]"
32 echoscip-shell system . . echo. " expected: [$2]"
33 return 1
34 fi
35 }
36
37 function check_existsscip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_exists().
38 {
39 # return 0 if file exists, 1 otherwise
40 data=$(a shell "ls $@ 2> /dev/null >/dev/null && echo -n exists")
41 if [scip-shell system . . `[`. "$data" = "exists" ]; then
42 return 0
43 else
44 return 1
45 fi
46 }
47
48 # Make sure adb is root so we can poke at com.android.backuptest's data
49 adb_root
50
51 # delete the old data
52 echoscip-shell system . . echo. --- Previous files
53 a shell "ls -l /data/data/com.android.backuptest/files"
54 a shell "rm /data/data/com.android.backuptest/files/*"
55 echoscip-shell system . . echo. --- Previous shared_prefs
56 a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
57 a shell "rm /data/data/com.android.backuptest/shared_prefs/*"
58 echoscip-shell system . . echo. --- Erased files and shared_prefs
59 a shell "ls -l /data/data/com.android.backuptest/files"
60 a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
61 echoscip-shell system . . echo. ---
62
63 echoscip-shell system . . echo.
64 echoscip-shell system . . echo.
65
66 # FIXME: there's probably a smarter way to do this
67 # FIXME: if we can get the android ID, that's probably the safest thing to do
68 # pick the most recent set and restore from it
69 restore_set=$(a shell bmgr list sets | headscip-shell system . . head. -n1 | awkscip-shell system . . awk. '{print $1}')
70
71 # run the restore
72 echoscip-shell system . . echo. "Restoring from set [$restore_set]"
73 a shell bmgr restore "$restore_set"
74
75 echoscip-shell system . . echo.
76 echoscip-shell system . . echo.
77
78 # check the results
79 export need_bug=0
80
81 # make sure files have the expected contents
82 check_filescip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_file(). files/file.txt "first file" || need_bug=1
83 check_filescip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_file(). files/another_file.txt "asdf" || need_bug=1
84 #check_file files/3.txt "3" || need_bug=1
85 check_filescip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_file(). files/empty.txt "" || need_bug=1
86 check_filescip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_file(). shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>' || need_bug=1
87
88 # make sure that missing files weren't somehow created
89 check_existsscip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_exists(). files/file_doesnt_exist.txt && need_bug=1
90 check_existsscip-shell shell android-platform-frameworks-base 1:14~beta1-5 check_exists(). files/no_files_here.txt && need_bug=1
91
92 if [scip-shell system . . `[`. \( "$need_bug" -ne 0 \) -a -d "$BUGREPORT_DIR" ]; then
93 dev_id=$(a get-serialno)
94 filename="${dev_id}_`datescip-shell system . . date. +%s`"
95 echoscip-shell system . . echo. "Grabbing bugreport; filename is $filename"
96 a bugreport > "$BUGREPORT_DIR/$filename.txt"
97 fi
98
99 echoscip-shell system . . echo.
100 echoscip-shell system . . echo. --- Restored files
101 a shell "ls -l /data/data/com.android.backuptest/files"
102 echoscip-shell system . . echo. --- Restored shared_prefs
103 a shell "ls -l /data/data/com.android.backuptest/shared_prefs"
104 echoscip-shell system . . echo. ---
105 echoscip-shell system . . echo.
106
107 echoscip-shell system . . echo. "Last 3 timestamps in 3.txt:"
108 a shell cat /data/data/com.android.backuptest/files/3.txtscip-shell filesystem . . `/data/data/com.android.backuptest/files/3.txt`. | tailscip-shell system . . tail. -n 3
109
110 exit $need_bug
111