Skip to content

Commit 3e3d90d

Browse files
committed
8230942: Support compressed cores in SA tests
Reviewed-by: dholmes, sspitsyn
1 parent 9f4484f commit 3e3d90d

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed

test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,30 @@
3434
* @run main/othervm/timeout=2400 -Xmx1g ClhsdbCDSCore
3535
*/
3636

37-
import java.util.List;
38-
import java.util.ArrayList;
39-
import java.util.Arrays;
40-
import java.util.Map;
41-
import java.util.HashMap;
42-
import jdk.test.lib.process.ProcessTools;
43-
import jdk.test.lib.Platform;
44-
import jdk.test.lib.process.OutputAnalyzer;
45-
import jdk.test.lib.cds.CDSTestUtils;
46-
import jdk.test.lib.cds.CDSOptions;
47-
import java.io.IOException;
4837
import java.io.File;
38+
import java.io.IOException;
4939
import java.nio.file.Files;
5040
import java.nio.file.Path;
5141
import java.nio.file.Paths;
52-
import jdk.test.lib.Asserts;
53-
import java.util.regex.Pattern;
42+
import java.util.ArrayList;
43+
import java.util.Arrays;
44+
import java.util.HashMap;
45+
import java.util.List;
46+
import java.util.Map;
47+
import java.util.Scanner;
5448
import java.util.regex.Matcher;
49+
import java.util.regex.Pattern;
50+
5551
import jdk.internal.misc.Unsafe;
56-
import java.util.Scanner;
52+
53+
import jdk.test.lib.Asserts;
54+
import jdk.test.lib.Platform;
55+
import jdk.test.lib.cds.CDSOptions;
56+
import jdk.test.lib.cds.CDSTestUtils;
57+
import jdk.test.lib.process.OutputAnalyzer;
58+
import jdk.test.lib.process.ProcessTools;
59+
import jdk.test.lib.SA.SATestUtils;
60+
5761
import jtreg.SkippedException;
5862

5963
class CrashApp {
@@ -102,6 +106,7 @@ public static void main(String[] args) throws Exception {
102106

103107
System.out.println(crashOut.getOutput());
104108
String crashOutputString = crashOut.getOutput();
109+
SATestUtils.unzipCores(new File("."));
105110
String coreFileLocation = getCoreFileLocation(crashOutputString);
106111
if (coreFileLocation == null) {
107112
if (Platform.isOSX()) {

test/hotspot/jtreg/serviceability/sa/TestJmapCore.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,19 +29,20 @@
2929
* @run driver/timeout=240 TestJmapCore run heap
3030
*/
3131

32+
import java.io.File;
33+
3234
import jdk.test.lib.Asserts;
3335
import jdk.test.lib.JDKToolFinder;
3436
import jdk.test.lib.JDKToolLauncher;
3537
import jdk.test.lib.Platform;
38+
import jdk.test.lib.Utils;
3639
import jdk.test.lib.classloader.GeneratingClassLoader;
3740
import jdk.test.lib.hprof.HprofParser;
3841
import jdk.test.lib.process.ProcessTools;
3942
import jdk.test.lib.process.OutputAnalyzer;
40-
import jdk.test.lib.Utils;
43+
import jdk.test.lib.SA.SATestUtils;
4144
import jtreg.SkippedException;
4245

43-
import java.io.File;
44-
4546
public class TestJmapCore {
4647
static final String pidSeparator = ":KILLED_PID";
4748

@@ -97,9 +98,11 @@ static void test(String type) throws Throwable {
9798
? ProcessTools.executeProcess(pb)
9899
: ProcessTools.executeProcess("sh", "-c", "ulimit -c unlimited && "
99100
+ ProcessTools.getCommandLine(pb));
101+
File pwd = new File(".");
102+
SATestUtils.unzipCores(pwd);
100103
File core;
101104
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));
103106
if (cores.length == 0) {
104107
// /cores/core.$pid might be generated on macosx by default
105108
String pid = output.firstMatch("^(\\d+)" + pidSeparator, 1);
@@ -110,7 +113,7 @@ static void test(String type) throws Throwable {
110113
} else {
111114
Asserts.assertTrue(cores.length == 1,
112115
"There are unexpected files containing core "
113-
+ ": " + String.join(",", new File(".").list()) + ".");
116+
+ ": " + String.join(",", pwd.list()) + ".");
114117
core = cores[0];
115118
}
116119
System.out.println("Found corefile: " + core.getAbsolutePath());

test/lib/jdk/test/lib/SA/SATestUtils.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
*/
2323
package jdk.test.lib.SA;
2424

25+
import java.io.File;
26+
import java.io.FileInputStream;
27+
import java.io.FileOutputStream;
2528
import java.io.IOException;
26-
import java.util.List;
2729
import java.util.ArrayList;
30+
import java.util.List;
31+
import java.util.concurrent.TimeUnit;
32+
import java.util.zip.GZIPInputStream;
33+
2834
import jdk.test.lib.Asserts;
2935
import jdk.test.lib.Platform;
30-
import java.util.concurrent.TimeUnit;
36+
import jtreg.SkippedException;
3137

3238
public class SATestUtils {
3339

@@ -77,4 +83,22 @@ public static List<String> addPrivileges(List<String> cmdStringList)
7783
outStringList.addAll(cmdStringList);
7884
return outStringList;
7985
}
86+
87+
public static void unzipCores(File dir) {
88+
File[] gzCores = dir.listFiles((directory, name) -> name.matches("core(\\.\\d+)?\\.gz"));
89+
for (File gzCore : gzCores) {
90+
String coreFileName = gzCore.getName().replace(".gz", "");
91+
System.out.println("Unzipping core into " + coreFileName);
92+
try (GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(gzCore));
93+
FileOutputStream fos = new FileOutputStream(coreFileName)) {
94+
byte[] buffer = new byte[1024];
95+
int length;
96+
while ((length = gzis.read(buffer)) > 0) {
97+
fos.write(buffer, 0, length);
98+
}
99+
} catch (IOException e) {
100+
throw new SkippedException("Not able to unzip file: " + gzCore.getAbsolutePath(), e);
101+
}
102+
}
103+
}
80104
}

0 commit comments

Comments
 (0)