--- old/test/compiler/compilercontrol/share/scenario/Scenario.java 2015-11-20 20:55:52.000000000 +0300 +++ new/test/compiler/compilercontrol/share/scenario/Scenario.java 2015-11-20 20:55:52.000000000 +0300 @@ -26,6 +26,7 @@ import compiler.compilercontrol.share.method.MethodDescriptor; import compiler.compilercontrol.share.processors.CommandProcessor; import compiler.compilercontrol.share.processors.LogProcessor; +import compiler.compilercontrol.share.processors.PrintDirectivesProcessor; import compiler.compilercontrol.share.processors.PrintProcessor; import compiler.compilercontrol.share.processors.QuietProcessor; import jdk.test.lib.Asserts; @@ -52,12 +53,14 @@ private final Map states; private final List> processors; private final Executor executor; + private final Consumer> jcmdProcessor; private Scenario(boolean isValid, List vmopts, Map states, List compileCommands, - List jcmdCommands) { + List jcmdCommands, + List directives) { this.isValid = isValid; this.states = states; processors = new ArrayList<>(); @@ -78,6 +81,7 @@ processors.add(new QuietProcessor(quieted)); List jcmdExecCommands = new ArrayList<>(); boolean addCommandMet = false; + boolean printCommandMet = false; for (JcmdCommand cmd : jcmdCommands) { switch (cmd.jcmdType) { case ADD: @@ -86,11 +90,19 @@ } addCommandMet = true; break; + case PRINT: + printCommandMet = true; + break; default: jcmdExecCommands.add(cmd.jcmdType.command); break; } } + // Add print command only in the end to get directives printed + if (printCommandMet) { + jcmdExecCommands.add(JcmdType.PRINT.command); + } + jcmdProcessor = new PrintDirectivesProcessor(directives); executor = new Executor(isValid, vmopts, states, jcmdExecCommands); } @@ -98,14 +110,20 @@ * Executes scenario */ public void execute() { - OutputAnalyzer output = executor.execute(); + List outputList = executor.execute(); + // The first one contains output from the test VM + OutputAnalyzer mainOuput = outputList.get(0); if (isValid) { - output.shouldHaveExitValue(0); - processors.forEach(processor -> processor.accept(output)); + mainOuput.shouldHaveExitValue(0); + processors.forEach(processor -> processor.accept(mainOuput)); + // only the last output contains directives got from print command + List last = new ArrayList<>(); + last.add(outputList.get(outputList.size() - 1)); + jcmdProcessor.accept(last); } else { - Asserts.assertNE(output.getExitValue(), 0, "VM should exit with " + Asserts.assertNE(mainOuput.getExitValue(), 0, "VM should exit with " + "error for incorrect directives"); - output.shouldContain("Parsing of compiler directives failed"); + mainOuput.shouldContain("Parsing of compiler directives failed"); } } @@ -181,6 +199,7 @@ private final Map> builders = new HashMap<>(); private final JcmdStateBuilder jcmdStateBuilder; + private final List jcmdCommands = new ArrayList<>(); public Builder() { builders.put(Type.FILE, new CommandFileBuilder(Type.FILE.fileName)); @@ -195,6 +214,7 @@ Collections.addAll(vmopts, vmOptions); if (compileCommand.type == Type.JCMD) { jcmdStateBuilder.add((JcmdCommand) compileCommand); + jcmdCommands.add((JcmdCommand) compileCommand); } else { StateBuilder builder = builders.get( compileCommand.type); @@ -217,11 +237,9 @@ Map directiveFileStates = builders.get(Type.DIRECTIVE).getStates(); - // get all jcmd commands - List jcmdCommands = jcmdStateBuilder - .getCompileCommands(); + // check if directives stack was cleared by jcmd boolean isClearedState = false; - if (jcmdClearedState(jcmdCommands)) { + if (jcmdContainsCommand(JcmdType.CLEAR)) { isClearedState = true; } @@ -255,6 +273,18 @@ ccList.addAll(builders.get(Type.OPTION).getCompileCommands()); ccList.addAll(builders.get(Type.FILE).getCompileCommands()); + /* + * Create a list of directives to check which one was printed + */ + List directives = new ArrayList<>(); + if (jcmdContainsCommand(JcmdType.PRINT)) { + if (!isClearedState) { + directives.addAll(builders.get(Type.DIRECTIVE) + .getCompileCommands()); + } + directives.addAll(jcmdStateBuilder.getCompileCommands()); + } + // Get all VM options after we build all states and files List options = new ArrayList<>(); options.addAll(vmopts); @@ -264,13 +294,13 @@ } options.addAll(jcmdStateBuilder.getOptions()); return new Scenario(isValid, options, finalStates, ccList, - jcmdCommands); + jcmdCommands, directives); } - // shows if jcmd have passed a clear command - private boolean jcmdClearedState(List jcmdCommands) { + // shows if jcmd have passed a specified jcmd command type + private boolean jcmdContainsCommand(JcmdType type) { for (JcmdCommand jcmdCommand : jcmdCommands) { - if (jcmdCommand.jcmdType == JcmdType.CLEAR) { + if (jcmdCommand.jcmdType == type) { return true; } }