Beispiel #1
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;
  }