Merge pull request #1366 from parrt/multi-threaded-tests

update doc, add lock so antlr used atomically in unit tests so we can run in parallel
This commit is contained in:
Terence Parr 2016-11-17 00:45:13 +01:00 committed by GitHub
commit c37848cfc5
12 changed files with 224 additions and 142 deletions

View File

@ -38,17 +38,24 @@ Checking connectivity... done.
$ cd antlr4
$ mvn compile
..
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.447 s]
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 3.113 s]
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 14.408 s]
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.276 s]
[INFO] ANTLR 4 Runtime Test Generator ..................... SUCCESS [ 0.773 s]
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 6.920 s]
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.432 s]
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 4.334 s]
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 1.686 s]
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.654 s]
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 0.096 s]
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 0.025 s]
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. SUCCESS [ 1.932 s]
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 0.018 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
...
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.324 s
[INFO] Finished at: 2016-11-16T13:49:38-08:00
[INFO] Final Memory: 42M/488M
[INFO] ------------------------------------------------------------------------
```
# Testing tool and targets
@ -81,38 +88,119 @@ antlr reports warnings from [-visitor, -Dlanguage=CSharp, -o, /var/folders/s1/h3
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.462 s]
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 9.163 s]
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 3.683 s]
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.897 s]
[INFO] ANTLR 4 Runtime Test Generator ..................... SUCCESS [07:11 min]
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 16.694 s]
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.445 s]
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 3.392 s]
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 1.373 s]
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.519 s]
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 0.086 s]
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 0.014 s]
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. SUCCESS [06:39 min]
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 6.922 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:43 min
...
[INFO] Total time: 06:53 min
[INFO] Finished at: 2016-11-16T15:36:56-08:00
[INFO] Final Memory: 44M/458M
[INFO] ------------------------------------------------------------------------
```
You should see these jars (building 4.5.2-SNAPSHOT):
Note: That is actually result of running the much faster:
`mvn -Dparallel=methods -DthreadCount=4 install`
You should see these jars (when building 4.6-SNAPSHOT):
```bash
/Users/parrt/.m2/repository/org/antlr $ find antlr4* -name '*.jar'
antlr4/4.5/antlr4-4.5.jar
antlr4/4.5.2-SNAPSHOT/antlr4-4.5.2-SNAPSHOT-tests.jar
antlr4/4.5.2-SNAPSHOT/antlr4-4.5.2-SNAPSHOT.jar
antlr4-maven-plugin/4.5/antlr4-maven-plugin-4.5.jar
antlr4-maven-plugin/4.5.2-SNAPSHOT/antlr4-maven-plugin-4.5.2-SNAPSHOT.jar
antlr4-runtime/4.5/antlr4-runtime-4.5.jar
antlr4-runtime/4.5.2-SNAPSHOT/antlr4-runtime-4.5.2-SNAPSHOT.jar
antlr4-runtime-testsuite/4.5.2-SNAPSHOT/antlr4-runtime-testsuite-4.5.2-SNAPSHOT-tests.jar
antlr4-runtime-testsuite/4.5.2-SNAPSHOT/antlr4-runtime-testsuite-4.5.2-SNAPSHOT.jar
antlr4-tool-testsuite/4.5.2-SNAPSHOT/antlr4-tool-testsuite-4.5.2-SNAPSHOT.jar
antlr4-maven-plugin/4.6-SNAPSHOT/antlr4-maven-plugin-4.6-SNAPSHOT.jar
antlr4-runtime-test-annotation-processors/4.6-SNAPSHOT/antlr4-runtime-test-annotation-processors-4.6-SNAPSHOT.jar
antlr4-runtime-test-annotations/4.6-SNAPSHOT/antlr4-runtime-test-annotations-4.6-SNAPSHOT.jar
antlr4-runtime-testsuite/4.6-SNAPSHOT/antlr4-runtime-testsuite-4.6-SNAPSHOT-tests.jar
antlr4-runtime-testsuite/4.6-SNAPSHOT/antlr4-runtime-testsuite-4.6-SNAPSHOT.jar
antlr4-runtime/4.6-SNAPSHOT/antlr4-runtime-4.6-SNAPSHOT.jar
antlr4-tool-testsuite/4.6-SNAPSHOT/antlr4-tool-testsuite-4.6-SNAPSHOT.jar
antlr4/4.6-SNAPSHOT/antlr4-4.6-SNAPSHOT-tests.jar
antlr4/4.6-SNAPSHOT/antlr4-4.6-SNAPSHOT.jar
```
Note that ANTLR is written in itself, which is why maven downloads antlr4-4.5.jar for boostrapping 4.5.2-SNAPSHOT purposes.
Note that ANTLR is written in itself, which is why maven downloads antlr4-4.5.jar for boostrapping 4.6-SNAPSHOT purposes.
## Running test subsets
### Run one test group across targets
```bash
$ mvn -Dtest=TestParserExec test
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.antlr.v4.test.runtime.cpp.TestParserExec
...
Tests run: 32, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 114.283 sec
Running org.antlr.v4.test.runtime.csharp.TestParserExec
...
```
Or run all lexer related tests:
```
$ mvn -Dtest=Test*Lexer* test
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.antlr.v4.test.runtime.cpp.TestCompositeLexers
...
```
### Run all tests for a single target
```bash
$ mvn -Dtest=java.* test
...
```
Or run all lexer related tests in Java target only:
```bash
$ mvn -Dtest=java.*Lexer* test
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.antlr.v4.test.runtime.java.TestCompositeLexers
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.277 sec
Running org.antlr.v4.test.runtime.java.TestLexerErrors
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.376 sec
Running org.antlr.v4.test.runtime.java.TestLexerExec
Tests run: 38, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.07 sec
Running org.antlr.v4.test.runtime.java.TestSemPredEvalLexer
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.255 sec
Results :
Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
```
## Testing in parallel
Use this to run tests in parallel:
```bash
$ mvn -Dparallel=methods -DthreadCount=4 test
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
...
```
This can be combined with other `-D` above.
## Building without testing
To build without running the tests (saves a lot of time), do this:
```bash

View File

@ -125,10 +125,11 @@ public abstract class BaseRuntimeTest {
descriptor.getInput(),
descriptor.showDiagnosticErrors()
);
if(delegate instanceof RuntimeTestAssert) {
if ( delegate instanceof RuntimeTestAssert ) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
} else {
}
else {
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
}
@ -165,11 +166,12 @@ public abstract class BaseRuntimeTest {
grammar = grammarST.render();
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
if(delegate instanceof RuntimeTestAssert) {
if ( delegate instanceof RuntimeTestAssert ) {
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
((RuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
} else {
}
else {
assertEquals(descriptor.getOutput(), found);
assertEquals(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
assertEquals(descriptor.getErrors(), delegate.getParseErrors());

View File

@ -1,5 +1,8 @@
package org.antlr.v4.test.runtime;
/** This interface acts like a tag on a Base*Test class that wants
* to use its own assertEquals() instead of jUnit's.
*/
public interface RuntimeTestAssert {
void assertEqualStrings(String expected, String actual);
}

View File

@ -1,18 +0,0 @@
package org.antlr.v4.test.runtime;
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(ParserExecDescriptors.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}

View File

@ -93,6 +93,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -124,10 +125,13 @@ public class BaseCppTest implements RuntimeTestSupport {
// new output dir for each test
String propName = getPropertyPrefix() + "-test-dir";
String prop = System.getProperty(propName);
if(prop!=null && prop.length()>0)
if(prop!=null && prop.length()>0) {
tmpdir = prop;
else
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
else {
tmpdir = new File(System.getProperty("java.io.tmpdir"),
getClass().getSimpleName()+"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
antlrToolErrors = new StringBuilder();
}
@ -363,7 +367,9 @@ public class BaseCppTest implements RuntimeTestSupport {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {
@ -645,7 +651,7 @@ public class BaseCppTest implements RuntimeTestSupport {
return true;
}
static boolean runtimeBuiltOnce = false;
static Boolean runtimeBuiltOnce = false;
public String execModule(String fileName) {
String runtimePath = locateRuntime();
@ -654,22 +660,24 @@ public class BaseCppTest implements RuntimeTestSupport {
String inputPath = new File(new File(tmpdir), "input").getAbsolutePath();
// Build runtime using cmake once.
if (!runtimeBuiltOnce) {
try {
String command[] = { "clang++", "--version" };
String output = runCommand(command, tmpdir, "printing compiler version");
System.out.println("Compiler version is: " + output);
}
catch (Exception e) {
System.err.println("Can't get compiler version");
}
synchronized (runtimeBuiltOnce) {
if ( !runtimeBuiltOnce ) {
try {
String command[] = {"clang++", "--version"};
String output = runCommand(command, tmpdir, "printing compiler version");
System.out.println("Compiler version is: "+output);
}
catch (Exception e) {
System.err.println("Can't get compiler version");
}
runtimeBuiltOnce = true;
if (!buildRuntime()) {
System.out.println("C++ runtime build failed\n");
return null;
runtimeBuiltOnce = true;
if ( !buildRuntime() ) {
System.out.println("C++ runtime build failed\n");
return null;
}
System.out.println("C++ runtime build succeeded\n");
}
System.out.println("C++ runtime build succeeded\n");
}
// Create symlink to the runtime. Currently only used on OSX.

View File

@ -57,7 +57,6 @@ import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@ -75,6 +74,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -162,7 +162,7 @@ public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
public void testSetUp() throws Exception {
if (CREATE_PER_TEST_DIRECTORIES) {
// new output dir for each test
String testDirectory = getClass().getSimpleName() + "-" + System.currentTimeMillis();
String testDirectory = getClass().getSimpleName() + "-"+Thread.currentThread().getName()+ "-" + System.currentTimeMillis();
tmpdir = new File(BASE_TEST_DIR, testDirectory).getAbsolutePath();
}
else {
@ -265,7 +265,9 @@ public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {
@ -908,7 +910,7 @@ public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
public void assertEqualStrings(String a, String b) {
assertEquals(a, b);
}
protected static void assertEquals(String a, String b) {
a = absorbExpectedDifferences(a);
b = absorbActualDifferences(b);
@ -928,19 +930,20 @@ public class BaseCSharpTest implements RuntimeTestSupport, RuntimeTestAssert {
a = a.replaceAll("\\^", "");
// work around the algo difference for full context
a = stripOutUnwantedLinesWith(a, "reportAttemptingFullContext","reportContextSensitivity", "reportAmbiguity");
if(a.isEmpty())
if(a.isEmpty()) {
a = null;
}
return a;
}
private static String absorbActualDifferences(String a) {
if(a==null)
return a;
if(a==null) return a;
// work around the algo difference for full context
// work around the algo difference for semantic predicates
a = stripOutUnwantedLinesWith(a, "reportContextSensitivity","eval=false");
if(a.isEmpty())
if(a.isEmpty()) {
a = null;
}
return a;
}

View File

@ -95,13 +95,10 @@ import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertArrayEquals;
public class BaseGoTest implements RuntimeTestSupport {
// -J-Dorg.antlr.v4.test.BaseTest.level=FINE
// private static final Logger LOGGER =
// Logger.getLogger(BaseTest.class.getName());
public File overall_tmpdir = null;
public File tmpdir = null; // this is where the parser package is stored, typically inside the tmpdir
private static File tmpGopath = null;
@ -209,11 +206,14 @@ public class BaseGoTest implements RuntimeTestSupport {
public void testSetUp() throws Exception {
// new output dir for each test
String prop = System.getProperty("antlr-go-test-dir");
if (prop != null && prop.length() > 0)
if (prop != null && prop.length() > 0) {
overall_tmpdir = new File(prop);
else
}
else {
String threadName = Thread.currentThread().getName();
overall_tmpdir = new File(System.getProperty("java.io.tmpdir"),
getClass().getSimpleName() + "-" + System.currentTimeMillis());
getClass().getSimpleName()+"-"+threadName+"-"+System.currentTimeMillis());
}
if ( overall_tmpdir.exists())
this.eraseDirectory(overall_tmpdir);
@ -348,7 +348,9 @@ public class BaseGoTest implements RuntimeTestSupport {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {

View File

@ -88,7 +88,6 @@ import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@ -100,8 +99,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
@ -110,9 +107,6 @@ import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertArrayEquals;
public class BaseJavaTest implements RuntimeTestSupport {
// -J-Dorg.antlr.v4.test.BaseTest.level=FINE
private static final Logger LOGGER = Logger.getLogger(BaseJavaTest.class.getName());
public static final String newline = System.getProperty("line.separator");
public static final String pathSep = System.getProperty("path.separator");
@ -143,7 +137,7 @@ public class BaseJavaTest implements RuntimeTestSupport {
* directories for all tests which completed successfully, and preserving
* the directories for tests which failed.</p>
*/
public static final boolean PRESERVE_TEST_DIR = Boolean.parseBoolean(System.getProperty("antlr.preserve-test-dir"));
public static final boolean PRESERVE_TEST_DIR = true; //Boolean.parseBoolean(System.getProperty("antlr.preserve-test-dir"));
/**
* The base test directory is the directory where generated files get placed
@ -204,9 +198,12 @@ public class BaseJavaTest implements RuntimeTestSupport {
@Override
public void testSetUp() throws Exception {
// STGroup.verbose = true;
// System.err.println("testSetUp "+Thread.currentThread().getName());
if ( CREATE_PER_TEST_DIRECTORIES ) {
// new output dir for each test
String testDirectory = getClass().getSimpleName()+"-"+System.currentTimeMillis();
String threadName = Thread.currentThread().getName();
String testDirectory = getClass().getSimpleName()+"-"+threadName+"-"+System.nanoTime();
tmpdir = new File(BASE_TEST_DIR, testDirectory).getAbsolutePath();
}
else {
@ -250,11 +247,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
return tool;
}
protected Tool newTool() {
org.antlr.v4.Tool tool = new Tool(new String[]{"-o", tmpdir});
return tool;
}
protected ATN createATN(Grammar g, boolean useSerializer) {
if ( g.atn==null ) {
semanticProcess(g);
@ -507,7 +499,9 @@ public class BaseJavaTest implements RuntimeTestSupport {
if ( defaultListener ) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i<equeue.errors.size(); i++) {
@ -563,7 +557,8 @@ public class BaseJavaTest implements RuntimeTestSupport {
public ParseTree execParser(String startRuleName, String input,
String parserName, String lexerName)
throws Exception {
throws Exception
{
Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
Parser parser = pl.a;
return execStartRule(startRuleName, parser);
@ -635,6 +630,9 @@ public class BaseJavaTest implements RuntimeTestSupport {
listenerName, visitorName, startRuleName, input, showDiagnosticErrors, false);
}
/** ANTLR isn't thread-safe to process grammars so we use a global lock for testing */
public static final Object antlrLock = new Object();
public String execParser(String grammarFileName,
String grammarStr,
String parserName,
@ -647,10 +645,10 @@ public class BaseJavaTest implements RuntimeTestSupport {
boolean profile)
{
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
grammarStr,
parserName,
lexerName,
"-visitor");
grammarStr,
parserName,
lexerName,
"-visitor");
assertTrue(success);
writeFile(tmpdir, "input", input);
return rawExecRecognizer(parserName,
@ -771,32 +769,8 @@ public class BaseJavaTest implements RuntimeTestSupport {
this.stderrDuringParse = stderrVacuum.toString();
}
return output;
} catch (MalformedURLException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (InterruptedException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (IllegalAccessException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (IllegalArgumentException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (InvocationTargetException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (NoSuchMethodException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (SecurityException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}

View File

@ -97,6 +97,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -137,10 +138,12 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
public void testSetUp() throws Exception {
// new output dir for each test
String prop = System.getProperty("antlr-javascript-test-dir");
if(prop!=null && prop.length()>0)
if(prop!=null && prop.length()>0) {
httpdir = prop;
else
httpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
else {
httpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
File dir = new File(httpdir);
if(dir.exists())
this.eraseFiles(dir);
@ -291,7 +294,9 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {

View File

@ -89,6 +89,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -118,12 +119,14 @@ public class BaseNodeTest implements RuntimeTestSupport {
public void testSetUp() throws Exception {
// new output dir for each test
String prop = System.getProperty("antlr-javascript-test-dir");
if (prop != null && prop.length() > 0)
if (prop != null && prop.length() > 0) {
tmpdir = prop;
else
}
else {
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass()
.getSimpleName() + "-" + System.currentTimeMillis())
.getAbsolutePath();
.getSimpleName()+"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis())
.getAbsolutePath();
}
File dir = new File(tmpdir);
if (dir.exists())
this.eraseFiles(dir);
@ -281,7 +284,9 @@ public class BaseNodeTest implements RuntimeTestSupport {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {

View File

@ -95,6 +95,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.antlr.v4.test.runtime.java.BaseJavaTest.antlrLock;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -138,10 +139,13 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
// new output dir for each test
String propName = getPropertyPrefix() + "-test-dir";
String prop = System.getProperty(propName);
if(prop!=null && prop.length()>0)
if(prop!=null && prop.length()>0) {
tmpdir = prop;
else
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
else {
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+
"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis()).getAbsolutePath();
}
antlrToolErrors = new StringBuilder();
}
@ -375,7 +379,9 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
if (defaultListener) {
antlr.addListener(new DefaultToolListener(antlr));
}
antlr.processGrammarsOnCommandLine();
synchronized (antlrLock) {
antlr.processGrammarsOnCommandLine();
}
if ( !defaultListener && !equeue.errors.isEmpty() ) {
for (int i = 0; i < equeue.errors.size(); i++) {

View File

@ -54,6 +54,7 @@
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
@ -73,6 +74,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/Test*.java</include>
</includes>
<systemPropertyVariables>
<antlr-python2-runtime>../../antlr4-python2/src</antlr-python2-runtime>
<antlr-python3-runtime>../../antlr4-python3/src</antlr-python3-runtime>