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));
}
}
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);
}
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());
}
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;
}
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());
}
Aggregations