Skip to content

Commit

Permalink
finetuning of the progress bars around testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 3, 2024
1 parent 42acc99 commit bda3846
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ default str getParserMethodName(Symbol s) = value2id(s);

public str newGenerate(str package, str name, Grammar gr) {
str src = "";
job("Generating parser <package>.<name>", void (void (str m, int w) worked) {
job("Generating <name>", void (void (str m, int w) worked) {
int uniqueItem = 1; // -1 and -2 are reserved by the SGTDBF implementation
int newItem() { uniqueItem += 1; return uniqueItem; };

Expand Down Expand Up @@ -85,7 +85,7 @@ public str newGenerate(str package, str name, Grammar gr) {
//println("optimizing lookahead automaton", 1);
//gr = compileLookaheads(gr);
worked("printing the source code of the parser class", 1);
worked("source code template", 1);
src = "package <package>;
'
Expand Down
14 changes: 12 additions & 2 deletions src/org/rascalmpl/repl/TerminalProgressBarMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void write() {
var msg = message.substring(0, 1).toUpperCase() + message.substring(1, message.length());

// fill up and cut off:
msg = threadLabel() + message;
msg = threadLabel() + msg;
msg = (msg + " ".repeat(Math.max(0, barWidth - msg.length()))).substring(0, barWidth);

// split
Expand Down Expand Up @@ -162,6 +162,9 @@ private String threadLabel() {
if (threadName.isEmpty()) {
return "";

Check warning on line 163 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L163

Added line #L163 was not covered by tests
}
else if ("main".equals(threadName)) {
return "";

Check warning on line 166 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L166

Added line #L166 was not covered by tests
}

return threadName + ": ";
}
Expand Down Expand Up @@ -388,7 +391,14 @@ public synchronized void write(int b) throws IOException {

@Override
public synchronized void endAllJobs() {
// eraseBars();
for (var pb : bars) {
if (pb.nesting > 0) {
writer.println("[INFO] " + pb.name + " is still at nesting level " + pb.nesting);

Check warning on line 396 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L396

Added line #L396 was not covered by tests
}
if (pb.current < pb.max) {
writer.println("[INFO] " + pb.name + " has not done all the work (" + pb.current + " of " + pb.max + ")");

Check warning on line 399 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L399

Added line #L399 was not covered by tests
}
}
bars.clear();
writer.write(ANSI.showCursor());
writer.flush();
Expand Down
3 changes: 3 additions & 0 deletions src/org/rascalmpl/semantics/dynamic/Import.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public static ModuleEnvironment loadModule(ISourceLocation x, String name, IEval
e.printStackTrace();
throw new ModuleImport(name, e.getMessage(), x);
}
finally {
eval.jobEnd("loading", true);
}

heap.removeModule(env);
throw new ImplementationError("Unexpected error while parsing module " + name + " and building an AST for it ", x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ private void runTests(RunNotifier notifier) {
newResult.accept(notifier);
}
}

monitor.endAllJobs();
assert results.isEmpty();
}

Expand Down Expand Up @@ -240,7 +242,7 @@ private boolean waitForRunSignal() {
}

private void processModules() {
evaluator.job("Importing test modules", 1, (jn) -> {
evaluator.job("Importing test modules", 0, (jn) -> {
try {
String module;

Expand Down
11 changes: 8 additions & 3 deletions src/org/rascalmpl/test/infrastructure/TestFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
import org.rascalmpl.interpreter.load.StandardLibraryContributor;
import org.rascalmpl.interpreter.result.Result;
import org.rascalmpl.interpreter.staticErrors.StaticError;
import org.rascalmpl.repl.TerminalProgressBarMonitor;
import org.rascalmpl.uri.URIResolverRegistry;
import org.rascalmpl.uri.URIUtil;
import io.usethesource.vallang.IBool;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.exceptions.FactTypeUseException;
import io.usethesource.vallang.type.TypeFactory;
import jline.TerminalFactory;

import org.rascalmpl.values.ValueFactoryFactory;


public class TestFramework {
private final static TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, TerminalFactory.get());
private final static Evaluator evaluator;
private final static GlobalEnvironment heap;
private final static ModuleEnvironment root;
Expand All @@ -57,9 +61,10 @@ public class TestFramework {
root = heap.addModule(new ModuleEnvironment("___test___", heap));

stderr = new PrintWriter(System.err);
stdout = new PrintWriter(System.out);
evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, System.out, root, heap);

stdout = new PrintWriter(monitor);
evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap);
evaluator.setMonitor(monitor);

evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
RascalJUnitTestRunner.configureProjectEvaluator(evaluator, RascalJUnitTestRunner.inferProjectRoot(TestFramework.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import java.util.concurrent.atomic.AtomicReference;

import org.junit.Test;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.interpreter.ITestResultListener;
import org.rascalmpl.interpreter.NullRascalMonitor;
import org.rascalmpl.interpreter.env.GlobalEnvironment;
import org.rascalmpl.interpreter.env.ModuleEnvironment;
import org.rascalmpl.interpreter.load.StandardLibraryContributor;
import org.rascalmpl.repl.TerminalProgressBarMonitor;
import org.rascalmpl.values.ValueFactoryFactory;

import io.usethesource.vallang.ISourceLocation;
import jline.TerminalFactory;

public class ParallelEvaluatorsTests {
private static final TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, TerminalFactory.get());
private static final IRascalMonitor monitor = new NullRascalMonitor();

private static final String[] testModules = new String[] {
"lang::rascal::tests::library::ValueIO",
Expand All @@ -35,7 +35,7 @@ private static Evaluator freshEvaluator() {
var heap = new GlobalEnvironment();
var root = heap.addModule(new ModuleEnvironment("___test___", heap));

var evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap);
var evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, System.out, root, heap);
evaluator.setMonitor(monitor);
evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
evaluator.setTestResultListener(new ITestResultListener() {
Expand Down Expand Up @@ -107,7 +107,7 @@ public void testMultipleEvaluators() {
}
}

});
}, "Evaluator parallel stress test " + i);
runner.setDaemon(true);
runner.start();
}
Expand All @@ -131,10 +131,8 @@ public void testMultipleEvaluators() {
}
finally {
close.set(true);
monitor.endAllJobs();
}



}

}

0 comments on commit bda3846

Please sign in to comment.