Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ public void setRegressionReason(String comment) {
*/
protected abstract void test() throws Exception;

/**
* Executes the performance test the given number of times. Use the outer time
* to execute the test several times in order to obtain a normalized average. Use
* the inner loop for very fast tests that would otherwise be difficult to measure
* due to Java's poor timer granularity. The inner loop is not needed for long
* tests that typically take more than a second to execute.
*
* @param testCase The test that is running (used to obtain an appropriate meter)
* @param outer The number of repetitions of the test.
* @param inner The number of repetitions within the performance timer.
*/
public final void run(TestCase testCase, int outer, int inner) {
run(testCase, null, outer, inner);
}

/**
* Executes the performance test the given number of times. Use the outer time
* to execute the test several times in order to obtain a normalized average. Use
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2025 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.core.tests.harness.session;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Test;

/**
* A specialization of the {@link Test} annotation for marking a repeated
* performance session test. When executed with a {@link SessionTestExtension},
* the specified number of repeated sessions will be executed. If of them gets
* the properties {@code eclipse.perf.dbloc} and {@code eclipse.perf.config}
* passed from the host. The last session also gets the
* {@code eclipse.perf.assertAgainst} property passed from the host to allow
* execution of performance assertions.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Test
public @interface PerformanceSessionTest {
/**
* {@return the number of repeated sessions to execute}
*/
int repetitions() default 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocatio
Method testMethod = extensionContext.getTestMethod().get();

boolean shouldFail = extensionContext.getTestMethod().get().getAnnotation(SessionShouldError.class) != null;
PerformanceSessionTest performanceSessionTestAnnotation = extensionContext.getTestMethod().get()
.getAnnotation(PerformanceSessionTest.class);
if (performanceSessionTestAnnotation != null) {
executePerformanceSessionTest(testClass, testMethod, shouldFail,
performanceSessionTestAnnotation.repetitions());
} else {
exeuteSession(testClass, testMethod, shouldFail);
}

}

private void executePerformanceSessionTest(Class<?> testClass, Method testMethod, boolean shouldFail,
int repetitions) throws Exception, Throwable {
try {
setSystemProperty("eclipse.perf.dbloc", System.getProperty("eclipse.perf.dbloc"));
setSystemProperty("eclipse.perf.config", System.getProperty("eclipse.perf.config"));
for (int i = 0; i < repetitions - 1; i++) {
exeuteSession(testClass, testMethod, shouldFail);
}
setSystemProperty("eclipse.perf.assertAgainst", System.getProperty("eclipse.perf.assertAgainst"));
exeuteSession(testClass, testMethod, shouldFail);
} finally {
setSystemProperty("eclipse.perf.assertAgainst", null);
setSystemProperty("eclipse.perf.dbloc", null);
setSystemProperty("eclipse.perf.config", null);
}
}

