Merge changes I6ae9881e,Id5aec329,Id0ebe6c8,I4135107c,I7f42f0cc into oreo-cts-dev
* changes:
[RESTRICT AUTOMERGE]: Give tests more control of crash parser behavior
[RESTRICT AUTOMERGE]: Give tests more control of crash parser behavior
[RESTRICT AUTOMERGE]: Find remaining Stagefright tests that shouldn't check the crash address
[RESTRICT AUTOMERGE]: Implement checkMinAddress into individual StagefrightTest testcases
[RESTRICT AUTOMERGE]: Add checkMinAddress flags to StagefrightTest
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 93d2d2d..60678e8 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.util.ArrayList;
@@ -59,12 +63,9 @@
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(Crash c) {
- return c.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.
@@ -78,31 +79,27 @@
* 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(
- List<Crash> crashes, boolean checkMinAddr, Pattern... processPatterns) {
- return !matchSecurityCrashes(crashes, checkMinAddr, processPatterns).isEmpty();
+ public static boolean securityCrashDetected(List<Crash> crashes, Config config) {
+ return matchSecurityCrashes(crashes, config).size() > 0;
}
/**
* 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 List<Crash> matchSecurityCrashes(
- List<Crash> crashes, boolean checkMinAddr, Pattern... processPatterns) {
+ public static List<Crash> matchSecurityCrashes(List<Crash> crashes, Config config) {
return crashes.stream()
- .filter(c -> matchesAny(getProcessFileName(c), processPatterns))
- .filter(c -> isSecuritySignal(c))
- .filter(c -> !checkMinAddr
+ .filter(c -> matchesAny(getProcessFileName(c), config.getProcessPatterns()))
+ .filter(c -> config.signals.contains(c.signal))
+ .filter(c -> !config.checkMinAddress
|| c.faultAddress == null || c.faultAddress.compareTo(MIN_CRASH_ADDR) >= 0)
.collect(Collectors.toList());
}
@@ -110,7 +107,7 @@
/**
* 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;
@@ -166,4 +163,53 @@
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 6a2ab6e..0f6ca1e 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
@@ -86,43 +86,52 @@
@Test
public void testValidCrash() throws Exception {
- assertTrue(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("synthetic_process_0")));
+ assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(Pattern.compile("synthetic_process_0"))));
}
@Test
public void testMissingName() throws Exception {
- assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("")));
+ assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(Pattern.compile(""))));
}
@Test
public void testSIGABRT() throws Exception {
- assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("installd")));
+ assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(Pattern.compile("installd"))));
}
@Test
public void testFaultAddressBelowMin() throws Exception {
- assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("synthetic_process_1")));
+ assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(Pattern.compile("synthetic_process_1"))));
}
@Test
public void testIgnoreMinAddressCheck() throws Exception {
- assertTrue(CrashUtils.securityCrashDetected(mCrashes, false,
- Pattern.compile("synthetic_process_1")));
+ assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(false)
+ .setProcessPatterns(Pattern.compile("synthetic_process_1"))));
}
@Test
public void testBadAbortMessage() throws Exception {
- assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("generic")));
+ assertFalse(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(Pattern.compile("generic"))));
}
@Test
public void testGoodAndBadCrashes() throws Exception {
- assertTrue(CrashUtils.securityCrashDetected(mCrashes, true,
- Pattern.compile("synthetic_process_0"), Pattern.compile("generic")));
+ assertTrue(CrashUtils.securityCrashDetected(mCrashes, new CrashUtils.Config()
+ .checkMinAddress(true)
+ .setProcessPatterns(
+ Pattern.compile("synthetic_process_0"),
+ Pattern.compile("generic"))));
}
}
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index d76b97c..61d71b9 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -122,7 +122,7 @@
}
public void testStagefright_bug_35763994() throws Exception {
- doStagefrightTest(R.raw.bug_35763994);
+ doStagefrightTest(R.raw.bug_35763994, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -132,7 +132,7 @@
@SecurityTest
public void testStagefright_cve_2016_2507() throws Exception {
- doStagefrightTest(R.raw.cve_2016_2507);
+ doStagefrightTest(R.raw.cve_2016_2507, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -222,13 +222,14 @@
@SecurityTest
public void testStagefright_cve_2016_2429_b_27211885() throws Exception {
- doStagefrightTest(R.raw.cve_2016_2429_b_27211885);
+ doStagefrightTest(R.raw.cve_2016_2429_b_27211885,
+ new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
public void testStagefright_bug_34031018() throws Exception {
- doStagefrightTest(R.raw.bug_34031018_32bit);
- doStagefrightTest(R.raw.bug_34031018_64bit);
+ doStagefrightTest(R.raw.bug_34031018_32bit, new CrashUtils.Config().checkMinAddress(false));
+ doStagefrightTest(R.raw.bug_34031018_64bit, new CrashUtils.Config().checkMinAddress(false));
}
/***********************************************************
@@ -248,7 +249,8 @@
@SecurityTest
public void testStagefright_cve_2017_0852_b_62815506() throws Exception {
- doStagefrightTest(R.raw.cve_2017_0852_b_62815506);
+ doStagefrightTest(R.raw.cve_2017_0852_b_62815506,
+ new CrashUtils.Config().checkMinAddress(false));
}
/***********************************************************
@@ -288,12 +290,12 @@
@SecurityTest
public void testStagefright_bug_33818508() throws Exception {
- doStagefrightTest(R.raw.bug_33818508);
+ doStagefrightTest(R.raw.bug_33818508, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
public void testStagefright_bug_32873375() throws Exception {
- doStagefrightTest(R.raw.bug_32873375);
+ doStagefrightTest(R.raw.bug_32873375, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -318,7 +320,7 @@
@SecurityTest
public void testStagefright_bug_32322258() throws Exception {
- doStagefrightTest(R.raw.bug_32322258);
+ doStagefrightTest(R.raw.bug_32322258, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -333,7 +335,8 @@
@SecurityTest
public void testStagefright_cve_2015_3862_b_22954006() throws Exception {
- doStagefrightTest(R.raw.cve_2015_3862_b_22954006);
+ doStagefrightTest(R.raw.cve_2015_3862_b_22954006,
+ new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -387,12 +390,13 @@
@SecurityTest
public void testStagefright_cve_2016_3755() throws Exception {
- doStagefrightTest(R.raw.cve_2016_3755);
+ doStagefrightTest(R.raw.cve_2016_3755, new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
public void testStagefright_cve_2016_3878_b_29493002() throws Exception {
- doStagefrightTest(R.raw.cve_2016_3878_b_29493002);
+ doStagefrightTest(R.raw.cve_2016_3878_b_29493002,
+ new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -402,11 +406,11 @@
@SecurityTest
public void testStagefright_bug_27855419_CVE_2016_2463() throws Exception {
- doStagefrightTest(R.raw.bug_27855419);
+ doStagefrightTest(R.raw.bug_27855419, new CrashUtils.Config().checkMinAddress(false));
}
public void testStagefright_bug_19779574() throws Exception {
- doStagefrightTest(R.raw.bug_19779574);
+ doStagefrightTest(R.raw.bug_19779574, new CrashUtils.Config().checkMinAddress(false));
}
/***********************************************************
@@ -416,7 +420,7 @@
@SecurityTest
public void testStagefright_bug_35467107() throws Exception {
- doStagefrightTest(R.raw.bug_35467107);
+ doStagefrightTest(R.raw.bug_35467107, new CrashUtils.Config().checkMinAddress(false));
}
/***********************************************************
@@ -435,27 +439,37 @@
}
private void doStagefrightTest(final int rid) throws Exception {
- doStagefrightTestMediaPlayer(rid);
- doStagefrightTestMediaCodec(rid);
- doStagefrightTestMediaMetadataRetriever(rid);
+ doStagefrightTest(rid, null);
+ }
+
+ private void doStagefrightTest(final int rid, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaPlayer(rid, config);
+ doStagefrightTestMediaCodec(rid, config);
+ doStagefrightTestMediaMetadataRetriever(rid, config);
Context context = getInstrumentation().getContext();
Resources resources = context.getResources();
CtsTestServer server = new CtsTestServer(context);
String rname = resources.getResourceEntryName(rid);
String url = server.getAssetUrl("raw/" + rname);
- doStagefrightTestMediaPlayer(url);
- doStagefrightTestMediaCodec(url);
- doStagefrightTestMediaMetadataRetriever(url);
+
+ doStagefrightTestMediaPlayer(url, config);
+ doStagefrightTestMediaCodec(url, config);
+ doStagefrightTestMediaMetadataRetriever(url, config);
server.shutdown();
}
private void doStagefrightTest(final int rid, int timeout) throws Exception {
+ doStagefrightTest(rid, null, timeout);
+ }
+
+ private void doStagefrightTest(
+ final int rid, CrashUtils.Config config, int timeout) throws Exception {
runWithTimeout(new Runnable() {
@Override
public void run() {
try {
- doStagefrightTest(rid);
+ doStagefrightTest(rid, config);
} catch (Exception e) {
fail(e.toString());
}
@@ -464,7 +478,12 @@
}
private void doStagefrightTestANR(final int rid) throws Exception {
- doStagefrightTestMediaPlayerANR(rid, null);
+ doStagefrightTestANR(rid, null);
+ }
+
+ private void doStagefrightTestANR(
+ final int rid, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaPlayerANR(rid, null, config);
}
private Surface getDummySurface() {
@@ -518,6 +537,8 @@
MediaPlayer.OnPreparedListener,
MediaPlayer.OnCompletionListener {
+ CrashUtils.Config config;
+
private final Pattern[] validProcessPatterns = {
Pattern.compile("adsprpcd"),
Pattern.compile("android\\.hardware\\.cas@\\d+?\\.\\d+?-service"),
@@ -537,6 +558,19 @@
Pattern.compile("vendor.*"),
};
+ MediaPlayerCrashListener() {
+ this(null);
+ }
+
+ MediaPlayerCrashListener(CrashUtils.Config config) {
+ if (config == null) {
+ config = new CrashUtils.Config();
+ }
+ // if a different process is needed for a test, it should be added to the main list.
+ config.setProcessPatterns(validProcessPatterns);
+ this.config = config;
+ }
+
@Override
public boolean onError(MediaPlayer mp, int newWhat, int extra) {
Log.i(TAG, "error: " + newWhat + "/" + extra);
@@ -582,7 +616,7 @@
if (crashes == null) {
Log.e(TAG, "Crash results not found for test " + getName());
return what;
- } else if (CrashUtils.securityCrashDetected(crashes, true, validProcessPatterns)) {
+ } else if (CrashUtils.securityCrashDetected(crashes, config)) {
return what;
} else {
Log.i(TAG, "Crash ignored due to no security crash found for test " +
@@ -630,11 +664,21 @@
}
private void doStagefrightTestMediaPlayer(final int rid) throws Exception {
- doStagefrightTestMediaPlayer(rid, null);
+ doStagefrightTestMediaPlayer(rid, null, null);
+ }
+
+ private void doStagefrightTestMediaPlayer(
+ final int rid, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaPlayer(rid, null, config);
}
private void doStagefrightTestMediaPlayer(final String url) throws Exception {
- doStagefrightTestMediaPlayer(-1, url);
+ doStagefrightTestMediaPlayer(url, null);
+ }
+
+ private void doStagefrightTestMediaPlayer(
+ final String url, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaPlayer(-1, url, config);
}
private void closeQuietly(AutoCloseable closeable) {
@@ -649,12 +693,17 @@
}
private void doStagefrightTestMediaPlayer(final int rid, final String uri) throws Exception {
+ doStagefrightTestMediaPlayer(rid, uri, null);
+ }
+
+ private void doStagefrightTestMediaPlayer(final int rid, final String uri,
+ CrashUtils.Config config) throws Exception {
String name = uri != null ? uri :
getInstrumentation().getContext().getResources().getResourceEntryName(rid);
Log.i(TAG, "start mediaplayer test for: " + name);
- final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener();
+ final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
LooperThread t = new LooperThread(new Runnable() {
@Override
@@ -699,16 +748,31 @@
}
private void doStagefrightTestMediaCodec(final int rid) throws Exception {
- doStagefrightTestMediaCodec(rid, null);
+ doStagefrightTestMediaCodec(rid, null, null);
+ }
+
+ private void doStagefrightTestMediaCodec(
+ final int rid, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaCodec(rid, null, config);
}
private void doStagefrightTestMediaCodec(final String url) throws Exception {
- doStagefrightTestMediaCodec(-1, url);
+ doStagefrightTestMediaCodec(url, null);
+ }
+
+ private void doStagefrightTestMediaCodec(
+ final String url, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaCodec(-1, url, config);
}
private void doStagefrightTestMediaCodec(final int rid, final String url) throws Exception {
+ doStagefrightTestMediaCodec(rid, url, null);
+ }
- final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener();
+ private void doStagefrightTestMediaCodec(
+ final int rid, final String url, CrashUtils.Config config) throws Exception {
+
+ final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
LooperThread thr = new LooperThread(new Runnable() {
@Override
@@ -864,17 +928,31 @@
}
private void doStagefrightTestMediaMetadataRetriever(final int rid) throws Exception {
- doStagefrightTestMediaMetadataRetriever(rid, null);
+ doStagefrightTestMediaMetadataRetriever(rid, null, null);
+ }
+ private void doStagefrightTestMediaMetadataRetriever(
+ final int rid, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaMetadataRetriever(rid, null, config);
}
private void doStagefrightTestMediaMetadataRetriever(final String url) throws Exception {
- doStagefrightTestMediaMetadataRetriever(-1, url);
+ doStagefrightTestMediaMetadataRetriever(url, null);
+ }
+
+ private void doStagefrightTestMediaMetadataRetriever(
+ final String url, CrashUtils.Config config) throws Exception {
+ doStagefrightTestMediaMetadataRetriever(-1, url, config);
}
private void doStagefrightTestMediaMetadataRetriever(
final int rid, final String url) throws Exception {
+ doStagefrightTestMediaMetadataRetriever(rid, url, null);
+ }
- final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener();
+ private void doStagefrightTestMediaMetadataRetriever(
+ final int rid, final String url, CrashUtils.Config config) throws Exception {
+
+ final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
LooperThread thr = new LooperThread(new Runnable() {
@Override
@@ -942,12 +1020,13 @@
thr.join();
}
- private void doStagefrightTestMediaPlayerANR(final int rid, final String uri) throws Exception {
+ private void doStagefrightTestMediaPlayerANR(final int rid, final String uri,
+ CrashUtils.Config config) throws Exception {
String name = uri != null ? uri :
getInstrumentation().getContext().getResources().getResourceEntryName(rid);
Log.i(TAG, "start mediaplayerANR test for: " + name);
- final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener();
+ final MediaPlayerCrashListener mpl = new MediaPlayerCrashListener(config);
LooperThread t = new LooperThread(new Runnable() {
@Override
@@ -993,11 +1072,13 @@
}
public void testBug36816007() throws Exception {
- doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240);
+ doStagefrightTestRawBlob(R.raw.bug_36816007, "video/avc", 320, 240,
+ new CrashUtils.Config().checkMinAddress(false));
}
public void testBug36895511() throws Exception {
- doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240);
+ doStagefrightTestRawBlob(R.raw.bug_36895511, "video/hevc", 320, 240,
+ new CrashUtils.Config().checkMinAddress(false));
}
@SecurityTest
@@ -1007,7 +1088,8 @@
@SecurityTest
public void testBug_70897394() throws Exception {
- doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240);
+ doStagefrightTestRawBlob(R.raw.bug_70897394_avc, "video/avc", 320, 240,
+ new CrashUtils.Config().checkMinAddress(false));
}
private void runWithTimeout(Runnable runner, int timeout) {
@@ -1032,9 +1114,15 @@
}, 5000);
}
- private void doStagefrightTestRawBlob(int rid, String mime, int initWidth, int initHeight) throws Exception {
+ private void doStagefrightTestRawBlob(
+ int rid, String mime, int initWidth, int initHeight) throws Exception {
+ doStagefrightTestRawBlob(rid, mime, initWidth, initHeight, new CrashUtils.Config());
+ }
- final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener();
+ private void doStagefrightTestRawBlob(int rid, String mime, int initWidth, int initHeight,
+ CrashUtils.Config config) throws Exception {
+
+ final MediaPlayerCrashListener mpcl = new MediaPlayerCrashListener(config);
final Context context = getInstrumentation().getContext();
final Resources resources = context.getResources();