Skip to content

Commit

Permalink
CODETOOLS-7902873: jcstress: Clean up text reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
shipilev authored Apr 6, 2021
1 parent 6715852 commit 22b10ed
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.openjdk.jcstress.Verbosity;
import org.openjdk.jcstress.infra.collectors.TestResult;
import org.openjdk.jcstress.infra.collectors.TestResultCollector;
import org.openjdk.jcstress.util.StringUtils;

import java.io.PrintWriter;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -141,9 +140,7 @@ private void printResult(TestResult r) {
if (!progressInteractive) {
output.println();
}
output.printf("%10s %s%n", "[" + ReportUtils.statusToLabel(r) + "]", StringUtils.chunkName(r.getName()));
ReportUtils.printDetails(output, r, true);
ReportUtils.printMessages(output, r);
ReportUtils.printResult(output, r, true);
}

if (shouldPrintStatusLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void emitTestReport(PrintWriter o, Collection<TestResult> results, TestIn

public String selectHTMLColor(Expect type, boolean isZero) {
String rgb = Integer.toHexString(selectColor(type, isZero).getRGB());
return "#" + rgb.substring(2, rgb.length());
return "#" + rgb.substring(2);
}

public Color selectColor(Expect type, boolean isZero) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ private static TestResult merged(TestConfig config, Collection<TestResult> merge
return root;
}

public static void printDetails(PrintWriter pw, TestResult r, boolean inProgress) {
pw.format(" (compilation: %s)%n", CompileMode.description(r.getConfig().getCompileMode(), r.getConfig().actorNames));
pw.format(" (JVM args: %s)%n", r.getConfig().jvmArgs);
public static void printResult(PrintWriter pw, TestResult r, boolean inProgress) {
String label = StringUtils.leftPadDash("[" + ReportUtils.statusToLabel(r) + "]", 10);
String testName = StringUtils.chunkName(r.getName());
pw.printf("%10s %s%n", label, testName);
pw.println();
pw.format(" Compilation: %s%n", CompileMode.description(r.getConfig().getCompileMode(), r.getConfig().actorNames));
pw.format(" JVM args: %s%n", r.getConfig().jvmArgs);
if (inProgress) {
pw.format(" (fork: #%d)%n", r.getConfig().forkId + 1);
pw.format(" Fork: #%d%n", r.getConfig().forkId + 1);
}
pw.println();

if (!r.hasSamples()) {
return;
Expand Down Expand Up @@ -162,17 +167,15 @@ public static void printDetails(PrintWriter pw, TestResult r, boolean inProgress
}

pw.println();
}

public static void printMessages(PrintWriter pw, TestResult r) {
boolean errMsgsPrinted = false;
for (String data : r.getMessages()) {
if (skipMessage(data)) continue;
if (!errMsgsPrinted) {
pw.println(" Messages: ");
pw.println(" Messages: ");
errMsgsPrinted = true;
}
pw.println(" " + data);
pw.println(" " + data);
}
if (errMsgsPrinted) {
pw.println();
Expand All @@ -182,10 +185,10 @@ public static void printMessages(PrintWriter pw, TestResult r) {
for (String data : r.getVmOut()) {
if (skipMessage(data)) continue;
if (!vmOutPrinted) {
pw.println(" VM output stream: ");
pw.println(" VM output stream: ");
vmOutPrinted = true;
}
pw.println(" " + data);
pw.println(" " + data);
}
if (vmOutPrinted) {
pw.println();
Expand All @@ -195,10 +198,10 @@ public static void printMessages(PrintWriter pw, TestResult r) {
for (String data : r.getVmErr()) {
if (skipMessage(data)) continue;
if (!vmErrPrinted) {
pw.println(" VM error stream: ");
pw.println(" VM error stream: ");
vmErrPrinted = true;
}
pw.println(" " + data);
pw.println(" " + data);
}
if (vmErrPrinted) {
pw.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.openjdk.jcstress.infra.Status;
import org.openjdk.jcstress.infra.collectors.InProcessCollector;
import org.openjdk.jcstress.infra.collectors.TestResult;
import org.openjdk.jcstress.util.StringUtils;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
Expand All @@ -49,20 +48,20 @@ public class TextReportPrinter {
private final PrintWriter pw;
private final Set<TestResult> emittedTests;

public TextReportPrinter(Options opts, InProcessCollector collector) throws FileNotFoundException {
public TextReportPrinter(Options opts, InProcessCollector collector) {
this.collector = collector;
this.pw = new PrintWriter(System.out, true);
this.verbosity = opts.verbosity();
this.emittedTests = new HashSet<>();
}

public void work() throws FileNotFoundException {
public void work() {
emittedTests.clear();

List<TestResult> byConfig = ReportUtils.mergedByConfig(collector.getTestResults());
Collections.sort(byConfig, Comparator
.comparing(TestResult::getName)
.thenComparing(Comparator.comparing(t -> t.getConfig().jvmArgs.toString())));
.thenComparing(t -> t.getConfig().jvmArgs.toString()));

pw.println("RUN RESULTS:");
pw.println("------------------------------------------------------------------------------------------------------------------------");
Expand Down Expand Up @@ -108,23 +107,25 @@ private void printXTests(List<TestResult> list,
pw.println(" " + subHeader);
pw.println();
pw.println(" " + list.stream().filter(predicate).count() + " matching test results. " + (!emitDetails ? " Use -v to print them." : ""));
pw.println();

if (emitDetails) {
boolean emitted = false;
for (TestResult result : list) {
if (predicate.test(result)) {
emitTest(result);
emitted = true;
}
}
if (emitted) {
pw.println();
}
}

pw.println();
}

public void emitTest(TestResult result) {
emittedTests.add(result);
pw.printf("%10s %s%n", "[" + ReportUtils.statusToLabel(result) + "]", StringUtils.chunkName(result.getName()));
ReportUtils.printDetails(pw, result, false);
ReportUtils.printMessages(pw, result);
ReportUtils.printResult(pw, result, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,21 @@ public static String getFirstLine(String src) {
}
return src;
}

static final String[] PADS;

static {
PADS = new String[10];
String p = "";
for (int c = 0; c < PADS.length; c++) {
PADS[c] = p;
p = p + ".";
}
}

public static String leftPadDash(String src, int count) {
int need = count - src.length() - 1;
if (need <= 0) return src;
return PADS[need] + " " + src;
}
}

0 comments on commit 22b10ed

Please sign in to comment.