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

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

Issue 1141793003: Update from https://crrev.com/329939 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « build/android/test_runner.py ('k') | build/common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Runs semi-automated update testing on a non-rooted device.""" 7 """Runs semi-automated update testing on a non-rooted device.
8
9 This script will help verify that app data is preserved during an update.
10 To use this script first run it with the create_app_data option.
11
12 ./update_verification.py create_app_data --old-apk <path> --app-data <path>
13
14 The script will then install the old apk, prompt you to create some app data
15 (bookmarks, etc.), and then save the app data in the path you gave it.
16
17 Next, once you have some app data saved, run this script with the test_update
18 option.
19
20 ./update_verification.py test_update --old-apk <path> --new-apk <path>
21 --app-data <path>
22
23 This will install the old apk, load the saved app data, install the new apk,
24 and ask the user to verify that all of the app data was preserved.
25 """
26
27 import argparse
8 import logging 28 import logging
9 import optparse
10 import os 29 import os
11 import shutil
12 import sys 30 import sys
13 import time 31 import time
14 32
33 from pylib import constants
15 from pylib.device import device_utils 34 from pylib.device import device_utils
35 from pylib.utils import apk_helper
36 from pylib.utils import run_tests_helper
16 37
17 def _SaveAppData(device, package_name, from_apk=None, data_dir=None): 38 def CreateAppData(device, old_apk, app_data):
18 def _BackupAppData(data_dir=None): 39 device.Install(old_apk)
19 device.adb.Backup(package_name)
20 backup_file = os.path.join(os.getcwd(), 'backup.ab')
21 assert os.path.exists(backup_file), 'Backup failed.'
22 if data_dir:
23 if not os.path.isdir(data_dir):
24 os.makedirs(data_dir)
25 shutil.move(backup_file, data_dir)
26 backup_file = os.path.join(data_dir, 'backup.ab')
27 print 'Application data saved to %s' % backup_file
28
29 if from_apk:
30 logging.info('Installing %s...', from_apk)
31 output = device.Install(from_apk, reinstall=True)
32 if 'Success' not in output:
33 raise Exception('Unable to install %s. output: %s' % (from_apk, output))
34
35 raw_input('Set the application state. Once ready, press enter and ' 40 raw_input('Set the application state. Once ready, press enter and '
36 'select "Backup my data" on the device.') 41 'select "Backup my data" on the device.')
37 _BackupAppData(data_dir) 42 package_name = apk_helper.GetPackageName(old_apk)
43 device.adb.Backup(app_data, packages=[package_name])
44 logging.critical('Application data saved to %s' % app_data)
38 45
46 def TestUpdate(device, old_apk, new_apk, app_data):
47 device.Install(old_apk)
48 device.adb.Restore(app_data)
49 # Restore command is not synchronous
50 raw_input('Select "Restore my data" on the device. Then press enter to '
51 'continue.')
39 52
40 def _VerifyAppUpdate(device, to_apk, app_data, from_apk=None): 53 package_name = apk_helper.GetPackageName(new_apk)
41 def _RestoreAppData(): 54 device_path = device.GetApplicationPath(package_name)
42 assert os.path.exists(app_data), 'Backup file does not exist!' 55 if not device_path:
43 device.adb.Restore(app_data) 56 raise Exception('Expected package %s to already be installed. '
44 # It seems restore command is not synchronous. 57 'Package name might have changed!' % package_name)
45 time.sleep(15)
46 58
47 if from_apk: 59 logging.info('Verifying that %s can be overinstalled.', new_apk)
48 logging.info('Installing %s...', from_apk) 60 device.adb.Install(new_apk, reinstall=True)
49 output = device.Install(from_apk, reinstall=True) 61 logging.critical('Successfully updated to the new apk. Please verify that '
50 if 'Success' not in output: 62 'the application data is preserved.')
51 raise Exception('Unable to install %s. output: %s' % (from_apk, output))
52
53 logging.info('Restoring the application data...')
54 raw_input('Press enter and select "Restore my data" on the device.')
55 _RestoreAppData()
56
57 logging.info('Verifying that %s cannot be installed side-by-side...',
58 to_apk)
59 output = device.Install(to_apk)
60 if 'INSTALL_FAILED_ALREADY_EXISTS' not in output:
61 if 'Success' in output:
62 raise Exception('Package name has changed! output: %s' % output)
63 else:
64 raise Exception(output)
65
66 logging.info('Verifying that %s can be overinstalled...', to_apk)
67 output = device.adb.Install(to_apk, reinstall=True)
68 if 'Success' not in output:
69 raise Exception('Unable to install %s.\n output: %s' % (to_apk, output))
70 logging.info('Successfully updated to the new apk. Please verify that the '
71 'the application data is preserved.')
72
73 63
74 def main(): 64 def main():
75 logger = logging.getLogger() 65 parser = argparse.ArgumentParser(
76 logger.setLevel(logging.DEBUG) 66 description="Script to do semi-automated upgrade testing.")
77 desc = ( 67 parser.add_argument('-v', '--verbose', action='count',
78 'Performs semi-automated application update verification testing. ' 68 help='Print verbose log information.')
79 'When given --save, it takes a snapshot of the application data ' 69 command_parsers = parser.add_subparsers(dest='command')
80 'on the device. (A dialog on the device will prompt the user to grant '
81 'permission to backup the data.) Otherwise, it performs the update '
82 'testing as follows: '
83 '1. Installs the |from-apk| (optional). '
84 '2. Restores the previously stored snapshot of application data '
85 'given by |app-data| '
86 '(A dialog on the device will prompt the user to grant permission to '
87 'restore the data.) '
88 '3. Verifies that |to-apk| cannot be installed side-by-side. '
89 '4. Verifies that |to-apk| can replace |from-apk|.')
90 parser = optparse.OptionParser(description=desc)
91 parser.add_option('--package-name', help='Package name for the application.')
92 parser.add_option('--save', action='store_true',
93 help=('Save a snapshot of application data. '
94 'This will be saved as backup.db in the '
95 'current directory if |app-data| directory '
96 'is not specifid.'))
97 parser.add_option('--from-apk',
98 help=('APK to update from. This is optional if you already '
99 'have the app installed.'))
100 parser.add_option('--to-apk', help='APK to update to.')
101 parser.add_option('--app-data',
102 help=('Path to the application data to be restored or the '
103 'directory where the data should be saved.'))
104 (options, args) = parser.parse_args()
105 70
106 if args: 71 subparser = command_parsers.add_parser('create_app_data')
107 parser.print_help(sys.stderr) 72 subparser.add_argument('--old-apk', required=True,
108 parser.error('Unknown arguments: %s.' % args) 73 help='Path to apk to update from.')
74 subparser.add_argument('--app-data', required=True,
75 help='Path to where the app data backup should be '
76 'saved to.')
77
78 subparser = command_parsers.add_parser('test_update')
79 subparser.add_argument('--old-apk', required=True,
80 help='Path to apk to update from.')
81 subparser.add_argument('--new-apk', required=True,
82 help='Path to apk to update to.')
83 subparser.add_argument('--app-data', required=True,
84 help='Path to where the app data backup is saved.')
85
86 args = parser.parse_args()
87 run_tests_helper.SetLogLevel(args.verbose)
109 88
110 devices = device_utils.DeviceUtils.HealthyDevices() 89 devices = device_utils.DeviceUtils.HealthyDevices()
111 if len(devices) != 1:
112 parser.error('Exactly 1 device must be attached.')
113 device = devices[0] 90 device = devices[0]
91 logging.info('Using device %s for testing.' % str(device))
114 92
115 if options.from_apk: 93 if args.command == 'create_app_data':
116 assert os.path.isfile(options.from_apk) 94 CreateAppData(device, args.old_apk, args.app_data)
117 95 elif args.command == 'test_update':
118 if options.save: 96 TestUpdate(device, args.old_apk, args.new_apk, args.app_data)
119 if not options.package_name:
120 parser.print_help(sys.stderr)
121 parser.error('Missing --package-name.')
122 _SaveAppData(device, options.package_name, from_apk=options.from_apk,
123 data_dir=options.app_data)
124 else: 97 else:
125 if not options.to_apk or not options.app_data: 98 raise Exception('Unknown test command: %s' % args.command)
126 parser.print_help(sys.stderr)
127 parser.error('Missing --to-apk or --app-data.')
128 assert os.path.isfile(options.to_apk)
129 assert os.path.isfile(options.app_data)
130 _VerifyAppUpdate(device, options.to_apk, options.app_data,
131 from_apk=options.from_apk)
132
133 99
134 if __name__ == '__main__': 100 if __name__ == '__main__':
135 main() 101 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/test_runner.py ('k') | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698