Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 1 | * Copyright (C) 2015 The Android Open Source Project |
| 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | |
| 15 | |
| 16 | INTRODUCTION |
| 17 | |
| 18 | The Android theme tests ensure that the Holo and Material themes have not been |
| 19 | modified. They consist of API-specific sets of reference images representing |
| 20 | specific themes and widgets that must be identical across devices. To pass the |
| 21 | theme tests, a device must be able to generate images that are identical to the |
| 22 | reference images. |
| 23 | |
| 24 | NOTE: Reference images should only be updated by the CTS test maintainers. Any |
| 25 | modifications to the reference images will invalidate the test results. |
| 26 | |
| 27 | |
| 28 | INSTRUCTIONS |
| 29 | |
| 30 | I. Generating reference images (CTS maintainers only) |
| 31 | |
| 32 | Reference images are typically only generated for new API revisions. To |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 33 | generate a new set of reference images from an emulator, do the following: |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 34 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 35 | 1. Ensure the Android SDK is installed locally. Either a public or internal |
| 36 | distribution is fine. From the console, set the ANDROID_SDK_ROOT env var: |
Alan Viverette | 598c692 | 2017-04-28 18:32:23 -0400 | [diff] [blame] | 37 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 38 | export ANDROID_SDK_ROOT = /path/to/sdk |
Alan Viverette | 598c692 | 2017-04-28 18:32:23 -0400 | [diff] [blame] | 39 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 40 | 2. Obtain an x86_64 emulator image from the build server by using the script |
| 41 | available internally at go/emu-dev. This script will install the image in |
| 42 | your SDK. |
Alan Viverette | 598c692 | 2017-04-28 18:32:23 -0400 | [diff] [blame] | 43 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 44 | 3. Use the SDK's AVD Manager tool to create a single virtual device using the |
| 45 | emulator image from step 2. The exact configuration doesn't really matter; |
| 46 | you can use Nexus 5 as a template. Name the emulator "theme_emulator". |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 47 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 48 | 4. From the console, set up your build environment for x86_64 and build CTS: |
Alan Viverette | 598c692 | 2017-04-28 18:32:23 -0400 | [diff] [blame] | 49 | |
| 50 | lunch sdk_x86_64-eng && make cts -j32 |
| 51 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 52 | 5. Use the reference image script to generate the reference images. The script |
| 53 | will automatically start the emulator in the required configurations and |
| 54 | install the resulting reference images in assets/<platform>/<dpi>.zip, |
| 55 | overwriting any existing images. |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 56 | |
Alan Viverette | 7d87cea | 2017-09-26 13:39:21 -0400 | [diff] [blame] | 57 | ./cts/hostsidetests/theme/generate_images.py theme_emulator |
| 58 | |
| 59 | You can also generate reference images using a real device. To generate a new set |
| 60 | of reference images from a real device, do the following: |
| 61 | |
| 62 | 1. Connect the device. Verify the device is connected: |
| 63 | |
| 64 | adb devices |
| 65 | |
| 66 | 2. Use the reference image script to generate the reference images: |
| 67 | |
| 68 | ./cts/hostsidetests/theme/generate_images.py |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 69 | |
Stan Iliev | 3baab43 | 2017-11-10 11:28:48 -0500 | [diff] [blame] | 70 | There is an option to build locally an Android system image and use an emulator that is stored in |
| 71 | Android source tree under "prebuilts/android-emulator/linux-x86_64/emulator". This option does not |
| 72 | require a SDK and can be used to generate images with locally modified source code: for example |
| 73 | right before making a test breaking change. |
| 74 | |
| 75 | 1. From the console, set up your build environment for sdk_phone_x86_64 and build Android and CTS: |
| 76 | |
| 77 | lunch sdk_phone_x86_64-userdebug && make -j32 && make cts -j32 |
| 78 | |
| 79 | 2. Use the reference image script to generate the reference images. The script |
| 80 | will automatically start the emulator in the required configurations and |
| 81 | install the resulting reference images in assets/<platform>/<dpi>.zip, |
| 82 | overwriting any existing images. |
| 83 | |
| 84 | ./cts/hostsidetests/theme/generate_images.py local |
| 85 | |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 86 | A complete collection of reference images for a given API revision must include |
| 87 | a set for each possible DPI bucket (tvdpi, xxhdpi, etc.) that may be tested. |
| 88 | |
Alan Viverette | 4f560b6 | 2016-06-06 09:58:40 -0400 | [diff] [blame] | 89 | For a list of devices and their DPI buckets, see Device Metrics: |
| 90 | |
| 91 | https://design.google.com/devices/ |
| 92 | |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 93 | |
| 94 | II. Building theme tests |
| 95 | |
| 96 | 1. If you have not already built the CTS tests, run an initial make: |
| 97 | |
| 98 | make cts -j32 |
| 99 | |
| 100 | 2. Subsequent changes to the theme tests, including changes to the reference |
| 101 | images, may be built using mmm: |
| 102 | |
| 103 | mmm cts/hostsidetests/theme -j32 |
| 104 | |
| 105 | |
| 106 | III. Running theme tests |
| 107 | |
Alan Viverette | b246d96 | 2016-08-03 12:38:20 -0400 | [diff] [blame] | 108 | To obtain reliable results, theme tests should be run against the device's |
| 109 | native density; however, many of the tests will also work in a scaled density. |
| 110 | If you don't possess a device for a given density and would still like to run |
| 111 | tests for that density, you can manually force scaling via: |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 112 | |
Alan Viverette | b246d96 | 2016-08-03 12:38:20 -0400 | [diff] [blame] | 113 | adb shell wm density <dpi> |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 114 | |
Alan Viverette | b246d96 | 2016-08-03 12:38:20 -0400 | [diff] [blame] | 115 | As of API 24, the results will NOT be 100% reliable due to scaling artifacts. |
| 116 | To reset the device to its native density, run: |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 117 | |
Alan Viverette | b246d96 | 2016-08-03 12:38:20 -0400 | [diff] [blame] | 118 | adb shell wm density reset |
Alan Viverette | c15ea9f | 2015-08-26 16:33:17 -0400 | [diff] [blame] | 119 | |
Alan Viverette | b246d96 | 2016-08-03 12:38:20 -0400 | [diff] [blame] | 120 | Once the device is in the desired state, do the following: |
| 121 | |
| 122 | 1. Connect the device that you wish to test. Confirm that is is connected with: |
| 123 | |
| 124 | adb devices |
| 125 | |
| 126 | 2. Run the theme tests using cts-tradefed: |
| 127 | |
| 128 | cts-tradefed run singleCommand cts-dev --module CtsThemeHostTestCases \ |
| 129 | --test android.theme.cts.ThemeHostTest |
| 130 | |
| 131 | 3. Wait for the tests to complete. This should take less than five minutes. |
| 132 | |
Alan Viverette | 40115c4 | 2017-04-04 13:11:08 -0400 | [diff] [blame] | 133 | If any test failures are encountered, diff PNGs will be generated and collected |
| 134 | in the "diffs" directory of the CTS results indicated by "Test Result:" in the |
| 135 | test output. |