diff options
| author | SzuWei Lin <szuweilin@google.com> | 2020-09-01 18:49:46 +0800 |
|---|---|---|
| committer | SzuWei Lin <szuweilin@google.com> | 2020-09-01 18:49:46 +0800 |
| commit | 376690a88bd92c63e23c99ffd89fe94da9862392 (patch) | |
| tree | 2f9dacbbe71bfbcf9fa27af8ad30f4b06e25636f | |
| parent | 9134a0a7d024d003907069f3a1856fe8cfcf132d (diff) | |
| parent | e733d2418a664aa03fe353c5581b359cad00aa76 (diff) | |
| download | platform_test_suite_harness-android10-gsi.tar.gz platform_test_suite_harness-android10-gsi.tar.bz2 platform_test_suite_harness-android10-gsi.zip | |
Merge branch android10-qpr3-releaseandroid10-gsi
Change-Id: Ia61c56d6809a119c32ceb0dd1580240464c618fe
5 files changed, 129 insertions, 44 deletions
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopier.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopier.java index d0c70436..e8d12288 100644 --- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopier.java +++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopier.java @@ -45,7 +45,8 @@ public class PreviousSessionFileCopier implements ITestInvocationListener { CertificationSuiteResultReporter.FAILURE_REPORT_NAME, CertificationSuiteResultReporter.SUMMARY_FILE, CertificationChecksumHelper.NAME, - "diffs"); + "diffs", + "proto"); private CompatibilityBuildHelper mBuildHelper; private File mPreviousSessionDir = null; diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/ApkInstrumentationPreparer.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/ApkInstrumentationPreparer.java index 80493f7b..a1e51827 100644 --- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/ApkInstrumentationPreparer.java +++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/ApkInstrumentationPreparer.java @@ -19,6 +19,8 @@ package com.android.compatibility.common.tradefed.targetprep; import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; import com.android.ddmlib.testrunner.TestResult.TestStatus; import com.android.tradefed.build.IBuildInfo; +import com.android.tradefed.config.IConfiguration; +import com.android.tradefed.config.IConfigurationReceiver; import com.android.tradefed.config.Option; import com.android.tradefed.config.OptionClass; import com.android.tradefed.device.DeviceNotAvailableException; @@ -37,11 +39,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Map.Entry; -/** - * Target preparer that instruments an APK. - */ -@OptionClass(alias="apk-instrumentation-preparer") -public class ApkInstrumentationPreparer extends PreconditionPreparer implements ITargetCleaner { +/** Target preparer that instruments an APK. */ +@OptionClass(alias = "apk-instrumentation-preparer") +public class ApkInstrumentationPreparer extends PreconditionPreparer + implements IConfigurationReceiver, ITargetCleaner { @Option(name = "apk", description = "Name of the apk to instrument", mandatory = true) protected String mApkFileName = null; @@ -59,6 +60,14 @@ public class ApkInstrumentationPreparer extends PreconditionPreparer implements @Option(name = "throw-error", description = "Whether to throw error for device test failure") protected boolean mThrowError = true; + private IConfiguration mConfiguration = null; + + /** {@inheritDoc} */ + @Override + public void setConfiguration(IConfiguration configuration) { + mConfiguration = configuration; + } + /** * {@inheritDoc} */ @@ -118,6 +127,7 @@ public class ApkInstrumentationPreparer extends PreconditionPreparer implements CLog.i("Instrumenting package: %s", mPackageName); CollectingTestListener listener = new CollectingTestListener(); AndroidJUnitTest instrTest = new AndroidJUnitTest(); + instrTest.setConfiguration(mConfiguration); instrTest.setDevice(device); instrTest.setInstallFile(apkFile); instrTest.setPackageName(mPackageName); diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopierTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopierTest.java index 918acd39..a0c3131b 100644 --- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopierTest.java +++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/result/suite/PreviousSessionFileCopierTest.java @@ -95,4 +95,13 @@ public class PreviousSessionFileCopierTest { // File are not overriden assertEquals("CURRENT", FileUtil.readStringFromFile(original)); } + + @Test + public void testCopy_fileExcluded() throws Exception { + new File(mPreviousDir, "proto").mkdir(); + mCopier.invocationStarted(mContext); + mCopier.invocationEnded(500L); + // Nothing was copied + assertEquals(0, mCurrentDir.listFiles().length); + } } diff --git a/common/util/src/com/android/compatibility/common/util/CrashUtils.java b/common/util/src/com/android/compatibility/common/util/CrashUtils.java index 430fafb9..c6433a89 100644 --- a/common/util/src/com/android/compatibility/common/util/CrashUtils.java +++ b/common/util/src/com/android/compatibility/common/util/CrashUtils.java @@ -17,6 +17,10 @@ package com.android.compatibility.common.util; import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.math.BigInteger; @@ -60,12 +64,9 @@ public class CrashUtils { private static Pattern sAbortMessageCheckPattern = Pattern.compile("(?i)Abort message.*?CHECK_"); - /** - * returns true if the signal is a segmentation fault or bus error. - */ - public static boolean isSecuritySignal(JSONObject crash) throws JSONException { - return crash.getString(SIGNAL).toLowerCase().matches("sig(segv|bus)"); - } + public static final String SIGSEGV = "SIGSEGV"; + public static final String SIGBUS = "SIGBUS"; + public static final String SIGABRT = "SIGABRT"; /** * returns the filename of the process. @@ -79,14 +80,12 @@ public class CrashUtils { * Determines if the given input has a {@link com.android.compatibility.common.util.Crash} that * should fail an sts test * - * @param processPatterns list of patterns that match applicable process names - * @param checkMinAddr if the minimum fault address should be respected * @param crashes list of crashes to check + * @param config crash detection configuration object * @return if a crash is serious enough to fail an sts test */ - public static boolean securityCrashDetected( - JSONArray crashes, boolean checkMinAddr, Pattern... processPatterns) { - return matchSecurityCrashes(crashes, checkMinAddr, processPatterns).length() > 0; + public static boolean securityCrashDetected(JSONArray crashes, Config config) { + return matchSecurityCrashes(crashes, config).length() > 0; } public static BigInteger getBigInteger(JSONObject source, String name) throws JSONException { @@ -105,27 +104,34 @@ public class CrashUtils { * Determines which given inputs have a {@link com.android.compatibility.common.util.Crash} that * should fail an sts test * - * @param processPatterns list of patterns that match applicable process names - * @param checkMinAddr if the minimum fault address should be respected * @param crashes list of crashes to check + * @param config crash detection configuration object * @return the list of crashes serious enough to fail an sts test */ - public static JSONArray matchSecurityCrashes( - JSONArray crashes, boolean checkMinAddr, Pattern... processPatterns) { + public static JSONArray matchSecurityCrashes(JSONArray crashes, Config config) { JSONArray securityCrashes = new JSONArray(); for (int i = 0; i < crashes.length(); i++) { try { JSONObject crash = crashes.getJSONObject(i); - if (!matchesAny(getProcessFileName(crash), processPatterns)) { + + // match process patterns + if (!matchesAny(getProcessFileName(crash), config.processPatterns)) { continue; } - if (!isSecuritySignal(crash)) { + + // match signal + String crashSignal = crash.getString(SIGNAL); + if (!config.signals.contains(crashSignal)) { continue; } - BigInteger faultAddress = getBigInteger(crash, FAULT_ADDRESS); - if (checkMinAddr && faultAddress != null - && faultAddress.compareTo(MIN_CRASH_ADDR) < 0) { - continue; + + // if check specified, reject crash if address is unlikely to be security-related + if (config.checkMinAddress) { + BigInteger faultAddress = getBigInteger(crash, FAULT_ADDRESS); + if (faultAddress != null + && faultAddress.compareTo(config.minCrashAddress) < 0) { + continue; + } } securityCrashes.put(crash); } catch (JSONException | NullPointerException e) {} @@ -136,7 +142,7 @@ public class CrashUtils { /** * returns true if the input matches any of the patterns. */ - private static boolean matchesAny(String input, Pattern... patterns) { + private static boolean matchesAny(String input, Collection<Pattern> patterns) { for (Pattern p : patterns) { if (p.matcher(input).matches()) { return true; @@ -195,4 +201,53 @@ public class CrashUtils { } return crashes; } + + public static class Config { + private boolean checkMinAddress = true; + private BigInteger minCrashAddress = MIN_CRASH_ADDR; + private List<String> signals = Arrays.asList(SIGSEGV, SIGBUS); + private List<Pattern> processPatterns = Collections.emptyList(); + + public Config setMinAddress(BigInteger minCrashAddress) { + this.minCrashAddress = minCrashAddress; + return this; + } + + public Config checkMinAddress(boolean checkMinAddress) { + this.checkMinAddress = checkMinAddress; + return this; + } + + public Config setSignals(String... signals) { + this.signals = Arrays.asList(signals); + return this; + } + + public Config appendSignals(String... signals) { + Collections.addAll(this.signals, signals); + return this; + } + + public Config setProcessPatterns(String... processPatternStrings) { + Pattern[] processPatterns = new Pattern[processPatternStrings.length]; + for (int i = 0; i < processPatternStrings.length; i++) { + processPatterns[i] = Pattern.compile(processPatternStrings[i]); + } + return setProcessPatterns(processPatterns); + } + + public Config setProcessPatterns(Pattern... processPatterns) { + this.processPatterns = Arrays.asList(processPatterns); + return this; + } + + public List<Pattern> getProcessPatterns() { + return Collections.unmodifiableList(processPatterns); + } + + public Config appendProcessPatterns(Pattern... processPatterns) { + Collections.addAll(this.processPatterns, processPatterns); + return this; + } + } } diff --git a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java index 2138b7b3..071733f8 100644 --- a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java +++ b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java @@ -91,51 +91,61 @@ public class CrashUtilsTest { @Test public void testValidCrash() throws Exception { - Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_0"))); + Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("synthetic_process_0")))); } @Test public void testMissingName() throws Exception { - Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile(""))); + Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("")))); } @Test public void testSIGABRT() throws Exception { - Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("installd"))); + Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("installd")))); } @Test public void testFaultAddressBelowMin() throws Exception { - Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_1"))); + Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("synthetic_process_1")))); } @Test public void testIgnoreMinAddressCheck() throws Exception { - Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, false, - Pattern.compile("synthetic_process_1"))); + Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(false) + .setProcessPatterns(Pattern.compile("synthetic_process_1")))); } @Test public void testBadAbortMessage() throws Exception { - Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("generic"))); + Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("generic")))); } @Test public void testGoodAndBadCrashes() throws Exception { - Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, true, - Pattern.compile("synthetic_process_0"), Pattern.compile("generic"))); + Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns( + Pattern.compile("synthetic_process_0"), + Pattern.compile("generic")))); } @Test public void testNullFaultAddress() throws Exception { JSONArray crashes = new JSONArray(); crashes.put(createCrashJson(8373, 8414, "loo", "com.android.bluetooth", null, "SIGSEGV")); - Assert.assertTrue(CrashUtils.securityCrashDetected(crashes, true, - Pattern.compile("com\\.android\\.bluetooth"))); + Assert.assertTrue(CrashUtils.securityCrashDetected(crashes, new CrashUtils.Config() + .checkMinAddress(true) + .setProcessPatterns(Pattern.compile("com\\.android\\.bluetooth")))); } } |
