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
diff --git a/test/071-dexfile-get-static-size/build b/test/071-dexfile-get-static-size/build
index 0bba66d..412ee6d 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/test1.dex b/test/071-dexfile-get-static-size/res/test1.dex
similarity index 100%
rename from test/071-dexfile-get-static-size/test1.dex
rename to test/071-dexfile-get-static-size/res/test1.dex
Binary files differ
diff --git a/test/071-dexfile-get-static-size/test2.dex b/test/071-dexfile-get-static-size/res/test2.dex
similarity index 100%
rename from test/071-dexfile-get-static-size/test2.dex
rename to test/071-dexfile-get-static-size/res/test2.dex
Binary files differ
diff --git a/test/071-dexfile-get-static-size/src/Main.java b/test/071-dexfile-get-static-size/src/Main.java
index 4bf4538..8dbbba5 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 @@
     }
 
     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/README.md b/test/README.md
index c68b40b..350350e 100644
--- a/test/README.md
+++ b/test/README.md
@@ -9,6 +9,8 @@
 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 631b14a..5e40b86 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -806,6 +806,10 @@
       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 [ "$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