Search in sources :

Example 1 with Constraint

use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.

the class SpecVerifier method fillArguments.

public void fillArguments(Context mo, TestCase tc) {
    Constraint c = tc.constraint();
    List<Constant> values = tc.args();
    // Check signature
    if (values.size() != c.args().size()) {
        throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
    }
    for (int i = 0; i < values.size(); i++) {
        UserVar<?> var = c.args().get(i);
        Type t = values.get(i).type();
        if (!var.type().equals(t)) {
            throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
        }
        mo.setValue(var.label(), values.get(i).eval(mo));
    }
}
Also used : Type(org.btrplace.safeplace.spec.type.Type) Constraint(org.btrplace.safeplace.spec.Constraint) Constant(org.btrplace.safeplace.spec.term.Constant) Constraint(org.btrplace.safeplace.spec.Constraint)

Example 2 with Constraint

use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.

the class DSN method newScanner.

public TestScanner newScanner() throws Exception {
    SpecScanner specScanner = new SpecScanner();
    List<Constraint> l = specScanner.scan();
    Bench.mode = Bench.Mode.REPLAY;
    return new TestScanner(l);
}
Also used : Constraint(org.btrplace.safeplace.spec.Constraint) TestScanner(org.btrplace.safeplace.testing.TestScanner) SpecScanner(org.btrplace.safeplace.spec.SpecScanner)

Example 3 with Constraint

use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.

the class DSN method funcFrequency.

// @Test
public void funcFrequency() throws Exception {
    SpecScanner sc = new SpecScanner();
    List<Constraint> l = sc.scan();
    Pattern p = Pattern.compile("([a-zA-Z]+\\()+");
    Map<String, Integer> map = new HashMap<>();
    for (Constraint c : l) {
        String prop = c.proposition().toString();
        Matcher m = p.matcher(prop);
        System.out.println(prop);
        int start = 0;
        while (m.find(start)) {
            String name = prop.substring(m.start(), m.end() - 1);
            if (Character.isLowerCase(name.charAt(0))) {
                if (!map.containsKey(name)) {
                    map.put(name, 1);
                } else {
                    map.put(name, map.get(name) + 1);
                }
            }
            System.out.println("\t" + prop.substring(m.start(), m.end() - 1));
            start = m.end();
        }
    }
    System.out.println(map);
    Path out = Paths.get(root, "func-freq.csv");
    Files.deleteIfExists(out);
    String cnt = "name;freq\n" + map.entrySet().stream().map(e -> e.getKey() + ";" + e.getValue() + "\n").collect(Collectors.joining());
    Files.write(out, cnt.getBytes());
}
Also used : Path(java.nio.file.Path) Pattern(java.util.regex.Pattern) Constraint(org.btrplace.safeplace.spec.Constraint) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) SpecScanner(org.btrplace.safeplace.spec.SpecScanner) Constraint(org.btrplace.safeplace.spec.Constraint)

Example 4 with Constraint

use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.

the class DefaultTestCampaign method check.

@Override
public ConfigurableFuzzer check(String c) {
    String lower = c.toLowerCase();
    Optional<Constraint> cstr = cstrs.stream().filter(x -> lower.equalsIgnoreCase(x.id())).findFirst();
    if (!cstr.isPresent()) {
        throw new IllegalArgumentException("No specification for constraint '" + c + "'");
    }
    List<Constraint> pre = cores.stream().filter(x -> !lower.equalsIgnoreCase(x.id())).collect(Collectors.toList());
    ConfigurableFuzzer f = new DefaultFuzzer(this, cstr.get(), pre);
    tcFuzzer = f;
    return f;
}
Also used : Fuzzer(org.btrplace.safeplace.testing.fuzzer.Fuzzer) VerifierResult(org.btrplace.safeplace.testing.verification.VerifierResult) ConfigurableFuzzer(org.btrplace.safeplace.testing.fuzzer.ConfigurableFuzzer) IOException(java.io.IOException) Verifier(org.btrplace.safeplace.testing.verification.Verifier) Schedule(org.btrplace.safeplace.testing.verification.btrplace.Schedule) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Consumer(java.util.function.Consumer) Constraint(org.btrplace.safeplace.spec.Constraint) Limits(org.btrplace.safeplace.testing.limit.Limits) List(java.util.List) CSchedule(org.btrplace.safeplace.testing.verification.btrplace.CSchedule) Replay(org.btrplace.safeplace.testing.fuzzer.Replay) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Optional(java.util.Optional) DefaultFuzzer(org.btrplace.safeplace.testing.fuzzer.DefaultFuzzer) Counting(org.btrplace.safeplace.testing.reporting.Counting) Report(org.btrplace.safeplace.testing.reporting.Report) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Path(java.nio.file.Path) SatConstraint(org.btrplace.model.constraint.SatConstraint) SpecVerifier(org.btrplace.safeplace.testing.verification.spec.SpecVerifier) DefaultFuzzer(org.btrplace.safeplace.testing.fuzzer.DefaultFuzzer) Constraint(org.btrplace.safeplace.spec.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) ConfigurableFuzzer(org.btrplace.safeplace.testing.fuzzer.ConfigurableFuzzer)

