src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/CompilationWrapperTest.java
author dlong
Mon, 06 Nov 2017 20:29:49 -0800
changeset 47798 9fe9292f5931
parent 47216 71c04702a3d5
child 48190 25cfedf27edc
permissions -rw-r--r--
8190710: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     1
/*
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     4
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     8
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    13
 * accompanied this code).
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    14
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    18
 *
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    21
 * questions.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    22
 */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    23
package org.graalvm.compiler.hotspot.test;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    24
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    25
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    26
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    27
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    28
import java.io.File;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    29
import java.io.IOException;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    30
import java.util.ArrayList;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    31
import java.util.Arrays;
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    32
import java.util.Collections;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    33
import java.util.Enumeration;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    34
import java.util.List;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    35
import java.util.zip.ZipEntry;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    36
import java.util.zip.ZipFile;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    37
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    38
import org.graalvm.compiler.core.GraalCompilerOptions;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    39
import org.graalvm.compiler.core.test.GraalCompilerTest;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    40
import org.graalvm.compiler.test.SubprocessUtil;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    41
import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    42
import org.junit.Assert;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    43
import org.junit.Test;
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    44
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    45
/**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    46
 * Tests support for dumping graphs and other info useful for debugging a compiler crash.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    47
 */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    48
public class CompilationWrapperTest extends GraalCompilerTest {
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    49
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    50
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    51
     * Tests compilation requested by the VM.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    52
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    53
    @Test
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    54
    public void testVMCompilation1() throws IOException, InterruptedException {
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    55
        testHelper(Collections.emptyList(), Arrays.asList("-XX:+BootstrapJVMCI",
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    56
                        "-XX:+UseJVMCICompiler",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    57
                        "-Dgraal.CompilationFailureAction=ExitVM",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    58
                        "-Dgraal.CrashAt=Object.*,String.*",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    59
                        "-version"));
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    60
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    61
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    62
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    63
     * Tests that {@code -Dgraal.ExitVMOnException=true} works as an alias for
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    64
     * {@code -Dgraal.CompilationFailureAction=ExitVM}.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    65
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    66
    @Test
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    67
    public void testVMCompilation2() throws IOException, InterruptedException {
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    68
        testHelper(Collections.emptyList(), Arrays.asList("-XX:+BootstrapJVMCI",
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    69
                        "-XX:+UseJVMCICompiler",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    70
                        "-Dgraal.ExitVMOnException=true",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    71
                        "-Dgraal.CrashAt=Object.*,String.*",
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    72
                        "-version"));
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    73
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
    74
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    75
    static class Probe {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    76
        final String substring;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    77
        final int expectedOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    78
        int actualOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    79
        String lastMatchingLine;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    80
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    81
        Probe(String substring, int expectedOccurrences) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    82
            this.substring = substring;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    83
            this.expectedOccurrences = expectedOccurrences;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    84
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    85
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    86
        boolean matches(String line) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    87
            if (line.contains(substring)) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    88
                actualOccurrences++;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    89
                lastMatchingLine = line;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    90
                return true;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    91
            }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    92
            return false;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    93
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    94
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    95
        String test() {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    96
            return expectedOccurrences == actualOccurrences ? null : String.format("expected %d, got %d occurrences", expectedOccurrences, actualOccurrences);
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    97
        }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    98
    }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
    99
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   100
    /**
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   101
     * Tests {@link GraalCompilerOptions#MaxCompilationProblemsPerAction} in context of a
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   102
     * compilation requested by the VM.
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   103
     */
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   104
    @Test
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   105
    public void testVMCompilation3() throws IOException, InterruptedException {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   106
        final int maxProblems = 4;
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   107
        Probe[] probes = {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   108
                        new Probe("To capture more information for diagnosing or reporting a compilation", maxProblems),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   109
                        new Probe("Retrying compilation of", maxProblems),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   110
                        new Probe("adjusting CompilationFailureAction from Diagnose to Print", 1),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   111
                        new Probe("adjusting CompilationFailureAction from Print to Silent", 1),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   112
        };
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   113
        testHelper(Arrays.asList(probes), Arrays.asList("-XX:+BootstrapJVMCI",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   114
                        "-XX:+UseJVMCICompiler",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   115
                        "-Dgraal.CompilationFailureAction=Diagnose",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   116
                        "-Dgraal.MaxCompilationProblemsPerAction=" + maxProblems,
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   117
                        "-Dgraal.CrashAt=Object.*,String.*",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   118
                        "-version"));
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   119
    }
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   120
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   121
    /**
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   122
     * Tests compilation requested by Truffle.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   123
     */
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   124
    @Test
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   125
    public void testTruffleCompilation1() throws IOException, InterruptedException {
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   126
        testHelper(Collections.emptyList(),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   127
                        Arrays.asList(
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   128
                                        "-Dgraal.CompilationFailureAction=ExitVM",
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   129
                                        "-Dgraal.CrashAt=root test1"),
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   130
                        "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   131
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   132
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   133
    /**
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   134
     * Tests that TruffleCompilationExceptionsAreFatal works as expected.
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   135
     */
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   136
    @Test
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   137
    public void testTruffleCompilation2() throws IOException, InterruptedException {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   138
        Probe[] probes = {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   139
                        new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   140
        };
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   141
        testHelper(Arrays.asList(probes),
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   142
                        Arrays.asList(
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   143
                                        "-Dgraal.CompilationFailureAction=Silent",
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   144
                                        "-Dgraal.TruffleCompilationExceptionsAreFatal=true",
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   145
                                        "-Dgraal.CrashAt=root test1"),
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   146
                        "org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   147
    }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   148
46762
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   149
    private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   150
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   151
    private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   152
        final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   153
        List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   154
        vmArgs.removeIf(a -> a.startsWith("-Dgraal."));
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   155
        vmArgs.remove("-esa");
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   156
        vmArgs.remove("-ea");
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   157
        vmArgs.add("-Dgraal.DumpPath=" + dumpPath);
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   158
        // Force output to a file even if there's a running IGV instance available.
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   159
        vmArgs.add("-Dgraal.PrintGraphFile=true");
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   160
        vmArgs.addAll(extraVmArgs);
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   161
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   162
        Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
46762
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   163
        if (VERBOSE) {
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   164
            System.out.println(proc);
f7defa99f173 8185829: Update Graal
dlong
parents: 46680
diff changeset
   165
        }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   166
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   167
        List<Probe> probes = new ArrayList<>(initialProbes);
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   168
        Probe diagnosticProbe = null;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   169
        if (!extraVmArgs.contains("-Dgraal.TruffleCompilationExceptionsAreFatal=true")) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   170
            diagnosticProbe = new Probe("Graal diagnostic output saved in ", 1);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   171
            probes.add(diagnosticProbe);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   172
            probes.add(new Probe("Forced crash after compiling", Integer.MAX_VALUE) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   173
                @Override
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   174
                String test() {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   175
                    return actualOccurrences > 0 ? null : "expected at least 1 occurrence";
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   176
                }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   177
            });
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   178
        }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   179
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   180
        for (String line : proc.output) {
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   181
            for (Probe probe : probes) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   182
                if (probe.matches(line)) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   183
                    break;
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   184
                }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   185
            }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   186
        }
46807
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   187
        for (Probe probe : probes) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   188
            String error = probe.test();
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   189
            if (error != null) {
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   190
                Assert.fail(String.format("Did not find expected occurences of '%s' in output of command: %s%n%s", probe.substring, error, proc));
8b2c620d7092 8186158: Update Graal
iveresov
parents: 46762
diff changeset
   191
            }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   192
        }
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   193
        if (diagnosticProbe != null) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   194
            String line = diagnosticProbe.lastMatchingLine;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   195
            int substringStart = line.indexOf(diagnosticProbe.substring);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   196
            int substringLength = diagnosticProbe.substring.length();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   197
            String diagnosticOutputZip = line.substring(substringStart + substringLength).trim();
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   198
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   199
            List<String> dumpPathEntries = Arrays.asList(dumpPath.list());
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   200
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   201
            File zip = new File(diagnosticOutputZip).getAbsoluteFile();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   202
            Assert.assertTrue(zip.toString(), zip.exists());
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   203
            Assert.assertTrue(zip + " not in " + dumpPathEntries, dumpPathEntries.contains(zip.getName()));
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   204
            try {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   205
                int bgv = 0;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   206
                int cfg = 0;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   207
                ZipFile dd = new ZipFile(diagnosticOutputZip);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   208
                List<String> entries = new ArrayList<>();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   209
                for (Enumeration<? extends ZipEntry> e = dd.entries(); e.hasMoreElements();) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   210
                    ZipEntry ze = e.nextElement();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   211
                    String name = ze.getName();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   212
                    entries.add(name);
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   213
                    if (name.endsWith(".bgv")) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   214
                        bgv++;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   215
                    } else if (name.endsWith(".cfg")) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   216
                        cfg++;
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   217
                    }
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   218
                }
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   219
                if (bgv == 0) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   220
                    Assert.fail(String.format("Expected at least one .bgv file in %s: %s%n%s", diagnosticOutputZip, entries, proc));
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   221
                }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   222
                if (cfg == 0) {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   223
                    Assert.fail(String.format("Expected at least one .cfg file in %s: %s", diagnosticOutputZip, entries));
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   224
                }
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   225
            } finally {
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   226
                zip.delete();
9fe9292f5931 8190710: Update Graal
dlong
parents: 47216
diff changeset
   227
                dumpPath.delete();
46680
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   228
            }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   229
        }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   230
    }
2894e4262fd6 8184768: Update Graal
iveresov
parents:
diff changeset
   231
}