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