Пример #1
0
    /**
     * process the sample by checking it against each existing invariant and issuing an error if any
     * invariant is falsified or weakened.
     */
    public void process_sample(PptMap all_ppts, PptTopLevel ppt, ValueTuple vt, Integer nonce) {

      this.all_ppts = all_ppts;

      debug.fine("processing sample from: " + ppt.name);

      // Add orig and derived variables
      FileIO.add_orig_variables(ppt, vt.vals, vt.mods, nonce);
      FileIO.add_derived_variables(ppt, vt.vals, vt.mods);

      // Intern the sample
      vt = new ValueTuple(vt.vals, vt.mods);

      // If this is an enter point, just remember it for later
      if (ppt.ppt_name.isEnterPoint()) {
        Assert.assertTrue(nonce != null);
        if (dir_file != null) {
          // Yoav: I had to do a hack to handle the case that several dtrace files are concatenated
          // together,
          // and Sung's dtrace files have unterminated calls, and when concatenating two files you
          // can have the same nonce.
          // So I have to remove the nonce found from the call_map
          call_map.remove(nonce);
        } else Assert.assertTrue(call_map.get(nonce) == null);
        call_map.put(nonce, new EnterCall(ppt, vt));
        debug.fine("Skipping enter sample");
        return;
      }

      // If this is an exit point, process the saved enter point
      if (ppt.ppt_name.isExitPoint()) {
        Assert.assertTrue(nonce != null);
        EnterCall ec = call_map.get(nonce);
        if (ec != null) {
          call_map.remove(nonce);
          debug.fine("Processing enter sample from " + ec.ppt.name);
          add(ec.ppt, ec.vt);
        } else { // didn't find the enter
          if (!quiet)
            System.out.printf("couldn't find enter for nonce %d at ppt %s\n", nonce, ppt.name());
          return;
        }
      }

      add(ppt, vt);
    }
Пример #2
0
  private static void checkInvariants() throws IOException {
    // Read the invariant file
    PptMap ppts = FileIO.read_serialized_pptmap(inv_file, true);

    // Yoav: make sure we have unique invariants
    InvariantFilters fi = InvariantFilters.defaultFilters();
    // Set<String> allInvariantsStr = new HashSet<String>();
    Set<Invariant> allInvariants = new HashSet<Invariant>();
    for (PptTopLevel ppt : ppts.all_ppts())
      for (Iterator<PptSlice> i = ppt.views_iterator(); i.hasNext(); ) {
        PptSlice slice = i.next();
        for (Invariant inv : slice.invs) {
          if (doConf && inv.getConfidence() < Invariant.dkconfig_confidence_limit) {
            // System.out.printf ("inv ignored (conf): %s:%s\n", inv.ppt.name(),
            //                   inv.format());
            continue;
          }

          if (doFilter && fi.shouldKeep(inv) == null) {
            // System.out.printf ("inv ignored (filter): %s:%s\n",
            //                     inv.ppt.name(), inv.format());
            continue;
          }
          activeInvariants.add(inv);

          // String n = invariant2str(ppt, inv);
          // if (!allInvariants.contains(inv) && allInvariantsStr.contains(n)) throw new
          // Daikon.TerminationMessage("Two invariants have the same ppt.name+inv.rep:"+n);
          allInvariants.add(inv);
          // allInvariantsStr.add(n);
        }
      }

    // Read and process the data trace files
    FileIO.Processor processor = new InvariantCheckProcessor();

    Daikon.FileIOProgress progress = new Daikon.FileIOProgress();
    progress.start();
    progress.clear();
    FileIO.read_data_trace_files(dtrace_files, ppts, processor, false);
    progress.shouldStop = true;
    System.out.println();
    System.out.printf(
        "%s: %,d errors found in %,d samples (%s)\n",
        inv_file, error_cnt, sample_cnt, toPercentage(error_cnt, sample_cnt));
    int failedCount = failedInvariants.size();
    int testedCount = testedInvariants.size();
    String percent = toPercentage(failedCount, testedCount);
    System.out.println(
        inv_file
            + ": "
            + failedCount
            + " false positives, out of "
            + testedCount
            + ", which is "
            + percent
            + ".");
    if (false) {
      for (Invariant inv : failedInvariants) {
        System.out.printf("+%s:%s\n", inv.ppt.name(), inv.format());
      }
    }
  }