Skip to content

Commit 66bef1b

Browse files
committed
Migrate Layout Performance Tests to JUnit 5
Migrate ComputeSizeTest, LayoutTest, and ResizeTest to JUnit 5. - Introduce LayoutPerformanceTestSuite for shared data providers. - Remove inheritance from PerformanceTestCaseJunit4. - Use CloseTestWindowsExtension. - Use PerformanceMeter directly. - Ensure INTRO_VIEW in UIPerformanceTestRule is visible.
1 parent 22d8db1 commit 66bef1b

5 files changed

Lines changed: 180 additions & 156 deletions

File tree

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/UIPerformanceTestRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class UIPerformanceTestRule extends ExternalResource implements BeforeAll
3434

3535
public static final String PROJECT_NAME = "Performance Project";
3636

37-
private static final String INTRO_VIEW = "org.eclipse.ui.internal.introview";
37+
public static final String INTRO_VIEW = "org.eclipse.ui.internal.introview";
3838
public static final String[] EDITOR_FILE_EXTENSIONS = { "perf_basic", "perf_outline", "perf_text" };
3939

4040
@Override

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/layout/ComputeSizeTest.java

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,86 +19,90 @@
1919
import org.eclipse.swt.SWT;
2020
import org.eclipse.swt.graphics.Point;
2121
import org.eclipse.swt.widgets.Composite;
22-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
22+
import org.eclipse.test.performance.Performance;
23+
import org.eclipse.test.performance.PerformanceMeter;
2324
import org.eclipse.ui.WorkbenchException;
24-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
25-
import org.junit.Rule;
26-
import org.junit.Test;
25+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
26+
import org.junit.jupiter.api.TestInfo;
27+
import org.junit.jupiter.api.extension.RegisterExtension;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
2730

