Пример #1
0
  @SuppressWarnings("unchecked")
  public static void runRandom(long timeout, String algo) throws Exception {
    // deserialize the predicates
    long t1 = System.currentTimeMillis();
    ObjectInputStream oin =
        new ObjectInputStream(
            new FileInputStream(new File("./pred/" + Config.MAINCLASS + ".pred")));
    Profile.predicates.addAll((ArrayList<Predicate>) oin.readObject());
    oin.close();
    System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
    Profile.printPredicates();

    // run random testing
    long t2 = System.currentTimeMillis();
    ProfileAnalyzer analyzer = new ProfileAnalyzer();

    long testTime = 0;
    int count = 0;
    long testSize = 0;

    long endTime = t2 + timeout;
    while (true) {
      // generate and run tests, and analyze the branch profiles
      HashSet<TestCase> testCases = null;
      if (algo.equals("ART")) {
        testCases = new AdaptiveRandomTestGenerator(null).generate();
      } else if (algo.equals("RT")) {
        testCases = new PureRandomTestGenerator(null).generate();
      } else {
        System.out.println("[melt] unsupported random testing tool");
        System.exit(0);
      }

      testSize += testCases.size();
      Iterator<TestCase> iterator = testCases.iterator();
      while (iterator.hasNext()) {
        TestCase testCase = iterator.next();
        long t = System.currentTimeMillis();
        TestRunner.run(testCase.getTest());
        testTime += System.currentTimeMillis() - t;
        Profile.tests.add(testCase);
        analyzer.update();
      }
      System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
      System.out.println("[melt] finish the " + (++count) + " th set of tests");
      // analyzer.printNodes();
      analyzer.computeCoverage(null);
      if (System.currentTimeMillis() > endTime) {
        break;
      }
    }

    long t3 = System.currentTimeMillis();
    System.out.println("[melt] " + Config.FORMAT.format(t3));
    System.out.println("[melt] predicates deserialized in " + (t2 - t1) + " ms");
    System.out.println("[melt] " + testSize + " tests run in " + testTime + " ms");
    System.out.println("[melt] random testing in " + (t3 - t2) + " ms" + "\n");
  }
Пример #2
0
  @SuppressWarnings("unchecked")
  private static void runConcolic() throws Exception {
    // deserialize the predicates
    long t1 = System.currentTimeMillis();
    ObjectInputStream oin =
        new ObjectInputStream(
            new FileInputStream(new File("./pred/" + Config.MAINCLASS + ".pred")));
    Profile.predicates.addAll((ArrayList<Predicate>) oin.readObject());
    oin.close();
    System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
    Profile.printPredicates();

    // running concolic testing
    long t2 = System.currentTimeMillis();
    ProfileAnalyzer analyzer = new ProfileAnalyzer();

    long testTime = 0;
    long testSize = 0;

    // generate and run tests, and analyze the branch profiles
    ConcolicExecution jdart = new ConcolicExecution(Config.JPFCONFIG);
    jdart.run();
    HashSet<Valuation> vals = jdart.getValuations();
    testSize += vals.size();
    Iterator<Valuation> iterator = vals.iterator();
    while (iterator.hasNext()) {
      Object[] test = Util.valuationToTest(iterator.next());
      long t = System.currentTimeMillis();
      TestRunner.run(test);
      testTime += System.currentTimeMillis() - t;
      Profile.tests.add(new TestCase(test));
      analyzer.update();
    }
    System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
    // analyzer.printNodes();
    analyzer.computeCoverage(null);

    long t3 = System.currentTimeMillis();
    System.out.println("[melt] " + Config.FORMAT.format(t3));
    System.out.println("[melt] predicates deserialized in " + (t2 - t1) + " ms");
    System.out.println("[melt] " + testSize + " tests run in " + testTime + " ms");
    System.out.println("[melt] concolic testing in " + (t3 - t2) + " ms");
  }
Пример #3
0
  @SuppressWarnings("unchecked")
  public static void run() throws Exception {
    // deserialize the predicates
    long t1 = System.currentTimeMillis();
    ObjectInputStream oin =
        new ObjectInputStream(
            new FileInputStream(new File("./pred/" + Config.MAINCLASS + ".pred")));
    Profile.predicates.addAll((ArrayList<Predicate>) oin.readObject());
    oin.close();
    System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
    Profile.printPredicates();

    // run melt
    long t2 = System.currentTimeMillis();
    ProfileAnalyzer analyzer = new ProfileAnalyzer();
    PathLearner learner = null;
    PredicateNode targetNode = null;

    long testTime = 0;
    long geneTime = 0;
    int count = 0;
    long testSize = 0;
    int redundant = 0;

    while (true) {
      // generate and run tests, and analyze the branch profiles
      long s = System.currentTimeMillis();
      HashSet<TestCase> testCases = new SearchBasedTestGenerator(learner).generate();
      geneTime += System.currentTimeMillis() - s;
      testSize += testCases.size();
      Iterator<TestCase> iterator = testCases.iterator();
      while (iterator.hasNext()) {
        final TestCase testCase = iterator.next();
        System.out.println("[melt]" + testCase);
        if (!Profile.testsSet.contains(testCase)) {
          long t = System.currentTimeMillis();
          // get taint results
          FutureTask<?> task1 =
              new FutureTask<Void>(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        TaintRunner.run(testCase.getTest());
                      } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                      }
                    }
                  },
                  null);
          new Thread(task1).start();
          // get executed predicates
          FutureTask<?> task2 =
              new FutureTask<Void>(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        TestRunner.run(testCase.getTest());
                      } catch (MalformedURLException e) {
                        e.printStackTrace();
                      }
                    }
                  },
                  null);
          new Thread(task2).start();
          while (!task1.isDone() || !task2.isDone()) {}
          // get the potential exception in task1 and task2
          task1.get();
          task2.get();
          long delta = System.currentTimeMillis() - t;
          testTime += delta;
          Profile.tests.add(testCase);
          Profile.testsSet.add(testCase);
          analyzer.update();
        } else {
          redundant++;
        }
      }
      System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
      System.out.println("[melt] finish the " + (++count) + " th set of tests");
      // analyzer.printNodes();
      analyzer.computeCoverage(targetNode);
      // find an partially explored branch to be covered
      targetNode = analyzer.findUnexploredBranch();
      System.out.println("[melt] " + Config.FORMAT.format(System.currentTimeMillis()));
      if (targetNode == null) {
        System.out.println("[melt] target branch not found \n");
        break;
      }
      System.out.println("[melt] target branch found " + targetNode.getPredicate());
      // update the classification models from the current node to the root node
      learner = new PathLearner(analyzer.getRoot(), targetNode);
      System.out.println(
          "[melt] prefix traces found "
              + (learner.getTraces() == null ? "null" : learner.getTraces().size()));
    }

    long t3 = System.currentTimeMillis();
    System.out.println("[melt] " + Config.FORMAT.format(t3));
    System.out.println("[melt] predicates deserialized in " + (t2 - t1) + " ms");
    System.out.println(
        "[melt] " + testSize + "(" + redundant + ") tests run in " + testTime + " ms");
    System.out.println(
        "[melt] " + testSize + "(" + redundant + ") tests generated in " + geneTime + " ms");
    System.out.println("[melt] concolic execution in " + SearchBasedTestGenerator.ceTime + " ms");
    System.out.println("[melt] melt in " + (t3 - t2) + " ms");
  }