test/jdk/java/lang/System/OsVersionTest.java
author jlaskey
Fri, 18 May 2018 08:43:49 -0300
changeset 50175 589ed2770141
parent 47216 71c04702a3d5
child 51675 b487c1e914d0
permissions -rw-r--r--
8200436: String::isBlank Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31875
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     1
/*
35775
00710c1b504a 8149529: Adapt SAP copyrights to new company name in jdk repository
goetz
parents: 31875
diff changeset
     2
 * Copyright (c) 2015 SAP SE. All rights reserved.
31875
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     4
 *
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     8
 *
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    13
 * accompanied this code).
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    14
 *
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    18
 *
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    21
 * questions.
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    22
 */
45709
841996818446 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 35775
diff changeset
    23
841996818446 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 35775
diff changeset
    24
import jdk.test.lib.Platform;
31875
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    25
import jdk.testlibrary.OutputAnalyzer;
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    26
import jdk.testlibrary.ProcessTools;
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    27
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    28
/*
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    29
 * @test
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    30
 * @bug 8132374
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    31
 * @summary Check that the value of the os.version property is equal
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    32
 *          to the value of the corresponding OS provided tools.
45709
841996818446 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 35775
diff changeset
    33
 * @library /lib/testlibrary /test/lib
841996818446 8182154: merge jdk.testlibrary.Platform and jdk.test.lib.Platform
iignatyev
parents: 35775
diff changeset
    34
 * @build jdk.test.lib.Platform
31875
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    35
 * @run main OsVersionTest
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    36
 * @author Volker Simonis
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    37
 */
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    38
public class OsVersionTest {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    39
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    40
    public static void main(String args[]) throws Throwable {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    41
        final String osVersion = System.getProperty("os.version");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    42
        if (osVersion == null) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    43
            throw new Error("Cant query 'os.version' property!");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    44
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    45
        if (Platform.isLinux() || Platform.isSolaris()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    46
            OutputAnalyzer output = ProcessTools.executeProcess("uname", "-r");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    47
            if (!osVersion.equals(output.getOutput().trim())) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    48
                throw new Error(osVersion + " != " + output.getOutput().trim());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    49
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    50
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    51
        else if (Platform.isOSX()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    52
            OutputAnalyzer output = ProcessTools.executeProcess("sw_vers", "-productVersion");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    53
            if (!osVersion.equals(output.getOutput().trim())) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    54
                throw new Error(osVersion + " != " + output.getOutput().trim());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    55
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    56
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    57
        else if (Platform.isAix()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    58
            OutputAnalyzer output1 = ProcessTools.executeProcess("uname", "-v");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    59
            OutputAnalyzer output2 = ProcessTools.executeProcess("uname", "-r");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    60
            String version = output1.getOutput().trim() + "." + output2.getOutput().trim();
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    61
            if (!osVersion.equals(version)) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    62
                throw new Error(osVersion + " != " + version);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    63
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    64
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    65
        else if (Platform.isWindows()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    66
            OutputAnalyzer output = ProcessTools.executeProcess("cmd", "/c", "ver");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    67
            String version = output.firstMatch(".+\\[Version ([0-9.]+)\\]", 1);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    68
            if (version == null || !version.startsWith(osVersion)) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    69
                throw new Error(osVersion + " != " + version);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    70
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    71
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    72
        else {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    73
            System.out.println("This test is currently not supported on " +
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    74
                               Platform.getOsName());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    75
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    76
    }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    77
}