jdk/test/tools/launcher/RunpathTest.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 20852 d09138f48ac1
child 41107 567f832618d7
permissions -rw-r--r--
Merge
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
/*
20201
50cc2d25a60b 8020552: [launcher] changes to support removal of Solaris 32-bit distribution
ksrini
parents: 13542
diff changeset
     2
 * Copyright (c) 2012, 2013, 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() {
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    43
        String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"};
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);
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    60
            throw new RuntimeException("FAILED: RPATH strings " +
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
        }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    63
        System.out.println(javacmd + " contains expected RPATHS");
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() {
20852
d09138f48ac1 8025991: tools/launcher/RunpathTest.java fails
chegar
parents: 20851
diff changeset
    67
        String expectedRpath = ".*RPATH.*\\$ORIGIN/../lib/" + getJreArch() + ".*";
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();
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    74
            rp.testRpath();
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    75
        }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    76
    }
93873f8b6528 7190813: (launcher) RPATH needs to have additional paths
omajid
parents:
diff changeset
    77
}