Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7903774: make all tests combinations printing nicer and/or configurable #153

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run() throws Exception {
parseResults();
}

private ConfigsWithScheduler getConfigs() {
ConfigsWithScheduler getConfigs() {
OSSupport.init();

VMSupport.initFlags(opts);
Expand Down Expand Up @@ -119,7 +119,7 @@ private ConfigsWithScheduler getConfigs() {
return new ConfigsWithScheduler(scheduler, configs);
}

private static class ConfigsWithScheduler {
static class ConfigsWithScheduler {
public final Scheduler scheduler;
public final List<TestConfig> configs;

Expand Down Expand Up @@ -227,25 +227,4 @@ public SortedSet<String> getTests() {
return s;
}

public int listTests(Options opts) {
JCStress.ConfigsWithScheduler configsWithScheduler = getConfigs();
Set<String> testsToPrint = new TreeSet<>();
for (TestConfig test : configsWithScheduler.configs) {
if (opts.verbosity().printAllTests()) {
testsToPrint.add(test.toDetailedTest());
} else {
testsToPrint.add(test.name);
}
}
if (opts.verbosity().printAllTests()) {
out.println("All matching tests combinations - " + testsToPrint.size());
} else {
out.println("All matching tests - " + testsToPrint.size());
}
for (String test : testsToPrint) {
out.println(test);
}
return testsToPrint.size();
}

}
3 changes: 2 additions & 1 deletion jcstress-core/src/main/java/org/openjdk/jcstress/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static void main(String[] args) throws Exception {

JCStress jcstress = new JCStress(opts);
if (opts.shouldList()) {
jcstress.listTests(opts);
TestListing testListing = new TestListing(jcstress);
testListing.listTests();
} else if (opts.shouldParse()) {
jcstress.parseResults();
} else {
Expand Down
32 changes: 25 additions & 7 deletions jcstress-core/src/main/java/org/openjdk/jcstress/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Options {
private int strideCount;
private final String[] args;
private boolean parse;
private boolean list;
private TestListing.ListingTypes list = TestListing.ListingTypes.NONE;
private Verbosity verbosity;
private int cpuCount;
private int heapPerFork;
Expand Down Expand Up @@ -81,9 +81,9 @@ public boolean parse() throws IOException {
OptionSpec<String> parse = parser.accepts("p", "Re-run parser on the result file. This will not run any tests.")
.withRequiredArg().ofType(String.class).describedAs("result file");

OptionSpec<Boolean> list = parser.accepts("l", "List the available tests matching the requested settings, " +
"after all filters (like CPU count) are applied. In verbose mode it prints all real combinations which will run.")
.withOptionalArg().ofType(Boolean.class).describedAs("bool");
OptionSpec<TestListing.ListingTypes> list = parser.accepts("l", "List the available tests. "
+ TestListing.ListingTypes.toDescription())
.withOptionalArg().ofType(TestListing.ListingTypes.class).describedAs("ListingTypes");

OptionSpec<String> testFilter = parser.accepts("t", "Regexp selector for tests.")
.withRequiredArg().ofType(String.class).describedAs("regexp");
Expand Down Expand Up @@ -184,7 +184,7 @@ public boolean parse() throws IOException {
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT).format(new Date());
this.resultFile = "jcstress-results-" + timestamp + ".bin.gz";
}
this.list = orDefault(set.has(list), false);
this.list = getList(set, list);
if (set.has("vvv")) {
this.verbosity = new Verbosity(3);
} else if (set.has("vv")) {
Expand Down Expand Up @@ -263,6 +263,18 @@ public boolean parse() throws IOException {
return true;
}

private TestListing.ListingTypes getList(OptionSet set, OptionSpec<TestListing.ListingTypes> listSpec) {
if (set.has(listSpec)) {
if (set.hasArgument(listSpec)) {
return set.valueOf(listSpec);
} else {
return TestListing.ListingTypes.ALL_MATCHING;
}
} else {
return TestListing.ListingTypes.NONE;
}
}

private List<String> processArgs(OptionSpec<String> op, OptionSet set) {
if (set.hasArgument(op)) {
try {
Expand Down Expand Up @@ -297,7 +309,7 @@ public void printSettingsOn(PrintStream out) {
out.printf(" Hardware CPUs in use: %d%n", getCPUCount());
out.printf(" Spinning style: %s%n", getSpinStyle());
out.printf(" Test selection: \"%s\"%n", getTestFilter());
out.printf(" Forks per test: %d normal, %d stress%n", getForks(), getForks()*getForksStressMultiplier());
out.printf(" Forks per test: %d normal, %d stress%n", getForks(), getForks() * getForksStressMultiplier());
out.printf(" Test stride: %d strides x %d tests, but taking no more than %d Mb%n", getStrideCount(), getStrideSize(), getMaxFootprintMb());
out.printf(" Test result blob: \"%s\"%n", resultFile);
out.printf(" Test results: \"%s\"%n", resultDir);
Expand Down Expand Up @@ -338,6 +350,10 @@ public boolean shouldParse() {
}

public boolean shouldList() {
return list != TestListing.ListingTypes.NONE;
}

public TestListing.ListingTypes listingType() {
return list;
}

Expand Down Expand Up @@ -392,6 +408,8 @@ public boolean isPretouchHeap() {
return pretouchHeap;
}

public TimeValue timeBudget() { return timeBudget; }
public TimeValue timeBudget() {
return timeBudget;
}

}
138 changes: 138 additions & 0 deletions jcstress-core/src/main/java/org/openjdk/jcstress/TestListing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2005, 2014, 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 org.openjdk.jcstress;

import org.openjdk.jcstress.infra.runners.TestConfig;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class TestListing {

public enum ListingTypes {
NONE, ALL, ALL_MATCHING, ALL_MATCHING_COMBINATIONS,
MATCHING_GROUPS, MATCHING_GROUPS_COUNT,
MATCHING_IGROUPS, MATCHING_IGROUPS_COUNT;

public static String toDescription() {
return "Optional parameter is: "
+ ALL + " all tests; "
+ ALL_MATCHING + " all tests eligible for this system and configuration (like CPU count); "
+ ALL_MATCHING_COMBINATIONS + " all real combinations which will run in this setup; "
+ MATCHING_GROUPS + " similar to above but the shared part is printed only once; "
+ MATCHING_GROUPS_COUNT + " same as above, only instead of lsiting, just count is used; "
+ MATCHING_IGROUPS + ", " + MATCHING_IGROUPS_COUNT + " same as above, only inverted; "
+ "Defaults to " + ALL_MATCHING + " if none provided.";
}
}

private final JCStress jcstress;

public TestListing(JCStress jcstress) {
this.jcstress = jcstress;
}

@SuppressWarnings("unchecked")
public int listTests() {
JCStress.ConfigsWithScheduler configsWithScheduler = jcstress.getConfigs();
Map<String, Object> testsToPrint = new TreeMap<>();
switch (jcstress.opts.listingType()) {
case ALL_MATCHING_COMBINATIONS:
for (TestConfig test : configsWithScheduler.configs) {
testsToPrint.put(test.toDetailedTest(), null);
}
jcstress.out.println("All matching tests combinations - " + testsToPrint.size());
break;
case MATCHING_GROUPS_COUNT:
for (TestConfig test : configsWithScheduler.configs) {
Integer counter = (Integer) testsToPrint.getOrDefault(test.getTestVariant(false), 0);
counter++;
testsToPrint.put(test.getTestVariant(false), counter);
}
jcstress.out.println("All existing combinations (each with count of test) " + testsToPrint.size());
break;
case MATCHING_IGROUPS_COUNT:
for (TestConfig test : configsWithScheduler.configs) {
Integer counter = (Integer) testsToPrint.getOrDefault(test.name, 0);
counter++;
testsToPrint.put(test.name, counter);
}
jcstress.out.println("All matching tests (each with count of combinations) " + testsToPrint.size());
break;
case MATCHING_GROUPS:
for (TestConfig test : configsWithScheduler.configs) {
Set<String> items = (Set<String>) testsToPrint.getOrDefault(test.getTestVariant(false), new TreeSet<String>());
items.add(test.name);
testsToPrint.put(test.getTestVariant(false), items);
}
jcstress.out.println("All existing combinations " + testsToPrint.size());
break;
case MATCHING_IGROUPS:
for (TestConfig test : configsWithScheduler.configs) {
Set<String> items = (Set<String>) (testsToPrint.getOrDefault(test.name, new TreeSet<String>()));
items.add(test.getTestVariant(false));
testsToPrint.put(test.name, items);
}
jcstress.out.println("All matching tests" + testsToPrint.size());
break;
case ALL_MATCHING:
for (TestConfig test : configsWithScheduler.configs) {
testsToPrint.put(test.name, null);
}
jcstress.out.println("All matching tests - " + testsToPrint.size());
break;
case ALL:
for (String test : jcstress.getTests()) {
testsToPrint.put(test, null);
}
jcstress.out.println("All existing tests combinations - " + testsToPrint.size());
break;
default:
throw new RuntimeException("Invalid option for listing: " + jcstress.opts.listingType());
}
for (Map.Entry<String, Object> test : testsToPrint.entrySet()) {
if (test.getValue() == null) {
jcstress.out.println(test.getKey());
} else {
if (test.getValue() instanceof Integer) {
jcstress.out.println(test.getValue() + " " + test.getKey());
} else if (test.getValue() instanceof Collection) {
jcstress.out.println(test.getKey() + " " + ((Collection) test.getValue()).size());
for (Object item : (Collection) test.getValue()) {
jcstress.out.println(" " + item);
}
} else {
jcstress.out.println(test.getKey() + "=?=" + test.getValue());
}
}
}
return testsToPrint.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TestConfig implements Serializable {
Expand Down Expand Up @@ -246,13 +247,12 @@ public void generateDirectives(PrintWriter pw, Verbosity verbosity) {
}


public String toDetailedTest() {
public String getTestVariant(boolean seed) {
//binaryName have correct $ instead of . in name; omitted
//generatedRunnerName name with suffix (usually _Test_jcstress) omitted
//super.toString() as TestConfig@hash - omitted
StringBuilder verboseOutput = new StringBuilder(name);
verboseOutput.append(" {")
.append(actorNames)
StringBuilder idString = new StringBuilder();
idString.append(actorNames)
.append(", spinLoopStyle: ").append(spinLoopStyle)
.append(", threads: ").append(threads)
.append(", forkId: ").append(forkId)
Expand All @@ -262,7 +262,26 @@ public String toDetailedTest() {
.append(", strideSize: ").append(strideSize)
.append(", strideCount: ").append(strideCount)
.append(", cpuMap: ").append(cpuMap)
.append(", ").append(jvmArgs)
.append(", ").append(seed ? jvmArgs : maskSeed(jvmArgs));
return idString.toString();
}

private List<String> maskSeed(List<String> jvmArgs) {
List<String> argsCopy = new ArrayList<>(jvmArgs.size());
for (String arg : jvmArgs) {
if (arg.startsWith("-XX:StressSeed=")) {
argsCopy.add(arg.replaceAll("[0-9]+", "yyyyyyyy"));
} else {
argsCopy.add(arg);
}
}
return argsCopy;
}

public String toDetailedTest() {
StringBuilder verboseOutput = new StringBuilder(name);
verboseOutput.append(" {")
.append(getTestVariant(true))
.append("}");
return verboseOutput.toString();
}
Expand Down