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

Parallel lock free testing, remove potential deadlocks, cache static data, go to descriptor via test #3752

Merged
merged 20 commits into from
Jun 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
84c9780
Implement fast parallel lock-free in-process testing for Java
KvanTTT Jun 21, 2022
e942e1a
Add final modifier to all static fields where it's possible
KvanTTT Jun 17, 2022
36b885c
Remove doubtful and not used static fields
KvanTTT Jun 17, 2022
4ccbb41
Fix potential deadlocks in Java runtime
KvanTTT Jun 17, 2022
dbce6b2
Unify C#, C++, Dart, Go, Python runtimes
KvanTTT Jun 19, 2022
8861ac4
Use AtomicInteger instead of int for static PredictionContext.globalN…
KvanTTT Jun 17, 2022
3c30268
Remove lock in Generator (now ANTLR tool is thread-safe)
KvanTTT Jun 17, 2022
7c5b3c2
Cache templates for codegen to static field, load only one time
KvanTTT Nov 26, 2021
f19cd67
Cache LeftRecursiveRules.stg to static field
KvanTTT Jun 18, 2022
6681a7a
Cache ANTLR error message templates to static field
KvanTTT Jun 18, 2022
93970f4
Cache runtime test templates to static field
KvanTTT Jun 18, 2022
1b9d77c
Clarify message of failed runtime tests
KvanTTT Jun 19, 2022
99fab5c
Pass testSourceUri to dynamicTest and to dynamicContainer for conveni…
KvanTTT Jun 20, 2022
8e6e1ed
Extract prepareGrammars method
KvanTTT Jun 20, 2022
2e8e3a8
Remove useless and outdated files
KvanTTT Jun 20, 2022
22cbf3c
Update pom.xml in runtime-testsuite
KvanTTT Jun 25, 2022
d287f1c
Use runtimePath instead of targetClassesPath for runtimes' sources
KvanTTT Jun 25, 2022
f235d33
Update doc
KvanTTT Jun 25, 2022
d40067d
Fix potential problems with concurrent access to hash maps
KvanTTT Jun 26, 2022
de255cc
Restore info about `mvn -Dtest=java.** test` in antlr-project-testing.md
KvanTTT Jun 26, 2022
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
28 changes: 18 additions & 10 deletions runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupString;
import org.stringtemplate.v4.StringRenderer;
import org.stringtemplate.v4.*;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -44,9 +42,9 @@
public abstract class RuntimeTests {
protected abstract RuntimeRunner createRuntimeRunner();

private final static StringRenderer rendered = new StringRenderer();

private final static HashMap<String, RuntimeTestDescriptor[]> testDescriptors = new HashMap<>();
private final static HashMap<String, STGroup> cachedTargetTemplates = new HashMap<>();
private final static StringRenderer rendered = new StringRenderer();

static {
File descriptorsDir = new File(Paths.get(RuntimeTestUtils.resourcePath.toString(), "org/antlr/v4/test/runtime/descriptors").toString());
Expand Down Expand Up @@ -120,10 +118,20 @@ private static void test(RuntimeTestDescriptor descriptor, RuntimeRunner runner)

FileUtils.mkdir(runner.getTempDirPath());

String sourceName = "org/antlr/v4/test/runtime/templates/" + targetName + ".test.stg";
String template = RuntimeTestUtils.getTextFromResource(sourceName);
STGroup targetTemplates = new STGroupString(sourceName, template, '<', '>');
targetTemplates.registerRenderer(String.class, rendered);
STGroup targetTemplates = cachedTargetTemplates.get(targetName);
if (targetTemplates == null) {
parrt marked this conversation as resolved.
Show resolved Hide resolved
synchronized (cachedTargetTemplates) {
targetTemplates = cachedTargetTemplates.get(targetName);
if (targetTemplates == null) {
ClassLoader classLoader = RuntimeTests.class.getClassLoader();
URL templates = classLoader.getResource("org/antlr/v4/test/runtime/templates/" + targetName + ".test.stg");
assert templates != null;
targetTemplates = new STGroupFile(templates, "UTF-8", '<', '>');
targetTemplates.registerRenderer(String.class, rendered);
cachedTargetTemplates.put(targetName, targetTemplates);
}
}
}

// write out any slave grammars
List<Pair<String, String>> slaveGrammars = descriptor.slaveGrammars;
Expand Down