hotspot/test/serviceability/sa/sadebugd/SADebugDTest.java
author dcubed
Thu, 11 Aug 2016 12:27:20 -0700
changeset 40352 c2a7d79947a1
parent 40348 1bcfc9cfdfa0
child 40631 ed82623d7831
permissions -rw-r--r--
8163879: quarantine serviceability/sa/sadebugd/SADebugDTest.java since it hangs intermittently Reviewed-by: hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40348
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     1
/*
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     4
 *
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     8
 *
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    13
 * accompanied this code).
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    14
 *
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    18
 *
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    21
 * questions.
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    22
 */
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    23
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    24
/*
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    25
 * @test
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    26
 * @summary Checks that the jshdb debugd utility sucessfully starts
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    27
 *          and tries to attach to a running process
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    29
 * @library /test/lib/share/classes
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    30
 *
40352
c2a7d79947a1 8163879: quarantine serviceability/sa/sadebugd/SADebugDTest.java since it hangs intermittently
dcubed
parents: 40348
diff changeset
    31
 * @ignore 8163805
40348
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    32
 * @run main/othervm SADebugDTest
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    33
 */
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    34
import java.io.File;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    35
import java.util.concurrent.CountDownLatch;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    36
import java.io.InputStreamReader;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    37
import java.io.BufferedReader;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    38
import java.io.Reader;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    39
import java.util.concurrent.TimeUnit;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    40
import java.util.function.Predicate;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    41
import static jdk.test.lib.Asserts.assertTrue;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    42
import static jdk.test.lib.Platform.shouldSAAttach;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    43
import static jdk.test.lib.process.ProcessTools.startProcess;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    44
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    45
public class SADebugDTest {
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    46
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    47
    private static final String GOLDEN = "Attaching to process ID %d and starting RMI services, please wait...";
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    48
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    49
    private static final String JAVA_HOME = (System.getProperty("test.jdk") != null)
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    50
            ? System.getProperty("test.jdk") : System.getProperty("java.home");
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    51
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    52
    private static final String JAVA_BIN_DIR
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    53
            = JAVA_HOME + File.separator + "bin" + File.separator;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    54
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    55
    private static final String JHSDB = JAVA_BIN_DIR + "jhsdb";
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    56
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    58
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    59
        if (!shouldSAAttach()) {
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    60
            log("Not possible to attach the SA. Skipping the test");
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    61
            return;
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    62
        }
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    63
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    64
        long ourPid = ProcessHandle.current().getPid();
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    65
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    66
        // The string we are expecting in the debugd ouput
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    67
        String golden = String.format(GOLDEN, ourPid);
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    68
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    69
        // We are going to run 'jhsdb debugd <our pid>'
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    70
        // The startProcess will block untl the 'golden' string appears in either process' stdout or stderr
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    71
        // In case of timeout startProcess kills the debugd process
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    72
        ProcessBuilder pb = new ProcessBuilder();
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    73
        pb.command(JHSDB, "debugd", String.valueOf(ourPid));
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    74
        Process debugd = startProcess("debugd", pb, null, (line) -> line.trim().contains(golden), 0, TimeUnit.SECONDS);
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    75
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    76
        // If we are here, this means we have received the golden line and the test has passed
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    77
        // The debugd remains running, we have to kill it
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    78
        debugd.destroy();
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    79
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    80
    }
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    81
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    82
    private static void log(String string) {
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    83
        System.out.println(string);
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    84
    }
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    85
1bcfc9cfdfa0 8163269: Testcase missed in push for JDK-8160817
dsamersoff
parents:
diff changeset
    86
}