Search in sources :

Example 6 with Constraint

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

the class TestSafePlace method launcher.

// @Test
public void launcher() throws Exception {
    SpecScanner specScanner = new SpecScanner();
    List<Constraint> l = specScanner.scan();
    TestScanner sc = new TestScanner(l);
    List<TestCampaign> campaigns = sc.test(TestSafePlace.class);
    // List<TestCampaign> campaigns = sc.testGroups("_resourceCapacity");
    if (campaigns.isEmpty()) {
        Assert.fail("Nothing to test");
    }
    campaigns.forEach(tc -> {
        // .setVerbosity(1);
        tc.schedulerParams().doRepair(false);
        tc.onDefect(DefectHooks.ignore);
        tc.limits().clear().tests(1000);
        System.out.println(tc.go());
    });
}
Also used : Constraint(org.btrplace.safeplace.spec.Constraint) SpecScanner(org.btrplace.safeplace.spec.SpecScanner)

Example 7 with Constraint

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

the class TestCase method fromJSON.

public static TestCase fromJSON(List<Constraint> cstrs, String c) throws ParseException, JSONConverterException {
    JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
    JSONObject o = (JSONObject) p.parse(new StringReader(c));
    String cId = o.getAsString("constraint");
    Optional<Constraint> opt = cstrs.stream().filter(x -> x.id().equals(cId)).findFirst();
    if (!opt.isPresent()) {
        throw new IllegalArgumentException("Unknown constraint '" + cId + "'");
    }
    Constraint cstr = opt.get();
    InstanceConverter ic = new InstanceConverter();
    ic.getConstraintsConverter().register(new ScheduleConverter());
    ReconfigurationPlanConverter rc = new ReconfigurationPlanConverter();
    Instance i = ic.fromJSON(o.getAsString("instance"));
    ReconfigurationPlan plan = rc.fromJSON(o.getAsString("plan"));
    TestCase tc = new TestCase(i, plan, cstr);
    List<Constant> l = new ArrayList<>();
    for (Object x : (JSONArray) o.get("args")) {
        l.add(Constant.fromJSON((JSONObject) x));
    }
    tc.args(l);
    if (cstr.isSatConstraint()) {
        tc.impl(cstr.instantiate(l.stream().map(x -> x.eval(null)).collect(Collectors.toList())));
    }
    if (tc.impl() != null) {
        tc.impl().setContinuous((Boolean) o.get("continuous"));
    }
    return tc;
}
Also used : Constant(org.btrplace.safeplace.spec.term.Constant) ModelView(org.btrplace.model.view.ModelView) JSONConverterException(org.btrplace.json.JSONConverterException) ReconfigurationPlanConverter(org.btrplace.json.plan.ReconfigurationPlanConverter) Collectors(java.util.stream.Collectors) InstanceConverter(org.btrplace.json.model.InstanceConverter) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) JSONParser(net.minidev.json.parser.JSONParser) Objects(java.util.Objects) Constraint(org.btrplace.safeplace.spec.Constraint) List(java.util.List) StringReader(java.io.StringReader) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) ParseException(net.minidev.json.parser.ParseException) ScheduleConverter(org.btrplace.safeplace.testing.verification.btrplace.ScheduleConverter) Optional(java.util.Optional) Instance(org.btrplace.model.Instance) Collections(java.util.Collections) SatConstraint(org.btrplace.model.constraint.SatConstraint) ScheduleConverter(org.btrplace.safeplace.testing.verification.btrplace.ScheduleConverter) Constraint(org.btrplace.safeplace.spec.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Instance(org.btrplace.model.Instance) Constant(org.btrplace.safeplace.spec.term.Constant) InstanceConverter(org.btrplace.json.model.InstanceConverter) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) StringReader(java.io.StringReader) ReconfigurationPlanConverter(org.btrplace.json.plan.ReconfigurationPlanConverter) JSONParser(net.minidev.json.parser.JSONParser) JSONObject(net.minidev.json.JSONObject)

Example 8 with Constraint

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

the class Validator method test.

@Override
public boolean test(TestCase o) {
    duration = -System.currentTimeMillis();
    try {
        for (Constraint c : cstrs) {
            TestCase tc = purge(o, c);
            TestCaseResult res = tester.test(tc);
            if (res.result() != Result.SUCCESS) {
                return false;
            }
        }
    } finally {
        duration += System.currentTimeMillis();
    }
    return true;
}
Also used : TestCaseResult(org.btrplace.safeplace.testing.TestCaseResult) Constraint(org.btrplace.safeplace.spec.Constraint) TestCase(org.btrplace.safeplace.testing.TestCase)

Example 9 with Constraint

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

the class DSN method specLength.

// @Test
public void specLength() throws Exception {
    SpecScanner sc = new SpecScanner();
    List<Constraint> l = sc.scan();
    System.out.println(l.stream().map(Constraint::pretty).collect(Collectors.joining("\n")));
    Path path = Paths.get(root, "inv.csv");
    String out = l.stream().map(c -> Integer.toString(c.proposition().toString().length())).collect(Collectors.joining("\n"));
    Files.write(path, out.getBytes());
    List<Integer> funcs = new ArrayList<>();
    List<Path> paths = Files.list(Paths.get("safeplace/src/main/java/org/btrplace/safeplace/spec/term/func")).filter(Files::isRegularFile).collect(Collectors.toList());
    for (Path p : paths) {
        try (InputStream in = Files.newInputStream(p)) {
            CompilationUnit cu = JavaParser.parse(in);
            new FunctionVisitor(funcs).visit(cu, null);
        }
    }
    path = Paths.get(root, "func.csv");
    out = funcs.stream().map(c -> Integer.toString(c)).collect(Collectors.joining("\n"));
    Files.write(path, out.getBytes());
}
Also used : Path(java.nio.file.Path) CSVReport(org.btrplace.safeplace.testing.reporting.CSVReport) java.util(java.util) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) Restriction(org.btrplace.safeplace.testing.fuzzer.Restriction) Constraint(org.btrplace.safeplace.spec.Constraint) Matcher(java.util.regex.Matcher) Assert(org.testng.Assert) CompilationUnit(com.github.javaparser.ast.CompilationUnit) SpecScanner(org.btrplace.safeplace.spec.SpecScanner) Path(java.nio.file.Path) SpecVerifier(org.btrplace.safeplace.testing.verification.spec.SpecVerifier) TestScanner(org.btrplace.safeplace.testing.TestScanner) Files(java.nio.file.Files) PrettyPrinterConfiguration(com.github.javaparser.printer.PrettyPrinterConfiguration) Verifier(org.btrplace.safeplace.testing.verification.Verifier) Collectors(java.util.stream.Collectors) Bench(org.btrplace.safeplace.testing.Bench) 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) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Constraint(org.btrplace.safeplace.spec.Constraint) InputStream(java.io.InputStream) SpecScanner(org.btrplace.safeplace.spec.SpecScanner)

Example 10 with Constraint

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

the class TestScannerTest method newScanner.

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

Aggregations

Constraint (org.btrplace.safeplace.spec.Constraint)10 SpecScanner (org.btrplace.safeplace.spec.SpecScanner)6 Path (java.nio.file.Path)4 Collectors (java.util.stream.Collectors)4 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 TestScanner (org.btrplace.safeplace.testing.TestScanner)3 JavaParser (com.github.javaparser.JavaParser)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.PrettyPrinterConfiguration)2 InputStream (java.io.InputStream)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 java.util (java.util)2 List (java.util.List)2 Optional (java.util.Optional)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2