1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24  /*
  25   * @test
  26   * @bug 6904403
  27   * @library /testlibrary
  28   * @summary Don't assert if we redefine finalize method
  29   * @compile -XDignore.symbol.file testme.java Martyr.java MartyrSon.java Agent.java Main.java
  30   * @run main testme
  31   */
  32 
  33 import com.oracle.java.testlibrary.*;
  34 import java.io.File;
  35 import java.util.Arrays;
  36 
  37 public class testme {
  38     public static void main(String[] args) {
  39         try {
  40           final String slash = File.separator;
  41 
  42           // Property below set by JTREG
  43           String testClasses = System.getProperty("test.classes", "?") + slash;
  44           String testJava = System.getProperty("test.jdk", "?") + slash;
  45           String testSrc = System.getProperty("test.src", "?") + slash;
  46 
  47           String jarFullName = testClasses + "testcase.jar";
  48           String manifestPath = testSrc + "manifest.mf";
  49 
  50           // Create jar file
  51           String[] jarArgs = new String[] {"-cfm", jarFullName, manifestPath, "-C", testClasses, "."};
  52 
  53           sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
  54           if (!jarTool.run(jarArgs)) {
  55               throw new Exception("jar failed: args=" + Arrays.toString(jarArgs));
  56           }
  57 
  58           // Launch another java
  59           String[] javaArgs = new String[]{
  60             String.format("-Xbootclasspath/a:%slib%stools.jar", testJava, slash),
  61             "-javaagent:" + jarFullName,
  62             "Main" };
  63 
  64           ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs);
  65           OutputAnalyzer out = new OutputAnalyzer(pb.start());
  66           out.shouldContain("Redefinition done");
  67 
  68           System.out.println(out.getStdout());
  69           System.err.println(out.getStderr());
  70 
  71         } catch (Throwable e) {
  72             System.err.println("Test FAILED. Unexpected exception");
  73             e.printStackTrace();
  74             System.exit(-1);
  75         }
  76     }
  77 }