private void exeuteSession(Class<?> testClass, Method testMethod, boolean shouldFail) throws Exception, Throwable {
try {
prepareSession();
testExecutor.executeRemotely(testClass.getName(), testMethod.getName(), shouldFail);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2025 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.core.tests.harness.session.samples;

import static org.eclipse.core.tests.harness.TestHarnessPlugin.PI_HARNESS;

import org.eclipse.core.tests.harness.session.PerformanceSessionTest;
import org.eclipse.core.tests.harness.session.SessionTestExtension;
import org.eclipse.test.performance.Dimension;
import org.eclipse.test.performance.Performance;
import org.eclipse.test.performance.PerformanceMeter;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* Examples demonstrating the behavior of performance session tests using the
* JUnit 5 platform. When executed, a warmup session is performed and five
* subsequent actual sessions with startup measurements will be performed.
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class SamplePerformanceSessionTest {
@RegisterExtension
SessionTestExtension sessionTestExtension = SessionTestExtension.forPlugin(PI_HARNESS).create();

@Test
@Order(0)
public void warmup() {
actualTest(true);
}

@PerformanceSessionTest(repetitions = 5)
@Order(1)
public void runMeasurements() {
actualTest(false);
}

private void actualTest(boolean warmup) {
PerformanceMeter meter = Performance.getDefault().createPerformanceMeter(getClass().getName() + ".startup");
try {
meter.stop();
if (!warmup) {
meter.commit();
}
Performance.getDefault().assertPerformanceInRelativeBand(meter, Dimension.ELAPSED_PROCESS, -50, 5);
} finally {
meter.dispose();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,16 @@
*******************************************************************************/
package org.eclipse.core.tests.runtime.perf;

import junit.framework.*;
import org.eclipse.core.tests.runtime.RuntimeTestsPlugin;
import org.eclipse.core.tests.session.*;
import org.eclipse.core.tests.session.SetupManager.SetupException;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

public class AllPerfTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(AllPerfTests.class.getName());

// make sure that the first run of the startup test is not recorded - it is heavily
// influenced by the presence and validity of the cached information
try {
PerformanceSessionTestSuite firstRun = new PerformanceSessionTestSuite(RuntimeTestsPlugin.PI_RUNTIME_TESTS, 1, StartupTest.class);
Setup setup = firstRun.getSetup();
setup.setSystemProperty("eclipseTest.ReportResults", "false");
suite.addTest(firstRun);
} catch (SetupException e) {
fail("Unable to create warm up test");
}

// For this test to take advantage of the new runtime processing, we set "-eclipse.activateRuntimePlugins=false"
try {
PerformanceSessionTestSuite headlessSuite = new PerformanceSessionTestSuite(RuntimeTestsPlugin.PI_RUNTIME_TESTS, 5, StartupTest.class);
Setup headlessSetup = headlessSuite.getSetup();
headlessSetup.setSystemProperty("eclipse.activateRuntimePlugins", "false");
suite.addTest(headlessSuite);
} catch (SetupException e) {
fail("Unable to setup headless startup performance test");
}

suite.addTest(new UIPerformanceSessionTestSuite(RuntimeTestsPlugin.PI_RUNTIME_TESTS, 5, UIStartupTest.class));
suite.addTestSuite(BenchPath.class);
suite.addTest(ContentTypePerformanceTest.suite());
suite.addTestSuite(PreferencePerformanceTest.class);
return suite;
}
@Suite
@SelectClasses({ //
StartupTest.class, //
UIStartupTest.class, //
BenchPath.class, //
ContentTypePerformanceTest.class, //
PreferencePerformanceTest.class, //
})
public class AllPerfTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@
package org.eclipse.core.tests.runtime.perf;

import java.util.HashMap;
import junit.framework.TestCase;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.harness.PerformanceTestRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

public class BenchPath extends TestCase {

public BenchPath() {
super();
}

public BenchPath(String testName) {
super(testName);
}
public class BenchPath {

/**
* Tests performance of equals and hashCode by using paths
* as keys in a hash map.
* Tests performance of equals and hashCode by using paths as keys in a hash
* map.
*/
public void testHash() {
@Test
public void testHash(TestInfo testInfo) throws Exception {
final int REPEAT = 500000;
final IPath[] paths = generateVariousPaths();
final HashMap<IPath, String> map = new HashMap<>(32);
Expand All @@ -47,13 +41,14 @@ protected void test() {
map.get(paths[p]);
}
}
}.run(this, 10, REPEAT);
}.run(getClass(), testInfo.getDisplayName(), 10, REPEAT);
}

/**
* Tests the performance of path creation
*/
public void testPathCreation() {
@Test
public void testPathCreation(TestInfo testInfo) throws Exception {
final int REPEAT = 50000;
new PerformanceTestRunner() {
@Override
Expand Down Expand Up @@ -82,13 +77,14 @@ protected void test() {
IPath.fromOSString("/Foo/bar/baz/blap/blam/abc.txt");
IPath.fromOSString("/Foo/bar/baz/blap/blam/blip/boop/abc.txt");
}
}.run(this, 20, REPEAT);
}.run(getClass(), testInfo.getDisplayName(), 20, REPEAT);
}

/**
* Tests the performance of Path.toOSString
*/
public void testToOSString() {
@Test
public void testToOSString(TestInfo testInfo) throws Exception {
final int REPEAT = 50000;
final IPath[] paths = generateVariousPaths();
new PerformanceTestRunner() {
Expand All @@ -98,13 +94,14 @@ protected void test() {
paths[p].toOSString();
}
}
}.run(this, 10, REPEAT);
}.run(getClass(), testInfo.getDisplayName(), 10, REPEAT);
}

/**
* Tests the performance of Path.toOSString
*/
public void testToString() {
@Test
public void testToString(TestInfo testInfo) throws Exception {
final int REPEAT = 50000;
final IPath[] paths = generateVariousPaths();
new PerformanceTestRunner() {
Expand All @@ -114,7 +111,7 @@ protected void test() {
paths[p].toString();
}
}
}.run(this, 10, REPEAT);
}.run(getClass(), testInfo.getDisplayName(), 10, REPEAT);
}

/**
Expand Down
Loading
Loading