diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Testable.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Testable.java index 6a3c3c4b8285..ceafe956ef26 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Testable.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Testable.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.e4.ui.internal.workbench.swt; +import java.util.Locale; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.jobs.Job; @@ -115,24 +116,61 @@ public void testingStarting() { @Override public void runTest(Runnable testRunnable) { Assert.isNotNull(workbench); - display.syncExec( - () -> { - display.addListener(SWT.Dispose, - e -> { - // lambda block to allow breakpoint for debugging - displayCheck = new Exception("Display is disposed"); - }); - - // Run actual test - testRunnable.run(); - - while (display.readAndDispatch()) { - // process all pending tasks - } - - // Display should be still there - checkDisplay(); - }); + display.syncExec(new TestExecutionRunnable(testRunnable)); + } + + private final class TestExecutionRunnable implements Runnable { + private final Runnable testRunnable; + + private TestExecutionRunnable(Runnable testRunnable) { + this.testRunnable = testRunnable; + } + + @Override + public void run() { + display.addListener(SWT.Dispose, + e -> { + // lambda block to allow breakpoint for debugging + displayCheck = new Exception("Display is disposed"); + }); + + try { + // Run actual test + testRunnable.run(); + } catch (OutOfMemoryError e) { + try { + e.printStackTrace(System.out); + printMemoryUse(); + } finally { + System.out.println("Calling System.exit() after OutOfMemoryError"); + System.exit(1); + } + } + + while (display.readAndDispatch()) { + // process all pending tasks + } + + // Display should be still there + checkDisplay(); + } + } + + private static void printMemoryUse() { + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + long max = Runtime.getRuntime().maxMemory(); + long total = Runtime.getRuntime().totalMemory(); + long free = Runtime.getRuntime().freeMemory(); + long used = total - free; + System.out.print("\n########### Memory usage reported by JVM ########"); + System.out.printf(Locale.GERMAN, "%n%,16d bytes max heap", max); + System.out.printf(Locale.GERMAN, "%n%,16d bytes heap allocated", total); + System.out.printf(Locale.GERMAN, "%n%,16d bytes free heap", free); + System.out.printf(Locale.GERMAN, "%n%,16d bytes used heap", used); + System.out.println("\n#################################################\n"); } /** diff --git a/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF index ed65721730fe..259fee3e9930 100644 --- a/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests.harness/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Harness Plug-in Bundle-SymbolicName: org.eclipse.ui.tests.harness;singleton:=true -Bundle-Version: 1.10.500.qualifier +Bundle-Version: 1.10.600.qualifier Eclipse-BundleShape: dir Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java index 436b0f884bce..28bded7017fb 100644 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java @@ -21,6 +21,7 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -212,6 +213,7 @@ protected void doSetUp() throws Exception { public final void tearDown() throws Exception { String name = runningTest != null ? runningTest : this.getName(); trace(TestRunLogUtil.formatTestFinishedMessage(name)); + prefMemento.resetPreferences(); doTearDown(); @@ -227,8 +229,28 @@ public final void tearDown() throws Exception { fWorkbench = null; assertEquals("Test leaked modal shell: [" + String.join(", ", leakedModalShellTitles) + "]", 0, leakedModalShellTitles.size()); + runGcAndPrintMemoryUse(name); } + public static void runGcAndPrintMemoryUse(String testName) { + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + long nax = Runtime.getRuntime().maxMemory(); + long total = Runtime.getRuntime().totalMemory(); + long free = Runtime.getRuntime().freeMemory(); + long used = total - free; + System.out.print("\n#################################################"); + System.out.print("\n" + testName); + System.out.print("\n########### Memory usage reported by JVM ########"); + System.out.printf(Locale.GERMAN, "%n%,16d bytes max heap", nax); + System.out.printf(Locale.GERMAN, "%n%,16d bytes heap allocated", total); + System.out.printf(Locale.GERMAN, "%n%,16d bytes free heap", free); + System.out.printf(Locale.GERMAN, "%n%,16d bytes used heap", used); + System.out.println("\n#################################################\n"); + } + /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/stress/OpenCloseTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/stress/OpenCloseTest.java index f9c7cd40acbf..4c60edde9287 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/stress/OpenCloseTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/stress/OpenCloseTest.java @@ -41,8 +41,12 @@ import org.eclipse.ui.intro.IIntroPart; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.tests.harness.util.FileUtil; +import org.eclipse.ui.tests.harness.util.UITestCase; +import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; /** * Test opening and closing of items. @@ -56,6 +60,8 @@ public class OpenCloseTest { private IWorkbench workbench; private IWorkbenchPage page; + @Rule + public TestName testName = new TestName(); @Before public void setup() { @@ -76,6 +82,10 @@ public void setup() { assertNotNull(page); } + @After + public void teardown() { + UITestCase.runGcAndPrintMemoryUse(testName.getMethodName()); + } /** * Test the opening and closing of a file.