2831
/**
2932
* Measures the performance of a widget's computeSize method
3033
*
3134
* @since 3.1
3235
*/
33-
public class ComputeSizeTest extends PerformanceTestCaseJunit4 {
36+
public class ComputeSizeTest {
3437

35-
@Rule
36-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
38+
@RegisterExtension
39+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
3740

38-
private final TestWidgetFactory widgetFactory;
3941
private final int xIterations = 10;
4042
private final int yIterations = 10;
4143

42-
public ComputeSizeTest(TestWidgetFactory widgetFactory) {
43-
this.widgetFactory = widgetFactory;
44-
}
45-
46-
@Test
47-
public void test() throws CoreException, WorkbenchException {
44+
@ParameterizedTest
45+
@MethodSource("org.eclipse.ui.tests.performance.layout.LayoutPerformanceTestSuite#data")
46+
public void test(TestWidgetFactory widgetFactory, boolean flushState, TestInfo testInfo) throws CoreException, WorkbenchException {
4847

4948
widgetFactory.init();
5049
final Composite widget = widgetFactory.getControl();
5150
//Rectangle initialBounds = widget.getBounds();
5251
final Point maxSize = widgetFactory.getMaxSize();
5352

54-
// Iteration counter. We increment this each pass through the loop in order to
55-
// generate slightly different test data each time
56-
final int[] counter = new int[] {0};
57-
58-
for (int j = 0; j < 100; j++) {
59-
// This counter determines whether we're computing a width,
60-
// height, or fixed
61-
// size and whether or not we flush the cache.
62-
63-
// We do things this way to avoid calling computeSize with the same (or
64-
// similar) values
65-
// twice in a row, which would be too easy to cache.
66-
int count = counter[0];
67-
68-
startMeasuring();
69-
for (int i = 0; i < 200; i++) {
70-
71-
for (int xIteration = 0; xIteration < xIterations; xIteration++) {
72-
73-
for (int yIteration = 0; yIteration < yIterations; yIteration++) {
74-
// Avoid giving the same x value twice in a row in order to make it hard to cache
75-
int xSize = maxSize.x * ((xIteration + yIteration) % xIterations) / xIterations;
76-
int ySize = maxSize.y * yIteration / yIterations;
77-
78-
// Alternate between flushing and not flushing the cache
79-
boolean flushState = (count % 2) != 0;
80-
81-
// Alternate between width, height, and fixed, and default size queries
82-
// (note: we need to alternate in order to make the result hard to cache)
83-
switch(count % 4) {
84-
case 0: widget.computeSize(xSize, SWT.DEFAULT, flushState); break;
85-
case 1: widget.computeSize(SWT.DEFAULT, ySize, flushState); break;
86-
case 2: widget.computeSize(xSize, ySize, flushState); break;
87-
case 3: widget.computeSize(SWT.DEFAULT, SWT.DEFAULT, flushState); break;
53+
Performance perf = Performance.getDefault();
54+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
55+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
56+
57+
try {
58+
// Iteration counter. We increment this each pass through the loop in order to
59+
// generate slightly different test data each time
60+
final int[] counter = new int[] {0};
61+
62+
for (int j = 0; j < 100; j++) {
63+
// This counter determines whether we're computing a width,
64+
// height, or fixed
65+
// size and whether or not we flush the cache.
66+
67+
// We do things this way to avoid calling computeSize with the same (or
68+
// similar) values
69+
// twice in a row, which would be too easy to cache.
70+
int count = counter[0];
71+
72+
meter.start();
73+
for (int i = 0; i < 200; i++) {
74+
75+
for (int xIteration = 0; xIteration < xIterations; xIteration++) {
76+
77+
for (int yIteration = 0; yIteration < yIterations; yIteration++) {
78+
// Avoid giving the same x value twice in a row in order to make it hard to cache
79+
int xSize = maxSize.x * ((xIteration + yIteration) % xIterations) / xIterations;
80+
int ySize = maxSize.y * yIteration / yIterations;
81+
82+
// Alternate between width, height, and fixed, and default size queries
83+
// (note: we need to alternate in order to make the result hard to cache)
84+
switch(count % 4) {
85+
case 0: widget.computeSize(xSize, SWT.DEFAULT, flushState); break;
86+
case 1: widget.computeSize(SWT.DEFAULT, ySize, flushState); break;
87+
case 2: widget.computeSize(xSize, ySize, flushState); break;
88+
case 3: widget.computeSize(SWT.DEFAULT, SWT.DEFAULT, flushState); break;
89+
}
90+
91+
count++;
8892
}
89-
90-
count++;
9193
}
92-
}
9394

95+
}
96+
meter.stop();
97+
processEvents();
98+
counter[0]++;
9499
}
95-
stopMeasuring();
96-
processEvents();
97-
counter[0]++;
98-
}
99100

100-
commitMeasurements();
101-
assertPerformance();
102-
widgetFactory.done();
101+
meter.commit();
102+
perf.assertPerformance(meter);
103+
} finally {
104+
meter.dispose();
105+
widgetFactory.done();
106+
}
103107
}
104108
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.eclipse.ui.tests.performance.layout;
2+
3+
import java.util.stream.Stream;
4+
5+
import org.eclipse.ui.tests.performance.UIPerformanceTestRule;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.platform.suite.api.SelectClasses;
8+
import org.junit.platform.suite.api.Suite;
9+
10+
@Suite
11+
@SelectClasses({ //
12+
ComputeSizeTest.class, //
13+
LayoutTest.class, //
14+
ResizeTest.class //
15+
})
16+
public class LayoutPerformanceTestSuite {
17+
18+
public static Stream<Arguments> data() {
19+
return Stream.of(
20+
Arguments.of(new ViewWidgetFactory(UIPerformanceTestRule.INTRO_VIEW), false),
21+
Arguments.of(new EditorWidgetFactory("1.perf_basic"), false)
22+
);
23+
}
24+
}

tests/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/layout/LayoutTest.java

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,77 +20,79 @@
2020
import org.eclipse.swt.graphics.Point;
2121
import org.eclipse.swt.graphics.Rectangle;
2222
import org.eclipse.swt.widgets.Composite;
23-
import org.eclipse.test.performance.PerformanceTestCaseJunit4;
23+
import org.eclipse.test.performance.Performance;
24+
import org.eclipse.test.performance.PerformanceMeter;
2425
import org.eclipse.ui.WorkbenchException;
25-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
26-
import org.junit.Rule;
27-
import org.junit.Test;
26+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
27+
import org.junit.jupiter.api.TestInfo;
28+
import org.junit.jupiter.api.extension.RegisterExtension;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.MethodSource;
2831

2932
/**
3033
* Measures the time required to layout the widget 10 times. Does not include
3134
* the time required for any deferred repaints.
3235
*
3336
* @since 3.1
3437
*/
35-
public class LayoutTest extends PerformanceTestCaseJunit4 {
38+
public class LayoutTest {
3639

37-
@Rule
38-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
39-
40-
private final TestWidgetFactory widgetFactory;
40+
@RegisterExtension
41+
CloseTestWindowsExtension closeTestWindows = new CloseTestWindowsExtension();
4142

4243
private final int xIterations = 100;
4344

4445
private final int yIterations = 10;
4546

46-
private final boolean flushState;
47-
48-
public LayoutTest(TestWidgetFactory widgetFactory, boolean flushState) {
49-
this.widgetFactory = widgetFactory;
50-
this.flushState = flushState;
51-
}
52-
5347
/**
5448
* Run the test
5549
*/
56-
@Test
57-
public void test() throws CoreException, WorkbenchException {
50+
@ParameterizedTest
51+
@MethodSource("org.eclipse.ui.tests.performance.layout.LayoutPerformanceTestSuite#data")
52+
public void test(TestWidgetFactory widgetFactory, boolean flushState, TestInfo testInfo) throws CoreException, WorkbenchException {
5853

5954
widgetFactory.init();
6055
final Composite widget = widgetFactory.getControl();
6156
final Point maxSize = widgetFactory.getMaxSize();
6257
Rectangle initialBounds = widget.getBounds();
6358
final Rectangle newBounds = Geometry.copy(initialBounds);
6459

65-
for (int xIteration = 0; xIteration < xIterations; xIteration++) {
60+
Performance perf = Performance.getDefault();
61+
String scenarioId = this.getClass().getName() + "." + testInfo.getDisplayName();
62+
PerformanceMeter meter = perf.createPerformanceMeter(scenarioId);
6663

67-
processEvents();
64+
try {
65+
for (int xIteration = 0; xIteration < xIterations; xIteration++) {
6866

69-
startMeasuring();
67+
processEvents();
7068

71-
for (int yIteration = 0; yIteration < yIterations; yIteration++) {
72-
// Avoid giving the same x value twice in a row in order to make
73-
// it hard to cache
74-
int xSize = maxSize.x
75-
* ((xIteration + yIteration) % xIterations)
76-
/ xIterations;
77-
int ySize = maxSize.y * yIteration / yIterations;
69+
meter.start();
7870

79-
newBounds.width = xSize;
80-
newBounds.height = ySize;
71+
for (int yIteration = 0; yIteration < yIterations; yIteration++) {
72+
// Avoid giving the same x value twice in a row in order to make
73+
// it hard to cache
74+
int xSize = maxSize.x
75+
* ((xIteration + yIteration) % xIterations)
76+
/ xIterations;
77+
int ySize = maxSize.y * yIteration / yIterations;
8178

82-
widget.setBounds(newBounds);
83-
widget.layout(flushState);
84-
}
79+
newBounds.width = xSize;
80+
newBounds.height = ySize;
8581

86-
stopMeasuring();
87-
}
82+
widget.setBounds(newBounds);
83+
widget.layout(flushState);
84+
}
8885

89-
commitMeasurements();
90-
assertPerformance();
86+
meter.stop();
87+
}
9188

92-
widget.setBounds(initialBounds);
93-
widgetFactory.done();
89+
meter.commit();
90+
perf.assertPerformance(meter);
91+
} finally {
92+
meter.dispose();
93+
widget.setBounds(initialBounds);
94+
widgetFactory.done();
95+
}
9496
}
9597
}
9698

0 commit comments

Comments
 (0)