Example #1
0
  public Model buildAuto(String fileName, String fileType) {
    FileIO builder = new FileIO();
    _autoModel = new Model();
    if (fileType.indexOf("prop") > -1) {
      try {
        _autoModel = builder.buildAutoModelFromProperties(fileName, _autoModel);
      } catch (AutoException ae) {
        System.out.print(ae.getErrMessage());
      }
    } else {
      try {

        _autoModel = builder.buildAutoModelObject(fileName, _autoModel);
      } catch (AutoException ae) {
        System.out.print(ae.getErrMessage());
        try {
          _autoModel = builder.buildAutoModelObject(fileName, _autoModel);
        } catch (AutoException e) {
          System.out.print("Could not resolve error " + ae.getErrMessage());
        }
      }
    }
    if (_autoModel != null) {
      _autoModel.setDefaultOptionChoices();
      addAuto(_autoModel);
    }
    return _autoModel;
  }
Example #2
0
  // This method starts from the ButtonListener class but ends up in the Ballot class, updating the
  // file of each Ballot
  public void updateBallots() {
    FileIO nullFile =
        new FileIO(); // need to create this just to gain access to the filename of the ballots file
    FileIO ballotFile = new FileIO(nullFile.getBallotsFileName());
    ArrayList<Ballot> ballots = ballotFile.createBallots();

    for (Ballot ballot : ballots) {
      ballot.updateFile();
    }
  }
Example #3
0
 // Initialize the buttons ArrayList because there the program messes up if the voter doesn't vote
 // for anything, the buttons array
 // will be null.
 public void initializeButtons() {
   FileIO nullFile =
       new FileIO(); // need to create this just to gain access to the filename of the ballots file
   FileIO ballotFile = new FileIO(nullFile.getBallotsFileName());
   _ballots = ballotFile.createBallots();
   buttons = new ArrayList<JToggleButton>();
   for (Ballot ballot : _ballots) {
     JToggleButton[] ballotButtons = ballot.getButtons();
     for (int i = 0; i < ballotButtons.length; i++) {
       buttons.add(ballotButtons[i]);
     }
   }
 }
Example #4
0
  // Grab the number of buttons from all of the ballots in the program.
  // This will define the votes array, which stores all of the true and false values...
  // as to whether the button is really selected or not (because button.isSelected() won't work for
  // me for some reason).
  public void setVotesLength() {
    FileIO nullFile =
        new FileIO(); // need to create this just to gain access to the filename of the ballots file
    FileIO ballotsFile = new FileIO(nullFile.getBallotsFileName());
    ArrayList<Ballot> throwAwayList = ballotsFile.createBallots();
    int numButtons = 0;

    for (Ballot ballot : throwAwayList) {
      numButtons += ballot.getNumButtons();
    }

    votes = new boolean[numButtons];
  }
