Skip to content

Commit

Permalink
Merge pull request #1957 from Ailloviee/getPidFix_v4
Browse files Browse the repository at this point in the history
Fix getPid failure in Windows
  • Loading branch information
llxia committed Jul 6, 2018
2 parents 9cf8de6 + 5a130ae commit 00d5b19
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
22 changes: 12 additions & 10 deletions test/TestConfig/settings.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ endif
export JVM_VERSION:=$(JVM_VERSION)
endif

ifneq (,$(findstring win,$(SPEC)))
P=;
D=\\
EXECUTABLE_SUFFIX=.exe
RUN_SCRIPT="cmd /c"
RUN_SCRIPT_STRING=$(RUN_SCRIPT)
SCRIPT_SUFFIX=.bat
PROPS_DIR=props_win
endif

# Environment variable OSTYPE is set to cygwin if running under cygwin.
ifndef CYGWIN
OSTYPE?=$(shell echo $$OSTYPE)
Expand All @@ -110,6 +100,18 @@ ifndef CYGWIN
endif
endif

ifneq (,$(findstring win,$(SPEC)))
P=;
ifneq ($(CYGWIN),1)
D=\\
endif
EXECUTABLE_SUFFIX=.exe
RUN_SCRIPT="cmd /c"
RUN_SCRIPT_STRING=$(RUN_SCRIPT)
SCRIPT_SUFFIX=.bat
PROPS_DIR=props_win
endif

ifeq ($(CYGWIN),1)
TEST_ROOT := $(shell cygpath -w $(TEST_ROOT))
endif
Expand Down
30 changes: 0 additions & 30 deletions test/functional/cmdLineTests/runtimemxbeanTests/exclude.xml

This file was deleted.

25 changes: 23 additions & 2 deletions test/functional/cmdLineTests/runtimemxbeanTests/getPidTest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,30 @@

my ($in, $out, $err);

my $perlPid = open3($in, $out, $err, $javaCmd);
my $perlPid;

my $javaPid = <$out>;
my $javaPid;

if ($^O eq 'cygwin') {
open3($in, $out, $err, $javaCmd);
$javaPid = <$out>;
# Command gets the list of PIDs of the Java processes system is running
$perlPid = `wmic process where "name='java.exe'" get ProcessID`;
print $in "getPid finished";
# String trim both sides of javaPid and perlPid for the index check
$javaPid =~ s/^\s+|\s+$//g;
$perlPid =~ s/^\s+|\s+$//g;
# After trimming, check if javaPid is in the list of PIDs system returns
# index() would return an index if it is in the list, return -1 otherwise
# (PASS if not -1)
if (index($perlPid, $javaPid) != -1) {
$perlPid = $javaPid;
}
} else {
$perlPid = open3($in, $out, $err, $javaCmd);
$javaPid = <$out>;
print $in "getPid finished";
}

if ($perlPid == $javaPid) {
print "PASS: RuntimeMXBean.getPid() returned correct PID.";
Expand Down
5 changes: 2 additions & 3 deletions test/functional/cmdLineTests/runtimemxbeanTests/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
<variations>
<variation>NoOptions</variation>
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) -DEXE='$(JAVA_COMMAND) $(JVM_OPTIONS)' -DTESTSJARPATH=$(Q)$(TEST_RESROOT)$(D)runtimemxbeanTests.jar$(Q) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)getPidTest.xml$(Q) \
-explainExcludes -xids all,$(PLATFORM),$(VARIATION) -xlist $(Q)$(TEST_RESROOT)$(D)exclude.xml$(Q) -nonZeroExitWhenError; \
$(TEST_STATUS)</command>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -DTESTDIR=$(Q)$(TEST_RESROOT)$(Q) -DRESJAR=$(CMDLINETESTER_RESJAR) -DEXE='$(JAVA_COMMAND) $(JVM_OPTIONS)' -DTESTSJARPATH=$(Q)$(TEST_RESROOT)$(D)runtimemxbeanTests.jar$(Q) -jar $(CMDLINETESTER_JAR) -config $(Q)$(TEST_RESROOT)$(D)getPidTest.xml$(Q) -explainExcludes -nonZeroExitWhenError; \
$(TEST_STATUS)</command>
<levels>
<level>sanity</level>
</levels>
Expand Down
19 changes: 13 additions & 6 deletions test/functional/cmdLineTests/runtimemxbeanTests/src/GetPid.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp. and others
*
Expand All @@ -24,11 +25,17 @@
import java.lang.management.ManagementFactory;

class GetPid {

public static void main(String[] args) {
RuntimeMXBean mb = ManagementFactory.getRuntimeMXBean();
long id = mb.getPid();
System.out.println(id);
public static void main(String args[]) {
RuntimeMXBean mb = ManagementFactory.getRuntimeMXBean();
long id = mb.getPid();
System.out.println(id);
try {
/*
* Puts Java process on hold until system receives input from
* testing script getPidTest.pl
*/
System.in.read();
} catch (Exception e) {
}
}

}

0 comments on commit 00d5b19

Please sign in to comment.