From 40d71da2bde1e33f5e6b9c47fd0b484bb6f4b4b0 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 3 Apr 2024 00:15:44 +0200 Subject: [PATCH] added the progress bar monitor to the parallel test runners. this breaks the monitor because it is not thread safe yet. --- ...ascalJUnitParallelRecursiveTestRunner.java | 37 ++++++----------- .../infrastructure/RascalJUnitTestRunner.java | 2 +- .../ParallelEvaluatorsTests.java | 40 +++++++++++++------ 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java b/src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java index 106e9d5052e..f45d313d38c 100644 --- a/src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java +++ b/src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java @@ -23,6 +23,8 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import jline.TerminalFactory; + import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.Runner; @@ -38,6 +40,7 @@ import org.rascalmpl.interpreter.load.StandardLibraryContributor; import org.rascalmpl.interpreter.result.AbstractFunction; import org.rascalmpl.interpreter.utils.RascalManifest; +import org.rascalmpl.repl.TerminalProgressBarMonitor; import org.rascalmpl.uri.URIUtil; import org.rascalmpl.values.ValueFactoryFactory; @@ -53,6 +56,7 @@ * */ public class RascalJUnitParallelRecursiveTestRunner extends Runner { + private final static TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, TerminalFactory.get()); private final int numberOfWorkers; private final Semaphore importsCompleted = new Semaphore(0); private final Semaphore waitForRunning = new Semaphore(0); @@ -67,7 +71,6 @@ public class RascalJUnitParallelRecursiveTestRunner extends Runner { private final ISourceLocation projectRoot; - public RascalJUnitParallelRecursiveTestRunner(Class clazz) { System.err.println("Rascal JUnit uses Rascal version " + RascalManifest.getRascalVersionNumber()); @@ -96,17 +99,12 @@ public RascalJUnitParallelRecursiveTestRunner(Class clazz) { @Override public Description getDescription() { if (rootDesc == null) { - long start = System.nanoTime(); fillModuleWorkList(); - long stop = System.nanoTime(); - reportTime("Iterating modules", start, stop); startModuleTesters(); - start = System.nanoTime(); rootDesc = Description.createSuiteDescription(projectRoot.toString()); processIncomingModuleDescriptions(rootDesc); - stop = System.nanoTime(); - reportTime("Importing modules, looking for tests", start, stop); + assert descriptions.isEmpty(); } return rootDesc; @@ -116,18 +114,10 @@ public Description getDescription() { public void run(RunNotifier notifier) { assert rootDesc != null; notifier.fireTestRunStarted(rootDesc); - long start = System.nanoTime(); runTests(notifier); - long stop = System.nanoTime(); - reportTime("Testing modules", start, stop); notifier.fireTestRunFinished(new Result()); } - private void reportTime(String job, long start, long stop) { - System.out.println(job + ": " + ((stop-start)/1000_000) + "ms"); - System.out.flush(); - } - private void processIncomingModuleDescriptions(Description rootDesc) { int completed = 0; while (completed < numberOfWorkers) { @@ -146,7 +136,6 @@ private void processIncomingModuleDescriptions(Description rootDesc) { } } - private void startModuleTesters() { for (int i = 0; i < numberOfWorkers; i++) { new ModuleTester("JUnit Rascal Evaluator " + (i + 1)).start(); @@ -189,9 +178,9 @@ private void runTests(RunNotifier notifier) { public class ModuleTester extends Thread { - private GlobalEnvironment heap; private ModuleEnvironment root; + private PrintWriter stderr = new PrintWriter(System.err); private PrintWriter stdout = new PrintWriter(System.out); private Evaluator evaluator; @@ -224,7 +213,6 @@ private void runTests() { continue; } - TestEvaluator runner = new TestEvaluator(evaluator, trl); runner.test(mod.getDisplayName()); @@ -260,10 +248,10 @@ private void processModules() { evaluator.doImport(new NullRascalMonitor(), module); } catch (Throwable e) { - synchronized(stderr) { - stderr.println("Could not import " + module + " for testing..."); - stderr.println(e.getMessage()); - e.printStackTrace(stderr); + synchronized(stdout) { + evaluator.warning("Could not import " + module + " for testing...", null); + evaluator.warning(e.getMessage(), null); + e.printStackTrace(evaluator.getOutPrinter()); } // register a failing module to make sure we report failure later on. @@ -303,7 +291,8 @@ private void initializeEvaluator() { heap = new GlobalEnvironment(); root = heap.addModule(new ModuleEnvironment("___junit_test___", heap)); - evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, System.out, root, heap); + evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap); + evaluator.setMonitor(monitor); evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance()); evaluator.getConfiguration().setErrors(true); @@ -315,8 +304,8 @@ private void initializeEvaluator() { public class Listener implements ITestResultListener { private final PrintWriter stderr; private final Description module; - private final IRascalMonitor monitor; private String context = ""; + private final IRascalMonitor monitor; public Listener(Description module, PrintWriter stderr, IRascalMonitor monitor) { this.module = module; diff --git a/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java b/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java index 6bc3ca4049e..bbc998e3319 100644 --- a/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java +++ b/src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java @@ -172,7 +172,7 @@ public static List getRecursiveModuleList(ISourceLocation root, List