1 /*
2 * Copyright (c) 2017, 2018, 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 */
40 import org.graalvm.compiler.api.directives.GraalDirectives;
41 import org.graalvm.compiler.core.test.GraalCompilerTest;
42 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
43 import org.graalvm.compiler.test.SubprocessUtil;
44 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
45 import org.junit.Assert;
46 import org.junit.Test;
47
48 import sun.misc.Unsafe;
49
50 /**
51 * Tests that a hs_err crash log contains expected content.
52 */
53 public class HsErrLogTest extends GraalCompilerTest {
54
55 @Test
56 public void test1() throws IOException, InterruptedException {
57 List<String> args = new ArrayList<>();
58 if (JavaVersionUtil.JAVA_SPEC <= 8) {
59 args.add("-XX:-UseJVMCIClassLoader");
60 }
61 args.add("-XX:+UseJVMCICompiler");
62 args.add("-XX:CompileOnly=" + Crasher.class.getName() + "::tryCrash");
63 args.add(Crasher.class.getName());
64 testHelper(args);
65 }
66
67 private static final boolean VERBOSE = Boolean.getBoolean(HsErrLogTest.class.getSimpleName() + ".verbose");
68
69 private static void testHelper(List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
70 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
71 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
72 vmArgs.remove("-esa");
73 vmArgs.remove("-ea");
74 vmArgs.addAll(extraVmArgs);
75
76 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
77 if (VERBOSE) {
78 System.out.println(proc);
79 }
80
81 Pattern re = Pattern.compile("# +(.*hs_err_pid[\\d]+\\.log)");
82
83 for (String line : proc.output) {
84 Matcher m = re.matcher(line);
85 if (m.matches()) {
86 File path = new File(m.group(1));
87 Assert.assertTrue(path.toString(), path.exists());
88 checkHsErr(path);
89 return;
90 }
91 }
92
93 Assert.fail("Could not find " + re.pattern());
94 }
95
96 private static void checkHsErr(File hsErrPath) {
97 try (BufferedReader br = new BufferedReader(new FileReader(hsErrPath))) {
98 String line = br.readLine();
99 String sig = Crasher.class.getName() + ".tryCrash(JI)I";
100 List<String> lines = new ArrayList<>();
101 while (line != null) {
102 if (line.contains(sig)) {
103 if (!VERBOSE) {
104 hsErrPath.delete();
105 }
106 return;
107 }
108 lines.add(line);
109 line = br.readLine();
110 }
111 throw new AssertionError("Could not find line containing \"" + sig + "\" in " + hsErrPath +
112 ":" + System.lineSeparator() + String.join(System.lineSeparator(), lines));
113 } catch (IOException e) {
|
1 /*
2 * Copyright (c) 2017, 2019, 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 */
40 import org.graalvm.compiler.api.directives.GraalDirectives;
41 import org.graalvm.compiler.core.test.GraalCompilerTest;
42 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
43 import org.graalvm.compiler.test.SubprocessUtil;
44 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
45 import org.junit.Assert;
46 import org.junit.Test;
47
48 import sun.misc.Unsafe;
49
50 /**
51 * Tests that a hs_err crash log contains expected content.
52 */
53 public class HsErrLogTest extends GraalCompilerTest {
54
55 @Test
56 public void test1() throws IOException, InterruptedException {
57 List<String> args = new ArrayList<>();
58 if (JavaVersionUtil.JAVA_SPEC <= 8) {
59 args.add("-XX:-UseJVMCIClassLoader");
60 } else {
61 args.add("--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.api.directives=ALL-UNNAMED");
62 }
63 args.add("-XX:+UseJVMCICompiler");
64 args.add("-XX:CompileOnly=" + Crasher.class.getName() + "::tryCrash");
65 args.add(Crasher.class.getName());
66 testHelper(args);
67 }
68
69 private static final boolean VERBOSE = Boolean.getBoolean(HsErrLogTest.class.getSimpleName() + ".verbose");
70
71 private static void testHelper(List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
72 List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
73 vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
74 vmArgs.remove("-esa");
75 vmArgs.remove("-ea");
76 vmArgs.addAll(extraVmArgs);
77
78 Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
79 if (VERBOSE) {
80 System.out.println(proc);
81 }
82
83 Pattern re = Pattern.compile("# +(.*hs_err_pid[\\d]+\\.log)");
84
85 for (String line : proc.output) {
86 Matcher m = re.matcher(line);
87 if (m.matches()) {
88 File path = new File(m.group(1));
89 Assert.assertTrue(path.toString(), path.exists());
90 checkHsErr(path);
91 return;
92 }
93 }
94
95 Assert.fail(String.format("Could not find %s%n%s", re.pattern(), proc));
96 }
97
98 private static void checkHsErr(File hsErrPath) {
99 try (BufferedReader br = new BufferedReader(new FileReader(hsErrPath))) {
100 String line = br.readLine();
101 String sig = Crasher.class.getName() + ".tryCrash(JI)I";
102 List<String> lines = new ArrayList<>();
103 while (line != null) {
104 if (line.contains(sig)) {
105 if (!VERBOSE) {
106 hsErrPath.delete();
107 }
108 return;
109 }
110 lines.add(line);
111 line = br.readLine();
112 }
113 throw new AssertionError("Could not find line containing \"" + sig + "\" in " + hsErrPath +
114 ":" + System.lineSeparator() + String.join(System.lineSeparator(), lines));
115 } catch (IOException e) {
|