From d890abfb880dcd4cb9b2fa2e09a7a058f5237044 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 31 May 2024 15:13:17 +0000 Subject: [PATCH] 7903443: Propagate verbose flag to agents Reviewed-by: jjg --- .../javatest/regtest/agent/AgentVerbose.java | 76 +++++++++++++++++++ .../javatest/regtest/agent/JUnitRunner.java | 22 ++++-- .../regtest/config/RegressionParameters.java | 23 ++++++ .../regtest/exec/RegressionScript.java | 7 +- .../com/sun/javatest/regtest/tool/Tool.java | 2 + 5 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 src/share/classes/com/sun/javatest/regtest/agent/AgentVerbose.java diff --git a/src/share/classes/com/sun/javatest/regtest/agent/AgentVerbose.java b/src/share/classes/com/sun/javatest/regtest/agent/AgentVerbose.java new file mode 100644 index 00000000..27060e91 --- /dev/null +++ b/src/share/classes/com/sun/javatest/regtest/agent/AgentVerbose.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.sun.javatest.regtest.agent; + +import java.util.Scanner; +import java.util.regex.MatchResult; + +public final class AgentVerbose { + public enum Mode { NONE, DEFAULT, SUMMARY, BRIEF, FULL } + + /** + * Returns a verbose instance. + * + * @param s string-representation to parse + * @return DEFAULT or a verbose instance parsed from the input string + */ + public static AgentVerbose ofStringRepresentation(String s) { + if (s == null || s.trim().isEmpty()) return new AgentVerbose(Mode.DEFAULT); + try (Scanner scanner = new Scanner(s)) { + scanner.findInLine("Verbose\\[p=(.+),f=(.+),e=(.+),t=(.+),m=(.+)]"); + MatchResult result = scanner.match(); + Mode p = Mode.valueOf(result.group(1)); + Mode f = Mode.valueOf(result.group(2)); + Mode e = Mode.valueOf(result.group(3)); + boolean t = Boolean.parseBoolean(result.group(4)); + boolean m = Boolean.parseBoolean(result.group(5)); + return new AgentVerbose(p, f, e, t, m); + } + } + + private AgentVerbose(Mode mode) { + this(mode, mode, mode, false, false); + } + + private AgentVerbose(Mode passMode, Mode failMode, Mode errorMode, boolean time, boolean multiRun) { + this.passMode = passMode; + this.failMode = failMode; + this.errorMode = errorMode; + this.time = time; + this.multiRun = multiRun; + } + + @Override + public String toString() { + return "Verbose[p=" + passMode + ",f=" + failMode + ",e=" + errorMode + ",t=" + time + ",m=" + multiRun + "]"; + } + + public final Mode passMode; + public final Mode failMode; + public final Mode errorMode; + public final boolean time; + public final boolean multiRun; +} diff --git a/src/share/classes/com/sun/javatest/regtest/agent/JUnitRunner.java b/src/share/classes/com/sun/javatest/regtest/agent/JUnitRunner.java index e5072075..69250b10 100644 --- a/src/share/classes/com/sun/javatest/regtest/agent/JUnitRunner.java +++ b/src/share/classes/com/sun/javatest/regtest/agent/JUnitRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -133,8 +133,10 @@ private static void runWithJUnitPlatform(Class mainClass) throws Exception { SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener(); + AgentVerbose verbose = AgentVerbose.ofStringRepresentation(System.getProperty("test.verbose")); + LauncherConfig launcherConfig = LauncherConfig.builder() - .addTestExecutionListeners(new PrintingListener(System.err)) + .addTestExecutionListeners(new PrintingListener(System.err, verbose)) .addTestExecutionListeners(summaryGeneratingListener) .build(); @@ -187,18 +189,21 @@ static class PrintingListener implements TestExecutionListener { final PrintWriter printer; final Lock lock; + final AgentVerbose verbose; - PrintingListener(PrintStream stream) { - this(new PrintWriter(stream, true)); + PrintingListener(PrintStream stream, AgentVerbose verbose) { + this(new PrintWriter(stream, true), verbose); } - PrintingListener(PrintWriter printer) { + PrintingListener(PrintWriter printer, AgentVerbose verbose) { this.printer = printer; this.lock = new ReentrantLock(); + this.verbose = verbose; } @Override public void executionSkipped(TestIdentifier identifier, String reason) { + if (verbose.passMode == AgentVerbose.Mode.NONE) return; if (identifier.isTest()) { String status = "SKIPPED"; String source = toSourceString(identifier); @@ -215,6 +220,7 @@ public void executionSkipped(TestIdentifier identifier, String reason) { @Override public void executionStarted(TestIdentifier identifier) { + if (verbose.passMode == AgentVerbose.Mode.NONE) return; if (identifier.isTest()) { String status = "STARTED"; String source = toSourceString(identifier); @@ -231,9 +237,12 @@ public void executionStarted(TestIdentifier identifier) { @Override public void executionFinished(TestIdentifier identifier, TestExecutionResult result) { + TestExecutionResult.Status status = result.getStatus(); + if (status == TestExecutionResult.Status.SUCCESSFUL) { + if (verbose.passMode == AgentVerbose.Mode.NONE) return; + } lock.lock(); try { - TestExecutionResult.Status status = result.getStatus(); if (status == TestExecutionResult.Status.ABORTED) { result.getThrowable().ifPresent(printer::println); // not the entire stack trace } @@ -253,6 +262,7 @@ public void executionFinished(TestIdentifier identifier, TestExecutionResult res @Override public void reportingEntryPublished(TestIdentifier identifier, ReportEntry entry) { + if (verbose.passMode == AgentVerbose.Mode.NONE) return; lock.lock(); try { printer.println(identifier.getDisplayName() + " -> " + entry.getTimestamp()); diff --git a/src/share/classes/com/sun/javatest/regtest/config/RegressionParameters.java b/src/share/classes/com/sun/javatest/regtest/config/RegressionParameters.java index 595e54d3..5a64bd78 100644 --- a/src/share/classes/com/sun/javatest/regtest/config/RegressionParameters.java +++ b/src/share/classes/com/sun/javatest/regtest/config/RegressionParameters.java @@ -65,6 +65,7 @@ import com.sun.javatest.regtest.agent.JDK_Version; import com.sun.javatest.regtest.agent.SearchPath; import com.sun.javatest.regtest.exec.TimeoutHandlerProvider; +import com.sun.javatest.regtest.report.Verbose; import com.sun.javatest.regtest.util.FileUtils; import com.sun.javatest.regtest.util.StringUtils; import com.sun.javatest.util.I18NResourceBundle; @@ -640,6 +641,7 @@ public boolean getCacheableValue(TestDescription td) throws Fault { private static final String CUSTOM_TEST_THREAD_FACTORY = ".testThreadFactory"; private static final String CUSTOM_TEST_THREAD_FACTORY_PATH = ".testThreadFactoryPath"; private static final String TEST_QUERIES = ".testQueries"; + private static final String TEST_VERBOSE = ".testVerbose"; @Override public void load(Map data, boolean checkChecksum) throws Interview.Fault { @@ -742,6 +744,11 @@ public void load(Map data, boolean checkChecksum) throws Intervi setTestQueries(List.of(StringUtils.splitSeparator("\n", v))); } + v = data.get(prefix + TEST_VERBOSE); + if (v != null) { + setVerbose(Verbose.decode(v)); + } + } catch (InvalidPathException e) { // This is unlikely to happen, but pretty serious if it does. // Since we only put valid paths into the parameters, there should be @@ -829,6 +836,10 @@ public void save(Map data) { if (testQueries != null) { data.put(prefix + TEST_QUERIES, join(testQueries, "\n")); } + + if (verbose != null) { + data.put(prefix + TEST_VERBOSE, verbose.toString()); + } } //--------------------------------------------------------------------- @@ -1318,6 +1329,18 @@ public boolean useWindowsSubsystemForLinux() { //--------------------------------------------------------------------- + public void setVerbose(Verbose verbose) { + this.verbose = verbose; + } + + public Verbose getVerbose() { + return verbose; + } + + private Verbose verbose; + + //--------------------------------------------------------------------- + public void setTestQueries(List testQueries) { this.testQueries = testQueries; } diff --git a/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java b/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java index 01da8cfb..095f2596 100644 --- a/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java +++ b/src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -75,6 +75,7 @@ import com.sun.javatest.regtest.config.RegressionParameters; import com.sun.javatest.regtest.config.RegressionTestSuite; import com.sun.javatest.regtest.report.SummaryReporter; +import com.sun.javatest.regtest.report.Verbose; import com.sun.javatest.regtest.tool.Version; import com.sun.javatest.regtest.util.FileUtils; import com.sun.javatest.regtest.util.StringUtils; @@ -1139,6 +1140,10 @@ Map getTestProperties() { if (testQuery != null) { p.put("test.query", testQuery); } + Verbose verbose = params.getVerbose(); + if (verbose != null) { + p.put("test.verbose", verbose.toString()); + } p.put("test.file", locations.absTestFile().toString()); p.put("test.src", locations.absTestSrcDir().toString()); p.put("test.src.path", toString(locations.absTestSrcPath())); diff --git a/src/share/classes/com/sun/javatest/regtest/tool/Tool.java b/src/share/classes/com/sun/javatest/regtest/tool/Tool.java index 1ea95d8c..ad980169 100644 --- a/src/share/classes/com/sun/javatest/regtest/tool/Tool.java +++ b/src/share/classes/com/sun/javatest/regtest/tool/Tool.java @@ -1844,6 +1844,8 @@ private RegressionParameters createParameters( rp.setUseWindowsSubsystemForLinux(useWindowsSubsystemForLinux); + rp.setVerbose(verbose); + rp.initExprContext(); // will invoke/init jdk.getProperties(params) return rp;