1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.angle.cts; 17 18 import com.android.tradefed.device.ITestDevice; 19 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 class CtsAngleCommon { 25 // General 26 static final int NUM_ATTEMPTS = 5; 27 static final int REATTEMPT_SLEEP_MSEC = 5000; 28 29 // Settings.Global 30 static final String SETTINGS_GLOBAL_ALL_USE_ANGLE = "angle_gl_driver_all_angle"; 31 static final String SETTINGS_GLOBAL_DRIVER_PKGS = "angle_gl_driver_selection_pkgs"; 32 static final String SETTINGS_GLOBAL_DRIVER_VALUES = "angle_gl_driver_selection_values"; 33 static final String SETTINGS_GLOBAL_ALLOWLIST = "angle_allowlist"; 34 static final String SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX = "show_angle_in_use_dialog_box"; 35 36 // System Properties 37 static final String PROPERTY_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported"; 38 static final String PROPERTY_TEMP_RULES_FILE = "debug.angle.rules"; 39 40 // Rules File 41 static final String DEVICE_TEMP_RULES_FILE_DIRECTORY = "/data/local/tmp"; 42 static final String DEVICE_TEMP_RULES_FILE_FILENAME = "a4a_rules.json"; 43 static final String DEVICE_TEMP_RULES_FILE_PATH = DEVICE_TEMP_RULES_FILE_DIRECTORY + "/" + DEVICE_TEMP_RULES_FILE_FILENAME; 44 45 // ANGLE 46 static final String ANGLE_DRIVER_TEST_PKG = "com.android.angleIntegrationTest.driverTest"; 47 static final String ANGLE_DRIVER_TEST_SEC_PKG = "com.android.angleIntegrationTest.driverTestSecondary"; 48 static final String ANGLE_DRIVER_TEST_CLASS = "AngleDriverTestActivity"; 49 static final String ANGLE_DRIVER_TEST_DEFAULT_METHOD = "testUseDefaultDriver"; 50 static final String ANGLE_DRIVER_TEST_ANGLE_METHOD = "testUseAngleDriver"; 51 static final String ANGLE_DRIVER_TEST_NATIVE_METHOD = "testUseNativeDriver"; 52 static final String ANGLE_DRIVER_TEST_APP = "CtsAngleDriverTestCases.apk"; 53 static final String ANGLE_DRIVER_TEST_SEC_APP = "CtsAngleDriverTestCasesSecondary.apk"; 54 static final String ANGLE_DRIVER_TEST_ACTIVITY = 55 ANGLE_DRIVER_TEST_PKG + "/com.android.angleIntegrationTest.common.AngleIntegrationTestActivity"; 56 static final String ANGLE_DRIVER_TEST_SEC_ACTIVITY = 57 ANGLE_DRIVER_TEST_SEC_PKG + "/com.android.angleIntegrationTest.common.AngleIntegrationTestActivity"; 58 static final String ANGLE_MAIN_ACTIVTY = "android.app.action.ANGLE_FOR_ANDROID"; 59 60 enum OpenGlDriverChoice { 61 DEFAULT, 62 NATIVE, 63 ANGLE 64 } 65 66 static final Map<OpenGlDriverChoice, String> sDriverGlobalSettingMap = buildDriverGlobalSettingMap(); buildDriverGlobalSettingMap()67 static Map<OpenGlDriverChoice, String> buildDriverGlobalSettingMap() { 68 Map<OpenGlDriverChoice, String> map = new HashMap<>(); 69 map.put(OpenGlDriverChoice.DEFAULT, "default"); 70 map.put(OpenGlDriverChoice.ANGLE, "angle"); 71 map.put(OpenGlDriverChoice.NATIVE, "native"); 72 73 return map; 74 } 75 76 static final Map<OpenGlDriverChoice, String> sDriverTestMethodMap = buildDriverTestMethodMap(); buildDriverTestMethodMap()77 static Map<OpenGlDriverChoice, String> buildDriverTestMethodMap() { 78 Map<OpenGlDriverChoice, String> map = new HashMap<>(); 79 map.put(OpenGlDriverChoice.DEFAULT, ANGLE_DRIVER_TEST_DEFAULT_METHOD); 80 map.put(OpenGlDriverChoice.ANGLE, ANGLE_DRIVER_TEST_ANGLE_METHOD); 81 map.put(OpenGlDriverChoice.NATIVE, ANGLE_DRIVER_TEST_NATIVE_METHOD); 82 83 return map; 84 } 85 getGlobalSetting(ITestDevice device, String globalSetting)86 static String getGlobalSetting(ITestDevice device, String globalSetting) throws Exception { 87 return device.getSetting("global", globalSetting); 88 } 89 setGlobalSetting(ITestDevice device, String globalSetting, String value)90 static void setGlobalSetting(ITestDevice device, String globalSetting, String value) throws Exception { 91 device.setSetting("global", globalSetting, value); 92 device.executeShellCommand("am refresh-settings-cache"); 93 } 94 clearSettings(ITestDevice device)95 static void clearSettings(ITestDevice device) throws Exception { 96 // Cached Activity Manager settings 97 setGlobalSetting(device, SETTINGS_GLOBAL_ALL_USE_ANGLE, "0"); 98 setGlobalSetting(device, SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX, "0"); 99 setGlobalSetting(device, SETTINGS_GLOBAL_DRIVER_PKGS, "\"\""); 100 setGlobalSetting(device, SETTINGS_GLOBAL_DRIVER_VALUES, "\"\""); 101 setGlobalSetting(device, SETTINGS_GLOBAL_ALLOWLIST, "\"\""); 102 103 // Properties 104 setProperty(device, PROPERTY_TEMP_RULES_FILE, "\"\""); 105 } 106 isAngleLoadable(ITestDevice device)107 static boolean isAngleLoadable(ITestDevice device) throws Exception { 108 String angleSupported = device.getProperty(PROPERTY_GFX_ANGLE_SUPPORTED); 109 110 return (angleSupported != null) && (angleSupported.equals("true")); 111 } 112 isNativeDriverAngle(ITestDevice device)113 static boolean isNativeDriverAngle(ITestDevice device) throws Exception { 114 String driverProp = device.getProperty("ro.hardware.egl"); 115 116 return (driverProp != null) && (driverProp.equals("angle")); 117 } 118 startActivity(ITestDevice device, String action)119 static void startActivity(ITestDevice device, String action) throws Exception { 120 // Run the ANGLE activity so it'll clear up any 'default' settings. 121 device.executeShellCommand("am start --user " + device.getCurrentUser() + 122 " -S -W -a \"" + action + "\""); 123 } 124 stopPackage(ITestDevice device, String pkgName)125 static void stopPackage(ITestDevice device, String pkgName) throws Exception { 126 device.executeShellCommand("am force-stop " + pkgName); 127 } 128 129 /** 130 * Work around the fact that INativeDevice.enableAdbRoot() is not supported. 131 */ setProperty(ITestDevice device, String property, String value)132 static void setProperty(ITestDevice device, String property, String value) throws Exception { 133 device.executeShellCommand("setprop " + property + " " + value); 134 } 135 } 136