< prev index next >
test/java/lang/ProcessHandle/InfoTest.java
Print this page
rev 12414 : 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
*** 134,144 ****
childCpuTime = Duration.ofNanos(nanos);
break; // found the result we're looking for
}
}
!
ProcessHandle.Info info = p1.info();
System.out.printf(" info: %s%n", info);
if (info.user().isPresent()) {
String user = info.user().get();
--- 134,153 ----
childCpuTime = Duration.ofNanos(nanos);
break; // found the result we're looking for
}
}
! if (Platform.isAix()) {
! // Unfortunately, on AIX the usr/sys times reported through
! // /proc/<pid>/status which are used by ProcessHandle.Info
! // are running slow compared to the corresponding times reported
! // by the times()/getrusage() system calls which are used by
! // OperatingSystemMXBean.getProcessCpuTime() and returned by
! // the JavaChild for the "cputime" command.
! // So we better wait a little bit to get plausible values here.
! Thread.sleep(1000);
! }
ProcessHandle.Info info = p1.info();
System.out.printf(" info: %s%n", info);
if (info.user().isPresent()) {
String user = info.user().get();
*** 164,179 ****
int offset = args.length - extraArgs.length;
for (int i = 0; i < extraArgs.length; i++) {
Assert.assertEquals(args[offset + i], extraArgs[i],
"Actual argument mismatch, index: " + i);
}
- } else if (Platform.isSolaris()) {
- Assert.assertEquals(args.length, 1,
- "Expected argument list length: 1");
- Assert.assertNotNull(args[0],
- "Expected an argument");
} else {
System.out.printf("No argument test for OS: %s%n", Platform.getOsName());
}
// Now check that the first argument is not the same as the executed command
if (args.length > 0) {
--- 173,186 ----
int offset = args.length - extraArgs.length;
for (int i = 0; i < extraArgs.length; i++) {
Assert.assertEquals(args[offset + i], extraArgs[i],
"Actual argument mismatch, index: " + i);
}
} else {
+ // Arguments on Solaris and AIX come from /proc/pid/psinfo and
+ // are usually truncated to 80 characters so there's not much
+ // we can check here.
System.out.printf("No argument test for OS: %s%n", Platform.getOsName());
}
// Now check that the first argument is not the same as the executed command
if (args.length > 0) {
*** 240,253 ****
--- 247,264 ----
String expected = Platform.isWindows() ? "sleep.exe" : "sleep";
Assert.assertTrue(command.endsWith(expected), "Command: expected: \'" +
expected + "\', actual: " + command);
// Verify the command exists and is executable
+ if (!Platform.isAix()) {
+ // On Aix, Info.command() only returns arg[0] as command which
+ // doesn't necessarily contains the full path to the executable.
File exe = new File(command);
Assert.assertTrue(exe.exists(), "command must exist: " + exe);
Assert.assertTrue(exe.canExecute(), "command must be executable: " + exe);
}
+ }
if (info.arguments().isPresent()) {
String[] args = info.arguments().get();
if (args.length > 0) {
Assert.assertEquals(args[0], String.valueOf(sleepTime));
}
*** 267,280 ****
--- 278,308 ----
*/
@Test
public static void test4() {
Duration myCputime1 = ProcessUtil.MXBeanCpuTime();
+ if (Platform.isAix()) {
+ // Unfortunately, on AIX the usr/sys times reported through
+ // /proc/<pid>/status which are used by ProcessHandle.Info
+ // are running slow compared to the corresponding times reported
+ // by the times()/getrusage() system calls which are used by
+ // OperatingSystemMXBean.getProcessCpuTime() and returned by
+ // the JavaChild for the "cputime" command.
+ // So we better wait a little bit to get plausible values here.
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {}
+ }
Optional<Duration> dur1 = ProcessHandle.current().info().totalCpuDuration();
Duration myCputime2 = ProcessUtil.MXBeanCpuTime();
+ if (Platform.isAix()) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {}
+ }
Optional<Duration> dur2 = ProcessHandle.current().info().totalCpuDuration();
if (dur1.isPresent() && dur2.isPresent()) {
Duration total1 = dur1.get();
Duration total2 = dur2.get();
< prev index next >