2727import java .io .ByteArrayOutputStream ;
2828import java .io .PrintStream ;
2929
30+ import org .junit .Assert ;
3031import org .junit .Test ;
3132
3233import 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- "\t B1 [dom B0, post dom null]\n " +
84- "\t B2 [dom B0, post dom null]\n " +
85- "\t B3 [dom B0, post dom null]\n " +
86- "Enter block B0 for TestIterator\n " +
87- "\t Enter block B1 for TestIterator\n " +
88- "\t Exit block B1 with value 1 for TestIterator\n " +
89- "\t Enter block B2 for TestIterator\n " +
90- "\t Exit block B2 with value 1 for TestIterator\n " +
91- "\t Enter block B3 for TestIterator\n " +
92- "\t Exit 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+ \t B1 [dom B0, post dom null]
93+ \t B2 [dom B0, post dom null]
94+ \t B3 [dom B0, post dom null]
95+ Enter block B0 for TestIterator
96+ \t Enter block B1 for TestIterator
97+ \t Exit block B1 with value 1 for TestIterator
98+ \t Enter block B2 for TestIterator
99+ \t Exit block B2 with value 1 for TestIterator
100+ \t Enter block B3 for TestIterator
101+ \t Exit 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