jdk/test/java/lang/System/OsVersionTest.java
author goetz
Wed, 27 Jan 2016 10:35:49 +0100
changeset 35775 00710c1b504a
parent 31875 dc0feb520d54
child 45709 841996818446
permissions -rw-r--r--
8149529: Adapt SAP copyrights to new company name in jdk repository Reviewed-by: simonis, chegar
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
 */
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    23
import jdk.testlibrary.OutputAnalyzer;
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    24
import jdk.testlibrary.Platform;
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    25
import jdk.testlibrary.ProcessTools;
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    26
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
 * @test
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    29
 * @bug 8132374
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    30
 * @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
    31
 *          to the value of the corresponding OS provided tools.
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    32
 * @library /lib/testlibrary
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    33
 * @run main OsVersionTest
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    34
 * @author Volker Simonis
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    35
 */
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    36
public class OsVersionTest {
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 static void main(String args[]) throws Throwable {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    39
        final String osVersion = System.getProperty("os.version");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    40
        if (osVersion == null) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    41
            throw new Error("Cant query 'os.version' property!");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    42
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    43
        if (Platform.isLinux() || Platform.isSolaris()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    44
            OutputAnalyzer output = ProcessTools.executeProcess("uname", "-r");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    45
            if (!osVersion.equals(output.getOutput().trim())) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    46
                throw new Error(osVersion + " != " + output.getOutput().trim());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    47
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    48
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    49
        else if (Platform.isOSX()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    50
            OutputAnalyzer output = ProcessTools.executeProcess("sw_vers", "-productVersion");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    51
            if (!osVersion.equals(output.getOutput().trim())) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    52
                throw new Error(osVersion + " != " + output.getOutput().trim());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    53
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    54
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    55
        else if (Platform.isAix()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    56
            OutputAnalyzer output1 = ProcessTools.executeProcess("uname", "-v");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    57
            OutputAnalyzer output2 = ProcessTools.executeProcess("uname", "-r");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    58
            String version = output1.getOutput().trim() + "." + output2.getOutput().trim();
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    59
            if (!osVersion.equals(version)) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    60
                throw new Error(osVersion + " != " + version);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    61
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    62
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    63
        else if (Platform.isWindows()) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    64
            OutputAnalyzer output = ProcessTools.executeProcess("cmd", "/c", "ver");
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    65
            String version = output.firstMatch(".+\\[Version ([0-9.]+)\\]", 1);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    66
            if (version == null || !version.startsWith(osVersion)) {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    67
                throw new Error(osVersion + " != " + version);
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    68
            }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    69
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    70
        else {
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    71
            System.out.println("This test is currently not supported on " +
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    72
                               Platform.getOsName());
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    73
        }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    74
    }
dc0feb520d54 8132374: AIX: fix value of os.version property
simonis
parents:
diff changeset
    75
}