< prev index next >

test/jdk/java/lang/ClassLoader/Assert.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
--- 1,7 ---
  /*
!  * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 22,23 ***
   */
  
  /*
   * @test
   * @bug 4290640 4785473
   * @build package1.Class1 package2.Class2 package1.package3.Class3 Assert
   * @run main/othervm Assert
   * @summary Test the assertion facility
   * @author Mike McCloskey
   * @key randomness
   */
  
  import package1.*;
  import package2.*;
  import package1.package3.*;
! import java.io.*;
  import java.util.Random;
  
  public class Assert {
  
      private static Class1 testClass1;
      private static Class2 testClass2;
      private static Class3 testClass3;
--- 22,30 ---
   */
  
  /*
   * @test
   * @bug 4290640 4785473
+  * @requires vm.flagless
+  * @library /test/lib
   * @build package1.Class1 package2.Class2 package1.package3.Class3 Assert
   * @run main/othervm Assert
   * @summary Test the assertion facility
   * @author Mike McCloskey
   * @key randomness
   */
  
+ import jdk.test.lib.process.OutputAnalyzer;
  import package1.*;
  import package2.*;
  import package1.package3.*;
! 
+ import java.util.ArrayList;
+ import java.util.List;
  import java.util.Random;
  
+ import static jdk.test.lib.process.ProcessTools.*;
+ 
  public class Assert {
  
      private static Class1 testClass1;
      private static Class2 testClass2;
      private static Class3 testClass3;

*** 54,11 ***
       *
       * This test spawns a new VM for each run because assertions are set on or
       * off at class load time. Once the class is loaded its assertion status
       * does not change.
       */
!     public static void main(String[] args) throws Exception {
  
          // Switch values: 0=don't touch, 1=off, 2 = on
          int[] switches = new int[7];
  
          int switchSource = 0;
--- 61,11 ---
       *
       * This test spawns a new VM for each run because assertions are set on or
       * off at class load time. Once the class is loaded its assertion status
       * does not change.
       */
!     public static void main(String[] args) throws Throwable {
  
          // Switch values: 0=don't touch, 1=off, 2 = on
          int[] switches = new int[7];
  
          int switchSource = 0;

*** 75,32 ***
                      switches[i] = temp % 3;
                      temp = temp / 3;
                  }
  
                  // Spawn new VM and load classes
!                 String command = System.getProperty("java.home") +
!                     File.separator + "bin" + File.separator + "java Assert";
- 
-                 StringBuffer commandString = new StringBuffer(command);
                  for(int j=0; j<7; j++)
!                     commandString.append(" "+switches[j]);
! 
-                 Process p = null;
-                 p = Runtime.getRuntime().exec(commandString.toString());
- 
                  if (debug) { // See output of test VMs
!                     BufferedReader blah = new BufferedReader(
!                                           new InputStreamReader(p.getInputStream()));
!                     String outString = blah.readLine();
-                     while (outString != null) {
-                         System.out.println("from BufferedReader:"+outString);
-                         outString = blah.readLine();
-                     }
                  }
! 
-                 p.waitFor();
-                 int result = p.exitValue();
                  if (debug) { // See which switch configs failed
                      if (result == 0) {
                          for(int k=6; k>=0; k--)
                              System.out.print(switches[k]);
                          System.out.println();
--- 82,21 ---
                      switches[i] = temp % 3;
                      temp = temp / 3;
                  }
  
                  // Spawn new VM and load classes
!                 List<String> commands = new ArrayList<>();
!                 commands.add("Assert");
                  for(int j=0; j<7; j++)
!                     commands.add(Integer.toString(switches[j]));
!                 OutputAnalyzer outputAnalyzer = executeCommand(createLimitedTestJavaProcessBuilder(commands));
                  if (debug) { // See output of test VMs
!                     outputAnalyzer.asLines()
!                                   .stream()
!                                   .forEach(s -> System.out.println(s));
                  }
!                 int result = outputAnalyzer.getExitValue();
                  if (debug) { // See which switch configs failed
                      if (result == 0) {
                          for(int k=6; k>=0; k--)
                              System.out.print(switches[k]);
                          System.out.println();
< prev index next >