Skip to content

Commit

Permalink
8314614: jdk/jshell/ImportTest.java failed with "InternalError: Faile…
Browse files Browse the repository at this point in the history
…d remote listen"

8312140: jdk/jshell tests failed with JDI socket timeouts

Reviewed-by: asotona
  • Loading branch information
lahodaj committed Nov 23, 2023
1 parent 864b39a commit 14193a0
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 40 deletions.
1 change: 1 addition & 0 deletions test/langtools/jdk/jshell/AnalyzeSnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void setUp() {
state = JShell.builder()
.out(new PrintStream(new ByteArrayOutputStream()))
.err(new PrintStream(new ByteArrayOutputStream()))
.executionEngine(Presets.TEST_DEFAULT_EXECUTION)
.build();
sca = state.sourceCodeAnalysis();
}
Expand Down
3 changes: 2 additions & 1 deletion test/langtools/jdk/jshell/CustomInputToolBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private void doTest(boolean interactiveTerminal, String code, String... expected
.interactiveTerminal(interactiveTerminal)
.promptCapture(true)
.persistence(new HashMap<>())
.start("--no-startup");
.start("--no-startup",
"--execution", Presets.TEST_DEFAULT_EXECUTION);

String actual = new String(out.toByteArray());
List<String> actualLines = Arrays.asList(actual.split("\\R"));
Expand Down
20 changes: 3 additions & 17 deletions test/langtools/jdk/jshell/ExecutionControlTestBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 @@ -25,28 +25,14 @@

import org.testng.annotations.Test;
import jdk.jshell.VarSnippet;
import java.net.InetAddress;

import static jdk.jshell.Snippet.Status.VALID;
import static jdk.jshell.Snippet.SubKind.*;

public class ExecutionControlTestBase extends KullaTesting {

String standardListenSpec() {
String loopback = InetAddress.getLoopbackAddress().getHostAddress();
return "jdi:hostname(" + loopback + ")";
}

String standardLaunchSpec() {
return "jdi:launch(true)";
}

String standardJdiSpec() {
return "jdi";
}

String standardSpecs() {
return "5(" + standardListenSpec() + "), 6(" + standardLaunchSpec() + "), 7(" + standardJdiSpec() + ")";
String alwaysPassingSpec() {
return "5(local)";
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 Down Expand Up @@ -129,9 +129,7 @@ public void setUp() {
Map<String, String> pm = provider.defaultParameters();
pm.put("0", "alwaysFailing");
pm.put("1", "alwaysFailing");
pm.put("2", standardListenSpec());
pm.put("3", standardLaunchSpec());
pm.put("4", standardJdiSpec());
pm.put("2", "local");
setUp(builder -> builder.executionEngine(provider, pm));
}

Expand Down Expand Up @@ -159,9 +157,7 @@ public void variables() {
assertTrue(log.contains("This operation intentionally broken"), log);
log = logged.get(Level.FINEST).get(0);
assertTrue(
log.contains("Success failover -- 2 = " + standardListenSpec())
|| log.contains("Success failover -- 3 = " + standardLaunchSpec())
|| log.contains("Success failover -- 4 = " + standardJdiSpec()),
log.contains("Success failover -- 2 = local"),
log);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 Down Expand Up @@ -43,6 +43,6 @@ public class FailOverExecutionControlDyingLaunchTest extends ExecutionControlTes
public void setUp() {
setUp(builder -> builder.executionEngine(
"failover:0(jdi:remoteAgent(DyingRemoteAgent),launch(true)), "
+ standardSpecs()));
+ alwaysPassingSpec()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 Down Expand Up @@ -42,6 +42,6 @@ public class FailOverExecutionControlHangingLaunchTest extends ExecutionControlT
public void setUp() {
setUp(builder -> builder.executionEngine(
"failover:0(jdi:remoteAgent(HangingRemoteAgent),launch(true)), "
+ standardSpecs()));
+ alwaysPassingSpec()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 Down Expand Up @@ -45,6 +45,6 @@ public void setUp() {
String loopback = InetAddress.getLoopbackAddress().getHostAddress();
setUp(builder -> builder.executionEngine(
"failover:0(jdi:remoteAgent(HangingRemoteAgent),hostname(" + loopback + ")),"
+ standardSpecs()));
+ alwaysPassingSpec()));
}
}
4 changes: 2 additions & 2 deletions test/langtools/jdk/jshell/FailOverExecutionControlTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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 Down Expand Up @@ -41,7 +41,7 @@ public class FailOverExecutionControlTest extends ExecutionControlTestBase {
@Override
public void setUp() {
setUp(builder -> builder.executionEngine("failover:0(expectedFailureNonExistent1), 1(expectedFailureNonExistent2), "
+ standardSpecs()));
+ alwaysPassingSpec()));
}

}
3 changes: 2 additions & 1 deletion test/langtools/jdk/jshell/IdGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public JShell.Builder getBuilder() {
return JShell.builder()
.in(inStream)
.out(new PrintStream(outStream))
.err(new PrintStream(errStream));
.err(new PrintStream(errStream))
.executionEngine(Presets.TEST_DEFAULT_EXECUTION);
}

public void testTempNameGenerator() {
Expand Down
7 changes: 5 additions & 2 deletions test/langtools/jdk/jshell/KullaTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public class KullaTesting {
private Set<Snippet> allSnippets = new LinkedHashSet<>();

static {
JShell js = JShell.create();
JShell js = JShell.builder()
.executionEngine(Presets.TEST_DEFAULT_EXECUTION)
.build();
MAIN_SNIPPET = js.eval("MAIN_SNIPPET").get(0).snippet();
js.close();
assertTrue(MAIN_SNIPPET != null, "Bad MAIN_SNIPPET set-up -- must not be null");
Expand Down Expand Up @@ -192,7 +194,8 @@ public int read(byte[] b, int off, int len) throws IOException {
JShell.Builder builder = JShell.builder()
.in(in)
.out(new PrintStream(outStream))
.err(new PrintStream(errStream));
.err(new PrintStream(errStream))
.executionEngine(Presets.TEST_DEFAULT_EXECUTION);
bc.accept(builder);
state = builder.build();
allSnippets = new LinkedHashSet<>();
Expand Down
59 changes: 59 additions & 0 deletions test/langtools/jdk/jshell/Presets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import java.net.InetAddress;
import java.util.*;

public class Presets {
public static final String TEST_DEFAULT_EXECUTION;
public static final String TEST_STANDARD_EXECUTION;

static {
String loopback = InetAddress.getLoopbackAddress().getHostAddress();

TEST_DEFAULT_EXECUTION = "failover:0(jdi:hostname(" + loopback + "))," +
"1(jdi:launch(true)), 2(jdi), 3(local)";
TEST_STANDARD_EXECUTION = "failover:0(jdi:hostname(" + loopback + "))," +
"1(jdi:launch(true)), 2(jdi)";
}

public static String[] addExecutionIfMissing(String[] args) {
if (Arrays.stream(args).noneMatch(Presets::remoteRelatedOption)) {
List<String> augmentedArgs = new ArrayList<>();

augmentedArgs.add("--execution");
augmentedArgs.add(Presets.TEST_DEFAULT_EXECUTION);
augmentedArgs.addAll(List.of(args));

return augmentedArgs.toArray(s -> new String[s]);
}

return args;
}

private static boolean remoteRelatedOption(String option) {
return "--execution".equals(option) ||
"--add-modules".equals(option) ||
option.startsWith("-R");
}
}
2 changes: 1 addition & 1 deletion test/langtools/jdk/jshell/ReplToolTesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected JavaShellToolBuilder builder(Locale locale) {
private void testRaw(Locale locale, String[] args,
String expectedErrorOutput, ReplTest... tests) {
testRawInit(tests);
testRawRun(locale, args);
testRawRun(locale, Presets.addExecutionIfMissing(args));
testRawCheck(locale, expectedErrorOutput);
}

Expand Down
2 changes: 1 addition & 1 deletion test/langtools/jdk/jshell/StartOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private JavaShellToolBuilder builder() {
protected int runShell(String... args) {
try {
return builder()
.start(args);
.start(Presets.addExecutionIfMissing(args));
} catch (Exception ex) {
fail("Repl tool died with exception", ex);
}
Expand Down
2 changes: 1 addition & 1 deletion test/langtools/jdk/jshell/ToolReloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testReloadCrashRestore() {
}

public void testEnvBadModule() {
test(
test(new String[] {"--execution", Presets.TEST_STANDARD_EXECUTION},
(a) -> assertVariable(a, "int", "x", "5", "5"),
(a) -> assertMethod(a, "int m(int z) { return z * z; }",
"(int)int", "m"),
Expand Down
3 changes: 2 additions & 1 deletion test/langtools/jdk/jshell/UITesting.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ protected void doRunTest(Test test) throws Exception {
.promptCapture(true)
.persistence(new HashMap<>())
.locale(Locale.US)
.run("--no-startup");
.run("--no-startup",
"--execution", Presets.TEST_DEFAULT_EXECUTION);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
Expand Down

0 comments on commit 14193a0

Please sign in to comment.