diff --git a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java index c2f09b0d84d6..b2aba2a8f135 100644 --- a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java +++ b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java @@ -27,8 +27,6 @@ import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.util.containers.HashMap; import com.intellij.util.io.ZipUtil; import junit.framework.Assert; -import junit.framework.AssertionFailedError; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FilenameFilter; @@ -38,11 +36,6 @@ import java.util.jar.JarFile; public class IdeaTestUtil extends PlatformTestUtil { - /** - * Measured on dual core p4 3HZ 1gig ram - */ - private static final long ETALON_TIMING = 438; - public static final Comparator DEFAULT_COMPARATOR = new Comparator() { public int compare(AbstractTreeNode o1, AbstractTreeNode o2) { @@ -52,7 +45,6 @@ public class IdeaTestUtil extends PlatformTestUtil { } }; - public static final boolean COVERAGE_ENABLED_BUILD = "true".equals(System.getProperty("idea.coverage.enabled.build")); public static final CvsVirtualFileFilter CVS_FILE_FILTER = new CvsVirtualFileFilter(); private static HashMap buildNameToFileMap(VirtualFile[] files, VirtualFileFilter filter) { @@ -153,56 +145,6 @@ public class IdeaTestUtil extends PlatformTestUtil { assertDirectoriesEqual(dirAfter, dirBefore, CVS_FILE_FILTER); } - public static void assertTiming(String message, long expected, long actual) { - if (COVERAGE_ENABLED_BUILD) return; - long expectedOnMyMachine = Math.max(1, expected * Timings.MACHINE_TIMING / ETALON_TIMING); - final double acceptableChangeFactor = 1.1; - - // Allow 10% more in case of test machine is busy. - // For faster machines (expectedOnMyMachine < expected) allow nonlinear performance rating: - // just perform better than acceptable expected - if (actual > expectedOnMyMachine * acceptableChangeFactor && - (expectedOnMyMachine > expected || actual > expected * acceptableChangeFactor)) { - int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine); - Assert.fail(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + expectedOnMyMachine + - ". Actual: " + actual + ". Expected on Etalon machine: " + expected + "; Actual on Etalon: " + - (actual * ETALON_TIMING / Timings.MACHINE_TIMING)); - } - else { - int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine); - System.out.println(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + - expectedOnMyMachine + ". Actual: " + actual + ". Expected on Etalon machine: " + expected + - "; Actual on Etalon: " + (actual * ETALON_TIMING / Timings.MACHINE_TIMING)); - } - } - - public static void assertTiming(String message, long expected, @NotNull Runnable actionToMeasure) { - assertTiming(message, expected, 4, actionToMeasure); - } - - public static long measure(@NotNull Runnable actionToMeasure) { - long start = System.currentTimeMillis(); - actionToMeasure.run(); - long finish = System.currentTimeMillis(); - return finish - start; - } - public static void assertTiming(String message, long expected, int attempts, @NotNull Runnable actionToMeasure) { - while (true) { - attempts--; - long duration = measure(actionToMeasure); - try { - assertTiming(message, expected, duration); - break; - } - catch (AssertionFailedError e) { - if (attempts == 0) throw e; - System.gc(); - System.gc(); - System.gc(); - } - } - } - public static void main(String[] args) { printDetectedPerformanceTimings(); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 44f9263ad9c7..d6504bd173f0 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -39,7 +39,9 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.SystemProperties; import com.intellij.util.ui.UIUtil; import junit.framework.Assert; +import junit.framework.AssertionFailedError; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -51,6 +53,12 @@ import java.util.*; * @author yole */ public class PlatformTestUtil { + /** + * Measured on dual core p4 3HZ 1gig ram + */ + protected static final long ETALON_TIMING = 438; + public static final boolean COVERAGE_ENABLED_BUILD = "true".equals(System.getProperty("idea.coverage.enabled.build")); + public static void registerExtension(final ExtensionPointName name, final T t, final Disposable parentDisposable) { registerExtension(Extensions.getRootArea(), name, t, parentDisposable); } @@ -326,4 +334,55 @@ public class PlatformTestUtil { Assert.assertTrue(presentation.isEnabled()); action.actionPerformed(event); } + + public static void assertTiming(String message, long expected, long actual) { + if (COVERAGE_ENABLED_BUILD) return; + long expectedOnMyMachine = Math.max(1, expected * Timings.MACHINE_TIMING / ETALON_TIMING); + final double acceptableChangeFactor = 1.1; + + // Allow 10% more in case of test machine is busy. + // For faster machines (expectedOnMyMachine < expected) allow nonlinear performance rating: + // just perform better than acceptable expected + if (actual > expectedOnMyMachine * acceptableChangeFactor && + (expectedOnMyMachine > expected || actual > expected * acceptableChangeFactor)) { + int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine); + Assert.fail(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + expectedOnMyMachine + + ". Actual: " + actual + ". Expected on Etalon machine: " + expected + "; Actual on Etalon: " + + (actual * ETALON_TIMING / Timings.MACHINE_TIMING)); + } + else { + int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine); + System.out.println(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + + expectedOnMyMachine + ". Actual: " + actual + ". Expected on Etalon machine: " + expected + + "; Actual on Etalon: " + (actual * ETALON_TIMING / Timings.MACHINE_TIMING)); + } + } + + public static void assertTiming(String message, long expected, @NotNull Runnable actionToMeasure) { + assertTiming(message, expected, 4, actionToMeasure); + } + + public static long measure(@NotNull Runnable actionToMeasure) { + long start = System.currentTimeMillis(); + actionToMeasure.run(); + long finish = System.currentTimeMillis(); + return finish - start; + } + + public static void assertTiming(String message, long expected, int attempts, @NotNull Runnable actionToMeasure) { + while (true) { + attempts--; + long duration = measure(actionToMeasure); + try { + assertTiming(message, expected, duration); + break; + } + catch (AssertionFailedError e) { + if (attempts == 0) throw e; + System.gc(); + System.gc(); + System.gc(); + } + } + } } diff --git a/java/testFramework/src/com/intellij/testFramework/Timings.java b/platform/testFramework/src/com/intellij/testFramework/Timings.java similarity index 100% rename from java/testFramework/src/com/intellij/testFramework/Timings.java rename to platform/testFramework/src/com/intellij/testFramework/Timings.java diff --git a/plugins/spellchecker/spellchecker.iml b/plugins/spellchecker/spellchecker.iml index edcc0cf37fa4..d81c1984675f 100644 --- a/plugins/spellchecker/spellchecker.iml +++ b/plugins/spellchecker/spellchecker.iml @@ -14,7 +14,6 @@ - diff --git a/plugins/spellchecker/testSrc/com/intellij/spellchecker/compress/DictionaryTest.java b/plugins/spellchecker/testSrc/com/intellij/spellchecker/compress/DictionaryTest.java index 783f40cceb7b..3eabd077f11a 100644 --- a/plugins/spellchecker/testSrc/com/intellij/spellchecker/compress/DictionaryTest.java +++ b/plugins/spellchecker/testSrc/com/intellij/spellchecker/compress/DictionaryTest.java @@ -21,7 +21,7 @@ import com.intellij.spellchecker.StreamLoader; import com.intellij.spellchecker.dictionary.Dictionary; import com.intellij.spellchecker.dictionary.Loader; import com.intellij.spellchecker.engine.Transformation; -import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.Consumer; import gnu.trove.THashSet; import junit.framework.TestCase; @@ -62,7 +62,7 @@ public class DictionaryTest extends TestCase { public void loadDictionaryTest(@NotNull final String name, int wordCount) throws IOException { final Transformation transform = new Transformation(); - IdeaTestUtil.assertTiming("Dictionary load time depends on words count. Approximate word count: " + wordCount + ".", times.get(name), + PlatformTestUtil.assertTiming("Dictionary load time depends on words count. Approximate word count: " + wordCount + ".", times.get(name), new Runnable() { public void run() { dictionary = CompressedDictionary.create(new StreamLoader(DefaultBundledDictionariesProvider.class.getResourceAsStream(name), name), transform); @@ -70,7 +70,7 @@ public class DictionaryTest extends TestCase { }); final Set wordsToStoreAndCheck = createWordSets(name, 50000, 1).getFirst(); - IdeaTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 2000, new Runnable() { + PlatformTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 2000, new Runnable() { public void run() { for (String s : wordsToStoreAndCheck) { assertTrue(dictionary.contains(s));