Example 5 with Constraint

use of org.btrplace.safeplace.spec.Constraint in project scheduler by btrplace.

the class DSN method testSloc.

// @Test
// Extract the number of line of codes of tests
public void testSloc() throws Exception {
    // Parse the legacy unit tests
    List<Integer> unitTests = new ArrayList<>();
    List<Path> paths = Files.list(Paths.get("choco/src/test/java/org/btrplace/scheduler/choco/constraint/")).filter(Files::isRegularFile).collect(Collectors.toList());
    for (Path p : paths) {
        try (InputStream in = Files.newInputStream(p)) {
            ParseResult<CompilationUnit> cu = new JavaParser().parse(in);
            new UnitTestsVisitor(unitTests).visit(cu.getResult().get(), null);
        }
    }
    // Parse the new unit tests
    List<Integer> safeTests = new ArrayList<>();
    try (InputStream in = Files.newInputStream(Paths.get("safeplace/src/test/java/org/btrplace/safeplace/testing/TestSafePlace.java"))) {
        ParseResult<CompilationUnit> cu = new JavaParser().parse(in);
        new SafeplaceTestsVisitor(safeTests).visit(cu.getResult().get(), null);
    }
    String sb = "testing;sloc\n" + unitTests.stream().map(i -> "btrPlace;" + i).collect(Collectors.joining("\n", "", "\n")) + safeTests.stream().map(i -> "safePlace;" + i).collect(Collectors.joining("\n", "", "\n"));
    Path path = Paths.get(root, "sloc.csv");
    Files.write(path, sb.getBytes());
}
Also used : Path(java.nio.file.Path) CompilationUnit(com.github.javaparser.ast.CompilationUnit) CSVReport(org.btrplace.safeplace.testing.reporting.CSVReport) PrettyPrinterConfiguration(com.github.javaparser.printer.configuration.PrettyPrinterConfiguration) ParseResult(com.github.javaparser.ParseResult) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Restriction(org.btrplace.safeplace.testing.fuzzer.Restriction) Constraint(org.btrplace.safeplace.spec.Constraint) Matcher(java.util.regex.Matcher) Assert(org.testng.Assert) Map(java.util.Map) CompilationUnit(com.github.javaparser.ast.CompilationUnit) SpecScanner(org.btrplace.safeplace.spec.SpecScanner) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) SpecVerifier(org.btrplace.safeplace.testing.verification.spec.SpecVerifier) TestScanner(org.btrplace.safeplace.testing.TestScanner) Files(java.nio.file.Files) Verifier(org.btrplace.safeplace.testing.verification.Verifier) Collectors(java.util.stream.Collectors) Bench(org.btrplace.safeplace.testing.Bench) List(java.util.List) StoredReport(org.btrplace.safeplace.testing.reporting.StoredReport) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Paths(java.nio.file.Paths) Result(org.btrplace.safeplace.testing.Result) TestCampaign(org.btrplace.safeplace.testing.TestCampaign) Pattern(java.util.regex.Pattern) CheckerVerifier(org.btrplace.safeplace.testing.verification.btrplace.CheckerVerifier) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Aggregations

Constraint (org.btrplace.safeplace.spec.Constraint)10 SpecScanner (org.btrplace.safeplace.spec.SpecScanner)6 Path (java.nio.file.Path)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 JavaParser (com.github.javaparser.JavaParser)2 ParseResult (com.github.javaparser.ParseResult)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)2 VoidVisitorAdapter (com.github.javaparser.ast.visitor.VoidVisitorAdapter)2 PrettyPrinterConfiguration (com.github.javaparser.printer.configuration.PrettyPrinterConfiguration)2 InputStream (java.io.InputStream)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 EnumSet (java.util.EnumSet)2