1 /* 2 * Copyright (C) 2023 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 17 package android.cts.gwp_asan; 18 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 21 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 22 23 import org.junit.After; 24 import org.junit.Assert; 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(DeviceJUnit4ClassRunner.class) 30 public abstract class GwpAsanBaseTest extends BaseHostJUnit4Test { 31 protected static final String TEST_PKG = "android.cts.gwp_asan"; 32 protected ITestDevice mDevice; 33 getTestApk()34 protected abstract String getTestApk(); getTestNameSuffix()35 protected abstract String getTestNameSuffix(); 36 37 @Before setUp()38 public void setUp() throws Exception { 39 mDevice = getDevice(); 40 installPackage(getTestApk(), new String[0]); 41 42 // Reset the rate-limiting counters inside DropBoxManager, which only allows up to six 43 // dropbox entries with the same {process name + entry tag} within any 10 minute period. We 44 // can run the full suite right now without hitting the limit, but running the tests 45 // multiple times runs into the limit. See 46 // `services/core/java/com/android/server/am/DropboxRateLimiter.java` for more information. 47 mDevice.executeShellCommand("am reset-dropbox-rate-limiter"); 48 } 49 50 @After tearDown()51 public void tearDown() throws Exception { 52 uninstallPackage(mDevice, TEST_PKG); 53 } 54 resetAppExitInfo()55 public void resetAppExitInfo() throws Exception { 56 mDevice.executeShellCommand("am clear-exit-info"); 57 } 58 runTest(String testClass, String testName)59 public void runTest(String testClass, String testName) throws Exception { 60 Assert.assertTrue(runDeviceTests(TEST_PKG, TEST_PKG + testClass, testName)); 61 } 62 63 @Test testGwpAsanEnabled()64 public void testGwpAsanEnabled() throws Exception { 65 runTest(".GwpAsanActivityTest", "testEnablement"); 66 runTest(".GwpAsanServiceTest", "testEnablement"); 67 } 68 69 @Test testCrashToDropbox()70 public void testCrashToDropbox() throws Exception { 71 runTest(".GwpAsanActivityTest", "testCrashToDropbox" + getTestNameSuffix() + "Enabled"); 72 runTest(".GwpAsanActivityTest", "testCrashToDropbox" + getTestNameSuffix() + "Default"); 73 runTest(".GwpAsanServiceTest", "testCrashToDropbox" + getTestNameSuffix() + "Enabled"); 74 runTest(".GwpAsanServiceTest", "testCrashToDropbox" + getTestNameSuffix() + "Default"); 75 } 76 77 @Test testAppExitInfo()78 public void testAppExitInfo() throws Exception { 79 resetAppExitInfo(); 80 runTest(".GwpAsanActivityTest", "testCrashToDropbox" + getTestNameSuffix() + "Default"); 81 runTest(".GwpAsanActivityTest", "checkAppExitInfo"); 82 } 83 } 84