Peter Wen | b51e454 | 2021-06-30 17:42:57 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 2 | # |
Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 3 | # Copyright 2013 The Chromium Authors |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 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 |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 28 | import logging |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 29 | import sys |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 30 | |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 31 | import devil_chromium |
| 32 | |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 33 | from devil.android import apk_helper |
John Budorick | 8b57e60 | 2020-09-01 16:57:50 | [diff] [blame] | 34 | from devil.android import device_denylist |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 35 | from devil.android import device_errors |
| 36 | from devil.android import device_utils |
| 37 | from devil.utils import run_tests_helper |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 38 | |
Peter Wen | b51e454 | 2021-06-30 17:42:57 | [diff] [blame] | 39 | |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 40 | def CreateAppData(device, old_apk, app_data, package_name): |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 41 | device.Install(old_apk) |
Ben Joyce | d782295 | 2021-08-17 17:19:03 | [diff] [blame] | 42 | input('Set the application state. Once ready, press enter and ' |
| 43 | 'select "Backup my data" on the device.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 44 | device.adb.Backup(app_data, packages=[package_name]) |
jbudorick | 58b4d36 | 2015-09-08 16:44:59 | [diff] [blame] | 45 | logging.critical('Application data saved to %s', app_data) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 46 | |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 47 | def TestUpdate(device, old_apk, new_apk, app_data, package_name): |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 48 | device.Install(old_apk) |
| 49 | device.adb.Restore(app_data) |
| 50 | # Restore command is not synchronous |
Ben Joyce | d782295 | 2021-08-17 17:19:03 | [diff] [blame] | 51 | input('Select "Restore my data" on the device. Then press enter to ' |
| 52 | 'continue.') |
Nate Fischer | d681a00 | 2019-09-17 16:42:09 | [diff] [blame] | 53 | if not device.IsApplicationInstalled(package_name): |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 54 | raise Exception('Expected package %s to already be installed. ' |
| 55 | 'Package name might have changed!' % package_name) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 56 | |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 57 | logging.info('Verifying that %s can be overinstalled.', new_apk) |
| 58 | device.adb.Install(new_apk, reinstall=True) |
| 59 | logging.critical('Successfully updated to the new apk. Please verify that ' |
| 60 | 'the application data is preserved.') |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 61 | |
| 62 | def main(): |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 63 | parser = argparse.ArgumentParser( |
| 64 | description="Script to do semi-automated upgrade testing.") |
| 65 | parser.add_argument('-v', '--verbose', action='count', |
| 66 | help='Print verbose log information.') |
John Budorick | 8b57e60 | 2020-09-01 16:57:50 | [diff] [blame] | 67 | parser.add_argument('--denylist-file', help='Device denylist JSON file.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 68 | command_parsers = parser.add_subparsers(dest='command') |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 69 | |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 70 | subparser = command_parsers.add_parser('create_app_data') |
| 71 | subparser.add_argument('--old-apk', required=True, |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 72 | help='Path to apk to update from.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 73 | subparser.add_argument('--app-data', required=True, |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 74 | help='Path to where the app data backup should be ' |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 75 | 'saved to.') |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 76 | subparser.add_argument('--package-name', |
| 77 | help='Chrome apk package name.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 78 | |
| 79 | subparser = command_parsers.add_parser('test_update') |
| 80 | subparser.add_argument('--old-apk', required=True, |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 81 | help='Path to apk to update from.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 82 | subparser.add_argument('--new-apk', required=True, |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 83 | help='Path to apk to update to.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 84 | subparser.add_argument('--app-data', required=True, |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 85 | help='Path to where the app data backup is saved.') |
| 86 | subparser.add_argument('--package-name', |
| 87 | help='Chrome apk package name.') |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 88 | |
| 89 | args = parser.parse_args() |
| 90 | run_tests_helper.SetLogLevel(args.verbose) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 91 | |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 92 | devil_chromium.Initialize() |
| 93 | |
John Budorick | 8b57e60 | 2020-09-01 16:57:50 | [diff] [blame] | 94 | denylist = (device_denylist.Denylist(args.denylist_file) |
| 95 | if args.denylist_file else None) |
jbudorick | dde688fb | 2015-08-27 03:00:17 | [diff] [blame] | 96 | |
John Budorick | 8b57e60 | 2020-09-01 16:57:50 | [diff] [blame] | 97 | devices = device_utils.DeviceUtils.HealthyDevices(denylist) |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 98 | if not devices: |
| 99 | raise device_errors.NoDevicesError() |
jbudorick | 119e457 | 2015-04-24 17:20:03 | [diff] [blame] | 100 | device = devices[0] |
jbudorick | 58b4d36 | 2015-09-08 16:44:59 | [diff] [blame] | 101 | logging.info('Using device %s for testing.', str(device)) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 102 | |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 103 | package_name = (args.package_name if args.package_name |
| 104 | else apk_helper.GetPackageName(args.old_apk)) |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 105 | if args.command == 'create_app_data': |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 106 | CreateAppData(device, args.old_apk, args.app_data, package_name) |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 107 | elif args.command == 'test_update': |
mikecase | 06ef720 | 2015-05-23 02:30:06 | [diff] [blame] | 108 | TestUpdate( |
| 109 | device, args.old_apk, args.new_apk, args.app_data, package_name) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 110 | else: |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 111 | raise Exception('Unknown test command: %s' % args.command) |
[email protected] | 3de785b4 | 2013-01-11 00:13:54 | [diff] [blame] | 112 | |
| 113 | if __name__ == '__main__': |
mikecase | 798b3dc | 2015-05-06 18:32:07 | [diff] [blame] | 114 | sys.exit(main()) |