Merge "PreloadCheck: Add preloaded-classes-blacklist"
This commit is contained in:
18
config/Android.bp
Normal file
18
config/Android.bp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) 2019 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
filegroup {
|
||||||
|
name: "preloaded-classes-blacklist",
|
||||||
|
srcs: ["preloaded-classes-blacklist"],
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
java_test_host {
|
java_test_host {
|
||||||
name: "PreloadCheck",
|
name: "PreloadCheck",
|
||||||
srcs: ["src/**/*.java"],
|
srcs: ["src/**/*.java"],
|
||||||
|
java_resources: [":preloaded-classes-blacklist"],
|
||||||
libs: ["tradefed"],
|
libs: ["tradefed"],
|
||||||
test_suites: ["general-tests"],
|
test_suites: ["general-tests"],
|
||||||
required: ["preload-check-device"],
|
required: ["preload-check-device"],
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ import com.android.tradefed.testtype.IDeviceTest;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
@RunWith(DeviceJUnit4ClassRunner.class)
|
@RunWith(DeviceJUnit4ClassRunner.class)
|
||||||
public class PreloadCheck implements IDeviceTest {
|
public class PreloadCheck implements IDeviceTest {
|
||||||
private ITestDevice mTestDevice;
|
private ITestDevice mTestDevice;
|
||||||
@@ -65,6 +68,35 @@ public class PreloadCheck implements IDeviceTest {
|
|||||||
run("com.android.preload.check.Initialized", "android.animation.Animator");
|
run("com.android.preload.check.Initialized", "android.animation.Animator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the classes mentioned in the embedded preloaded-classes blacklist.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testBlackList() throws Exception {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(getClass()
|
||||||
|
.getResourceAsStream("/preloaded-classes-blacklist")))) {
|
||||||
|
String s;
|
||||||
|
while ((s = br.readLine()) != null) {
|
||||||
|
s = s.trim();
|
||||||
|
if (s.startsWith("#") || s.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
run("com.android.preload.check.NotInitialized", s);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append('\n');
|
||||||
|
}
|
||||||
|
sb.append(t.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
throw new RuntimeException(sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void run(String cmd, String... args) throws Exception {
|
private void run(String cmd, String... args) throws Exception {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("app_process ")
|
sb.append("app_process ")
|
||||||
@@ -72,9 +104,16 @@ public class PreloadCheck implements IDeviceTest {
|
|||||||
.append(" /system/bin ")
|
.append(" /system/bin ")
|
||||||
.append(cmd);
|
.append(cmd);
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
sb.append(' ').append(arg);
|
sb.append(' ').append(escape(arg));
|
||||||
}
|
}
|
||||||
String res = mTestDevice.executeShellCommand(sb.toString());
|
String res = mTestDevice.executeShellCommand(sb.toString());
|
||||||
assertEquals(sb.toString(), "OK", res.trim());
|
assertEquals(sb.toString(), "OK", res.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String escape(String input) {
|
||||||
|
if (input.indexOf('$') == -1) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
return input.replace("$", "\\$");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user