8210039: move OSInfo to top level testlibrary · openjdk/jdk11u-dev@c94ce2c (original) (raw)

1

1

`/*

`

2

``

`-

`

``

2

`+

`

3

3

` * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

`

4

4

` *

`

5

5

` * This code is free software; you can redistribute it and/or modify it

`

29

29

` * @author Jaroslav Bachorik

`

30

30

` *

`

31

31

` * @library /lib/testlibrary

`

``

32

`+

`

32

33

` *

`

33

34

` * @build TestTotalSwap jdk.testlibrary.*

`

34

35

` * @run main TestTotalSwap

`

`@@ -55,7 +56,7 @@

`

55

56

`import com.sun.management.OperatingSystemMXBean;

`

56

57

`import java.lang.management.*;

`

57

58

``

58

``

`-

import jdk.testlibrary.OSInfo;

`

``

59

`+

import jdk.test.lib.Platform;

`

59

60

`import jdk.testlibrary.ProcessTools;

`

60

61

`import jdk.testlibrary.OutputAnalyzer;

`

61

62

``

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

`

110

111

` }

`

111

112

``

112

113

`private static long getSwapSizeFromOs() throws Throwable {

`

113

``

`-

OSInfo.OSType os = OSInfo.getOSType();

`

114

``

-

115

``

`-

switch (os) {

`

``

114

`+

if (Platform.isLinux()) {

`

116

115

`// total used free shared buffers cached

`

117

116

`// Mem: 16533540864 13638467584 2895073280 534040576 1630248960 6236909568

`

118

117

`// -/+ buffers/cache: 5771309056 10762231808

`

119

118

`// Swap: 15999168512 0 15999168512

`

120

``

-

121

``

`-

case LINUX: {

`

122

``

`-

String swapSizeStr = ProcessTools.executeCommand("free", "-b")

`

123

``

`-

.firstMatch("Swap:\s+([0-9]+)\s+.*", 1);

`

124

``

`-

return Long.parseLong(swapSizeStr);

`

125

``

`-

}

`

126

``

`-

case SOLARIS: {

`

127

``

`-

// swapfile dev swaplo blocks free

`

128

``

`-

// /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528

`

129

``

`-

OutputAnalyzer out= ProcessTools.executeCommand(

`

``

119

`+

String swapSizeStr = ProcessTools.executeCommand("free", "-b")

`

``

120

`+

.firstMatch("Swap:\s+([0-9]+)\s+.*", 1);

`

``

121

`+

return Long.parseLong(swapSizeStr);

`

``

122

`+

} else if (Platform.isSolaris()) {

`

``

123

`+

// swapfile dev swaplo blocks free

`

``

124

`+

// /dev/dsk/c0t0d0s1 136,1 16 1638608 1600528

`

``

125

`+

OutputAnalyzer out= ProcessTools.executeCommand(

`

130

126

`"/usr/sbin/swap",

`

131

127

`"-l"

`

132

``

`-

);

`

``

128

`+

);

`

133

129

``

134

``

`-

long swapSize = 0;

`

``

130

`+

long swapSize = 0;

`

135

131

``

136

``

`-

for (String line : out.asLines()) {

`

137

``

`-

if (line.contains("swapfile")) continue;

`

``

132

`+

for (String line : out.asLines()) {

`

``

133

`+

if (line.contains("swapfile")) continue;

`

138

134

``

139

``

`-

String[] vals = line.split("\s+");

`

140

``

`-

if (vals.length == 5) {

`

141

``

`-

swapSize += Long.parseLong(vals[3]) * 512; // size is reported in 512b blocks

`

142

``

`-

}

`

``

135

`+

String[] vals = line.split("\s+");

`

``

136

`+

if (vals.length == 5) {

`

``

137

`+

swapSize += Long.parseLong(vals[3]) * 512; // size is reported in 512b blocks

`

143

138

` }

`

144

``

-

145

``

`-

return swapSize;

`

146

139

` }

`

147

``

`-

case MACOSX: {

`

148

``

`-

// total = 8192.00M used = 7471.11M free = 720.89M (encrypted)

`

149

``

`-

String swapSizeStr = ProcessTools.executeCommand(

`

``

140

+

``

141

`+

return swapSize;

`

``

142

`+

} else if (Platform.isOSX()) {

`

``

143

`+

// total = 8192.00M used = 7471.11M free = 720.89M (encrypted)

`

``

144

`+

String swapSizeStr = ProcessTools.executeCommand(

`

150

145

`"/usr/sbin/sysctl",

`

151

146

`"-n",

`

152

147

`"vm.swapusage"

`

153

``

`-

).firstMatch("total\s+=\s+([0-9]+(\.[0-9]+)?[Mm]?).*", 1);

`

154

``

`-

if (swapSizeStr.toLowerCase().endsWith("m")) {

`

155

``

`-

swapSizeStr = swapSizeStr.substring(0, swapSizeStr.length() - 1);

`

156

``

`-

return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024); // size in MB

`

157

``

`-

}

`

158

``

`-

return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024);

`

159

``

`-

}

`

160

``

`-

default: {

`

161

``

`-

System.err.println("Unsupported operating system: " + os);

`

``

148

`+

).firstMatch("total\s+=\s+([0-9]+(\.[0-9]+)?[Mm]?).*", 1);

`

``

149

`+

if (swapSizeStr.toLowerCase().endsWith("m")) {

`

``

150

`+

swapSizeStr = swapSizeStr.substring(0, swapSizeStr.length() - 1);

`

``

151

`+

return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024); // size in MB

`

162

152

` }

`

``

153

`+

return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024);

`

``

154

`+

} else {

`

``

155

`+

System.err.println("Unsupported operating system: " + Platform.getOsName());

`

163

156

` }

`

164

157

``

165

158

`return -1;

`