Ejemplo n.º 1
0
  private boolean executeTestAndCollectRuntimeValues(
      Object result,
      TestCase currentTest,
      ClassLoader unitTestClassLoader,
      SpecificationTestCasesListener<T> listener) {

    LoggingInstrumenter.setValue(result);
    Result testResult = TestSuiteExecution.runTestCase(currentTest, unitTestClassLoader, listener);
    if (testResult.getFailureCount() == 0) {
      return true;
    }
    return false;
  }
Ejemplo n.º 2
0
  @Override
  public Collection<Specification<T>> buildFor(
      final URL[] classpath, final String[] testClasses, final Collection<TestCase> failures) {
    final LoggingInstrumenter<T> logging = createLoggingInstrumenter();
    SpoonedClass fork = cleanSpoon.forked(sourceLocation.getContainingClassName());
    final ClassLoader unitTestClassLoader = fork.processedAndDumpedToClassLoader(logging);

    final SpecificationTestCasesListener<T> listener =
        run(classpath, failures, unitTestClassLoader);

    if (this.find) {
      logging.disable();
      TestSuiteExecution.runCasesIn(testClasses, unitTestClassLoader, listener);
    }
    return listener.specifications();
  }
Ejemplo n.º 3
0
  private SpecificationTestCasesListener<T> run(
      final URL[] classpath, final Collection<TestCase> failures, ClassLoader unitTestClassLoader) {
    final SpecificationTestCasesListener<T> listener =
        new SpecificationTestCasesListener<>(runtimeValues);

    // create the classpath for JPF
    String stringClassPath = createClassPath(classpath);

    String mainClass = "nopol.repair.NopolTestRunner";
    // TestExecutorProcessor.createMainTestClass(spoon, mainClass);

    List<TestCase> passedTest = new ArrayList<>(failures.size());
    Iterator<TestCase> iterator = failures.iterator();
    while (iterator.hasNext()) {
      TestCase testCase = iterator.next();
      logger.debug("SYMBOLIC EXECUTION on " + sourceLocation + " Test " + testCase);
      String[] args = new String[1];
      args[0] = testCase.className() + "." + testCase.testName();

      Config conf =
          JPFUtil.createConfig(
              args, mainClass, stringClassPath, outputSourceFile.getAbsolutePath());
      final JPF jpf = new JPF(conf);

      // executes JPF
      JPFListener jpfListener = new JPFListener();
      jpf.addSearchListener(jpfListener);

      ExecutorService executor = Executors.newFixedThreadPool(1);

      Future<?> future =
          executor.submit(
              new Runnable() {
                @Override
                public void run() {
                  jpf.run();
                }
              });

      executor.shutdown();
      try {
        future.get(60, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        continue;
      } catch (ExecutionException e) {
        e.printStackTrace();
        continue;
      } catch (TimeoutException e) {
        future.cancel(true);
        continue;
      }

      // get the JPF result
      Object result = jpfListener.getResult();
      if (result == null) {
        continue;
      }
      logger.debug(
          "SYMBOLIC VALUE on " + sourceLocation + " for Test " + testCase + " Value: " + result);
      // collect runtime
      boolean passed =
          executeTestAndCollectRuntimeValues(result, testCase, unitTestClassLoader, listener);
      if (passed) {
        this.find = true;
        TestSuiteExecution.runTestCases(failures, unitTestClassLoader, listener);
        if (!passedTest.contains(testCase)) {
          passedTest.add(testCase);
        }
        if (passedTest.size() == failures.size()) {
          break;
        }
      }
    }

    return listener;
  }
Ejemplo n.º 4
0
 private Collection<TestCase> failingTests(String[] testClasses) {
   TestCasesListener listener = new TestCasesListener();
   TestSuiteExecution.runCasesIn(testClasses, spooner.dumpedToClassLoader(), listener);
   return listener.failedTests();
 }