Search in sources :

Example 1 with Compilation

use of com.dat3m.dartagnan.parsers.program.utils.Compilation 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();
}
Also used : Options(org.sosy_lab.common.configuration.Options) Arrays(java.util.Arrays) Property(com.dat3m.dartagnan.configuration.Property) Compilation(com.dat3m.dartagnan.parsers.program.utils.Compilation) ArrayList(java.util.ArrayList) Option(org.sosy_lab.common.configuration.Option) SVCOMPSanitizer(com.dat3m.svcomp.utils.SVCOMPSanitizer) Files(com.google.common.io.Files) BoogieSan(com.dat3m.svcomp.utils.BoogieSan) WitnessGraph(com.dat3m.dartagnan.witness.WitnessGraph) UNROLLBOUND(com.dat3m.dartagnan.witness.GraphAttributes.UNROLLBOUND) BaseOptions(com.dat3m.dartagnan.utils.options.BaseOptions) ImmutableSet(com.google.common.collect.ImmutableSet) Configuration(org.sosy_lab.common.configuration.Configuration) OptionInfo.collectOptions(com.dat3m.dartagnan.configuration.OptionInfo.collectOptions) OptionNames(com.dat3m.dartagnan.configuration.OptionNames) Set(java.util.Set) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) List(java.util.List) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) ParserWitness(com.dat3m.dartagnan.parsers.witness.ParserWitness) Configuration(org.sosy_lab.common.configuration.Configuration) ParserWitness(com.dat3m.dartagnan.parsers.witness.ParserWitness) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) WitnessGraph(com.dat3m.dartagnan.witness.WitnessGraph) SVCOMPSanitizer(com.dat3m.svcomp.utils.SVCOMPSanitizer) BufferedReader(java.io.BufferedReader) File(java.io.File)

Aggregations

OptionInfo.collectOptions (com.dat3m.dartagnan.configuration.OptionInfo.collectOptions)1 OptionNames (com.dat3m.dartagnan.configuration.OptionNames)1 Property (com.dat3m.dartagnan.configuration.Property)1 Compilation (com.dat3m.dartagnan.parsers.program.utils.Compilation)1 ParserWitness (com.dat3m.dartagnan.parsers.witness.ParserWitness)1 BaseOptions (com.dat3m.dartagnan.utils.options.BaseOptions)1 UNROLLBOUND (com.dat3m.dartagnan.witness.GraphAttributes.UNROLLBOUND)1 WitnessGraph (com.dat3m.dartagnan.witness.WitnessGraph)1 BoogieSan (com.dat3m.svcomp.utils.BoogieSan)1 SVCOMPSanitizer (com.dat3m.svcomp.utils.SVCOMPSanitizer)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Files (com.google.common.io.Files)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 Integer.parseInt (java.lang.Integer.parseInt)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1