test/jdk/tools/launcher/RunpathTest.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 50865 2c3edd0a6222
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     1
/*
48522
c674ff28c69d 8194287: tools/launcher/RunpathTest.java fails with java.lang.NullPointerException
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     4
 *
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     7
 * published by the Free Software Foundation.
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     8
 *
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    13
 * accompanied this code).
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    14
 *
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    18
 *
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    21
 * questions.
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    22
 */
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    23
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    24
/*
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    25
 * @test
20846
8287d2ea9523 8023231: Remove comma from jtreg bug line
erikj
parents: 20845
diff changeset
    26
 * @bug 7190813 8022719
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    27
 * @summary Check for extended  RPATHs on *nixes
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file RunpathTest.java
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    29
 * @run main RunpathTest
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    30
 * @author ksrini
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    31
 */
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    32
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    33
import java.io.File;
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    34
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    35
public class RunpathTest extends TestHelper {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    36
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    37
    final String elfreaderCmd;
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    38
    RunpathTest() {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    39
        elfreaderCmd = findElfReader();
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    40
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    41
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    42
    final String findElfReader() {
41107
567f832618d7 8165161: Solaris: /usr/ccs /opt/sfw and /opt/csw are dead, references should be expunged
alanbur
parents: 20852
diff changeset
    43
        String[] paths = {"/usr/sbin", "/usr/bin"};
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    44
        final String cmd = isSolaris ? "elfdump" : "readelf";
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    45
        for (String x : paths) {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    46
            File p = new File(x);
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    47
            File e = new File(p, cmd);
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    48
            if (e.canExecute()) {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    49
                return e.getAbsolutePath();
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    50
            }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    51
        }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    52
        System.err.println("Warning: no suitable elf reader!");
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    53
        return null;
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    54
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    55
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    56
    void elfCheck(String javacmd, String expectedRpath) {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    57
        final TestResult tr = doExec(elfreaderCmd, "-d", javacmd);
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    58
        if (!tr.matches(expectedRpath)) {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    59
            System.out.println(tr);
50865
2c3edd0a6222 8205916: [test] Fix jdk/tools/launcher/RunpathTest to handle both, RPATH and RUNPATH
simonis
parents: 48522
diff changeset
    60
            throw new RuntimeException("FAILED: RPATH/RUNPATH strings " +
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    61
                    expectedRpath + " not found in " + javaCmd);
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    62
        }
50865
2c3edd0a6222 8205916: [test] Fix jdk/tools/launcher/RunpathTest to handle both, RPATH and RUNPATH
simonis
parents: 48522
diff changeset
    63
        System.out.println(javacmd + " contains expected RPATHS/RUNPATH");
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    64
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    65
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    66
    void testRpath() {
50865
2c3edd0a6222 8205916: [test] Fix jdk/tools/launcher/RunpathTest to handle both, RPATH and RUNPATH
simonis
parents: 48522
diff changeset
    67
        String expectedRpath = ".*R(UN)?PATH.*\\$ORIGIN/../lib.*";
20852
d09138f48ac1 8025991: tools/launcher/RunpathTest.java fails
chegar
parents: 20851
diff changeset
    68
        elfCheck(javaCmd, expectedRpath);
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    69
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    70
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    71
    public static void main(String... args) throws Exception {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    72
        if (isSolaris || isLinux) {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    73
            RunpathTest rp = new RunpathTest();
48522
c674ff28c69d 8194287: tools/launcher/RunpathTest.java fails with java.lang.NullPointerException
ksrini
parents: 47216
diff changeset
    74
            if (rp.elfreaderCmd == null) {
c674ff28c69d 8194287: tools/launcher/RunpathTest.java fails with java.lang.NullPointerException
ksrini
parents: 47216
diff changeset
    75
                System.err.println("Warning: test passes vacuously");
c674ff28c69d 8194287: tools/launcher/RunpathTest.java fails with java.lang.NullPointerException
ksrini
parents: 47216
diff changeset
    76
                return;
c674ff28c69d 8194287: tools/launcher/RunpathTest.java fails with java.lang.NullPointerException
ksrini
parents: 47216
diff changeset
    77
            }
13542
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    78
            rp.testRpath();
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    79
        }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    80
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    81
}