Skip to content

Commit

Permalink
7903443: Propagate verbose flag to agents
Browse files Browse the repository at this point in the history
Reviewed-by: jjg
  • Loading branch information
sormuras committed May 31, 2024
1 parent 779d1b2 commit d890abf
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 7 deletions.
76 changes: 76 additions & 0 deletions src/share/classes/com/sun/javatest/regtest/agent/AgentVerbose.java
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 16 additions & 6 deletions src/share/classes/com/sun/javatest/regtest/agent/JUnitRunner.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> data, boolean checkChecksum) throws Interview.Fault {
Expand Down Expand Up @@ -742,6 +744,11 @@ public void load(Map<String, String> 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
Expand Down Expand Up @@ -829,6 +836,10 @@ public void save(Map<String, String> data) {
if (testQueries != null) {
data.put(prefix + TEST_QUERIES, join(testQueries, "\n"));
}

if (verbose != null) {
data.put(prefix + TEST_VERBOSE, verbose.toString());
}
}

//---------------------------------------------------------------------
Expand Down Expand Up @@ -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<String> testQueries) {
this.testQueries = testQueries;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1139,6 +1140,10 @@ Map<String, String> 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()));
Expand Down
2 changes: 2 additions & 0 deletions src/share/classes/com/sun/javatest/regtest/tool/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,8 @@ private RegressionParameters createParameters(

rp.setUseWindowsSubsystemForLinux(useWindowsSubsystemForLinux);

rp.setVerbose(verbose);

rp.initExprContext(); // will invoke/init jdk.getProperties(params)

return rp;
Expand Down

0 comments on commit d890abf

Please sign in to comment.