test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
changeset 58384 9a3a700ca571
parent 58127 41082cd965cc
child 58679 9c3209ff7550
equal deleted inserted replaced
58379:8511c662083b 58384:9a3a700ca571
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    27  * @requires vm.hasSA
    27  * @requires vm.hasSA
    28  * @library /test/lib
    28  * @library /test/lib
    29  * @run driver/timeout=240 TestJmapCore run heap
    29  * @run driver/timeout=240 TestJmapCore run heap
    30  */
    30  */
    31 
    31 
       
    32 import java.io.File;
       
    33 
    32 import jdk.test.lib.Asserts;
    34 import jdk.test.lib.Asserts;
    33 import jdk.test.lib.JDKToolFinder;
    35 import jdk.test.lib.JDKToolFinder;
    34 import jdk.test.lib.JDKToolLauncher;
    36 import jdk.test.lib.JDKToolLauncher;
    35 import jdk.test.lib.Platform;
    37 import jdk.test.lib.Platform;
       
    38 import jdk.test.lib.Utils;
    36 import jdk.test.lib.classloader.GeneratingClassLoader;
    39 import jdk.test.lib.classloader.GeneratingClassLoader;
    37 import jdk.test.lib.hprof.HprofParser;
    40 import jdk.test.lib.hprof.HprofParser;
    38 import jdk.test.lib.process.ProcessTools;
    41 import jdk.test.lib.process.ProcessTools;
    39 import jdk.test.lib.process.OutputAnalyzer;
    42 import jdk.test.lib.process.OutputAnalyzer;
    40 import jdk.test.lib.Utils;
    43 import jdk.test.lib.SA.SATestUtils;
    41 import jtreg.SkippedException;
    44 import jtreg.SkippedException;
    42 
       
    43 import java.io.File;
       
    44 
    45 
    45 public class TestJmapCore {
    46 public class TestJmapCore {
    46     static final String pidSeparator = ":KILLED_PID";
    47     static final String pidSeparator = ":KILLED_PID";
    47 
    48 
    48     public static final String HEAP_OOME = "heap";
    49     public static final String HEAP_OOME = "heap";
    95         System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));
    96         System.out.println("Run test with ulimit: " + (useDefaultUlimit ? "default" : "unlimited"));
    96         OutputAnalyzer output = useDefaultUlimit
    97         OutputAnalyzer output = useDefaultUlimit
    97             ? ProcessTools.executeProcess(pb)
    98             ? ProcessTools.executeProcess(pb)
    98             : ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && "
    99             : ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && "
    99                     + ProcessTools.getCommandLine(pb));
   100                     + ProcessTools.getCommandLine(pb));
       
   101         File pwd = new File(".");
       
   102         SATestUtils.unzipCores(pwd);
   100         File core;
   103         File core;
   101         String pattern = Platform.isWindows() ? ".*\\.mdmp" : "core(\\.\\d+)?";
   104         String pattern = Platform.isWindows() ? ".*\\.mdmp" : "core(\\.\\d+)?";
   102         File[] cores = new File(".").listFiles((dir, name) -> name.matches(pattern));
   105         File[] cores = pwd.listFiles((dir, name) -> name.matches(pattern));
   103         if (cores.length == 0) {
   106         if (cores.length == 0) {
   104             // /cores/core.$pid might be generated on macosx by default
   107             // /cores/core.$pid might be generated on macosx by default
   105             String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1);
   108             String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1);
   106             core = new File("cores/core." + pid);
   109             core = new File("cores/core." + pid);
   107             if (!core.exists()) {
   110             if (!core.exists()) {
   108                 throw new SkippedException("Has not been able to find coredump");
   111                 throw new SkippedException("Has not been able to find coredump");
   109             }
   112             }
   110         } else {
   113         } else {
   111             Asserts.assertTrue(cores.length == 1,
   114             Asserts.assertTrue(cores.length == 1,
   112                     "There are unexpected files containing core "
   115                     "There are unexpected files containing core "
   113                     + ": " + String.join(",", new File(".").list()) + ".");
   116                     + ": " + String.join(",", pwd.list()) + ".");
   114             core = cores[0];
   117             core = cores[0];
   115         }
   118         }
   116         System.out.println("Found corefile: " + core.getAbsolutePath());
   119         System.out.println("Found corefile: " + core.getAbsolutePath());
   117 
   120 
   118         File dumpFile = new File("heap.hprof");
   121         File dumpFile = new File("heap.hprof");