OSDN Git Service

Use standard loading code in many tests
authorAlex Light <allight@google.com>
Mon, 17 Apr 2017 17:06:44 +0000 (10:06 -0700)
committerAlex Light <allight@google.com>
Mon, 17 Apr 2017 17:06:44 +0000 (10:06 -0700)
In order to prepare for use in CTS tests make tests 902, 914, 915,
917, 919, 926, 930, 932, 940, 942, 945, 981 & 982 use standard OnLoad
functions. Final configuration is done during test initialization.

Bug: 32072923
Test: ./test/testrunner/testrunner.py --host -j40
Change-Id: I84b2e17d0e024255d2dc49452f3d74dfd64abd22

48 files changed:
test/902-hello-transformation/src/art/Redefinition.java
test/902-hello-transformation/src/art/Test902.java
test/914-hello-obsolescence/src/art/Redefinition.java
test/914-hello-obsolescence/src/art/Test914.java
test/915-obsolete-2/src/art/Redefinition.java
test/915-obsolete-2/src/art/Test915.java
test/916-obsolete-jit/src/art/Redefinition.java
test/917-fields-transformation/src/art/Redefinition.java
test/917-fields-transformation/src/art/Test917.java
test/919-obsolete-fields/src/art/Redefinition.java
test/919-obsolete-fields/src/art/Test919.java
test/921-hello-failure/src/art/Redefinition.java
test/926-multi-obsolescence/src/art/Redefinition.java
test/926-multi-obsolescence/src/art/Test926.java
test/930-hello-retransform/src/art/Redefinition.java
test/930-hello-retransform/src/art/Test930.java
test/932-transform-saves/src/art/Redefinition.java
test/932-transform-saves/src/art/Test932.java
test/934-load-transform/src/art/Redefinition.java
test/935-non-retransformable/src/art/Redefinition.java
test/937-hello-retransform-package/src/art/Redefinition.java
test/938-load-transform-bcp/src/art/Redefinition.java
test/939-hello-transformation-bcp/src/art/Redefinition.java
test/940-recursive-obsolete/src/art/Redefinition.java
test/940-recursive-obsolete/src/art/Test940.java
test/941-recurive-obsolete-jit/src/art/Redefinition.java
test/942-private-recursive/src/art/Redefinition.java
test/942-private-recursive/src/art/Test942.java
test/943-private-recursive-jit/src/art/Redefinition.java
test/944-transform-classloaders/src/art/Redefinition.java
test/944-transform-classloaders/src/art/Test944.java
test/945-obsolete-native/src/art/Redefinition.java
test/945-obsolete-native/src/art/Test945.java
test/946-obsolete-throw/src/art/Redefinition.java
test/947-reflect-method/src/art/Redefinition.java
test/948-change-annotations/src/art/Redefinition.java
test/949-in-memory-transform/src/art/Redefinition.java
test/950-redefine-intrinsic/src/art/Redefinition.java
test/951-threaded-obsolete/src/art/Redefinition.java
test/980-redefine-object/src/art/Redefinition.java
test/981-dedup-original-dex/src/art/Redefinition.java
test/981-dedup-original-dex/src/art/Test981.java
test/982-ok-no-retransform/src/art/Redefinition.java
test/982-ok-no-retransform/src/art/Test982.java
test/983-source-transform-verify/src/art/Redefinition.java
test/984-obsolete-invoke/src/art/Redefinition.java
test/ti-agent/common_helper.cc
test/ti-agent/common_load.cc

index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 323d158..e95558f 100644 (file)
@@ -70,6 +70,7 @@ public class Test902 {
     "yAIAAAMQAAABAAAA2AIAAAYgAAABAAAA5AIAAAAQAAABAAAA9AIAAA==");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 0c7cded..ef2710d 100644 (file)
@@ -71,6 +71,7 @@ public class Test914 {
     "AA==");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 1b20e5b..63c7f34 100644 (file)
