Path: blob/master/test/jdk/java/lang/System/OsVersionTest.java
41149 views
/*1* Copyright (c) 2015, 2021 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import jdk.test.lib.Platform;24import jdk.test.lib.process.OutputAnalyzer;25import jdk.test.lib.process.ProcessTools;26import jtreg.SkippedException;2728/*29* @test30* @bug 813237431* @summary Check that the value of the os.version property is equal32* to the value of the corresponding OS provided tools.33* @library /test/lib34* @run main OsVersionTest35* @author Volker Simonis36*/37public class OsVersionTest {3839public static void main(String args[]) throws Throwable {40final String osVersion = System.getProperty("os.version");41if (osVersion == null) {42throw new Error("Cant query 'os.version' property!");43}44if (Platform.isLinux()) {45OutputAnalyzer output = ProcessTools.executeProcess("uname", "-r");46if (!osVersion.equals(output.getOutput().trim())) {47throw new Error(osVersion + " != " + output.getOutput().trim());48}49}50else if (Platform.isOSX()) {51OutputAnalyzer output = ProcessTools.executeProcess("sw_vers", "-productVersion");52String swVersOutput = output.getOutput().trim();53if (!osVersion.equals(swVersOutput)) {54// This section can be removed if minimum build SDK is xcode 12+55if (swVersOutput.startsWith(osVersion)) {56throw new SkippedException("MacOS version only matches in parts, this is expected when " +57"JDK was built with Xcode < 12 and MacOS version patch is > 0");58}59throw new Error(osVersion + " != " + swVersOutput);60}61}62else if (Platform.isAix()) {63OutputAnalyzer output1 = ProcessTools.executeProcess("uname", "-v");64OutputAnalyzer output2 = ProcessTools.executeProcess("uname", "-r");65String version = output1.getOutput().trim() + "." + output2.getOutput().trim();66if (!osVersion.equals(version)) {67throw new Error(osVersion + " != " + version);68}69}70else if (Platform.isWindows()) {71OutputAnalyzer output = ProcessTools.executeProcess("cmd", "/c", "ver");72String version = output.firstMatch(".+\\[Version ([0-9.]+)\\]", 1);73if (version == null || !version.startsWith(osVersion)) {74throw new Error(osVersion + " != " + version);75}76}77else {78System.out.println("This test is currently not supported on " +79Platform.getOsName());80}81}82}838485