hotspot/test/runtime/libadimalloc.solaris.sparc/Testlibadimalloc.java
author ctornqvi
Fri, 19 Aug 2016 10:06:30 -0400
changeset 40631 ed82623d7831
parent 38152 80e5da81fb2c
child 44633 d2f5e8921045
permissions -rw-r--r--
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder Reviewed-by: coleenp, gtriantafill, mseledtsov, iignatyev, dholmes, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     4
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     8
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    13
 * accompanied this code).
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    14
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    18
 *
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    21
 * questions.
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    22
 */
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    23
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    24
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    25
/*
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    26
 * @test Testlibadimalloc.java
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    27
 * @bug 8141445
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    28
 * @summary make sure the Solaris Sparc M7 libadimalloc.so library generates SIGSEGV's on buffer overflow
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    29
 * @requires (os.family == "solaris" & os.arch == "sparcv9")
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 34233
diff changeset
    30
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    31
 * @library /test/lib
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    32
 * @compile SEGVOverflow.java
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    33
 * @run driver Testlibadimalloc
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    34
 */
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    35
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    36
import java.io.*;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    37
import java.nio.file.*;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    38
import java.util.*;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    39
import jdk.test.lib.process.ProcessTools;
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    40
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    41
public class Testlibadimalloc {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    42
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    43
    // Expected return value when java program cores
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    44
    static final int EXPECTED_RET_VAL = 6;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    45
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    46
    public static void main(String[] args) throws Throwable {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    47
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    48
        // See if the libadimalloc.so library exists
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    49
        Path path = Paths.get("/usr/lib/64/libadimalloc.so");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    50
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    51
        // If the libadimalloc.so file does not exist, pass the test
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    52
        if (!(Files.isRegularFile(path) || Files.isSymbolicLink(path))) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    53
            System.out.println("Test skipped; libadimalloc.so does not exist");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    54
            return;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    55
        }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    56
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    57
        // Get the JDK, library and class path properties
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    58
        String libpath = System.getProperty("java.library.path");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    59
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    60
        // Create a new java process for the SEGVOverflow Java/JNI test
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    61
        ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    62
            "-Djava.library.path=" + libpath + ":.", "SEGVOverflow");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    63
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    64
        // Add the LD_PRELOAD_64 value to the environment
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    65
        Map<String, String> env = builder.environment();
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    66
        env.put("LD_PRELOAD_64", "libadimalloc.so");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    67
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    68
        // Start the process, get the pid and then wait for the test to finish
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    69
        Process process = builder.start();
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    70
        long pid = process.getPid();
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    71
        int retval = process.waitFor();
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    72
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    73
        // make sure the SEGVOverflow test crashed
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    74
        boolean found = false;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    75
        if (retval == EXPECTED_RET_VAL) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    76
            String filename = "hs_err_pid" + pid + ".log";
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    77
            Path filepath = Paths.get(filename);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    78
            // check to see if hs_err_file exists
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    79
            if (Files.isRegularFile(filepath)) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    80
                // see if the crash was due to a SEGV_ACCPERR signal
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    81
                File hs_err_file = new File(filename);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    82
                Scanner scanner = new Scanner(hs_err_file);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    83
                while (!found && scanner.hasNextLine()) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    84
                    String nextline = scanner.nextLine();
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    85
                    if (nextline.contains("SEGV_ACCPERR")) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    86
                         found = true;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    87
                    }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    88
                }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    89
            } else {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    90
                System.out.println("Test failed; hs_err_file does not exist: "
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    91
                                   + filepath);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    92
            }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    93
        } else {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    94
            System.out.println("Test failed; java test program did not " +
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    95
                               "return expected error: expected = " +
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    96
                               EXPECTED_RET_VAL + ", retval = " + retval);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    97
        }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    98
        // If SEGV_ACCPERR was not found in the hs_err file fail the test
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    99
        if (!found) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   100
            System.out.println("FAIL: SEGV_ACCPERR not found");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   101
            throw new RuntimeException("FAIL: SEGV_ACCPERR not found");
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   102
        }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   103
    }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   104
}