use of org.btrplace.safeplace.testing.TestCase in project scheduler by btrplace.
the class DefaultFuzzer method get.
@Override
public TestCase get() {
ReconfigurationPlan p;
fuzzingDuration = -System.currentTimeMillis();
lastValidationDuration = 0;
iterations = 0;
TestCase tc;
do {
lastValidationDuration += predicates.lastDuration();
p = fuzzer.get();
tc = new TestCase(InstanceConverter.toInstance(p), p, cstr);
iterations++;
if (iterations > 10000) {
// We abandon the fuzzing stage. Too hard to get a validation.
return null;
}
} while (!predicates.test(tc));
lastValidationDuration += predicates.lastDuration();
List<Constant> specArgs = new ArrayList<>();
for (UserVar<?> v : cstr.args()) {
Domain<?> d = domain(v, p.getOrigin());
Object o = v.pick(d);
specArgs.add(new Constant(o, v.type()));
}
tc.args(specArgs);
if (cstr.isSatConstraint()) {
SatConstraint impl = cstr.instantiate(specArgs.stream().map(c -> c.eval(null)).collect(Collectors.toList()));
tc.instance().getSatConstraints().add(impl);
fuzzRestriction(impl);
tc.impl(impl);
}
fuzzingDuration += System.currentTimeMillis();
store(tc);
return tc;
}
use of org.btrplace.safeplace.testing.TestCase in project scheduler by btrplace.
the class Replay method get.
@Override
public TestCase get() {
try {
String json = in.readLine();
if (json == null) {
return null;
}
TestCase tc = TestCase.fromJSON(constraints, json);
if (restriction.size() == 1) {
if (restriction.contains(Restriction.CONTINUOUS) && !tc.impl().setContinuous(true)) {
throw new IllegalArgumentException("Cannot be CONTINUOUS");
} else if (!tc.impl().setContinuous(false)) {
throw new IllegalArgumentException("Cannot be DISCRETE");
}
}
return tc;
} catch (IOException | ParseException | JSONConverterException e) {
throw new IllegalArgumentException(e);
}
}
use of org.btrplace.safeplace.testing.TestCase 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;
}
Aggregations