@@ -108,6 +108,7 @@ public class Test915 {
     "AAABAAAAEAUAAA==");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index f47e8ee..245e92e 100644 (file)
@@ -77,6 +77,7 @@ public class Test917 {
     "AAEAAACMAgAABCAAAAIAAACgAgAAAxAAAAEAAACwAgAABiAAAAEAAAC8AgAAABAAAAEAAADMAgAA");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform("Hello", "Goodbye"),
            new Transform("start", "end"));
   }
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index d422f4e..11971ef 100644 (file)
@@ -149,6 +149,7 @@ public class Test919 {
   }
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     TestWatcher w = new TestWatcher();
     doTest(new Transform(w), w);
   }
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index e114f11..843d05c 100644 (file)
@@ -123,6 +123,7 @@ public class Test926 {
         "AHwDAAA="));
 
   public static void run() throws Exception {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform(), new Transform2());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 0dc84e3..6c0fc16 100644 (file)
@@ -64,6 +64,7 @@ public class Test930 {
     "yAIAAAMQAAABAAAA2AIAAAYgAAABAAAA5AIAAAAQAAABAAAA9AIAAA==");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_RETRANSFORM);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 69bf609..3a62232 100644 (file)
@@ -102,6 +102,7 @@ public class Test932 {
     "yAIAAAMQAAABAAAA2AIAAAYgAAABAAAA5AIAAAAQAAABAAAA9AIAAA==");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_RETRANSFORM);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 9a9382e..d67d772 100644 (file)
@@ -91,6 +91,7 @@ public class Test940 {
     "AxAAAAEAAACcBAAABiAAAAEAAACoBAAAABAAAAEAAAC4BAAA");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 1666a08..cccc2fd 100644 (file)
@@ -100,6 +100,7 @@ public class Test942 {
     "BAAAAxAAAAEAAADYBAAABiAAAAEAAADkBAAAABAAAAEAAAD0BAAA");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index e7747c2..fe1c024 100644 (file)
@@ -115,6 +115,7 @@ public class Test944 {
         "AgAAAMwCAAADEAAAAQAAANwCAAAGIAAAAQAAAOgCAAAAEAAAAQAAAPgCAAA="));
 
   public static void run() throws Exception {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest();
     System.out.println("Passed");
   }
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index f77323d..6cf31f6 100644 (file)
@@ -81,6 +81,7 @@ public class Test945 {
     "AQAAALgDAAA=");
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 42a7647..3a97268 100644 (file)
@@ -138,6 +138,7 @@ public class Test981 {
     "AyAAAAIAAAAWAgAAACAAAAEAAAAhAgAAABAAAAEAAAAwAgAA");
 
   public static void run() throws Exception {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_RETRANSFORM);
     doTest();
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index c043bbd..080d47f 100644 (file)
@@ -26,6 +26,7 @@ public class Test982 {
   }
 
   public static void run() {
+    Redefinition.setTestConfiguration(Redefinition.Config.COMMON_RETRANSFORM);
     doTest(new Transform());
   }
 
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 8cd2568..0350ab4 100644 (file)
@@ -36,6 +36,25 @@ public class Redefinition {
     }
   }
 
