test/lib/jdk/test/lib/Platform.java
author sgehwolf
Fri, 12 Jul 2019 19:37:25 +0200
changeset 55746 709913d8ace9
parent 53273 bbc79e0ec9ee
child 55757 07e998f8f816
permissions -rw-r--r--
8227642: [TESTBUG] Make docker tests podman compatible Reviewed-by: mseledtsov, iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     1
/*
53273
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     4
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     8
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    13
 * accompanied this code).
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    14
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    18
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    21
 * questions.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    22
 */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    23
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    24
package jdk.test.lib;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    25
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
    26
import java.io.File;
45453
e72b2abd7f92 8181820: jdk/test/lib/Platform should not depend on jdk/test/lib/Utils
epavlova
parents: 43394
diff changeset
    27
import java.io.IOException;
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
    28
import java.io.RandomAccessFile;
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    29
import java.util.regex.Pattern;
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    30
import java.security.AccessController;
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    31
import java.security.PrivilegedAction;
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    32
import java.security.PrivilegedActionException;
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    33
import java.security.PrivilegedExceptionAction;
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    34
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    35
public class Platform {
55746
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    36
    // Use this property to specify docker location on your system.
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    37
    // E.g.: "/usr/local/bin/docker". We define this constant here so
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    38
    // that it can be used in VMProps as well which checks docker support
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    39
    // via this command
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    40
    public static final String DOCKER_COMMAND =
709913d8ace9 8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents: 53273
diff changeset
    41
        System.getProperty("jdk.test.docker.command", "docker");
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    42
    public  static final String vmName      = privilegedGetProperty("java.vm.name");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    43
    public  static final String vmInfo      = privilegedGetProperty("java.vm.info");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    44
    private static final String osVersion   = privilegedGetProperty("os.version");
41264
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
    45
    private static       int osVersionMajor = -1;
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
    46
    private static       int osVersionMinor = -1;
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    47
    private static final String osName      = privilegedGetProperty("os.name");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    48
    private static final String dataModel   = privilegedGetProperty("sun.arch.data.model");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    49
    private static final String vmVersion   = privilegedGetProperty("java.vm.version");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    50
    private static final String jdkDebug    = privilegedGetProperty("jdk.debug");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    51
    private static final String osArch      = privilegedGetProperty("os.arch");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    52
    private static final String userName    = privilegedGetProperty("user.name");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    53
    private static final String compiler    = privilegedGetProperty("sun.management.compiler");
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    54
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    55
    private static String privilegedGetProperty(String key) {
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    56
        return AccessController.doPrivileged((
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    57
                PrivilegedAction<String>) () -> System.getProperty(key));
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
    58
    }
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    59
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    60
    public static boolean isClient() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    61
        return vmName.endsWith(" Client VM");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    62
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    63
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    64
    public static boolean isServer() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    65
        return vmName.endsWith(" Server VM");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    66
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    67
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    68
    public static boolean isGraal() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    69
        return vmName.endsWith(" Graal VM");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    70
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    71
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    72
    public static boolean isZero() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    73
        return vmName.endsWith(" Zero VM");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    74
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    75
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    76
    public static boolean isMinimal() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    77
        return vmName.endsWith(" Minimal VM");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    78
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    79
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    80
    public static boolean isEmbedded() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    81
        return vmName.contains("Embedded");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    82
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    83
43394
68ed4de0f9c8 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 42508
diff changeset
    84
    public static boolean isEmulatedClient() {
68ed4de0f9c8 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 42508
diff changeset
    85
        return vmInfo.contains(" emulated-client");
68ed4de0f9c8 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 42508
diff changeset
    86
    }
68ed4de0f9c8 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 42508
diff changeset
    87
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    88
    public static boolean isTieredSupported() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    89
        return compiler.contains("Tiered Compilers");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    90
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    91
35439
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    92
    public static boolean isInt() {
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    93
        return vmInfo.contains("interpreted");
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    94
    }
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    95
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    96
    public static boolean isMixed() {
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    97
        return vmInfo.contains("mixed");
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    98
    }
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
    99
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   100
    public static boolean isComp() {
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   101
        return vmInfo.contains("compiled");
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   102
    }
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   103
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   104
    public static boolean is32bit() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   105
        return dataModel.equals("32");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   106
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   107
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   108
    public static boolean is64bit() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   109
        return dataModel.equals("64");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   110
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   111
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   112
    public static boolean isAix() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   113
        return isOs("aix");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   114
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   115
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   116
    public static boolean isLinux() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   117
        return isOs("linux");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   118
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   119
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   120
    public static boolean isOSX() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   121
        return isOs("mac");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   122
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   123
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   124
    public static boolean isSolaris() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   125
        return isOs("sunos");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   126
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   127
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   128
    public static boolean isWindows() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   129
        return isOs("win");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   130
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   131
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   132
    private static boolean isOs(String osname) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   133
        return osName.toLowerCase().startsWith(osname.toLowerCase());
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   134
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   135
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   136
    public static String getOsName() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   137
        return osName;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   138
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   139
41264
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   140
    // Os version support.
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   141
    private static void init_version() {
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   142
        String[] osVersionTokens = osVersion.split("\\.");
41264
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   143
        try {
49930
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   144
            if (osVersionTokens.length > 0) {
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   145
                osVersionMajor = Integer.parseInt(osVersionTokens[0]);
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   146
                if (osVersionTokens.length > 1) {
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   147
                    osVersionMinor = Integer.parseInt(osVersionTokens[1]);
41264
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   148
                }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   149
            }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   150
        } catch (NumberFormatException e) {
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   151
            osVersionMajor = osVersionMinor = 0;
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   152
        }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   153
    }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   154
49930
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   155
    public static String getOsVersion() {
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   156
        return osVersion;
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   157
    }
3aaaa5370999 8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13
bpb
parents: 48155
diff changeset
   158
41264
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   159
    // Returns major version number from os.version system property.
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   160
    // E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version).
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   161
    public static int getOsVersionMajor() {
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   162
        if (osVersionMajor == -1) init_version();
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   163
        return osVersionMajor;
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   164
    }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   165
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   166
    // Returns minor version number from os.version system property.
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   167
    // E.g. 10 on Solaris 10 and 0 on SLES 11.3 (for the linux kernel version).
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   168
    public static int getOsVersionMinor() {
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   169
        if (osVersionMinor == -1) init_version();
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   170
        return osVersionMinor;
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   171
    }
28502a6422d6 8165235: [TESTBUG] RTM tests must check OS version
goetz
parents: 40614
diff changeset
   172
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   173
    public static boolean isDebugBuild() {
40614
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39949
diff changeset
   174
        return (jdkDebug.toLowerCase().contains("debug"));
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   175
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   176
41041
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   177
    public static boolean isSlowDebugBuild() {
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   178
        return (jdkDebug.toLowerCase().equals("slowdebug"));
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   179
    }
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   180
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   181
    public static boolean isFastDebugBuild() {
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   182
        return (jdkDebug.toLowerCase().equals("fastdebug"));
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   183
    }
9004ed3bcbd8 8165315: [ppc] Port "8133749: NMT detail stack trace cleanup"
goetz
parents: 40614
diff changeset
   184
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   185
    public static String getVMVersion() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   186
        return vmVersion;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   187
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   188
42508
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   189
    public static boolean isAArch64() {
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   190
        return isArch("aarch64");
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   191
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   192
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   193
    public static boolean isARM() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   194
        return isArch("arm.*");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   195
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   196
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   197
    public static boolean isPPC() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   198
        return isArch("ppc.*");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   199
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   200
42508
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   201
    // Returns true for IBM z System running linux.
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   202
    public static boolean isS390x() {
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   203
        return isArch("s390.*") || isArch("s/390.*") || isArch("zArch_64");
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   204
    }
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   205
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   206
    // Returns true for sparc and sparcv9.
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   207
    public static boolean isSparc() {
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   208
        return isArch("sparc.*");
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   209
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   210
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   211
    public static boolean isX64() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   212
        // On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64'
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   213
        return isArch("(amd64)|(x86_64)");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   214
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   215
42508
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   216
    public static boolean isX86() {
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   217
        // On Linux it's 'i386', Windows 'x86' without '_64' suffix.
e63749e2c454 8166837: [TESTBUG] Fix tests on Linux/s390x
goetz
parents: 41265
diff changeset
   218
        return isArch("(i386)|(x86(?!_64))");
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   219
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   220
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   221
    public static String getOsArch() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   222
        return osArch;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   223
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   224
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   225
    /**
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   226
     * Return a boolean for whether SA and jhsdb are ported/available
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   227
     * on this platform.
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   228
     */
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   229
    public static boolean hasSA() {
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   230
        if (isAix()) {
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   231
            return false; // SA not implemented.
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   232
        } else if (isLinux()) {
52590
c6b63df2765f 8213794: ARM32: disable TypeProfiling, CriticalJNINatives, Serviceablity tests for ARM32
bulasevich
parents: 52030
diff changeset
   233
            if (isS390x() || isARM()) {
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   234
                return false; // SA not implemented.
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   235
            }
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   236
        }
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   237
        // Other platforms expected to work:
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   238
        return true;
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   239
    }
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   240
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   241
    /**
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   242
     * Return a boolean for whether we expect to be able to attach
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   243
     * the SA to our own processes on this system.  This requires
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   244
     * that SA is ported/available on this platform.
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   245
     */
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   246
    public static boolean shouldSAAttach() throws IOException {
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   247
        if (!hasSA()) return false;
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 50625
diff changeset
   248
        if (isLinux()) {
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   249
            return canPtraceAttachLinux();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   250
        } else if (isOSX()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   251
            return canAttachOSX();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   252
        } else {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   253
            // Other platforms expected to work:
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   254
            return true;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   255
        }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   256
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   257
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   258
    /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   259
     * On Linux, first check the SELinux boolean "deny_ptrace" and return false
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   260
     * as we expect to be denied if that is "1".  Then expect permission to attach
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   261
     * if we are root, so return true.  Then return false for an expected denial
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   262
     * if "ptrace_scope" is 1, and true otherwise.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   263
     */
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   264
    private static boolean canPtraceAttachLinux() throws IOException {
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   265
        // SELinux deny_ptrace:
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   266
        File deny_ptrace = new File("/sys/fs/selinux/booleans/deny_ptrace");
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   267
        if (deny_ptrace.exists()) {
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   268
            try (RandomAccessFile file = AccessController.doPrivileged(
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   269
                    (PrivilegedExceptionAction<RandomAccessFile>) () -> new RandomAccessFile(deny_ptrace, "r"))) {
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   270
                if (file.readByte() != '0') {
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   271
                    return false;
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   272
                }
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   273
            } catch (PrivilegedActionException e) {
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   274
                @SuppressWarnings("unchecked")
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   275
                IOException t = (IOException) e.getException();
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   276
                throw t;
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   277
            }
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   278
        }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   279
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   280
        // YAMA enhanced security ptrace_scope:
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   281
        // 0 - a process can PTRACE_ATTACH to any other process running under the same uid
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   282
        // 1 - restricted ptrace: a process must be a children of the inferior or user is root
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   283
        // 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   284
        // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   285
        File ptrace_scope = new File("/proc/sys/kernel/yama/ptrace_scope");
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   286
        if (ptrace_scope.exists()) {
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   287
            try (RandomAccessFile file = AccessController.doPrivileged(
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   288
                    (PrivilegedExceptionAction<RandomAccessFile>) () -> new RandomAccessFile(ptrace_scope, "r"))) {
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   289
                byte yama_scope = file.readByte();
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   290
                if (yama_scope == '3') {
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   291
                    return false;
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   292
                }
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   293
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   294
                if (!userName.equals("root") && yama_scope != '0') {
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   295
                    return false;
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   296
                }
51637
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   297
            } catch (PrivilegedActionException e) {
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   298
                @SuppressWarnings("unchecked")
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   299
                IOException t = (IOException) e.getException();
e9177e7749e7 8210039: move OSInfo to top level testlibrary
iignatyev
parents: 50791
diff changeset
   300
                throw t;
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   301
            }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   302
        }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   303
        // Otherwise expect to be permitted:
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   304
        return true;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   305
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   306
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   307
    /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   308
     * On OSX, expect permission to attach only if we are root.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   309
     */
45694
b27907b3cd38 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 45453
diff changeset
   310
    private static boolean canAttachOSX() {
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   311
        return userName.equals("root");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   312
    }
35439
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   313
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   314
    private static boolean isArch(String archnameRE) {
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   315
        return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE)
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   316
                      .matcher(osArch)
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   317
                      .matches();
c82750faebf7 8066599: Add methods to check VM mode to c.o.j.t.Platform
fzhinkin
parents: 34597
diff changeset
   318
    }
46244
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   319
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   320
    /**
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   321
     * Returns file extension of shared library, e.g. "so" on linux, "dll" on windows.
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   322
     * @return file extension
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   323
     */
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   324
    public static String sharedLibraryExt() {
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   325
        if (isWindows()) {
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   326
            return "dll";
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   327
        } else if (isOSX()) {
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   328
            return "dylib";
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   329
        } else {
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   330
            return "so";
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   331
        }
b5e5ec91094d 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 45694
diff changeset
   332
    }
48155
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   333
53273
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   334
    /*
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   335
     * Returns name of system variable containing paths to shared native libraries.
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   336
     */
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   337
    public static String sharedLibraryPathVariableName() {
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   338
        if (isWindows()) {
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   339
            return "PATH";
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   340
        } else if (isOSX()) {
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   341
            return "DYLD_LIBRARY_PATH";
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   342
        } else if (isAix()) {
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   343
            return "LIBPATH";
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   344
        } else {
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   345
            return "LD_LIBRARY_PATH";
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   346
        }
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   347
    }
bbc79e0ec9ee 8216265: [testbug] Introduce Platform.sharedLibraryPathVariableName() and adapt all tests.
goetz
parents: 52590
diff changeset
   348
52030
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   349
    public static boolean isDefaultCDSArchiveSupported() {
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   350
        return (is64bit()  &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   351
                isServer() &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   352
                (isLinux()   ||
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   353
                 isOSX()     ||
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   354
                 isSolaris() ||
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   355
                 isWindows()) &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   356
                !isZero()    &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   357
                !isMinimal() &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   358
                !isAArch64() &&
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   359
                !isARM());
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   360
    }
57862a02bf4b 8202951: Implementation of JEP 341: Default CDS Archives
jiangli
parents: 51659
diff changeset
   361
48155
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   362
    /*
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   363
     * This should match the #if condition in ClassListParser::load_class_from_source().
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   364
     */
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   365
    public static boolean areCustomLoadersSupportedForCDS() {
51659
ca3003390cf0 8185145: AppCDS custom loader support on Mac OS X
ccheung
parents: 51637
diff changeset
   366
        return (is64bit() && (isLinux() || isSolaris() || isOSX()));
48155
551de50b4ff7 8191927: Enable AppCDS for custom loaders on all 64-bit Linux and AIX
iklam
parents: 46244
diff changeset
   367
    }
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   368
}