test/hotspot/jtreg/runtime/appcds/VerifierTest.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff test/hotspot/jtreg/runtime/appcds

test/hotspot/jtreg/runtime/appcds/VerifierTest.java

Print this page




  29 
  30 import java.util.*;
  31 import jdk.internal.org.objectweb.asm.*;
  32 
  33 /**
  34  * The testsets contained in this class are executed by ./VerifierTest_*.java, so that
  35  * individual testsets can be executed in parallel to shorten the total time required.
  36  */
  37 public class VerifierTest implements Opcodes {
  38     // Test verification settings for dumping & runtime
  39     static final String VFY_ALL = "-Xverify:all";
  40     static final String VFY_REMOTE = "-Xverify:remote"; // default
  41     static final String VFY_NONE = "-Xverify:none";
  42 
  43     static final String ERR =
  44         "ERROR: class VerifierTestC was loaded unexpectedly";
  45     static final String MAP_FAIL =
  46         "shared archive file was created with less restrictive verification setting";
  47     static final String VFY_ERR = "java.lang.VerifyError";
  48     static final String PASS_RESULT = "Hi, how are you?";


  49 
  50     enum Testset1Part {
  51         A, B
  52     }
  53 
  54     public static void main(String[] args) throws Exception {
  55         String subCaseId = args[0];
  56         String jarName_verifier_test_tmp = "verifier_test_tmp" + "_" + subCaseId;
  57         String jarName_verifier_test = "verifier_test" + "_" + subCaseId;
  58         String jarName_greet = "greet" + "_" + subCaseId;
  59         String jarName_hi = "hi" + "_" + subCaseId;
  60 
  61 
  62         JarBuilder.build(jarName_verifier_test_tmp, "VerifierTest0", "VerifierTestA",
  63                          "VerifierTestB", "VerifierTestC", "VerifierTestD", "VerifierTestE",
  64                          "UnverifiableBase", "UnverifiableIntf", "UnverifiableIntfSub");
  65         JarBuilder.build(jarName_greet, "Greet");
  66         JarBuilder.build(jarName_hi, "Hi", "Hi$MyClass");
  67 
  68         File dir = new File(System.getProperty("test.classes", "."));


 120             output.shouldNotHaveExitValue(0);
 121         }
 122     }
 123 
 124     static void testset_1(String jar, String[] noAppClasses, String[] appClasses, Testset1Part part)
 125         throws Exception
 126     {
 127         String config[][] = {
 128             // {dump_list, dumptime_verification_setting,
 129             //  runtime_verification_setting, expected_output_str},
 130 
 131             // Dump app/ext with -Xverify:remote
 132             {"app",   VFY_REMOTE, VFY_REMOTE, VFY_ERR},
 133             {"app",   VFY_REMOTE, VFY_ALL,    MAP_FAIL},
 134             {"app",   VFY_REMOTE, VFY_NONE,   ERR },
 135             // Dump app/ext with -Xverify:all
 136             {"app",   VFY_ALL,    VFY_REMOTE, VFY_ERR },
 137             {"app",   VFY_ALL,    VFY_ALL,    VFY_ERR },
 138             {"app",   VFY_ALL,    VFY_NONE,   ERR },
 139             // Dump app/ext with -Xverify:none
 140             {"app",   VFY_NONE,   VFY_REMOTE, MAP_FAIL},
 141             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
 142             {"app",   VFY_NONE,   VFY_NONE,   ERR },
 143             // Dump sys only with -Xverify:remote
 144             {"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
 145             {"noApp", VFY_REMOTE, VFY_ALL,    VFY_ERR},
 146             {"noApp", VFY_REMOTE, VFY_NONE,   ERR},
 147             // Dump sys only with -Xverify:all
 148             {"noApp", VFY_ALL, VFY_REMOTE,    VFY_ERR},
 149             {"noApp", VFY_ALL, VFY_ALL,       VFY_ERR},
 150             {"noApp", VFY_ALL, VFY_NONE,      ERR},
 151             // Dump sys only with -Xverify:none
 152             {"noApp", VFY_NONE, VFY_REMOTE,   VFY_ERR},
 153             {"noApp", VFY_NONE, VFY_ALL,      VFY_ERR},
 154             {"noApp", VFY_NONE, VFY_NONE,     ERR},
 155         };
 156 
 157         int loop_start, loop_stop;
 158 
 159         // Further break down testset_1 into two parts (to be invoked from VerifierTest_1A.java
 160         // and VerifierTest_1B.java) to improve parallel test execution time.


 171             break;
 172         }
 173 
 174         String prev_dump_setting = "";
 175         for (int i = loop_start; i < loop_stop; i ++) {
 176             String dump_list[] = config[i][0].equals("app") ? appClasses :
 177                 noAppClasses;
 178             String dump_setting = config[i][1];
 179             String runtime_setting = config[i][2];
 180             String expected_output_str = config[i][3];
 181             System.out.println("Test case [" + i + "]: dumping " + config[i][0] +
 182                                " with " + dump_setting +
 183                                ", run with " + runtime_setting);
 184             if (!dump_setting.equals(prev_dump_setting)) {
 185                 OutputAnalyzer dumpOutput = TestCommon.dump(
 186                                                             jar, dump_list, dump_setting,
 187                                                             // FIXME: the following options are for working around a GC
 188                                                             // issue - assert failure when dumping archive with the -Xverify:all
 189                                                             "-Xms256m",
 190                                                             "-Xmx256m");




 191             }
 192             TestCommon.run("-cp", jar,
 193                            runtime_setting,
 194                            "VerifierTest0")
 195                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
 196             prev_dump_setting = dump_setting;
 197         }
 198     }
 199 
 200     static void testset_2(String jarName_greet, String jarName_hi) throws Exception {
 201         String appClasses[];
 202         String jar;
 203 
 204         // The following section is for testing the scenarios where
 205         // the classes are verifiable during dump time.
 206         appClasses = TestCommon.list("Hi",
 207                                      "Greet",
 208                                      "Hi$MyClass");
 209         jar = TestCommon.getTestJar(jarName_hi + ".jar") + File.pathSeparator +
 210             TestCommon.getTestJar(jarName_greet + ".jar");
 211         String config2[][] = {
 212             // {dump_list, dumptime_verification_setting,
 213             //  runtime_verification_setting, expected_output_str},
 214 
 215             // Dump app/ext with -Xverify:remote
 216             {"app",   VFY_REMOTE, VFY_REMOTE, PASS_RESULT},
 217             {"app",   VFY_REMOTE, VFY_ALL,    MAP_FAIL},
 218             {"app",   VFY_REMOTE, VFY_NONE,   PASS_RESULT },
 219             // Dump app/ext with -Xverify:all
 220             {"app",   VFY_ALL,    VFY_REMOTE, PASS_RESULT },
 221             {"app",   VFY_ALL,    VFY_ALL,    PASS_RESULT },
 222             {"app",   VFY_ALL,    VFY_NONE,   PASS_RESULT },
 223             // Dump app/ext with -Xverify:none
 224             {"app",   VFY_NONE,   VFY_REMOTE, MAP_FAIL},
 225             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
 226             {"app",   VFY_NONE,   VFY_NONE,   PASS_RESULT },
 227         };

 228         for (int i = 0; i < config2.length; i ++) {
 229             // config2[i][0] is always set to "app" in this test
 230             String dump_setting = config2[i][1];
 231             String runtime_setting = config2[i][2];
 232             String expected_output_str = config2[i][3];
 233             System.out.println("Test case [" + i + "]: dumping " + config2[i][0] +
 234                                " with " + dump_setting +
 235                                ", run with " + runtime_setting);

 236             OutputAnalyzer dumpOutput = TestCommon.dump(
 237                                                         jar, appClasses, dump_setting,
 238                                                         "-XX:+UnlockDiagnosticVMOptions",
 239                                                         // FIXME: the following options are for working around a GC
 240                                                         // issue - assert failure when dumping archive with the -Xverify:all
 241                                                         "-Xms256m",
 242                                                         "-Xmx256m");





 243             TestCommon.run("-cp", jar,
 244                            runtime_setting,
 245                            "Hi")
 246                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));

 247         }
 248     }
 249 
 250     static void createTestJarFile(File jarSrcFile, File jarFile) throws Exception {
 251         jarFile.delete();
 252         Files.copy(jarSrcFile.toPath(), jarFile.toPath());
 253 
 254         File dir = new File(System.getProperty("test.classes", "."));
 255         File outdir = new File(dir, "verifier_test_classes");
 256         outdir.mkdir();
 257 
 258         writeClassFile(new File(outdir, "UnverifiableBase.class"), makeUnverifiableBase());
 259         writeClassFile(new File(outdir, "UnverifiableIntf.class"), makeUnverifiableIntf());
 260 
 261         JarBuilder.update(jarFile.getPath(), outdir.getPath());
 262     }
 263 
 264     static void writeClassFile(File file, byte bytecodes[]) throws Exception {
 265         try (FileOutputStream fos = new FileOutputStream(file)) {
 266             fos.write(bytecodes);




  29 
  30 import java.util.*;
  31 import jdk.internal.org.objectweb.asm.*;
  32 
  33 /**
  34  * The testsets contained in this class are executed by ./VerifierTest_*.java, so that
  35  * individual testsets can be executed in parallel to shorten the total time required.
  36  */
  37 public class VerifierTest implements Opcodes {
  38     // Test verification settings for dumping & runtime
  39     static final String VFY_ALL = "-Xverify:all";
  40     static final String VFY_REMOTE = "-Xverify:remote"; // default
  41     static final String VFY_NONE = "-Xverify:none";
  42 
  43     static final String ERR =
  44         "ERROR: class VerifierTestC was loaded unexpectedly";
  45     static final String MAP_FAIL =
  46         "shared archive file was created with less restrictive verification setting";
  47     static final String VFY_ERR = "java.lang.VerifyError";
  48     static final String PASS_RESULT = "Hi, how are you?";
  49     static final String VFY_INFO_MESSAGE =
  50         "All non-system classes will be verified (-Xverify:remote) during CDS dump time.";
  51 
  52     enum Testset1Part {
  53         A, B
  54     }
  55 
  56     public static void main(String[] args) throws Exception {
  57         String subCaseId = args[0];
  58         String jarName_verifier_test_tmp = "verifier_test_tmp" + "_" + subCaseId;
  59         String jarName_verifier_test = "verifier_test" + "_" + subCaseId;
  60         String jarName_greet = "greet" + "_" + subCaseId;
  61         String jarName_hi = "hi" + "_" + subCaseId;
  62 
  63 
  64         JarBuilder.build(jarName_verifier_test_tmp, "VerifierTest0", "VerifierTestA",
  65                          "VerifierTestB", "VerifierTestC", "VerifierTestD", "VerifierTestE",
  66                          "UnverifiableBase", "UnverifiableIntf", "UnverifiableIntfSub");
  67         JarBuilder.build(jarName_greet, "Greet");
  68         JarBuilder.build(jarName_hi, "Hi", "Hi$MyClass");
  69 
  70         File dir = new File(System.getProperty("test.classes", "."));


 122             output.shouldNotHaveExitValue(0);
 123         }
 124     }
 125 
 126     static void testset_1(String jar, String[] noAppClasses, String[] appClasses, Testset1Part part)
 127         throws Exception
 128     {
 129         String config[][] = {
 130             // {dump_list, dumptime_verification_setting,
 131             //  runtime_verification_setting, expected_output_str},
 132 
 133             // Dump app/ext with -Xverify:remote
 134             {"app",   VFY_REMOTE, VFY_REMOTE, VFY_ERR},
 135             {"app",   VFY_REMOTE, VFY_ALL,    MAP_FAIL},
 136             {"app",   VFY_REMOTE, VFY_NONE,   ERR },
 137             // Dump app/ext with -Xverify:all
 138             {"app",   VFY_ALL,    VFY_REMOTE, VFY_ERR },
 139             {"app",   VFY_ALL,    VFY_ALL,    VFY_ERR },
 140             {"app",   VFY_ALL,    VFY_NONE,   ERR },
 141             // Dump app/ext with -Xverify:none
 142             {"app",   VFY_NONE,   VFY_REMOTE, VFY_ERR},
 143             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
 144             {"app",   VFY_NONE,   VFY_NONE,   ERR },
 145             // Dump sys only with -Xverify:remote
 146             {"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
 147             {"noApp", VFY_REMOTE, VFY_ALL,    VFY_ERR},
 148             {"noApp", VFY_REMOTE, VFY_NONE,   ERR},
 149             // Dump sys only with -Xverify:all
 150             {"noApp", VFY_ALL, VFY_REMOTE,    VFY_ERR},
 151             {"noApp", VFY_ALL, VFY_ALL,       VFY_ERR},
 152             {"noApp", VFY_ALL, VFY_NONE,      ERR},
 153             // Dump sys only with -Xverify:none
 154             {"noApp", VFY_NONE, VFY_REMOTE,   VFY_ERR},
 155             {"noApp", VFY_NONE, VFY_ALL,      VFY_ERR},
 156             {"noApp", VFY_NONE, VFY_NONE,     ERR},
 157         };
 158 
 159         int loop_start, loop_stop;
 160 
 161         // Further break down testset_1 into two parts (to be invoked from VerifierTest_1A.java
 162         // and VerifierTest_1B.java) to improve parallel test execution time.


 173             break;
 174         }
 175 
 176         String prev_dump_setting = "";
 177         for (int i = loop_start; i < loop_stop; i ++) {
 178             String dump_list[] = config[i][0].equals("app") ? appClasses :
 179                 noAppClasses;
 180             String dump_setting = config[i][1];
 181             String runtime_setting = config[i][2];
 182             String expected_output_str = config[i][3];
 183             System.out.println("Test case [" + i + "]: dumping " + config[i][0] +
 184                                " with " + dump_setting +
 185                                ", run with " + runtime_setting);
 186             if (!dump_setting.equals(prev_dump_setting)) {
 187                 OutputAnalyzer dumpOutput = TestCommon.dump(
 188                                                             jar, dump_list, dump_setting,
 189                                                             // FIXME: the following options are for working around a GC
 190                                                             // issue - assert failure when dumping archive with the -Xverify:all
 191                                                             "-Xms256m",
 192                                                             "-Xmx256m");
 193                 if (dump_setting.equals(VFY_NONE) &&
 194                     runtime_setting.equals(VFY_REMOTE)) {
 195                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
 196                 }
 197             }
 198             TestCommon.run("-cp", jar,
 199                            runtime_setting,
 200                            "VerifierTest0")
 201                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
 202             prev_dump_setting = dump_setting;
 203         }
 204     }
 205 
 206     static void testset_2(String jarName_greet, String jarName_hi) throws Exception {
 207         String appClasses[];
 208         String jar;
 209 
 210         // The following section is for testing the scenarios where
 211         // the classes are verifiable during dump time.
 212         appClasses = TestCommon.list("Hi",
 213                                      "Greet",
 214                                      "Hi$MyClass");
 215         jar = TestCommon.getTestJar(jarName_hi + ".jar") + File.pathSeparator +
 216             TestCommon.getTestJar(jarName_greet + ".jar");
 217         String config2[][] = {
 218             // {dump_list, dumptime_verification_setting,
 219             //  runtime_verification_setting, expected_output_str},
 220 
 221             // Dump app/ext with -Xverify:remote
 222             {"app",   VFY_REMOTE, VFY_REMOTE, PASS_RESULT},
 223             {"app",   VFY_REMOTE, VFY_ALL,    MAP_FAIL},
 224             {"app",   VFY_REMOTE, VFY_NONE,   PASS_RESULT },
 225             // Dump app/ext with -Xverify:all
 226             {"app",   VFY_ALL,    VFY_REMOTE, PASS_RESULT },
 227             {"app",   VFY_ALL,    VFY_ALL,    PASS_RESULT },
 228             {"app",   VFY_ALL,    VFY_NONE,   PASS_RESULT },
 229             // Dump app/ext with -Xverify:none
 230             {"app",   VFY_NONE,   VFY_REMOTE, PASS_RESULT},
 231             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
 232             {"app",   VFY_NONE,   VFY_NONE,   PASS_RESULT },
 233         };
 234         String prev_dump_setting = "";
 235         for (int i = 0; i < config2.length; i ++) {
 236             // config2[i][0] is always set to "app" in this test
 237             String dump_setting = config2[i][1];
 238             String runtime_setting = config2[i][2];
 239             String expected_output_str = config2[i][3];
 240             System.out.println("Test case [" + i + "]: dumping " + config2[i][0] +
 241                                " with " + dump_setting +
 242                                ", run with " + runtime_setting);
 243             if (!dump_setting.equals(prev_dump_setting)) {
 244                 OutputAnalyzer dumpOutput = TestCommon.dump(
 245                                                             jar, appClasses, dump_setting,
 246                                                             "-XX:+UnlockDiagnosticVMOptions",
 247                                                             // FIXME: the following options are for working around a GC
 248                                                             // issue - assert failure when dumping archive with the -Xverify:all
 249                                                             "-Xms256m",
 250                                                             "-Xmx256m");
 251                 if (dump_setting.equals(VFY_NONE) &&
 252                     runtime_setting.equals(VFY_REMOTE)) {
 253                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
 254                 }
 255             }
 256             TestCommon.run("-cp", jar,
 257                            runtime_setting,
 258                            "Hi")
 259                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
 260            prev_dump_setting = dump_setting;
 261         }
 262     }
 263 
 264     static void createTestJarFile(File jarSrcFile, File jarFile) throws Exception {
 265         jarFile.delete();
 266         Files.copy(jarSrcFile.toPath(), jarFile.toPath());
 267 
 268         File dir = new File(System.getProperty("test.classes", "."));
 269         File outdir = new File(dir, "verifier_test_classes");
 270         outdir.mkdir();
 271 
 272         writeClassFile(new File(outdir, "UnverifiableBase.class"), makeUnverifiableBase());
 273         writeClassFile(new File(outdir, "UnverifiableIntf.class"), makeUnverifiableIntf());
 274 
 275         JarBuilder.update(jarFile.getPath(), outdir.getPath());
 276     }
 277 
 278     static void writeClassFile(File file, byte bytecodes[]) throws Exception {
 279         try (FileOutputStream fos = new FileOutputStream(file)) {
 280             fos.write(bytecodes);


test/hotspot/jtreg/runtime/appcds/VerifierTest.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File