+  // A set of possible test configurations. Test should set this if they need to.
+  // This must be kept in sync with the defines in ti-agent/common_helper.cc
+  public static enum Config {
+    COMMON_REDEFINE(0),
+    COMMON_RETRANSFORM(1),
+    COMMON_TRANSFORM(2);
+
+    private final int val;
+    private Config(int val) {
+      this.val = val;
+    }
+  }
+
+  public static void setTestConfiguration(Config type) {
+    nativeSetTestConfiguration(type.val);
+  }
+
+  private static native void nativeSetTestConfiguration(int type);
+
   // Transforms the class
   public static native void doCommonClassRedefinition(Class<?> target,
                                                       byte[] classfile,
index 154d756..dc9e26d 100644 (file)
 #include "common_helper.h"
 
 #include <dlfcn.h>
+#include <map>
 #include <stdio.h>
 #include <sstream>
 #include <deque>
+#include <vector>
 
 #include "android-base/stringprintf.h"
-#include "art_method.h"
 #include "jni.h"
-#include "jni_internal.h"
 #include "jvmti.h"
-#include "scoped_thread_state_change-inl.h"
-#include "stack.h"
-#include "utils.h"
 
 #include "jni_binder.h"
 #include "jvmti_helper.h"
 
 namespace art {
 
+static void SetupCommonRetransform();
+static void SetupCommonRedefine();
+static void SetupCommonTransform();
+
 template <bool is_redefine>
 static void throwCommonRedefinitionError(jvmtiEnv* jvmti,
                                          JNIEnv* env,
@@ -152,11 +153,7 @@ jint OnLoad(JavaVM* vm,
     printf("Unable to get jvmti env!\n");
     return 1;
   }
-  jvmtiCapabilities caps;
-  jvmti_env->GetPotentialCapabilities(&caps);
-  caps.can_retransform_classes = 0;
-  caps.can_retransform_any_class = 0;
-  jvmti_env->AddCapabilities(&caps);
+  SetupCommonRedefine();
   return 0;
 }
 
@@ -331,14 +328,7 @@ jint OnLoad(JavaVM* vm,
     printf("Unable to get jvmti env!\n");
     return 1;
   }
-  SetAllCapabilities(jvmti_env);
-  jvmtiEventCallbacks cb;
-  memset(&cb, 0, sizeof(cb));
-  cb.ClassFileLoadHook = CommonClassFileLoadHookRetransformable;
-  if (jvmti_env->SetEventCallbacks(&cb, sizeof(cb)) != JVMTI_ERROR_NONE) {
-    printf("Unable to set class file load hook cb!\n");
-    return 1;
-  }
+  SetupCommonRetransform();
   return 0;
 }
 
@@ -346,8 +336,6 @@ jint OnLoad(JavaVM* vm,
 
 namespace common_transform {
 
-using art::common_retransform::CommonClassFileLoadHookRetransformable;
-
 // Get all capabilities except those related to retransformation.
 jint OnLoad(JavaVM* vm,
             char* options ATTRIBUTE_UNUSED,
@@ -356,6 +344,34 @@ jint OnLoad(JavaVM* vm,
     printf("Unable to get jvmti env!\n");
     return 1;
   }
+  SetupCommonTransform();
+  return 0;
+}
+
+}  // namespace common_transform
+
+#define CONFIGURATION_COMMON_REDEFINE 0
+#define CONFIGURATION_COMMON_RETRANSFORM 1
+#define CONFIGURATION_COMMON_TRANSFORM 2
+
+static void SetupCommonRedefine() {
+  jvmtiCapabilities caps;
+  jvmti_env->GetPotentialCapabilities(&caps);
+  caps.can_retransform_classes = 0;
+  caps.can_retransform_any_class = 0;
+  jvmti_env->AddCapabilities(&caps);
+}
+
+static void SetupCommonRetransform() {
+  SetAllCapabilities(jvmti_env);
+  jvmtiEventCallbacks cb;
+  memset(&cb, 0, sizeof(cb));
+  cb.ClassFileLoadHook = common_retransform::CommonClassFileLoadHookRetransformable;
+  jvmtiError res = jvmti_env->SetEventCallbacks(&cb, sizeof(cb));
+  CHECK_EQ(res, JVMTI_ERROR_NONE);
+}
+
+static void SetupCommonTransform() {
   // Don't set the retransform caps
   jvmtiCapabilities caps;
   jvmti_env->GetPotentialCapabilities(&caps);
@@ -366,14 +382,30 @@ jint OnLoad(JavaVM* vm,
   // Use the same callback as the retransform test.
   jvmtiEventCallbacks cb;
   memset(&cb, 0, sizeof(cb));
-  cb.ClassFileLoadHook = CommonClassFileLoadHookRetransformable;
-  if (jvmti_env->SetEventCallbacks(&cb, sizeof(cb)) != JVMTI_ERROR_NONE) {
-    printf("Unable to set class file load hook cb!\n");
-    return 1;
-  }
-  return 0;
+  cb.ClassFileLoadHook = common_retransform::CommonClassFileLoadHookRetransformable;
+  jvmtiError res = jvmti_env->SetEventCallbacks(&cb, sizeof(cb));
+  CHECK_EQ(res, JVMTI_ERROR_NONE);
 }
 
-}  // namespace common_transform
-
+extern "C" JNIEXPORT void JNICALL Java_art_Redefinition_nativeSetTestConfiguration(JNIEnv*,
+                                                                                   jclass,
+                                                                                   jint type) {
+  switch (type) {
+    case CONFIGURATION_COMMON_REDEFINE: {
+      SetupCommonRedefine();
+      return;
+    }
+    case CONFIGURATION_COMMON_RETRANSFORM: {
+      SetupCommonRetransform();
+      return;
+    }
+    case CONFIGURATION_COMMON_TRANSFORM: {
+      SetupCommonTransform();
+      return;
+    }
+    default: {
+      LOG(FATAL) << "Unknown test configuration: " << type;
+    }
+  }
+}
 }  // namespace art
index 9e7b75d..3455409 100644 (file)
@@ -60,31 +60,17 @@ static jint MinimalOnLoad(JavaVM* vm,
 // MinimalOnLoad.
 static AgentLib agents[] = {
   { "901-hello-ti-agent", Test901HelloTi::OnLoad, nullptr },
-  { "902-hello-transformation", common_redefine::OnLoad, nullptr },
   { "909-attach-agent", nullptr, Test909AttachAgent::OnAttach },
-  { "914-hello-obsolescence", common_redefine::OnLoad, nullptr },
-  { "915-obsolete-2", common_redefine::OnLoad, nullptr },
   { "916-obsolete-jit", common_redefine::OnLoad, nullptr },
-  { "917-fields-transformation", common_redefine::OnLoad, nullptr },
-  { "919-obsolete-fields", common_redefine::OnLoad, nullptr },
   { "921-hello-failure", common_retransform::OnLoad, nullptr },
-  { "926-multi-obsolescence", common_redefine::OnLoad, nullptr },
-  { "930-hello-retransform", common_retransform::OnLoad, nullptr },
-  { "932-transform-saves", common_retransform::OnLoad, nullptr },
   { "934-load-transform", common_retransform::OnLoad, nullptr },
   { "935-non-retransformable", common_transform::OnLoad, nullptr },
   { "936-search-onload", Test936SearchOnload::OnLoad, nullptr },
   { "937-hello-retransform-package", common_retransform::OnLoad, nullptr },
   { "938-load-transform-bcp", common_retransform::OnLoad, nullptr },
   { "939-hello-transformation-bcp", common_redefine::OnLoad, nullptr },
-  { "940-recursive-obsolete", common_redefine::OnLoad, nullptr },
   { "941-recursive-obsolete-jit", common_redefine::OnLoad, nullptr },
-  { "942-private-recursive", common_redefine::OnLoad, nullptr },
   { "943-private-recursive-jit", common_redefine::OnLoad, nullptr },
-  { "944-transform-classloaders", common_redefine::OnLoad, nullptr },
-  { "945-obsolete-native", common_redefine::OnLoad, nullptr },
-  { "981-dedup-original-dex", common_retransform::OnLoad, nullptr },
-  { "982-ok-no-retransform", common_retransform::OnLoad, nullptr },
   { "983-source-transform-verify", Test983SourceTransformVerify::OnLoad, nullptr },
 };