Navigation Menu

Skip to content

Commit

Permalink
8279351: [TESTBUG] SADebugDTest.java does not handle "Address already…
Browse files Browse the repository at this point in the history
… in use" error

Reviewed-by: cjplummer
  • Loading branch information
YaSuenag committed Jan 4, 2022
1 parent 93c7d90 commit d1e6f26
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, 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
Expand All @@ -23,7 +23,7 @@

/**
* @test
* @bug 8163805 8224252 8196751
* @bug 8163805 8224252 8196751 8279351
* @summary Checks that the jshdb debugd utility successfully starts
* and tries to attach to a running process
* @requires vm.hasSA
Expand Down Expand Up @@ -71,6 +71,16 @@ private static void runTests() throws Exception {
}
}

private static boolean checkOutput(final String line, final boolean useRmiPort, final int rmiPort) {
if (!useRmiPort && line.contains(GOLDEN)) {
testResult = true;
} else if (useRmiPort && line.contains(RMI_CONNECTOR_IS_BOUND + rmiPort)) {
testResult = true;
} else if (line.contains(ADDRESS_ALREADY_IN_USE)) {
portInUse = true;
}
return (line.contains(GOLDEN) || portInUse);
}

private static void testWithPid(final boolean useRmiPort, final boolean useRegistryPort, final boolean useHostName) throws Exception {
LingeredApp app = null;
Expand All @@ -95,9 +105,8 @@ private static void testWithPid(final boolean useRmiPort, final boolean useRegis
jhsdbLauncher.addToolArg(Integer.toString(registryPort));
}

int rmiPort = -1;
final int rmiPort = useRmiPort ? Utils.findUnreservedFreePort(REGISTRY_DEFAULT_PORT, registryPort) : -1;
if (useRmiPort) {
rmiPort = Utils.findUnreservedFreePort(REGISTRY_DEFAULT_PORT, registryPort);
jhsdbLauncher.addToolArg("--rmiport");
jhsdbLauncher.addToolArg(Integer.toString(rmiPort));
}
Expand All @@ -107,28 +116,16 @@ private static void testWithPid(final boolean useRmiPort, final boolean useRegis
}
ProcessBuilder pb = SATestUtils.createProcessBuilder(jhsdbLauncher);

final int finalRmiPort = rmiPort;

// The startProcess will block until the 'golden' string appears in either process' stdout or stderr
// In case of timeout startProcess kills the debugd process
Process debugd = startProcess("debugd", pb, null,
l -> {
if (!useRmiPort && l.contains(GOLDEN)) {
testResult = true;
} else if (useRmiPort && l.contains(RMI_CONNECTOR_IS_BOUND + finalRmiPort)) {
testResult = true;
} else if (l.contains(ADDRESS_ALREADY_IN_USE)) {
portInUse = true;
}
return (l.contains(GOLDEN) || portInUse);
}, 20, TimeUnit.SECONDS);
Process debugd = startProcess("debugd", pb, null, l -> checkOutput(l, useRmiPort, rmiPort), 20, TimeUnit.SECONDS);

// If we are here, this means we have received the golden line and the test has passed
// The debugd remains running, we have to kill it
debugd.destroy();
debugd.waitFor();

if (!testResult) {
if (!testResult && !portInUse) {
throw new RuntimeException("Expected message \"" +
RMI_CONNECTOR_IS_BOUND + rmiPort + "\" is not found in the output.");
}
Expand Down

3 comments on commit d1e6f26

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d1e6f26 Jan 12, 2023

Choose a reason for hiding this comment

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

@MBaesken the backport was successfully created on the branch MBaesken-backport-d1e6f261 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d1e6f261 from the openjdk/jdk repository.

The commit being backported was authored by Yasumasa Suenaga on 4 Jan 2022 and was reviewed by Chris Plummer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-d1e6f261:MBaesken-backport-d1e6f261
$ git checkout MBaesken-backport-d1e6f261
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-d1e6f261

Please sign in to comment.