Skip to content

Commit f3db2ea

Browse files
committed
[GR-70893] LoggingCFGDecoratorTest: add real output to error message.
PullRequest: graal/22417
2 parents e96584e + 8f48bf9 commit f3db2ea

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/LoggingCFGDecoratorTest.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.ByteArrayOutputStream;
2828
import java.io.PrintStream;
2929

30+
import org.junit.Assert;
3031
import org.junit.Test;
3132

3233
import jdk.graal.compiler.api.directives.GraalDirectives;
@@ -38,7 +39,7 @@ public class LoggingCFGDecoratorTest extends GraalCompilerTest {
3839

3940
public static int foo(int a) {
4041
int result = 0;
41-
if (a == 0) {
42+
if (GraalDirectives.injectBranchProbability(0.99, a == 0)) {
4243
result = 1;
4344
} else {
4445
result = 2;
@@ -76,20 +77,29 @@ public String toString() {
7677
ControlFlowGraph.LoggingCFGDecorator<?> dec = new ControlFlowGraph.LoggingCFGDecorator<>(o, visitor, cfg);
7778
cfg.visitDominatorTreeDefault(dec);
7879
String result = baos.toString();
79-
assert result.contains(ExpectedOutput);
80+
Assert.assertTrue(assertStringContains(result, ExpectedOutput));
8081
}
8182

82-
private static final String ExpectedOutput = "B0 [dom null, post dom null]\n" +
83-
"\tB1 [dom B0, post dom null]\n" +
84-
"\tB2 [dom B0, post dom null]\n" +
85-
"\tB3 [dom B0, post dom null]\n" +
86-
"Enter block B0 for TestIterator\n" +
87-
"\tEnter block B1 for TestIterator\n" +
88-
"\tExit block B1 with value 1 for TestIterator\n" +
89-
"\tEnter block B2 for TestIterator\n" +
90-
"\tExit block B2 with value 1 for TestIterator\n" +
91-
"\tEnter block B3 for TestIterator\n" +
92-
"\tExit block B3 with value 1 for TestIterator\n" +
93-
"Exit block B0 with value 1 for TestIterator";
83+
private static boolean assertStringContains(String set, String key) {
84+
if (!set.contains(key)) {
85+
throw new AssertionError(String.format("String %s does not contain %s", set, key));
86+
}
87+
return true;
88+
}
89+
90+
private static final String ExpectedOutput = """
91+
B0 [dom null, post dom null]
92+
\tB1 [dom B0, post dom null]
93+
\tB2 [dom B0, post dom null]
94+
\tB3 [dom B0, post dom null]
95+
Enter block B0 for TestIterator
96+
\tEnter block B1 for TestIterator
97+
\tExit block B1 with value 1 for TestIterator
98+
\tEnter block B2 for TestIterator
99+
\tExit block B2 with value 1 for TestIterator
100+
\tEnter block B3 for TestIterator
101+
\tExit block B3 with value 1 for TestIterator
102+
Exit block B0 with value 1 for TestIterator
103+
""".replace("\n", System.lineSeparator());
94104

95105
}

0 commit comments

Comments
 (0)