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 33 generate a new set of reference images from an emulator, do the following: 34 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: 37 38 export ANDROID_SDK_ROOT = /path/to/sdk 39 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. 43 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". 47 48 4. From the console, set up your build environment for x86_64 and build CTS: 49 50 lunch sdk_x86_64-eng && make cts -j32 51 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. 56 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 69 70 A complete collection of reference images for a given API revision must include 71 a set for each possible DPI bucket (tvdpi, xxhdpi, etc.) that may be tested. 72 73 For a list of devices and their DPI buckets, see Device Metrics: 74 75 https://design.google.com/devices/ 76 77 78 II. Building theme tests 79 80 1. If you have not already built the CTS tests, run an initial make: 81 82 make cts -j32 83 84 2. Subsequent changes to the theme tests, including changes to the reference 85 images, may be built using mmm: 86 87 mmm cts/hostsidetests/theme -j32 88 89 90 III. Running theme tests 91 92 To obtain reliable results, theme tests should be run against the device's 93 native density; however, many of the tests will also work in a scaled density. 94 If you don't possess a device for a given density and would still like to run 95 tests for that density, you can manually force scaling via: 96 97 adb shell wm density <dpi> 98 99 As of API 24, the results will NOT be 100% reliable due to scaling artifacts. 100 To reset the device to its native density, run: 101 102 adb shell wm density reset 103 104 Once the device is in the desired state, do the following: 105 106 1. Connect the device that you wish to test. Confirm that is is connected with: 107 108 adb devices 109 110 2. Run the theme tests using cts-tradefed: 111 112 cts-tradefed run singleCommand cts-dev --module CtsThemeHostTestCases \ 113 --test android.theme.cts.ThemeHostTest 114 115 3. Wait for the tests to complete. This should take less than five minutes. 116 117 If any test failures are encountered, diff PNGs will be generated and collected 118 in the "diffs" directory of the CTS results indicated by "Test Result:" in the 119 test output. 120