Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: build/android/run_update_verification.py

Issue 11672004: [Android] Add a tool for application update verification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Runs semi-automated update testing on a non-rooted device."""
8 import logging
9 import optparse
10 import os
11 import sys
12 import time
13
14 from pylib import android_commands
15
16
17 def _SaveAppData(adb, package_name, from_apk):
18 def _BackupAppData():
19 adb.Adb().SendCommand('backup %s' % package_name)
20 backup_file = os.path.join(os.getcwd(), 'backup.ab')
21 assert os.path.exists(backup_file), 'Backup failed.'
22 print 'Application data saved to %s' % backup_file
23
24 logging.info('Installing %s...', from_apk)
klundberg 2013/01/02 17:23:41 Seems like it should be possible to call _SaveAppD
frankf 2013/01/10 23:15:05 I made from_apk optional for both modes. On 2013/
25 output = adb.Install(from_apk, reinstall=True)
26 if 'Success' not in output:
27 raise Exception('Unable to install %s. output: %s' % (from_apk, output))
28
29 raw_input('Set the application sate. Once ready, press enter and '
klundberg 2013/01/02 17:23:41 sate/state
frankf 2013/01/10 23:15:05 Done.
30 'select "Backup my data" on the device.')
31 _BackupAppData()
32
33
34 def _VerifyAppUpdate(adb, from_apk, to_apk, app_data):
35 def _RestoreAppData():
36 assert os.path.exists(app_data), 'Backup file doesn not exist!'
klundberg 2013/01/02 17:23:41 doesn not/does not
frankf 2013/01/10 23:15:05 Done.
37 adb.Adb().SendCommand('restore %s' % app_data)
38 # It seems restore command is not synchronous.
39 time.sleep(15)
40
41 logging.info('Installing %s...', from_apk)
42 output = adb.Install(from_apk, reinstall=True)
43 if 'Success' not in output:
44 raise Exception('Unable to install %s. output: %s' % (from_apk, output))
45
46 logging.info('Restoring the application data...')
47 raw_input('Press enter and select "Restore my data" on the device.')
48 _RestoreAppData()
49
50 logging.info('Verifying that %s cannot be installed side-by-side...',
51 to_apk)
52 output = adb.Install(to_apk)
53 if 'INSTALL_FAILED_ALREADY_EXISTS' not in output:
54 if 'Success' in output:
55 raise Exception('Package name has changed! output: %s' % output)
56 else:
57 raise Exception(output)
58
59 logging.info('Verifying that %s can replace %s...', from_apk, to_apk)
60 output = adb.Install(to_apk, reinstall=True)
61 if 'Success' not in output:
62 raise Exception('Unable to install %s. Maybe the sign key has changed?'
63 'output: %s' % (to_apk, output))
64 logging.info('Successfully updated to the new apk. Please verify that the '
65 'the application data is preserved.')
66
67
68 def main():
69 logger = logging.getLogger()
70 logger.setLevel(logging.DEBUG)
71 desc = (
72 'Performs semi-automated application update verification testing. '
73 'When given --save, it takes a snapshot of the application data '
74 'on the device. (A dialog on the device will prompt the user to grant '
75 'permission to backup the data.) Otherwise, it performs the update '
76 'testing as follows: '
77 '1. Installs the |from-apk|. '
78 '2. Restores the previously stored snapshot of application data '
79 'given by |app-data|. '
80 '(A dialog on the device will prompt the user to grant permission to '
81 'restore the data.) '
82 '3. Verifies that |to-apk| cannot be installed side-by-side. '
83 '4. Verifying that |to-apk| can replace |from-apk|.')
84 parser = optparse.OptionParser(description=desc)
85 parser.add_option('--package-name', help='Package name for the application.')
86 parser.add_option('--save', action='store_true',
87 help=('Save a snapshot of application data. '
88 'This will be saved as backup.db in the '
89 'current directory.'))
klundberg 2013/01/02 17:23:41 How about making it possible to specify the file w
frankf 2013/01/10 23:15:05 Done.
90 parser.add_option('--from-apk', help='APK to update from.')
91 parser.add_option('--to-apk', help='APK to update to.')
92 parser.add_option('--app-data',
93 help=('Path to the previously stored '
94 'application data'))
95 (options, args) = parser.parse_args()
96
97 if args:
98 parser.print_help(sys.stderr)
99 parser.error('Unknown arguments: %s.' % args)
100
101 if len(android_commands.GetAttachedDevices()) != 1:
102 parser.error('Exactly 1 device must be attached.')
103 adb = android_commands.AndroidCommands()
104
105 if not options.from_apk:
106 parser.print_help(sys.stderr)
107 parser.error('Missing --from-apk.')
108
109 if options.save:
110 if not options.package_name:
111 parser.print_help(sys.stderr)
112 parser.error('Missing --package-name.')
113 _SaveAppData(adb, options.package_name, options.from_apk)
114 else:
115 if not options.to_apk or not options.app_data:
116 parser.print_help(sys.stderr)
117 parser.error('Missing --to-apk or --app-data.')
118 assert os.path.exists(options.from_apk)
craigdh 2013/01/02 18:26:20 os.path.isfile instead?
frankf 2013/01/10 23:15:05 Done.
119 assert os.path.exists(options.to_apk)
120 assert os.path.exists(options.app_data)
121 _VerifyAppUpdate(adb, options.from_apk, options.to_apk, options.app_data)
122
123
124 if __name__ == '__main__':
125 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698