hotspot/test/runtime/libadimalloc.solaris.sparc/Testlibadimalloc.java
author stefank
Fri, 10 Jun 2016 14:06:36 +0200
changeset 39230 b991240ffb0d
parent 38152 80e5da81fb2c
child 40631 ed82623d7831
permissions -rw-r--r--
8159237: PreservedMarks verification code fails Reviewed-by: lmesnik, jwilhelm
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
/*
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
34233
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    31
 * @library /testlibrary
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    32
 * @build jdk.test.lib.*
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    33
 * @compile SEGVOverflow.java
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    34
 * @run driver Testlibadimalloc
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
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    37
import java.io.*;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    38
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
    39
import java.util.*;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    40
import jdk.test.lib.ProcessTools;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    41
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    42
public class Testlibadimalloc {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    43
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    44
    // 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
    45
    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
    46
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    47
    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
    48
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    49
        // 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
    50
        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
    51
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    52
        // 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
    53
        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
    54
            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
    55
            return;
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
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    58
        // 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
    59
        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
    60
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    61
        // 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
    62
        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
    63
            "-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
    64
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    65
        // 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
    66
        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
    67
        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
    68
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    69
        // 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
    70
        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
    71
        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
    72
        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
    73
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    74
        // 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
    75
        boolean found = false;
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    76
        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
    77
            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
    78
            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
    79
            // 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
    80
            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
    81
                // 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
    82
                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
    83
                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
    84
                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
    85
                    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
    86
                    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
    87
                         found = true;
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
                }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    90
            } else {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    91
                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
    92
                                   + filepath);
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    93
            }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    94
        } else {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    95
            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
    96
                               "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
    97
                               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
    98
        }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
    99
        // 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
   100
        if (!found) {
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   101
            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
   102
            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
   103
        }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   104
    }
2cf348387c44 8141445: Use of Solaris/SPARC M7 libadimalloc.so can generate unknown signal in hs_err file
gthornbr
parents:
diff changeset
   105
}