From 7d2ec61d8ed54d520ea9def9224740c592461b9c Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Fri, 19 Jan 2018 14:19:59 +0000 Subject: Copy 'res' folder to device for run-tests Sometimes tests need to push resources to target for a run-test. The scripts currently do not have an option how to bundle additional files with the test. To this end, this patch tests for presence of folder named 'res' and if it exists, copies it into DEX_LOCATION on the device. Test 071 was converted to become the first test using this new feature. Test: art/test.py -b -r -t 071-dexfile-get-static Change-Id: I7eac4b15ca19fce6c616f5cc732b7ac65b8174b8 --- test/071-dexfile-get-static-size/build | 12 +++++------- test/071-dexfile-get-static-size/res/test1.dex | Bin 0 -> 1864 bytes test/071-dexfile-get-static-size/res/test2.dex | Bin 0 -> 1264 bytes test/071-dexfile-get-static-size/src/Main.java | 20 +------------------- test/071-dexfile-get-static-size/test1.dex | Bin 1864 -> 0 bytes test/071-dexfile-get-static-size/test2.dex | Bin 1264 -> 0 bytes test/README.md | 2 ++ test/etc/run-test-jar | 9 ++++++++- 8 files changed, 16 insertions(+), 27 deletions(-) create mode 100644 test/071-dexfile-get-static-size/res/test1.dex create mode 100644 test/071-dexfile-get-static-size/res/test2.dex delete mode 100644 test/071-dexfile-get-static-size/test1.dex delete mode 100644 test/071-dexfile-get-static-size/test2.dex (limited to 'test') diff --git a/test/071-dexfile-get-static-size/build b/test/071-dexfile-get-static-size/build index 0bba66d065..412ee6dd46 100755 --- a/test/071-dexfile-get-static-size/build +++ b/test/071-dexfile-get-static-size/build @@ -16,15 +16,13 @@ ./default-build "$@" -# Create and add as resources to the test jar file: +# Bundle with the test the following resources: # 1. test1.dex # 2. test2.dex # 3. test-jar.jar, containing test1.dex as classes.dex # 4. multi-jar.jar, containing test1.dex as classes.dex and test2.dex as classes2.dex mkdir test-jar -cp test1.dex test-jar/classes.dex -cp test2.dex test-jar/classes2.dex -zip -j test-jar.jar test-jar/classes.dex -zip -j multi-jar.jar test-jar/classes.dex test-jar/classes2.dex -jar uf ${TEST_NAME}.jar test1.dex test2.dex test-jar.jar multi-jar.jar - +cp res/test1.dex test-jar/classes.dex +cp res/test2.dex test-jar/classes2.dex +zip -j res/test-jar.jar test-jar/classes.dex +zip -j res/multi-jar.jar test-jar/classes.dex test-jar/classes2.dex diff --git a/test/071-dexfile-get-static-size/res/test1.dex b/test/071-dexfile-get-static-size/res/test1.dex new file mode 100644 index 0000000000..84602d03c2 Binary files /dev/null and b/test/071-dexfile-get-static-size/res/test1.dex differ diff --git a/test/071-dexfile-get-static-size/res/test2.dex b/test/071-dexfile-get-static-size/res/test2.dex new file mode 100644 index 0000000000..a07c46ef59 Binary files /dev/null and b/test/071-dexfile-get-static-size/res/test2.dex differ diff --git a/test/071-dexfile-get-static-size/src/Main.java b/test/071-dexfile-get-static-size/src/Main.java index 4bf453801e..8dbbba56c3 100644 --- a/test/071-dexfile-get-static-size/src/Main.java +++ b/test/071-dexfile-get-static-size/src/Main.java @@ -14,26 +14,9 @@ * limitations under the License. */ -import java.io.InputStream; -import java.io.OutputStream; -import java.io.FileOutputStream; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class Main { - private static void extractResource(String resource, String filename) throws Exception { - ClassLoader loader = Main.class.getClassLoader(); - InputStream is = loader.getResourceAsStream(resource); - OutputStream os = new FileOutputStream(filename); - int read; - byte[] buf = new byte[4096]; - while ((read = is.read(buf)) >= 0) { - os.write(buf, 0, read); - } - is.close(); - os.close(); - } - private static long getDexFileSize(String filename) throws Exception { ClassLoader loader = Main.class.getClassLoader(); Class DexFile = loader.loadClass("dalvik.system.DexFile"); @@ -47,8 +30,7 @@ public class Main { } private static void test(String resource) throws Exception { - String filename = System.getenv("DEX_LOCATION") + "/" + resource; - extractResource(resource, filename); + String filename = System.getenv("DEX_LOCATION") + "/res/" + resource; long size = getDexFileSize(filename); System.out.println("Size for " + resource + ": " + size); } diff --git a/test/071-dexfile-get-static-size/test1.dex b/test/071-dexfile-get-static-size/test1.dex deleted file mode 100644 index 84602d03c2..0000000000 Binary files a/test/071-dexfile-get-static-size/test1.dex and /dev/null differ diff --git a/test/071-dexfile-get-static-size/test2.dex b/test/071-dexfile-get-static-size/test2.dex deleted file mode 100644 index a07c46ef59..0000000000 Binary files a/test/071-dexfile-get-static-size/test2.dex and /dev/null differ diff --git a/test/README.md b/test/README.md index c68b40b135..350350e9e6 100644 --- a/test/README.md +++ b/test/README.md @@ -9,6 +9,8 @@ directory are compiled separately but to the same output directory; this can be used to exercise "API mismatch" situations by replacing class files created in the first pass. The "src-ex" directory is built separately, and is intended for exercising class loaders. +Resources can be stored in the "res" directory, which is distributed +together with the executable files. The gtests are in named directories and contain a .java source file. diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar index 631b14afc8..5e40b86aa0 100755 --- a/test/etc/run-test-jar +++ b/test/etc/run-test-jar @@ -806,6 +806,10 @@ if [ "$HOST" = "n" ]; then if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then adb push profile $DEX_LOCATION fi + # Copy resource folder + if [ -d res ]; then + adb push res $DEX_LOCATION + fi else adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 @@ -814,7 +818,10 @@ if [ "$HOST" = "n" ]; then if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then adb push profile $DEX_LOCATION >/dev/null 2>&1 fi - + # Copy resource folder + if [ -d res ]; then + adb push res $DEX_LOCATION >/dev/null 2>&1 + fi fi LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA -- cgit v1.2.3-59-g8ed1b