Skip to content
Permalink
Browse files
8210039: move OSInfo to top level testlibrary
Reviewed-by: mdoerr
Backport-of: 315e71f
  • Loading branch information
GoeLin committed Mar 14, 2022
1 parent 5f40afc commit c94ce2cce4414bc693a543c686a47c9c66a41e7d
Show file tree
Hide file tree
Showing 78 changed files with 615 additions and 721 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,7 @@
import javax.crypto.*;
import javax.crypto.spec.*;

import jdk.test.lib.OSVersion;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;

@@ -376,9 +377,6 @@ private static boolean checkKeys(Key k1, Key k2) {

// The cases on CFB128 mode have to be skipped on pre-S11.3.
private static boolean isBadSolaris() {
return Platform.isSolaris()
&& Platform.getOsVersionMajor() <= 5
&& Platform.getOsVersionMinor() <= 11
&& Utils.distro().compareTo("11.3") < 0;
return Platform.isSolaris() && OSVersion.current().compareTo(new OSVersion(11, 3)) < 0;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
* @author Jaroslav Bachorik
*
* @library /lib/testlibrary
* @library /test/lib
*
* @build TestTotalSwap jdk.testlibrary.*
* @run main TestTotalSwap
@@ -55,7 +56,7 @@
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.*;

import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;
import jdk.testlibrary.ProcessTools;
import jdk.testlibrary.OutputAnalyzer;

@@ -110,56 +111,48 @@ public static void main(String args[]) throws Throwable {
}

private static long getSwapSizeFromOs() throws Throwable {
OSInfo.OSType os = OSInfo.getOSType();

switch (os) {
if (Platform.isLinux()) {
// total used free shared buffers cached
// Mem: 16533540864 13638467584 2895073280 534040576 1630248960 6236909568
// -/+ buffers/cache: 5771309056 10762231808
// Swap: 15999168512 0 15999168512

case LINUX: {
String swapSizeStr = ProcessTools.executeCommand("free", "-b")
.firstMatch("Swap:\\s+([0-9]+)\\s+.*", 1);
return Long.parseLong(swapSizeStr);
}
case SOLARIS: {
// swapfile dev swaplo blocks free
// /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528
OutputAnalyzer out= ProcessTools.executeCommand(
String swapSizeStr = ProcessTools.executeCommand("free", "-b")
.firstMatch("Swap:\\s+([0-9]+)\\s+.*", 1);
return Long.parseLong(swapSizeStr);
} else if (Platform.isSolaris()) {
// swapfile dev swaplo blocks free
// /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528
OutputAnalyzer out= ProcessTools.executeCommand(
"/usr/sbin/swap",
"-l"
);
);

long swapSize = 0;
long swapSize = 0;

for (String line : out.asLines()) {
if (line.contains("swapfile")) continue;
for (String line : out.asLines()) {
if (line.contains("swapfile")) continue;

String[] vals = line.split("\\s+");
if (vals.length == 5) {
swapSize += Long.parseLong(vals[3]) * 512; // size is reported in 512b blocks
}
String[] vals = line.split("\\s+");
if (vals.length == 5) {
swapSize += Long.parseLong(vals[3]) * 512; // size is reported in 512b blocks
}

return swapSize;
}
case MACOSX: {
// total = 8192.00M used = 7471.11M free = 720.89M (encrypted)
String swapSizeStr = ProcessTools.executeCommand(

return swapSize;
} else if (Platform.isOSX()) {
// total = 8192.00M used = 7471.11M free = 720.89M (encrypted)
String swapSizeStr = ProcessTools.executeCommand(
"/usr/sbin/sysctl",
"-n",
"vm.swapusage"
).firstMatch("total\\s+=\\s+([0-9]+(\\.[0-9]+)?[Mm]?).*", 1);
if (swapSizeStr.toLowerCase().endsWith("m")) {
swapSizeStr = swapSizeStr.substring(0, swapSizeStr.length() - 1);
return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024); // size in MB
}
return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024);
}
default: {
System.err.println("Unsupported operating system: " + os);
).firstMatch("total\\s+=\\s+([0-9]+(\\.[0-9]+)?[Mm]?).*", 1);
if (swapSizeStr.toLowerCase().endsWith("m")) {
swapSizeStr = swapSizeStr.substring(0, swapSizeStr.length() - 1);
return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024); // size in MB
}
return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024);
} else {
System.err.println("Unsupported operating system: " + Platform.getOsName());
}

return -1;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,15 +28,15 @@
@summary awt Choice doesn't fire ItemStateChange when selecting item after select() call
@author Oleg Pekhovskiy: area=awt-choice
@library ../../regtesthelpers
@library ../../../../lib/testlibrary
@library /test/lib
@modules java.desktop/sun.awt
@build Util
@build jdk.testlibrary.OSInfo
@build jdk.test.lib.Platform
@run main ItemStateChangeTest
*/

import jdk.test.lib.Platform;
import test.java.awt.regtesthelpers.Util;
import jdk.testlibrary.OSInfo;

import java.awt.*;
import java.awt.event.*;
@@ -51,7 +51,7 @@ public static void main(String args[]) {

public ItemStateChangeTest() {

if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
if (!Platform.isWindows()) {
return;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,15 +26,15 @@
@bug 6399679
@summary Choice is not invalidated when the frame gets resized programmatically when the drop-down is visible
@author andrei.dmitriev area=awt.choice
@library ../../../../lib/testlibrary
@build jdk.testlibrary.OSInfo
@library /test/lib
@build jdk.test.lib.Platform
@run main ResizeAutoClosesChoice
*/

import java.awt.*;
import java.awt.event.*;

import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;

public class ResizeAutoClosesChoice
{
@@ -46,7 +46,7 @@
static Button button = new Button("This button causes Frame to be resized on pack()");
public static void main(String args[]) throws Exception
{
if(OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {
if (Platform.isOSX()) {
System.out.println("Not for OS OX");
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,16 +34,17 @@
import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.BufferedImage;
import javax.swing.JApplet;
import jdk.testlibrary.OSInfo;

import jdk.test.lib.Platform;

/**
* @test
* @bug 8028212
* @summary [macosx] Custom Cursor HiDPI support
* @author Alexander Scherbatiy
* @library ../../../../lib/testlibrary
* @library /test/lib
* @modules java.desktop/sun.awt.image
* @build jdk.testlibrary.OSInfo
* @build jdk.test.lib.Platform
* @run applet/manual=yesno MultiResolutionCursorTest.html
*/
public class MultiResolutionCursorTest extends JApplet {
@@ -58,7 +59,7 @@ public void init() {
// etc.
this.setLayout(new BorderLayout());

if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {
if (Platform.isOSX()) {
String[] instructions = {
"Verify that high resolution custom cursor is used"
+ " on HiDPI displays.",
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,24 +27,25 @@
* @requires (os.family == "windows")
* @summary Incorrect Exception message from java.awt.Desktop.open()
* @author Dmitry Markov
* @library ../../../../lib/testlibrary
* @library /test/lib
* @modules java.desktop/sun.awt
* @build jdk.testlibrary.OSInfo
* @build jdk.test.lib.Platform
* @run main bug8064934
*/
import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;

public class bug8064934 {
private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" +
" the specified file for this operation.";

public static void main(String[] args) {
// This test is intended only for Windows
if (AccessController.doPrivileged(OSInfo.getOSTypeAction()) != OSInfo.OSType.WINDOWS) {
if (!AccessController.doPrivileged((PrivilegedAction<Boolean>) Platform::isWindows)) {
System.out.println("The test is for Windows platform only");
return;
}
@@ -26,21 +26,22 @@
@bug 8003399
@summary JFileChooser gives wrong path to selected file when saving to Libraries folder on Windows 7
@author Semyon Sadetsky
@library /lib/testlibrary
@build jdk.testlibrary.OSInfo
@library /test/lib
@build jdk.test.lib.OSVersion jdk.test.lib.Platform
@run main bug8003399
*/

import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;
import jdk.test.lib.OSVersion;

import javax.swing.filechooser.FileSystemView;
import java.io.File;

public class bug8003399 {

public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) > 0 ) {
if (Platform.isWindows() &&
OSVersion.current().compareTo(OSVersion.WINDOWS_VISTA) > 0 ) {
FileSystemView fsv = FileSystemView.getFileSystemView();
for (File file : fsv.getFiles(fsv.getHomeDirectory(), false)) {
if(file.isDirectory()) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,13 +27,14 @@
@summary filechooser in Windows-Libraries folder: columns are mixed up
@author Semyon Sadetsky
@modules java.desktop/sun.awt.shell
@library /lib/testlibrary
@build jdk.testlibrary.OSInfo
@library /test/lib
@build jdk.test.lib.OSVersion jdk.test.lib.Platform
@run main bug8017487
*/


import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;
import jdk.test.lib.OSVersion;

import sun.awt.shell.ShellFolder;
import sun.awt.shell.ShellFolderColumnInfo;
@@ -43,8 +44,8 @@
public class bug8017487
{
public static void main(String[] p_args) throws Exception {
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) > 0 ) {
if (Platform.isWindows() &&
OSVersion.current().compareTo(OSVersion.WINDOWS_VISTA) > 0 ) {
test();
System.out.println("ok");
}
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
@@ -28,9 +28,9 @@
@summary We should support "apple.awt.fileDialogForDirectories" property.
@author Sergey Bylokhov area=awt.filedialog
@library ../../regtesthelpers
@library ../../../../lib/testlibrary
@library /test/lib
@build Sysout
@build jdk.testlibrary.OSInfo
@build jdk.test.lib.Platform
@run applet/manual=yesno FileDialogForDirectories.html
-->
<head>
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
*/


import jdk.testlibrary.OSInfo;
import jdk.test.lib.Platform;
import test.java.awt.regtesthelpers.Sysout;

import java.applet.Applet;
@@ -39,7 +39,7 @@ public class FileDialogForDirectories extends Applet implements ActionListener {

@Override
public void init() {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
if (!Platform.isOSX()) {
Sysout.createDialogWithInstructions(new String[]{
"Press PASS, this test is for MacOS X only."});
return;

1 comment on commit c94ce2c

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on c94ce2c Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.