use of com.dat3m.dartagnan.witness.WitnessGraph in project Dat3M by hernanponcedeleon.
the class Dartagnan method main.
public static void main(String[] args) throws Exception {
if (Arrays.asList(args).contains("--help")) {
collectOptions();
return;
}
CreateGitInfo();
String[] argKeyword = Arrays.stream(args).filter(s -> s.startsWith("-")).toArray(String[]::new);
// TODO: We don't parse configs yet
Configuration config = Configuration.fromCmdLineArguments(argKeyword);
Dartagnan o = new Dartagnan(config);
if (Arrays.stream(args).noneMatch(a -> supportedFormats.stream().anyMatch(a::endsWith))) {
throw new IllegalArgumentException("Input program not given or format not recognized");
}
// get() is guaranteed to success
File fileProgram = new File(Arrays.stream(args).filter(a -> supportedFormats.stream().anyMatch(a::endsWith)).findFirst().get());
logger.info("Program path: " + fileProgram);
if (Arrays.stream(args).noneMatch(a -> a.endsWith(".cat"))) {
throw new IllegalArgumentException("CAT model not given or format not recognized");
}
// get() is guaranteed to success
File fileModel = new File(Arrays.stream(args).filter(a -> a.endsWith(".cat")).findFirst().get());
logger.info("CAT file path: " + fileModel);
Wmm mcm = new ParserCat().parse(fileModel);
Program p = new ProgramParser().parse(fileProgram);
EnumSet<Property> properties = o.getProperty();
WitnessGraph witness = new WitnessGraph();
if (o.runValidator()) {
logger.info("Witness path: " + o.getWitnessPath());
witness = new ParserWitness().parse(new File(o.getWitnessPath()));
}
VerificationTask task = VerificationTask.builder().withConfig(config).withWitness(witness).build(p, mcm, properties);
ShutdownManager sdm = ShutdownManager.create();
Thread t = new Thread(() -> {
try {
if (o.hasTimeout()) {
// Converts timeout from secs to millisecs
Thread.sleep(1000L * o.getTimeout());
sdm.requestShutdown("Shutdown Request");
logger.warn("Shutdown Request");
}
} catch (InterruptedException e) {
// Verification ended, nothing to be done.
}
});
try {
t.start();
Configuration solverConfig = Configuration.builder().setOption(PHANTOM_REFERENCES, valueOf(o.usePhantomReferences())).build();
try (SolverContext ctx = SolverContextFactory.createSolverContext(solverConfig, BasicLogManager.create(solverConfig), sdm.getNotifier(), o.getSolver());
ProverEnvironment prover = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
Result result = UNKNOWN;
if (properties.contains(RACES)) {
if (properties.size() > 1) {
System.out.println("Data race detection cannot be combined with other properties");
System.exit(1);
}
result = DataRaceSolver.run(ctx, prover, task);
} else {
// Property is either LIVENESS and/or REACHABILITY
switch(o.getMethod()) {
case TWO:
try (ProverEnvironment prover2 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
result = TwoSolvers.run(ctx, prover, prover2, task);
}
break;
case INCREMENTAL:
result = IncrementalSolver.run(ctx, prover, task);
break;
case ASSUME:
result = AssumeSolver.run(ctx, prover, task);
break;
case CAAT:
result = RefinementSolver.run(ctx, prover, RefinementTask.fromVerificationTaskWithDefaultBaselineWMM(task));
break;
}
}
// Verification ended, we can interrupt the timeout Thread
t.interrupt();
if (result.equals(FAIL) && o.generateGraphviz()) {
ExecutionModel m = new ExecutionModel(task);
m.initialize(prover.getModel(), ctx);
String name = task.getProgram().getName().substring(0, task.getProgram().getName().lastIndexOf('.'));
generateGraphvizFile(m, 1, (x, y) -> true, System.getenv("DAT3M_HOME") + "/output/", name);
}
if (p.getFormat().equals(SourceLanguage.LITMUS)) {
if (p.getAssFilter() != null) {
System.out.println("Filter " + (p.getAssFilter()));
}
System.out.println("Condition " + p.getAss().toStringWithType());
System.out.println(result == FAIL ? "Ok" : "No");
} else {
if (result == FAIL) {
if (TRUE.equals(prover.getModel().evaluate(REACHABILITY.getSMTVariable(ctx)))) {
System.out.println("Safety violation found");
}
if (TRUE.equals(prover.getModel().evaluate(LIVENESS.getSMTVariable(ctx)))) {
System.out.println("Liveness violation found");
}
}
System.out.println(result);
}
try {
WitnessBuilder w = new WitnessBuilder(task, ctx, prover, result);
// and if we are not doing witness validation
if (properties.contains(REACHABILITY) && w.canBeBuilt() && !o.runValidator()) {
w.build().write();
}
} catch (InvalidConfigurationException e) {
logger.warn(e.getMessage());
}
}
} catch (InterruptedException e) {
logger.warn("Timeout elapsed. The SMT solver was stopped");
System.out.println("TIMEOUT");
System.exit(0);
} catch (Exception e) {
logger.error(e.getMessage());
System.out.println("ERROR");
System.exit(1);
}
}
use of com.dat3m.dartagnan.witness.WitnessGraph in project Dat3M by hernanponcedeleon.
the class ParserWitness method parse.
public WitnessGraph parse(CharStream charStream) {
XMLLexer lexer = new XMLLexer(charStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
XMLParser parser = new XMLParser(tokenStream);
parser.addErrorListener(new ParserErrorListener());
ParserRuleContext parserEntryPoint = parser.document();
VisitorXML visitor = new VisitorXML();
WitnessGraph graph = (WitnessGraph) parserEntryPoint.accept(visitor);
if (graph.hasAttributed("producer")) {
logger.info("Witness graph produced by " + graph.getAttributed("producer"));
}
logger.info("Witness graph stats: #Nodes " + graph.getNodes().size());
logger.info("Witness graph stats: #Edges " + graph.getEdges().size());
return graph;
}
use of com.dat3m.dartagnan.witness.WitnessGraph in project Dat3M by hernanponcedeleon.
the class SVCOMPRunner method main.
public static void main(String[] args) throws Exception {
if (Arrays.asList(args).contains("--help")) {
collectOptions();
return;
}
if (Arrays.stream(args).noneMatch(a -> supportedFormats.stream().anyMatch(a::endsWith))) {
throw new IllegalArgumentException("Input program not given or format not recognized");
}
if (Arrays.stream(args).noneMatch(a -> a.endsWith(".cat"))) {
throw new IllegalArgumentException("CAT model not given or format not recognized");
}
File fileModel = new File(Arrays.stream(args).filter(a -> a.endsWith(".cat")).findFirst().get());
String programPath = Arrays.stream(args).filter(a -> supportedFormats.stream().anyMatch(a::endsWith)).findFirst().get();
File fileProgram = new File(programPath);
String[] argKeyword = Arrays.stream(args).filter(s -> s.startsWith("-")).toArray(String[]::new);
Configuration config = Configuration.fromCmdLineArguments(argKeyword);
SVCOMPRunner r = new SVCOMPRunner();
config.recursiveInject(r);
WitnessGraph witness = new WitnessGraph();
if (r.witnessPath != null) {
witness = new ParserWitness().parse(new File(r.witnessPath));
if (!fileProgram.getName().equals(Paths.get(witness.getProgram()).getFileName().toString())) {
throw new RuntimeException("The witness was generated from a different program than " + fileProgram);
}
}
int bound = witness.hasAttributed(UNROLLBOUND.toString()) ? parseInt(witness.getAttributed(UNROLLBOUND.toString())) : r.umin;
File tmp = new SVCOMPSanitizer(fileProgram).run(bound);
// First time we compiler with standard atomic header to catch compilation problems
compileWithClang(tmp);
String output = "UNKNOWN";
while (output.equals("UNKNOWN")) {
compileWithSmack(tmp);
// If not removed here, file is not removed when we reach the timeout
// File can be safely deleted since it was created by the SVCOMPSanitizer
// (it not the original C file) and we already created the Boogie file
tmp.delete();
String boogieName = System.getenv().get("DAT3M_HOME") + "/output/" + Files.getNameWithoutExtension(programPath) + ".bpl";
if (r.sanitize) {
BoogieSan.write(boogieName);
}
ArrayList<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.add("-Dlog4j.configurationFile=" + System.getenv().get("DAT3M_HOME") + "/dartagnan/src/main/resources/log4j2.xml");
cmd.add("-DLOGNAME=" + Files.getNameWithoutExtension(programPath));
cmd.addAll(Arrays.asList("-jar", System.getenv().get("DAT3M_HOME") + "/dartagnan/target/dartagnan-3.0.0.jar"));
cmd.add(fileModel.toString());
cmd.add(boogieName);
cmd.add(String.format("--%s=%s", PROPERTY, r.property.asStringOption()));
cmd.add(String.format("--%s=%s", BOUND, bound));
cmd.add(String.format("--%s=%s", WITNESS_ORIGINAL_PROGRAM_PATH, programPath));
cmd.addAll(filterOptions(config));
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
try {
Process proc = processBuilder.start();
BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
proc.waitFor();
while (read.ready()) {
output = read.readLine();
System.out.println(output);
}
if (proc.exitValue() == 1) {
BufferedReader error = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
while (error.ready()) {
System.out.println(error.readLine());
}
System.exit(0);
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
if (bound > r.umax) {
System.out.println("PASS");
break;
}
// We always do iterations 1 and 2 and then use the step
bound = bound == 1 ? 2 : bound + r.step;
tmp = new SVCOMPSanitizer(fileProgram).run(bound);
}
tmp.delete();
}
Aggregations