Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix procdump #89

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stf.build/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ test.SampleEchoFile:
$(STF_COMMAND) -test=SampleEchoFile
test.SampleJUnitTestRun:
$(STF_COMMAND) -test=SampleJUnitTestRun
# test.SampleOverrunProcess is expected to fail, so ignore
test.SampleOverrunProcess:
- $(STF_COMMAND) -test=SampleOverrunProcess
test.SampleRunJDKTool:
$(STF_COMMAND) -test=SampleRunJDKTool
test.SampleRunJmod:
Expand Down
13 changes: 11 additions & 2 deletions stf.core/scripts/stf/ProcessMgmt/Windows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use Time::Local;

use stf::ProcessMgmt::Result;

use Config;

#Function prototypes
sub _open_file;

Expand Down Expand Up @@ -281,9 +283,16 @@ sub start {
open (STDOUT, '>>&STDOUT_OLD');
open (STDERR, '>>&STDERR_OLD');


if ($result) {
my ( $handle, $pid ) = unpack "Lx4L", $ProcessInformation;

my $handle;
my $pid;
if($Config{ptrsize} == 8) {
( $handle, $pid ) = unpack "Qx8L", $ProcessInformation;
}
else {
( $handle, $pid ) = unpack "Lx4L", $ProcessInformation;
}

$self->{handle} = $handle;
$self->{pid} = $pid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

package net.adoptopenjdk.stf.processManagement;

import static net.adoptopenjdk.stf.extensions.core.StfCoreExtension.Echo.ECHO_ON;

import net.adoptopenjdk.stf.extensions.core.StfCoreExtension;
import net.adoptopenjdk.stf.plugin.interfaces.StfPluginInterface;
import net.adoptopenjdk.stf.processManagement.apps.MiniClient;
import net.adoptopenjdk.stf.processes.ExpectedOutcome;
import net.adoptopenjdk.stf.runner.modes.HelpTextGenerator;


/**
* This sample test shows the synchronous running of a Java process.
* When executed STF will:
* - start the processes
* - monitor the process for core and java dumps.
* - fail the test if the process runs for longer than the expected run time.
* - kill the process if a test failure is detected.
*
* This is the most basic scenario covered by the STF process control methods.
*/
public class SampleOverrunProcess implements StfPluginInterface {
public void help(HelpTextGenerator help) throws Exception {
help.outputSection("SampleRunProcess");
help.outputText("This test demonstrates the synchronous running of processes.");
}

public void pluginInit(StfCoreExtension stf) throws Exception {
}

public void setUp(StfCoreExtension test) throws Exception {
}

public void execute(StfCoreExtension test) throws Exception {
// Runs a java process with two arguments.
// The first argument tells MiniClient to exit with a zero exit code.
// The second argument tells MiniClient to sleep for 3 minutes.
// doRunForegroundProcess is set to expect the process to finish within 10 seconds, which it will not
// because it is sleeping for 3 minutes.
// STF will then take core dumps of the running process three times at thirty second intervals before killing it.
// This sample can therefore be used to test the hang detection and core dumping capability of STF.
// Run via 'make test.sampleOverrunProcess'.
test.doRunForegroundProcess("Run client", "CL", ECHO_ON, ExpectedOutcome.exitValue(0).within("10s"),
test.createJavaProcessDefinition()
.addProjectToClasspath("stf.samples")
.runClass(MiniClient.class)
.addArg("0")
.addArg("180000")); // 180 secs in milliseconds
}

public void tearDown(StfCoreExtension stf) throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,33 @@ public class MiniClient {

public static void main(String[] args) {
log("Client started");
long sleepTime = 2500L;
if (args.length > 1) {
// Sleep for the supplied value
sleepTime = Long.parseLong(args[1]);
log("Client sleeping for " + sleepTime + " milliseconds");
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
log("Client interrupted");
e.printStackTrace();
}
}
if (args.length > 0) {
// Exit the client using the supplied exit value
int exitValue = Integer.parseInt(args[0]);
log("Client exiting with value of " + exitValue);
System.exit(exitValue);
}

try {
Thread.sleep(2500);
} catch (InterruptedException e) {
log("Client interrupted");
e.printStackTrace();
// If no arguments were supplied just exit after a short interval.
if (args.length == 0) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
log("Client interrupted");
e.printStackTrace();
}
}

log("Client completed normally");
Expand Down