예제 #1
0
 public static String[] getClassRoots() {
   String testRoots = System.getProperty("test.roots");
   if (testRoots != null) {
     System.out.println(
         "Collecting tests from roots specified by test.roots property: " + testRoots);
     return testRoots.split(";");
   }
   final String[] roots = ExternalClasspathClassLoader.getRoots();
   if (roots != null) {
     System.out.println(
         "Collecting tests from roots specified by classpath.file property: "
             + Arrays.toString(roots));
     return roots;
   } else {
     final ClassLoader loader = TestAll.class.getClassLoader();
     if (loader instanceof URLClassLoader) {
       final URL[] urls = ((URLClassLoader) loader).getURLs();
       final String[] classLoaderRoots = new String[urls.length];
       for (int i = 0; i < urls.length; i++) {
         classLoaderRoots[i] = VfsUtil.urlToPath(VfsUtil.convertFromUrl(urls[i]));
       }
       System.out.println(
           "Collecting tests from classloader: " + Arrays.toString(classLoaderRoots));
       return classLoaderRoots;
     }
     return System.getProperty("java.class.path").split(File.pathSeparator);
   }
 }
예제 #2
0
  private void beforeFirstTest() {
    if ((ourMode & START_GUARD) != 0) {
      Thread timeAndMemoryGuard =
          new Thread() {
            @Override
            public void run() {
              log("Starting Time and Memory Guard");
              while (true) {
                try {
                  try {
                    Thread.sleep(10000);
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                  // check for time spent on current test
                  if (myLastTestStartTime != 0) {
                    long currTime = System.currentTimeMillis();
                    long secondsSpent = (currTime - myLastTestStartTime) / 1000L;
                    Thread currentThread = getCurrentThread();
                    if (!mySavingMemorySnapshot) {
                      if (secondsSpent > PlatformTestCase.ourTestTime * myLastTestTestMethodCount) {
                        UsefulTestCase.printThreadDump();
                        log(
                            "Interrupting current Test (out of time)! Test class: "
                                + myLastTestClass
                                + " Seconds spent = "
                                + secondsSpent);
                        myInterruptedByOutOfTime = true;
                        if (currentThread != null) {
                          currentThread.interrupt();
                          if (!currentThread.isInterrupted()) {
                            //noinspection deprecation
                            currentThread.stop(
                                new RuntimeException("Current Test Interrupted: OUT OF TIME!"));
                          }

                          break;
                        }
                      }
                    }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
              log("Time and Memory Guard finished.");
            }
          };
      timeAndMemoryGuard.setDaemon(true);
      timeAndMemoryGuard.start();
    }
    myStartTime = System.currentTimeMillis();
  }
예제 #3
0
  // [myakovlev] Do not delete - it is for debugging
  public static void tryGc(int times) {
    if ((ourMode & RUN_GC) == 0) return;

    for (int qqq = 1; qqq < times; qqq++) {
      try {
        Thread.sleep(qqq * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.gc();
      // long mem = Runtime.getRuntime().totalMemory();
      log("Runtime.getRuntime().totalMemory() = " + Runtime.getRuntime().totalMemory());
    }
  }
예제 #4
0
  private void runNextTest(final TestResult testResult, int totalTests, Class testCaseClass) {
    myRunTests++;
    if (!checkAvaliableMemory(35, testResult)) {
      testResult.stop();
      return;
    }
    if (testResult.errorCount() + testResult.failureCount() > MAX_FAILURE_TEST_COUNT) {
      addErrorMessage(
          testResult,
          "Too many errors. Tests stopped. Total "
              + myRunTests
              + " of "
              + totalTests
              + " tests run");
      testResult.stop();
      return;
    }
    if (myStartTime == 0) {
      boolean ourClassLoader =
          getClass().getClassLoader().getClass().getName().startsWith("com.intellij.");
      if (!ourClassLoader) {
        beforeFirstTest();
      }
    } else {
      if (myInterruptedByOutOfTime) {
        addErrorMessage(
            testResult,
            "Current Test Interrupted: OUT OF TIME! Class = "
                + myLastTestClass
                + " Total "
                + myRunTests
                + " of "
                + totalTests
                + " tests run");
        testResult.stop();
        return;
      }
    }

    log("\nRunning " + testCaseClass.getName());
    final Test test = getTest(testCaseClass);

    if (test == null) return;

    myLastTestClass = null;

    myLastTestClass = testCaseClass.getName();
    myLastTestStartTime = System.currentTimeMillis();
    myLastTestTestMethodCount = test.countTestCases();

    try {
      test.run(testResult);
    } catch (Throwable t) {
      if (t instanceof OutOfMemoryError) {
        if ((ourMode & SAVE_MEMORY_SNAPSHOT) != 0) {
          try {
            mySavingMemorySnapshot = true;
            log("OutOfMemoryError detected. Saving memory snapshot started");
          } finally {
            log("Saving memory snapshot finished");
            mySavingMemorySnapshot = false;
          }
        }
      }
      testResult.addError(test, t);
    }
  }