コード例 #1
0
 private static String getNextLine(LineNumberReader input) {
   try {
     return input.readLine();
   } catch (IOException e) {
     throw new RuntimeException("Exception reading next line");
   }
 }
コード例 #2
0
 /**
  * @return String containing error messages for any failed cases. In the case that there are no
  *     failed cases, the empty string is returned. In the case where commands is empty (there
  *     are no more test cases and the end of the file has been reached), null is returned.
  */
 public static String runTest(LineNumberReader commands) {
   boolean endOfFile = initFields(commands, false);
   if (endOfFile) {
     return null;
   }
   while (true) {
     String commandLine = getNextRealLine(commands);
     int lineNumber = commands.getLineNumber();
     if (InvariantAddAndCheckTester.isComment(commandLine)) {
       continue;
     } else if (isTestTerminator(commandLine)) {
       break;
     } else if (isAddCommand(commandLine) || isCheckCommand(commandLine)) {
       exicuteCheckOrAddCommand(commandLine, lineNumber);
     } else if (isCompareCommand(commandLine)) {
     } else {
       throw new RuntimeException("unrecognized command");
     }
   }
   return results.toString();
 }
コード例 #3
0
 /**
  * @return a String containing the proper add and check commands for this input lines of this
  *     test case.
  */
 public static String generateTest(LineNumberReader commands) {
   boolean endOfFile = initFields(commands, true);
   if (endOfFile) return null;
   while (true) {
     String commandLine = getNextLine(commands).trim();
     int lineNumber = commands.getLineNumber();
     if (InvariantAddAndCheckTester.isComment(commandLine)) {
       results.append(commandLine + lineSep);
     } else if (isTestTerminator(commandLine)) {
       results.append(commandLine + lineSep + lineSep);
       break;
     } else if (isAddCommand(commandLine) || isCheckCommand(commandLine)) {
       generateCheckOrAddCommand(commandLine, lineNumber);
     } else if (isCompareCommand(commandLine)) {
       // generateCompareCommand(commandLine);
     } else {
       throw new RuntimeException("unrecognized command");
     }
   }
   return results.toString();
 }
コード例 #4
0
    private void add(PptTopLevel ppt, ValueTuple vt) {
      // Add the sample to any splitters
      if (ppt.has_splitters()) {
        for (PptSplitter ppt_split : ppt.splitters) {
          PptConditional ppt_cond = ppt_split.choose_conditional(vt);
          if (ppt_cond != null) add(ppt_cond, vt);
          else debug.fine(": sample doesn't pick conditional");
        }
      }

      // if this is a numbered exit, apply to the combined exit as well
      if (!(ppt instanceof PptConditional) && ppt.ppt_name.isNumberedExitPoint()) {
        PptTopLevel parent = all_ppts.get(ppt.ppt_name.makeExit());
        if (parent != null) {
          parent.get_missingOutOfBounds(ppt, vt);
          add(parent, vt);
        }
      }

      // If the point has no variables, skip it
      if (ppt.var_infos.length == 0) return;

      // We should have received sample here before, or there is nothing
      // to check.
      // Yoav added: It can be that the different dtrace and inv files have different program points
      if (false && ppt.num_samples() <= 0)
        Assert.assertTrue(
            ppt.num_samples() > 0,
            "ppt " + ppt.name + " has 0 samples and " + ppt.var_infos.length + " variables");

      // Loop through each slice
      slice_loop:
      for (Iterator<PptSlice> i = ppt.views_iterator(); i.hasNext(); ) {
        PptSlice slice = i.next();
        if (debug_detail.isLoggable(Level.FINE))
          debug_detail.fine(
              ": processing slice " + slice + "vars: " + Debug.toString(slice.var_infos, vt));

        // If any variables are missing, skip this slice
        for (int j = 0; j < slice.var_infos.length; j++) {
          VarInfo v = slice.var_infos[j];
          int mod = vt.getModified(v);
          if (v.isMissing(vt)) {
            if (debug_detail.isLoggable(Level.FINE))
              debug_detail.fine(": : Skipping slice, " + v.name() + " missing");
            continue slice_loop;
          }
          if (v.missingOutOfBounds()) {
            if (debug_detail.isLoggable(Level.FINE))
              debug.fine(": : Skipping slice, " + v.name() + " out of bounds");
            continue slice_loop;
          }
        }

        // Loop through each invariant
        for (Invariant inv : slice.invs) {
          if (debug_detail.isLoggable(Level.FINE))
            debug_detail.fine(": : Processing invariant: " + inv);
          if (!inv.isActive()) {
            if (debug_detail.isLoggable(Level.FINE))
              debug_detail.fine(": : skipped non-active " + inv);
            continue;
          }

          // Yoav added
          if (!activeInvariants.contains(inv)) {
            // System.out.printf ("skipping invariant %s:%s\n", inv.ppt.name(),
            //                   inv.format());
            continue;
          }

          // String invRep = invariant2str(ppt, inv);
          testedInvariants.add(inv);

          InvariantStatus status = inv.add_sample(vt, 1);
          sample_cnt++;
          if (status != InvariantStatus.NO_CHANGE) {
            LineNumberReader lnr = FileIO.data_trace_state.reader;
            String line = (lnr == null) ? "?" : String.valueOf(lnr.getLineNumber());
            if (!quiet) {
              output_stream.println(
                  "At ppt "
                      + ppt.name
                      + ", Invariant '"
                      + inv.format()
                      + "' invalidated by sample "
                      + Debug.toString(slice.var_infos, vt)
                      + "at line "
                      + line
                      + " in file "
                      + FileIO.data_trace_state.filename);
            }
            failedInvariants.add(inv);
            activeInvariants.remove(inv);
            error_cnt++;
          }
        }
      }
    }