84 lines
3.9 KiB
Python
84 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Qualify real NeitzelLib preview sessions on classpath and named module path."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--target-java-home", required=True)
|
|
args = parser.parse_args()
|
|
java_home = Path(args.target_java_home).resolve()
|
|
env = dict(os.environ, JAVA_HOME=str(java_home))
|
|
output = ROOT / "designer-target-tools/target/preview-fixtures"
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
results = []
|
|
|
|
|
|
def run(label, command, timeout=180):
|
|
result = subprocess.run([str(x) for x in command], env=env, cwd=ROOT,
|
|
capture_output=True, text=True, timeout=timeout)
|
|
log = result.stdout + result.stderr
|
|
(output / (label + ".log")).write_text(log)
|
|
if result.returncode:
|
|
raise RuntimeError(label + "\n" + log[-12000:])
|
|
return log
|
|
|
|
|
|
def build(path, label):
|
|
run(label, [ROOT / "mvnw", "-B", "-ntp", "-f", path / "pom.xml", "package",
|
|
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:build-classpath",
|
|
"-DincludeScope=test", "-Dmdep.outputFile=target/runtime.txt"])
|
|
|
|
|
|
def launch(path, arrangement, mode, label):
|
|
if arrangement == "classpath":
|
|
target = path / "app/target"
|
|
cp = os.pathsep.join([str(target / "test-classes"), str(target / "classes"),
|
|
(target / "runtime.txt").read_text().strip()])
|
|
command = ["-cp", cp, "fixture.checks.PreviewChecks"]
|
|
else:
|
|
target = path / "checks/target"
|
|
cp = str(target / "checks-modulepath-1.jar") + os.pathsep + (target / "runtime.txt").read_text().strip()
|
|
command = ["--module-path", cp, "--add-modules", "ALL-MODULE-PATH",
|
|
"-m", "fixture.checks/fixture.checks.PreviewChecks"]
|
|
log = run(label, [java_home / "bin/java", *command, mode], timeout=30)
|
|
match = re.search(r"PASS " + re.escape(mode) + r" (\d+)", log)
|
|
assert match, log
|
|
results.append({"scenario": label, "checks": int(match[1])})
|
|
print(label + ": " + match[0], flush=True)
|
|
return log
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="designer-preview-") as temp:
|
|
for arrangement in ("classpath", "modulepath"):
|
|
path = Path(temp) / arrangement
|
|
shutil.copytree(ROOT / "integration-fixtures/preview" / arrangement, path,
|
|
ignore=shutil.ignore_patterns("target"))
|
|
build(path, arrangement + "-build")
|
|
first = None
|
|
for mode in ("discovery", "standard", "async", "timeout", "cancel",
|
|
"readiness-failure", "wrong-model", "invalid-attribute",
|
|
"cleanup-failure", "factory-failure", "full", "full-empty", "card", "unstable"):
|
|
log = launch(path, arrangement, mode, arrangement + "-" + mode)
|
|
if mode == "standard":
|
|
first = re.search(r"SESSION (\S+) models=1", log)[1]
|
|
repeat = launch(path, arrangement, "standard", arrangement + "-fresh-process")
|
|
assert first != re.search(r"SESSION (\S+) models=1", repeat)[1], "Service identity reused"
|
|
if arrangement == "modulepath":
|
|
descriptor = path / "app/src/main/java/module-info.java"
|
|
original = descriptor.read_text()
|
|
for mode, declaration in (("missing-components", "opens fixture.components;"),
|
|
("missing-model", "opens fixture.model to fx;")):
|
|
descriptor.write_text(re.sub(r"\s+".join(map(re.escape, declaration.split())), "", original))
|
|
build(path, mode + "-build")
|
|
launch(path, arrangement, mode, mode)
|
|
descriptor.write_text(original)
|
|
(output / "results.json").write_text(json.dumps(results, indent=2) + "\n")
|
|
print(f"PASS {len(results)} target processes, {sum(r['checks'] for r in results)} fixture checks")
|