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

Backport-of: d1e6f26160e811b8d6f44108899422a62c0be388
  • Loading branch information
MBaesken committed Jan 16, 2023
1 parent 1032a0f commit e490cad
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

1 comment on commit e490cad

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.