Example #5
0
  public boolean buildAuto(Properties autoProp) {
    FileIO builder = new FileIO();
    _autoModel = new Model();
    try {
      builder.parseProperties(autoProp, _autoModel);
    } catch (AutoException e) {
      System.err.println(e.getMessage());
      if (e.getErrCode() == 102065) // missing properties, don't continue with this file.
      _autoModel = null;
    }

    if (_autoModel != null) {
      _autoModel.setDefaultOptionChoices();
      addAuto(_autoModel);
      return this.isAutoHere(_autoModel.getModelName());
    } else return false;
  }
    /**
     * 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);
    }
 /**
  * This does the work of main, but it never calls System.exit, so it is appropriate to be called
  * progrmmatically. Termination of the program with a message to the user is indicated by throwing
  * Daikon.TerminationMessage.
  *
  * @see #main(String[])
  * @see daikon.Daikon.TerminationMessage
  */
 public static void mainHelper(final String[] args)
     throws FileNotFoundException, IOException, ClassNotFoundException {
   daikon.LogHelper.setupLogs(daikon.LogHelper.INFO);
   LongOpt[] longopts =
       new LongOpt[] {
         new LongOpt(Daikon.suppress_redundant_SWITCH, LongOpt.NO_ARGUMENT, null, 0),
         new LongOpt(Daikon.config_option_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
         new LongOpt(Daikon.debugAll_SWITCH, LongOpt.NO_ARGUMENT, null, 0),
         new LongOpt(Daikon.debug_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
       };
   Getopt g = new Getopt("daikon.ExtractConsequent", args, "h", longopts);
   int c;
   while ((c = g.getopt()) != -1) {
     switch (c) {
       case 0:
         // got a long option
         String option_name = longopts[g.getLongind()].getName();
         if (Daikon.help_SWITCH.equals(option_name)) {
           System.out.println(usage);
           throw new Daikon.TerminationMessage();
         } else if (Daikon.suppress_redundant_SWITCH.equals(option_name)) {
           Daikon.suppress_redundant_invariants_with_simplify = true;
         } else if (Daikon.config_option_SWITCH.equals(option_name)) {
           String item = Daikon.getOptarg(g);
           daikon.config.Configuration.getInstance().apply(item);
           break;
         } else if (Daikon.debugAll_SWITCH.equals(option_name)) {
           Global.debugAll = true;
         } else if (Daikon.debug_SWITCH.equals(option_name)) {
           LogHelper.setLevel(Daikon.getOptarg(g), LogHelper.FINE);
         } else {
           throw new RuntimeException("Unknown long option received: " + option_name);
         }
         break;
       case 'h':
         System.out.println(usage);
         throw new Daikon.TerminationMessage();
       case '?':
         break; // getopt() already printed an error
       default:
         System.out.println("getopt() returned " + c);
         break;
     }
   }
   // The index of the first non-option argument -- the name of the file
   int fileIndex = g.getOptind();
   if (args.length - fileIndex != 1) {
     throw new Daikon.TerminationMessage("Wrong number of arguments." + Daikon.lineSep + usage);
   }
   String filename = args[fileIndex];
   PptMap ppts =
       FileIO.read_serialized_pptmap(
           new File(filename), true // use saved config
           );
   extract_consequent(ppts);
 }
Example #8
0
  // Update the true/false value of every button in the program, and set every value to its
  // respective position in the votes array
  public void updateButtons(String text) {
    FileIO nullFile =
        new FileIO(); // need to create this just to gain access to the filename of the ballots file
    FileIO ballotFile = new FileIO(nullFile.getBallotsFileName());
    _ballots = ballotFile.createBallots();
    buttons = new ArrayList<JToggleButton>();
    for (Ballot ballot : _ballots) {
      JToggleButton[] ballotButtons = ballot.getButtons();
      for (int i = 0; i < ballotButtons.length; i++) {
        buttons.add(ballotButtons[i]);
      }
    }

    int numButtons = 0;
    for (Ballot ballot : _ballots) {
      numButtons += ballot.getButtons().length;
    }

    for (int i = 0; i < numButtons; i++) {
      if (buttons.get(i).getText().equals(text)) {
        votes[i] = true;
      }
    }
  }
  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());
      }
    }
  }
Example #10
0
  // This is where all the action happens.  If an action is performed (button press for example), it
  // goes through this method
  // that takes an ActionEvent, which is created at the time of the action.
  public void actionPerformed(ActionEvent e) {
    // Try to cast the ActionEvent source as JToggleButton (if successful, the button is a ballot
    // choice)
    try {
      JToggleButton theButton = (JToggleButton) e.getSource();
      String buttonText = theButton.getText();

      if (theButton.isSelected()) {
        theButton.setForeground(Color.RED);
        switchButton = true;
        switchButtonText = buttonText;
        updateButtons(
            buttonText); // switches this button's respective vote position to 1 (true), meaning it
                         // is selected
      } else if (!theButton.isSelected()) {
        theButton.setForeground(Color.BLACK);
        unvoteButton = true;
        unvoteButtonText = buttonText;
      }
      // If the program can't cast the source to a JToggleButton, cast it as a JButton, which is
      // 100% what the source will be at this point.
      // This button will be one of two things: the login button or the cast vote button.
    } catch (Exception exception) {
      JButton theButton = (JButton) e.getSource();

      String buttonText = theButton.getText();

      // If the user hits the Login button, check if the ID is valid.
      // If the ID is not valid, don't let them vote.  However, if it is valid, disable login and
      // enable everything else.
      if (buttonText.equals("Login")) {
        String voterID =
            JOptionPane.showInputDialog(theButton, "Enter your voter ID: ", "Login", 3);
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();

        if (votersFile.checkValidID(voterID)) {
          Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));
          if (theVoter.getVotedStatus().equals("false")) {
            setVoterID(voterID);
          } else {
            JOptionPane.showMessageDialog(
                theButton, "You already voted " + theVoter.getVoterName() + "!");
          }
        } else {
          JOptionPane.showMessageDialog(theButton, "Invalid ID!", "Error", 0);
        }
        // If the user hits the cast vote button, update the respective ballot files and disable
        // every button except
        // for the login button.
      } else if (buttonText.equals("Cast vote")) {
        int confirm = JOptionPane.showConfirmDialog(theButton, "Are you sure?");
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();
        Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));

        if (confirm == 0) {
          JOptionPane.showMessageDialog(theButton, "Thanks for voting!");
          updateBallots();
          votersFile.updateVoterFile(theVoter.getVoterID());
          setVoterID("-1");
          votersFile.initializeVoters();
        }
      }
    }
  }